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