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