Manager now sets ocrLanguage instead of recognizer. Last one checks input item for validity.
This commit is contained in:
parent
c1dab33e7c
commit
a57e0b1af8
10
Manager.cpp
10
Manager.cpp
@ -170,6 +170,10 @@ void Manager::applySettings () {
|
|||||||
QNetworkProxy::setApplicationProxy (proxy);
|
QNetworkProxy::setApplicationProxy (proxy);
|
||||||
settings.endGroup ();
|
settings.endGroup ();
|
||||||
|
|
||||||
|
settings.beginGroup (settings_names::recogntionGroup);
|
||||||
|
defaultOrcLanguage_ = GET (ocrLanguage).toString ();
|
||||||
|
settings.endGroup ();
|
||||||
|
|
||||||
settings.beginGroup (settings_names::translationGroup);
|
settings.beginGroup (settings_names::translationGroup);
|
||||||
defaultTranslationLanguage_ = GET (translationLanguage).toString ();
|
defaultTranslationLanguage_ = GET (translationLanguage).toString ();
|
||||||
doTranslation_ = GET (doTranslation).toBool ();
|
doTranslation_ = GET (doTranslation).toBool ();
|
||||||
@ -215,6 +219,12 @@ void Manager::handleSelection (ProcessingItem item) {
|
|||||||
if ((doTranslation_ && !altMod) || (!doTranslation_ && altMod)) {
|
if ((doTranslation_ && !altMod) || (!doTranslation_ && altMod)) {
|
||||||
item.translateLanguage = defaultTranslationLanguage_;
|
item.translateLanguage = defaultTranslationLanguage_;
|
||||||
}
|
}
|
||||||
|
if (item.ocrLanguage.isEmpty ()) {
|
||||||
|
item.ocrLanguage = defaultOrcLanguage_;
|
||||||
|
}
|
||||||
|
if (item.sourceLanguage.isEmpty ()) {
|
||||||
|
item.sourceLanguage = dictionary_->ocrToTranslateCodes (item.ocrLanguage);
|
||||||
|
}
|
||||||
emit requestRecognize (item);
|
emit requestRecognize (item);
|
||||||
++itemProcessingCount_;
|
++itemProcessingCount_;
|
||||||
updateNormalIcon ();
|
updateNormalIcon ();
|
||||||
|
@ -71,6 +71,7 @@ class Manager : public QObject {
|
|||||||
//! Used threads. For proper termination.
|
//! Used threads. For proper termination.
|
||||||
QList<QThread *> threads_;
|
QList<QThread *> threads_;
|
||||||
QString defaultTranslationLanguage_;
|
QString defaultTranslationLanguage_;
|
||||||
|
QString defaultOrcLanguage_;
|
||||||
bool doTranslation_;
|
bool doTranslation_;
|
||||||
int itemProcessingCount_;
|
int itemProcessingCount_;
|
||||||
};
|
};
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
#include "ProcessingItem.h"
|
#include "ProcessingItem.h"
|
||||||
|
|
||||||
bool ProcessingItem::isValid () const {
|
bool ProcessingItem::isValid (bool checkOnlyInput) const {
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
valid &= (!screenPos.isNull ());
|
valid &= (!screenPos.isNull ());
|
||||||
valid &= (!source.isNull ());
|
valid &= (!source.isNull ());
|
||||||
|
valid &= (!ocrLanguage.isEmpty ());
|
||||||
|
if (!checkOnlyInput) {
|
||||||
valid &= (!recognized.isEmpty ());
|
valid &= (!recognized.isEmpty ());
|
||||||
|
}
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ struct ProcessingItem {
|
|||||||
|
|
||||||
Qt::KeyboardModifiers modifiers;
|
Qt::KeyboardModifiers modifiers;
|
||||||
|
|
||||||
bool isValid () const;
|
bool isValid (bool checkOnlyInput = false) const;
|
||||||
};
|
};
|
||||||
Q_DECLARE_METATYPE (ProcessingItem)
|
Q_DECLARE_METATYPE (ProcessingItem)
|
||||||
|
|
||||||
|
@ -56,9 +56,11 @@ bool Recognizer::initEngine (tesseract::TessBaseAPI * &engine, const QString &la
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Recognizer::recognize (ProcessingItem item) {
|
void Recognizer::recognize (ProcessingItem item) {
|
||||||
ST_ASSERT (!item.source.isNull ());
|
if (!item.isValid (true)) {
|
||||||
bool isCustomLanguage = (!item.ocrLanguage.isEmpty () &&
|
emit recognized (item);
|
||||||
item.ocrLanguage != ocrLanguage_);
|
return;
|
||||||
|
}
|
||||||
|
bool isCustomLanguage = (item.ocrLanguage != ocrLanguage_);
|
||||||
tesseract::TessBaseAPI *engine = (isCustomLanguage) ? NULL : engine_;
|
tesseract::TessBaseAPI *engine = (isCustomLanguage) ? NULL : engine_;
|
||||||
QString language = (isCustomLanguage) ? item.ocrLanguage : ocrLanguage_;
|
QString language = (isCustomLanguage) ? item.ocrLanguage : ocrLanguage_;
|
||||||
if (engine == NULL) {
|
if (engine == NULL) {
|
||||||
|
Loading…
Reference in New Issue
Block a user