From affb98dccf265f3a140ccf5c8734439b117dbc2b Mon Sep 17 00:00:00 2001 From: Zhang Yong Date: Tue, 15 Jun 2021 19:12:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=81=94=E8=B0=83=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 依据联调结果,调整展示方案 Log: 联调 Change-Id: Id8bd869b9565f628bf29d929daaf8a5d10b89a42 --- src/mainwidget.cpp | 29 ++++++++++++++++++----------- src/mainwidget.h | 4 ++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/mainwidget.cpp b/src/mainwidget.cpp index 8bc556c..7ef6130 100644 --- a/src/mainwidget.cpp +++ b/src/mainwidget.cpp @@ -75,6 +75,10 @@ MainWidget::~MainWidget() m_tipIconLabel->deleteLater(); m_tipIconLabel = nullptr; } + if (m_currentImg) { + delete m_currentImg; + m_currentImg = nullptr; + } } @@ -174,6 +178,10 @@ void MainWidget::setupConnect() connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::paletteTypeChanged, this, &MainWidget::setIcons); connect(m_exportBtn, &DIconButton::clicked, this, &MainWidget::slotExport); connect(m_copyBtn, &DIconButton::clicked, this, &MainWidget::slotCopy); + connect(this, &MainWidget::sigResult, this, [ = ](const QString & result) { + loadString(result); + deleteLoadingUi(); + }); } void MainWidget::retranslateUi(QWidget *Widget) @@ -243,9 +251,8 @@ void MainWidget::openImage(const QString &path) if (!m_loadImagethread) { m_loadImagethread = QThread::create([ = ]() { QMutexLocker locker(&m_mutex); - m_result = TessOcrUtils::instance()->getRecogitionResult(path, ResultType::RESULT_HTML); - loadHtml(m_result.result); - deleteLoadingUi(); + m_result = TessOcrUtils::instance()->getRecogitionResult(path, ResultType::RESULT_STRING); + emit sigResult(m_result.result); }); } @@ -261,13 +268,16 @@ void MainWidget::openImage(const QImage &img) m_imageview->fitWindow(); m_imgName = ""; } + if (m_currentImg) { + delete m_currentImg; + m_currentImg = nullptr; + } + m_currentImg = new QImage(img); if (!m_loadImagethread) { m_loadImagethread = QThread::create([ = ]() { QMutexLocker locker(&m_mutex); - QImage a = img; - m_result = TessOcrUtils::instance()->getRecogitionResult(&a, ResultType::RESULT_HTML); - loadHtml(m_result.result); - deleteLoadingUi(); + m_result = TessOcrUtils::instance()->getRecogitionResult(m_currentImg, ResultType::RESULT_STRING); + emit sigResult(m_result.result); }); } connect(m_loadImagethread, &QThread::finished, m_loadImagethread, &QObject::deleteLater); @@ -284,10 +294,7 @@ void MainWidget::loadHtml(const QString &html) void MainWidget::loadString(const QString &string) { if (!string.isEmpty()) { - QStringList templist = string.split("\r\n", QString::KeepEmptyParts); - for (int i = 0; i < templist.size(); i++) { - m_plainTextEdit->appendPlainText(templist.at(i)); - } + m_plainTextEdit->appendPlainText(string); } } diff --git a/src/mainwidget.h b/src/mainwidget.h index 30014f0..ed21dda 100644 --- a/src/mainwidget.h +++ b/src/mainwidget.h @@ -74,6 +74,10 @@ private: QThread *m_loadImagethread{nullptr}; QMutex m_mutex; RecognitionResult m_result; + QImage *m_currentImg{nullptr}; +signals: + void sigResult(const QString &); + }; #endif // WIDGET_H