Clear processing queue after settings update
This commit is contained in:
parent
5afd8e7e7f
commit
409ad6d3c2
@ -40,8 +40,10 @@ void Corrector::correct(const TaskPtr &task)
|
|||||||
SOFT_ASSERT(task, return );
|
SOFT_ASSERT(task, return );
|
||||||
SOFT_ASSERT(task->isValid(), return );
|
SOFT_ASSERT(task->isValid(), return );
|
||||||
|
|
||||||
|
queue_.push_back(task);
|
||||||
|
|
||||||
if (task->recognized.isEmpty()) {
|
if (task->recognized.isEmpty()) {
|
||||||
manager_.corrected(task);
|
finishCorrection(task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,22 +54,40 @@ void Corrector::correct(const TaskPtr &task)
|
|||||||
LTRACE() << "Corrected with user data";
|
LTRACE() << "Corrected with user data";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (task->useHunspell) {
|
if (!task->useHunspell) {
|
||||||
emit correctAuto(task);
|
finishCorrection(task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
finishCorrection(task);
|
if (queue_.size() == 1)
|
||||||
|
processQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Corrector::processQueue()
|
||||||
|
{
|
||||||
|
if (queue_.empty())
|
||||||
|
return;
|
||||||
|
emit correctAuto(queue_.front());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Corrector::updateSettings()
|
void Corrector::updateSettings()
|
||||||
{
|
{
|
||||||
|
queue_.clear();
|
||||||
emit resetAuto(settings_.hunspellDir);
|
emit resetAuto(settings_.hunspellDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Corrector::finishCorrection(const TaskPtr &task)
|
void Corrector::finishCorrection(const TaskPtr &task)
|
||||||
{
|
{
|
||||||
manager_.corrected(task);
|
manager_.corrected(task);
|
||||||
|
|
||||||
|
SOFT_ASSERT(!queue_.empty(), return );
|
||||||
|
if (queue_.front() == task) {
|
||||||
|
queue_.pop_front();
|
||||||
|
} else {
|
||||||
|
LERROR() << "processed not first item in correction queue";
|
||||||
|
queue_.clear();
|
||||||
|
}
|
||||||
|
processQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Corrector::substituteUser(const QString &source,
|
QString Corrector::substituteUser(const QString &source,
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
#include <deque>
|
||||||
|
|
||||||
class Corrector : public QObject
|
class Corrector : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -22,8 +24,10 @@ private:
|
|||||||
void finishCorrection(const TaskPtr &task);
|
void finishCorrection(const TaskPtr &task);
|
||||||
QString substituteUser(const QString &source,
|
QString substituteUser(const QString &source,
|
||||||
const LanguageId &language) const;
|
const LanguageId &language) const;
|
||||||
|
void processQueue();
|
||||||
|
|
||||||
Manager &manager_;
|
Manager &manager_;
|
||||||
const Settings &settings_;
|
const Settings &settings_;
|
||||||
QThread *workerThread_;
|
QThread *workerThread_;
|
||||||
|
std::deque<TaskPtr> queue_;
|
||||||
};
|
};
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
#include "recognizerworker.h"
|
#include "recognizerworker.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
#include "task.h"
|
||||||
#include "tesseract.h"
|
#include "tesseract.h"
|
||||||
|
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
@ -15,7 +16,7 @@ Recognizer::Recognizer(Manager &manager, const Settings &settings)
|
|||||||
auto worker = new RecognizeWorker;
|
auto worker = new RecognizeWorker;
|
||||||
connect(this, &Recognizer::reset, //
|
connect(this, &Recognizer::reset, //
|
||||||
worker, &RecognizeWorker::reset);
|
worker, &RecognizeWorker::reset);
|
||||||
connect(this, &Recognizer::recognize, //
|
connect(this, &Recognizer::recognizeImpl, //
|
||||||
worker, &RecognizeWorker::handle);
|
worker, &RecognizeWorker::handle);
|
||||||
connect(worker, &RecognizeWorker::finished, //
|
connect(worker, &RecognizeWorker::finished, //
|
||||||
this, &Recognizer::recognized);
|
this, &Recognizer::recognized);
|
||||||
@ -26,9 +27,35 @@ Recognizer::Recognizer(Manager &manager, const Settings &settings)
|
|||||||
worker->moveToThread(workerThread_);
|
worker->moveToThread(workerThread_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Recognizer::recognize(const TaskPtr &task)
|
||||||
|
{
|
||||||
|
SOFT_ASSERT(task, return );
|
||||||
|
SOFT_ASSERT(task->isValid(), return );
|
||||||
|
|
||||||
|
queue_.push_back(task);
|
||||||
|
if (queue_.size() == 1)
|
||||||
|
processQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Recognizer::processQueue()
|
||||||
|
{
|
||||||
|
if (queue_.empty())
|
||||||
|
return;
|
||||||
|
emit recognizeImpl(queue_.front());
|
||||||
|
}
|
||||||
|
|
||||||
void Recognizer::recognized(const TaskPtr &task)
|
void Recognizer::recognized(const TaskPtr &task)
|
||||||
{
|
{
|
||||||
manager_.recognized(task);
|
manager_.recognized(task);
|
||||||
|
|
||||||
|
SOFT_ASSERT(!queue_.empty(), return );
|
||||||
|
if (queue_.front() == task) {
|
||||||
|
queue_.pop_front();
|
||||||
|
} else {
|
||||||
|
LERROR() << "processed not first item in recognition queue";
|
||||||
|
queue_.clear();
|
||||||
|
}
|
||||||
|
processQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
Recognizer::~Recognizer()
|
Recognizer::~Recognizer()
|
||||||
@ -43,5 +70,6 @@ void Recognizer::updateSettings()
|
|||||||
{
|
{
|
||||||
SOFT_ASSERT(!settings_.tessdataPath.isEmpty(), return );
|
SOFT_ASSERT(!settings_.tessdataPath.isEmpty(), return );
|
||||||
|
|
||||||
|
queue_.clear();
|
||||||
emit reset(settings_.tessdataPath);
|
emit reset(settings_.tessdataPath);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
#include <deque>
|
||||||
|
|
||||||
class Recognizer : public QObject
|
class Recognizer : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -12,15 +14,18 @@ public:
|
|||||||
~Recognizer();
|
~Recognizer();
|
||||||
|
|
||||||
void updateSettings();
|
void updateSettings();
|
||||||
|
void recognize(const TaskPtr &task);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void recognize(const TaskPtr &task);
|
void recognizeImpl(const TaskPtr &task);
|
||||||
void reset(const QString &tessdataPath);
|
void reset(const QString &tessdataPath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void recognized(const TaskPtr &task);
|
void recognized(const TaskPtr &task);
|
||||||
|
void processQueue();
|
||||||
|
|
||||||
Manager &manager_;
|
Manager &manager_;
|
||||||
const Settings &settings_;
|
const Settings &settings_;
|
||||||
QThread *workerThread_;
|
QThread *workerThread_;
|
||||||
|
std::deque<TaskPtr> queue_;
|
||||||
};
|
};
|
||||||
|
@ -117,6 +117,7 @@ void Translator::updateSettings()
|
|||||||
{
|
{
|
||||||
view_->setPage(nullptr);
|
view_->setPage(nullptr);
|
||||||
pages_.clear();
|
pages_.clear();
|
||||||
|
queue_.clear();
|
||||||
url_->clear();
|
url_->clear();
|
||||||
|
|
||||||
tabs_->blockSignals(true);
|
tabs_->blockSignals(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user