Custom assertion.
This commit is contained in:
parent
2b15c64ebf
commit
b5246c9694
@ -7,6 +7,7 @@
|
||||
|
||||
#include "GoogleWebTranslator.h"
|
||||
#include "Settings.h"
|
||||
#include "StAssert.h"
|
||||
|
||||
GoogleWebTranslator::GoogleWebTranslator()
|
||||
: QObject (), view_ (new QWebView),
|
||||
@ -82,7 +83,7 @@ void GoogleWebTranslator::replyFinished(QNetworkReply *reply)
|
||||
}
|
||||
|
||||
void GoogleWebTranslator::load(const ProcessingItem &item) {
|
||||
Q_ASSERT (!item.recognized.isEmpty ());
|
||||
ST_ASSERT (!item.recognized.isEmpty ());
|
||||
if (translationLanguage_.isEmpty ()) {
|
||||
emit error (tr ("Неверные парметры для перевода."));
|
||||
return;
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <tesseract/host.h>
|
||||
|
||||
#include "ImageProcessing.h"
|
||||
#include "StAssert.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
@ -113,10 +114,10 @@ QImage convertImage(Pix &image)
|
||||
Pix *prepareImage(const QImage &image, int preferredScale)
|
||||
{
|
||||
Pix* pix = convertImage (image);
|
||||
Q_ASSERT (pix != NULL);
|
||||
ST_ASSERT (pix != NULL);
|
||||
|
||||
Pix* gray = pixConvertRGBToGray (pix, 0.0, 0.0, 0.0);
|
||||
Q_ASSERT (gray != NULL);
|
||||
ST_ASSERT (gray != NULL);
|
||||
pixDestroy (&pix);
|
||||
|
||||
Pix* scaled = gray;
|
||||
@ -137,7 +138,7 @@ Pix *prepareImage(const QImage &image, int preferredScale)
|
||||
|
||||
scaled = pixScale (gray, scale, scale);
|
||||
}
|
||||
Q_ASSERT (scaled != NULL);
|
||||
ST_ASSERT (scaled != NULL);
|
||||
if (scaled != gray)
|
||||
{
|
||||
pixDestroy (&gray);
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "Translator.h"
|
||||
#include "ResultDialog.h"
|
||||
#include "LanguageHelper.h"
|
||||
#include "StAssert.h"
|
||||
|
||||
Manager::Manager(QObject *parent) :
|
||||
QObject(parent),
|
||||
@ -134,12 +135,12 @@ Manager::~Manager()
|
||||
void Manager::capture()
|
||||
{
|
||||
QList<QScreen*> screens = QApplication::screens ();
|
||||
Q_ASSERT (!screens.isEmpty ());
|
||||
ST_ASSERT (!screens.isEmpty ());
|
||||
QScreen* screen = screens.first ();
|
||||
Q_CHECK_PTR (screen);
|
||||
WId desktopId = QApplication::desktop ()->winId ();
|
||||
QPixmap pixmap = screen->grabWindow (desktopId);
|
||||
Q_ASSERT (!pixmap.isNull ());
|
||||
ST_ASSERT (!pixmap.isNull ());
|
||||
emit showPixmap (pixmap);
|
||||
}
|
||||
|
||||
@ -203,7 +204,7 @@ void Manager::copyLastToClipboard()
|
||||
|
||||
void Manager::showResult(ProcessingItem item)
|
||||
{
|
||||
Q_ASSERT (item.isValid ());
|
||||
ST_ASSERT (item.isValid ());
|
||||
lastItem_ = item;
|
||||
if (useResultDialog_)
|
||||
{
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "Settings.h"
|
||||
#include "ImageProcessing.h"
|
||||
#include "StAssert.h"
|
||||
|
||||
Recognizer::Recognizer(QObject *parent) :
|
||||
QObject(parent),
|
||||
@ -60,7 +61,7 @@ bool Recognizer::initEngine(tesseract::TessBaseAPI *&engine, const QString& lang
|
||||
|
||||
void Recognizer::recognize(ProcessingItem item)
|
||||
{
|
||||
Q_ASSERT (!item.source.isNull ());
|
||||
ST_ASSERT (!item.source.isNull ());
|
||||
bool isCustomLanguage = (!item.ocrLanguage.isEmpty () &&
|
||||
item.ocrLanguage != ocrLanguage_);
|
||||
tesseract::TessBaseAPI* engine = (isCustomLanguage) ? NULL : engine_;
|
||||
@ -74,7 +75,7 @@ void Recognizer::recognize(ProcessingItem item)
|
||||
}
|
||||
|
||||
Pix* image = prepareImage (item.source.toImage (), imageScale_);
|
||||
Q_ASSERT (image != NULL);
|
||||
ST_ASSERT (image != NULL);
|
||||
engine->SetImage (image);
|
||||
char* outText = engine->GetUTF8Text();
|
||||
engine->Clear();
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "ResultDialog.h"
|
||||
#include "ui_ResultDialog.h"
|
||||
#include "StAssert.h"
|
||||
|
||||
#include <QDesktopWidget>
|
||||
|
||||
@ -32,10 +33,10 @@ bool ResultDialog::eventFilter(QObject* object, QEvent* event)
|
||||
|
||||
void ResultDialog::showResult(ProcessingItem item)
|
||||
{
|
||||
Q_ASSERT (!item.source.isNull ());
|
||||
Q_ASSERT (!item.recognized.isEmpty ());
|
||||
Q_ASSERT (!item.translated.isEmpty ());
|
||||
Q_ASSERT (!item.screenPos.isNull ());
|
||||
ST_ASSERT (!item.source.isNull ());
|
||||
ST_ASSERT (!item.recognized.isEmpty ());
|
||||
ST_ASSERT (!item.translated.isEmpty ());
|
||||
ST_ASSERT (!item.screenPos.isNull ());
|
||||
|
||||
ui->sourceLabel->setPixmap (item.source);
|
||||
ui->recognizeLabel->setText (item.recognized);
|
||||
@ -61,7 +62,7 @@ void ResultDialog::showResult(ProcessingItem item)
|
||||
{
|
||||
|
||||
QRect screenRect = desktop->availableGeometry (this);
|
||||
Q_ASSERT (screenRect.isValid ());
|
||||
ST_ASSERT (screenRect.isValid ());
|
||||
QPoint newPos (screenRect.width () - width (), screenRect.height () - height ());
|
||||
move (newPos);
|
||||
}
|
||||
|
@ -41,7 +41,8 @@ HEADERS += \
|
||||
ResultDialog.h \
|
||||
ImageProcessing.h \
|
||||
LanguageHelper.h \
|
||||
GoogleWebTranslator.h
|
||||
GoogleWebTranslator.h \
|
||||
StAssert.h
|
||||
|
||||
FORMS += \
|
||||
SettingsEditor.ui \
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "SelectionDialog.h"
|
||||
#include "ui_SelectionDialog.h"
|
||||
#include "LanguageHelper.h"
|
||||
#include "StAssert.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
@ -139,9 +140,9 @@ bool SelectionDialog::eventFilter(QObject* object, QEvent* event)
|
||||
return QDialog::eventFilter (object, event);
|
||||
}
|
||||
item.ocrLanguage = dictionary_.ocrUiToCode (action->text ());
|
||||
Q_ASSERT (!item.ocrLanguage.isEmpty ());
|
||||
ST_ASSERT (!item.ocrLanguage.isEmpty ());
|
||||
item.sourceLanguage = dictionary_.translateForOcrCode (item.ocrLanguage);
|
||||
Q_ASSERT (!item.sourceLanguage.isEmpty ());
|
||||
ST_ASSERT (!item.sourceLanguage.isEmpty ());
|
||||
}
|
||||
emit selected (item);
|
||||
accept ();
|
||||
@ -153,7 +154,7 @@ bool SelectionDialog::eventFilter(QObject* object, QEvent* event)
|
||||
|
||||
void SelectionDialog::setPixmap(QPixmap pixmap)
|
||||
{
|
||||
Q_ASSERT (!pixmap.isNull ());
|
||||
ST_ASSERT (!pixmap.isNull ());
|
||||
currentPixmap_ = pixmap;
|
||||
QPalette palette = this->palette ();
|
||||
palette.setBrush (this->backgroundRole (), pixmap);
|
||||
|
15
StAssert.h
Normal file
15
StAssert.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef ST_ASSERT_H
|
||||
#define ST_ASSERT_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#if !defined(ST_ASSERT)
|
||||
# if defined(ST_NO_ASSERT)
|
||||
# define ST_ASSERT(CONDITION)
|
||||
# else
|
||||
# define ST_ASSERT(CONDITION) assert(CONDITION)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif // ST_ASSERT_H
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "Settings.h"
|
||||
#include "GoogleWebTranslator.h"
|
||||
#include "StAssert.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -51,7 +52,7 @@ void Translator::translate(ProcessingItem item)
|
||||
emit translateAlternative(item);
|
||||
return;
|
||||
}
|
||||
Q_ASSERT (!item.recognized.isEmpty ());
|
||||
ST_ASSERT (!item.recognized.isEmpty ());
|
||||
QString sourceLanguage = item.sourceLanguage.isEmpty () ? sourceLanguage_ :
|
||||
item.sourceLanguage;
|
||||
if (translationLanguage_.isEmpty () || sourceLanguage.isEmpty ())
|
||||
@ -78,9 +79,9 @@ void Translator::translatedAlternative(ProcessingItem item, bool success)
|
||||
|
||||
void Translator::replyFinished(QNetworkReply* reply)
|
||||
{
|
||||
Q_ASSERT (items_.contains (reply));
|
||||
ST_ASSERT (items_.contains (reply));
|
||||
ProcessingItem item = items_.take (reply);
|
||||
Q_ASSERT (reply->isFinished ());
|
||||
ST_ASSERT (reply->isFinished ());
|
||||
if (reply->error () != QNetworkReply::NoError)
|
||||
{
|
||||
useAlternativeTranslation_ = true;
|
||||
|
Loading…
Reference in New Issue
Block a user