feat: Add progress in system correction page while empty scan data transfering.

This commit is contained in:
sunwen
2024-09-19 15:45:23 +08:00
parent 2d7c359a64
commit f679b81fb4
9 changed files with 259 additions and 67 deletions

View File

@@ -44,7 +44,7 @@ void ReconStateDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
progressBarOption.maximum = 100;
progressBarOption.progress = progress;
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
painter->restore();
return;
}
case 104:
@@ -92,6 +92,6 @@ void ReconStateDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
}
painter->drawText(option.rect, Qt::AlignCenter, displayText);
painter->restore();
}
painter->restore();
}

View File

@@ -1,5 +1,6 @@
#include "SystemCorrectionForm.h"
#include "db/SQLHelper.h"
#include "device/DeviceManager.h"
#include "event/EventCenter.h"
#include "dialogs/DialogManager.h"
#include "log/LogManager.h"
@@ -9,11 +10,15 @@
#include <QDate>
#include <QSpacerItem>
#include <QPushButton>
#include <QTimer>
SystemCorrectionForm::SystemCorrectionForm(QWidget* aParent)
: QWidget(aParent)
, mCurrentEmptyScanDate(new QLabel(this))
, mExpirationEmptyScanDate(new QLabel(this))
, mCurrentEmptyScanState(new QLabel(this))
, mTimer(new QTimer(this))
, mEmptyScanState()
{
setObjectName("SystemCorrectionForm");
init();
@@ -67,6 +72,10 @@ void SystemCorrectionForm::init()
mExpirationEmptyScanDate->setText(tr("Expiration date for Empty Scanning %1").arg(dateFormat));
vboxLayout->addWidget(mExpirationEmptyScanDate);
mEmptyScanState = SQLHelper::queryValue("SELECT State FROM EScan ORDER BY ScanDateTime DESC LIMIT 1").toInt();
mCurrentEmptyScanState->setText(tr("Current state for Empty Scanning %1").arg(getStateString(mEmptyScanState)));
vboxLayout->addWidget(mCurrentEmptyScanState);
QWidget* emptyScanButtonArea = new QWidget(this);
QHBoxLayout* emptyScanButtonLayout = new QHBoxLayout(emptyScanButtonArea);
QPushButton* emptyScanButton = new QPushButton(this);
@@ -90,6 +99,7 @@ void SystemCorrectionForm::init()
emptyScanDescribe->setText(tr("Empty water scanning involves collecting ultrasound data while the tank is filled with water and free of any objects. It is essential to ensure that the tank is fully filled with water and devoid of any objects before conducting the scan. The purpose of collecting empty water data is to obtain baseline information on the time and energy variations of ultrasound propagation inside the inspection tank. This information is utilized for reconstructing reference data for transmission ultrasound imaging. Additionally, empty water data can be utilized for system status assessment and spatial calibration of the system. Therefore, empty water scanning should be performed regularly, with a frequency of once every month."));
mCurrentEmptyScanDate->setText(tr("Current date for Empty Scanning %1-%2-%3").arg(lastScanDate.year()).arg(lastScanDate.month()).arg(lastScanDate.day()));
mExpirationEmptyScanDate->setText(tr("Expiration date for Empty Scanning %1").arg(dateFormat));
mCurrentEmptyScanState->setText(tr("Current state for Empty Scanning %1").arg(getStateString(mEmptyScanState)));
emptyScanButton->setText(tr("Excute empty scan"));
});
@@ -105,8 +115,12 @@ void SystemCorrectionForm::init()
LOG_USER_OPERATION("Start Empty Scan")
});
mTimer->setInterval(1000);
connect(mTimer, &QTimer::timeout, this, &SystemCorrectionForm::updateEmptyScanTransferProgress);
connect(EventCenter::Default(), &EventCenter::EmptyScanFinished, this, &SystemCorrectionForm::updateEmptyScanDate);
connect(EventCenter::Default(), &EventCenter::EmptyScanDataStateUpdated, this, &SystemCorrectionForm::updateEmptyScanState);
connect(EventCenter::Default(), &EventCenter::EmptyScanDataExpire, this, &SystemCorrectionForm::updateEmptyScanDateExpire);
connect(EventCenter::Default(), &EventCenter::EmptyScanDataBroked, this, &SystemCorrectionForm::updateEmptyScanBroked);
}
void SystemCorrectionForm::updateEmptyScanDate()
@@ -117,4 +131,58 @@ void SystemCorrectionForm::updateEmptyScanDate()
QString dateText = tr("%1-%2-%3").arg(expirationScanDate.year()).arg(expirationScanDate.month()).arg(expirationScanDate.day());;
QString dateFormat = QString(" %1").arg(dateText);
mExpirationEmptyScanDate->setText(tr("Expiration date for Empty Scanning %1").arg(dateFormat));
mEmptyScanState = 0;
mCurrentEmptyScanState->setText(tr("Current state for Empty Scanning %1").arg(getStateString(mEmptyScanState)));
}
void SystemCorrectionForm::updateEmptyScanState()
{
mEmptyScanState = SQLHelper::queryValue("SELECT State FROM EScan ORDER BY ScanDateTime DESC LIMIT 1").toInt();
if(mEmptyScanState == 100 && !mTimer->isActive())
{
mTimer->start();
}
else if(mEmptyScanState != 100 && mTimer->isActive())
{
mTimer->stop();
}
mCurrentEmptyScanState->setText(tr("Current state for Empty Scanning %1").arg(getStateString(mEmptyScanState)));
}
void SystemCorrectionForm::updateEmptyScanTransferProgress()
{
if(DeviceManager::Default()->updateTransferProgress())
{
int progress = DeviceManager::Default()->getTransferProgress();
mCurrentEmptyScanState->setText(tr("Current state for Empty Scanning %1").arg(getStateString(mEmptyScanState) + QString::number(progress) + "%"));
}
}
void SystemCorrectionForm::updateEmptyScanBroked()
{
mEmptyScanState = -1;
mCurrentEmptyScanState->setText(tr("Current state for Empty Scanning %1").arg(getStateString(mEmptyScanState)));
}
void SystemCorrectionForm::updateEmptyScanDateExpire()
{
mEmptyScanState = -2;
mCurrentEmptyScanState->setText(tr("Current state for Empty Scanning %1").arg(getStateString(mEmptyScanState)));
}
QString SystemCorrectionForm::getStateString(int aState)
{
switch (aState)
{
case -2: return QString("<font color='red'>&nbsp;&nbsp;%1</font>").arg(tr("Expired"));
case -1: return QString("<font color='red'>&nbsp;&nbsp;%1</font>").arg(tr("Broked"));
case 0: return tr("Wait To Transfer");
case 100: return tr("Transferring");
case 104: return QString("<font color='red'>&nbsp;&nbsp;%1</font>").arg(tr("Transfer Failed"));
case 200: return tr("Transfer succeed");
case 204: return QString("<font color='red'>&nbsp;&nbsp;%1</font>").arg(tr("Recon Error"));
case 300: return tr("Normal");
case 304: return QString("<font color='red'>&nbsp;&nbsp;%1</font>").arg(tr("Recon Error"));
default: return QString("<font color='red'>&nbsp;&nbsp;%1</font>").arg(tr("Unknow"));
}
}

View File

@@ -4,6 +4,7 @@
#include <QWidget>
class QLabel;
class QTimer;
class SystemCorrectionForm : public QWidget
{
@@ -15,13 +16,21 @@ public:
private:
void init();
QString getStateString(int aState);
private slots:
void updateEmptyScanDate();
void updateEmptyScanState();
void updateEmptyScanTransferProgress();
void updateEmptyScanDateExpire();
void updateEmptyScanBroked();
private:
QLabel* mCurrentEmptyScanDate;
QLabel* mExpirationEmptyScanDate;
QLabel* mCurrentEmptyScanState;
QTimer* mTimer;
int mEmptyScanState;
};
#endif // SYSTEMCORRECTIONFORM_H