diff --git a/src/DateSelectDialog.cpp b/src/DateSelectDialog.cpp index 073d695..2f724c5 100644 --- a/src/DateSelectDialog.cpp +++ b/src/DateSelectDialog.cpp @@ -9,8 +9,8 @@ #include "components/DateSlidePickerBox.h" DateSelectDialog::DateSelectDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) { this->setFixedSize(460, 380); - QVBoxLayout* layout = new QVBoxLayout(formWidget); - box = new DateSlidePickerBox(formWidget); + QVBoxLayout* layout = new QVBoxLayout(mFormWidget); + box = new DateSlidePickerBox(mFormWidget); box->setObjectName("slider_one"); box->setSelectedValue("1990-01-01"); lbl_error = new QLabel(this); diff --git a/src/EditPatientDialog.cpp b/src/EditPatientDialog.cpp index 6c8f897..4fb709b 100644 --- a/src/EditPatientDialog.cpp +++ b/src/EditPatientDialog.cpp @@ -23,7 +23,7 @@ int queryValue(QSqlTableModel* model, int colID, const QVariant& var) } EditPatientDialog::EditPatientDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) { - QVBoxLayout* layout = new QVBoxLayout(formWidget); + QVBoxLayout* layout = new QVBoxLayout(mFormWidget); layout->setSpacing(10); // add title QLabel* lbl_title = new QLabel(this); diff --git a/src/db/SQLHelper.cpp b/src/db/SQLHelper.cpp index 944e301..1f883cf 100644 --- a/src/db/SQLHelper.cpp +++ b/src/db/SQLHelper.cpp @@ -10,7 +10,7 @@ #include #include QSqlDatabase* SQLHelper::defaultDatabase= nullptr; -QHash* SQLHelper::cache= new QHash; +static QHash cache; bool SQLHelper::Open() { if (defaultDatabase) return true; defaultDatabase= new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE", "USCTDB")); @@ -26,11 +26,11 @@ bool SQLHelper::Open(QSqlDatabase *base) { } void SQLHelper::Close() { - for(auto item : cache->values()) + for(auto item : cache.values()) { delete item; } - cache->clear(); + cache.clear(); if(defaultDatabase->isValid() && defaultDatabase->isOpen()) { defaultDatabase->close(); @@ -39,25 +39,25 @@ void SQLHelper::Close() { } } -void prepareSQL(QSqlQuery& query,QMap* params) +void prepareSQL(QSqlQuery& query,const QMap& params) { - if (!params) return; - for (auto key : params->keys()) + if (params.empty()) return; + for (const auto & key : params.keys()) { - query.bindValue(key,params->value(key)); + query.bindValue(key,params.value(key)); } } QSqlTableModel* SQLHelper::getTable(const QString &tableName) { - if (cache->contains(tableName)) return (QSqlTableModel*)(*cache)[tableName]; + if (cache.contains(tableName)) return (QSqlTableModel*)cache[tableName]; CenterAlignSqlTableModel *model = new CenterAlignSqlTableModel(nullptr,*defaultDatabase); model->setTable(tableName); - (*cache)[tableName] = model; - return (QSqlTableModel*)(*cache)[tableName]; + cache[tableName] = model; + return (QSqlTableModel*)(cache)[tableName]; } -int SQLHelper::QueryCount(QString sql, QMap* params) { +int SQLHelper::QueryCount(const QString& sql, const QMap& params) { QSqlQuery query(*defaultDatabase); prepareSQL(query, params); if (query.exec(sql)) @@ -68,7 +68,7 @@ int SQLHelper::QueryCount(QString sql, QMap* params) { return 0; } -int SQLHelper::ExecuteNoQuery(QString sql, QMap* params) { +int SQLHelper::ExecuteNoQuery(const QString& sql, const QMap& params) { QSqlQuery query(*defaultDatabase); query.prepare(sql); prepareSQL(query, params); @@ -79,7 +79,7 @@ int SQLHelper::ExecuteNoQuery(QString sql, QMap* params) { return 0; } -void SQLHelper::QueryFirst(QString sql, QMap& result, QMap* params) { +void SQLHelper::QueryFirst(const QString &sql, QMap& result, const QMap& params) { QSqlQuery query(*defaultDatabase); query.prepare(sql); prepareSQL(query, params); @@ -95,8 +95,8 @@ void SQLHelper::QueryFirst(QString sql, QMap& result, QMap *params) { - if (cache->contains(queryName)) return (*cache)[queryName]; +QSqlQueryModel *SQLHelper::QueryModel(const QString& queryName, const QString& sql, const QMap ¶ms) { + if (cache.contains(queryName)) return cache[queryName]; QSqlQueryModel* model = new QSqlQueryModel; QSqlQuery query(*defaultDatabase); @@ -108,16 +108,16 @@ QSqlQueryModel *SQLHelper::QueryModel(QString queryName, QString sql, QMapcontains(queryName)) return (*cache)[queryName]; +QSqlQueryModel *SQLHelper::QueryModel(const QString& queryName) { + if (cache.contains(queryName)) return cache[queryName]; return nullptr; } -void SQLHelper::QueryMap(QString sql, QMap &result, QMap *params) { +void SQLHelper::QueryMap(const QString& sql, QMap &result, const QMap ¶ms) { QSqlQuery query(*defaultDatabase); query.prepare(sql); prepareSQL(query, params); diff --git a/src/db/SQLHelper.h b/src/db/SQLHelper.h index 629a117..0a9a1ea 100644 --- a/src/db/SQLHelper.h +++ b/src/db/SQLHelper.h @@ -16,16 +16,15 @@ public: static bool Open(); static bool Open(QSqlDatabase* base); static void Close(); - static void QueryFirst(QString sql, QMap& result, QMap* params = nullptr); - static int QueryCount(QString sql, QMap* params = nullptr); - static int ExecuteNoQuery(QString sql, QMap* params = nullptr); - static void QueryMap(QString sql, QMap& result, QMap* params = nullptr); - static QSqlQueryModel* QueryModel(QString queryName); - static QSqlQueryModel* QueryModel(QString queryName, QString sql, QMap* params = nullptr); + static void QueryFirst(const QString &sql, QMap& result, const QMap ¶ms = QMap()); + static int QueryCount(const QString &sql, const QMap ¶ms = QMap()); + static int ExecuteNoQuery(const QString &sql,const QMap ¶ms = QMap()); + static void QueryMap(const QString& sql, QMap& result, const QMap ¶ms = QMap()); + static QSqlQueryModel* QueryModel(const QString &queryName); + static QSqlQueryModel* QueryModel(const QString &queryName, const QString &sql, const QMap ¶ms = QMap()); static QSqlTableModel* getTable(const QString & tableName); private: static QSqlDatabase* defaultDatabase; - static QHash* cache; }; diff --git a/src/device/DeviceManager.cpp b/src/device/DeviceManager.cpp index ed12d00..f4afc2b 100644 --- a/src/device/DeviceManager.cpp +++ b/src/device/DeviceManager.cpp @@ -1,35 +1,44 @@ // // Created by Krad on 2021/10/12. // -#include "ShimLib/ShimLib.h" + #include "DeviceManager.h" -#include "../event/EventCenter.h" + #include #include #include #include + #include "appvals/AppGlobalValues.h" #include "json/ScanJson.h" -#include "json/jsonobject.h" +#include "ShimLib/ShimLib.h" +#include "event/EventCenter.h" + #define TRIGGER_EVENT EventCenter::Default()->triggerEvent #define THROW_ERROR(errormsg)\ TRIGGER_EVENT(GUIEvents::GUIErrorRaise, nullptr, (QObject*)&errormsg); +namespace { + const char* names[3] = {"Initializing","Scanning", "CE Measuring"}; + const int PREVIEW_IMAGE_WH = 140; +} + const char* getStatusString(int status) { switch (status) { - case SCANNING: - return "SCANNING"; - case READY: - return "Ready"; - case BUSY: - return "BUSY"; - case ERROR: - return "ERROR"; - } - return ""; + case SCANNING: + return "SCANNING"; + case READY: + return "Ready"; + case BUSY: + return "BUSY"; + case ERROR: + return "ERROR"; + default: + return nullptr; + } } std::string getJsonFromPatInf(QObject* obj) @@ -37,241 +46,102 @@ std::string getJsonFromPatInf(QObject* obj) return ((QString*)obj)->toStdString(); } -void ErrorCallback(const char* msg) +void errorCallback(const char* msg) { DeviceManager::Default()->emitErrorCallback(msg); } -void DeviceManager::emitErrorCallback(const char *msg) { - errorOccurred=true; - printf("Error Callback , message:%s\r\n", msg); - QString m(msg); - emit raiseGlobalError( m); +const char * getPhaseName(int phase){ + return names[phase-1]; } - void DeviceManager::initDevice() { - InitLib(ErrorCallback); + InitLib(errorCallback); - deviceInfTimerID = startTimer(10000); + mDeviceInfTimerID = startTimer(10000); // empty scan connect(EventCenter::Default(), &EventCenter::RequestEmptyScan, [=](QObject* sender, QObject* detail) { - std::string json = getJsonFromPatInf(detail); - startScan(json.c_str(), true); - }); + startScan(getJsonFromPatInf(detail).c_str(), true); + }); // Patient scan connect(EventCenter::Default(), &EventCenter::RequestPatientScan, [=](QObject* sender, QObject* detail) { - std::string json = getJsonFromPatInf(detail); - qDebug() << json.c_str(); - if (!json.empty()) - { - startScan(json.c_str()); - } - }); + startScan(getJsonFromPatInf(detail).c_str()); + }); // Continue Scan connect(EventCenter::Default(), &EventCenter::RequestContinueScan, [=](QObject* sender, QObject* detail) { postContinueCommand(true); }); // stop - connect(EventCenter::Default(), &EventCenter::RequestStop, [=]() { - qDebug() << "GetStatus"; - StatusInfo inf = GetStatus(); - qDebug() << "Stop request status, status:%s" << getStatusString(inf.status); - - // check device status========================================= - //device is ready return - if (inf.status != SCANNING) { - //double check - QThread::msleep(100); - inf = GetStatus(); - if (inf.status != SCANNING){ - TRIGGER_EVENT(GUIEvents::ResponseStop, nullptr, nullptr); - return; - } - } - AppGlobalValues::setInProcessing(true); - TRIGGER_EVENT(GUIEvents::InvokeOperationStart, nullptr, nullptr); - //ScanControl fail - qDebug() << "Request stop!"; - if (timerID != -1)killTimer(timerID); - if (ScanControl(STOP)) { - qDebug() << "Stop fail!"; - QString msg("Stop operation fail!"); - THROW_ERROR(msg); - qDebug() << "Error thrown!"; - lastStatus = -1; - previewing = false; - QString s("%1 %2"); - s = s.arg(QDateTime::currentDateTime().toString("yyyy/MM/dd HH:mm:ss"), msg); - TRIGGER_EVENT(GUIEvents::GlobalBannerMessage, nullptr, (QObject*)&msg); - return; - } - lastStatus = -1; - previewing = false; - QString s("%1 %2"); - s = s.arg(QDateTime::currentDateTime().toString("yyyy/MM/dd HH:mm:ss"), ("Scan Stopped!")); - TRIGGER_EVENT(GUIEvents::GlobalBannerMessage, nullptr, (QObject*)&s); - // preview end - TRIGGER_EVENT(GUIEvents::InvokeOperationEnd, nullptr, nullptr); - TRIGGER_EVENT(GUIEvents::ResponseStop, nullptr, nullptr); - AppGlobalValues::setInProcessing(false); - }); + connect(EventCenter::Default(), &EventCenter::RequestStop,this, &DeviceManager::stopScan); // preview - connect(EventCenter::Default(), &EventCenter::RequestPreviewScan, [=]() { - // check device status========================================= - qDebug() << "GetStatus"; - StatusInfo inf = GetStatus(); - qDebug() << "PreviewScan request status, status:" << getStatusString(inf.status); - if (inf.status == READY) - { - AppGlobalValues::setInProcessing(true); - TRIGGER_EVENT(GUIEvents::InvokeOperationStart, nullptr, nullptr); - //ScanControl - qDebug() << "Request preview!"; - if (!ScanControl(PREVIEW_SCAN)) - { - qDebug() << "Preview success!"; -// lastStatus = SCANNING; - previewing = true; - // timerID = startTimer(500); - TRIGGER_EVENT(GUIEvents::ResponsePreview, nullptr, nullptr); - // end scan without prompt - TRIGGER_EVENT(GUIEvents::InvokeOperationEnd, nullptr, nullptr); - QString s("Device Previewing!"); - TRIGGER_EVENT(GUIEvents::GlobalBannerMessage, nullptr, (QObject*)&s); - return; - } - } - qDebug() << "Preview fail!"; - QString msg(inf.status != READY ? "Can't start preview,Device is not ready!" : "Start preview operation fail!"); - THROW_ERROR(msg); - qDebug() << "Error thrown!"; - }); + connect(EventCenter::Default(), &EventCenter::RequestPreviewScan,this, &DeviceManager::startPreview); // init the preview data caller thread - previewDataCaller = QThread::create([=]() { - while (!endLoop) - { - if (!previewing) { - QThread::sleep(3); - continue; - } - // check device status========================================= - qDebug() << "GetStatus"; - StatusInfo inf = GetStatus(); - qDebug() << "GetPreviewData request status, status:" << getStatusString(inf.status); - // device is preview scanning, try get preview data - if (inf.status == SCANNING) { - qDebug() << "Preview data reader read start!"; - const char* data = GetPreviewData(); - if (!data){ - continue; - } - qDebug() << "Preview data reader read end!"; - QByteArray bytes = QByteArray::fromRawData(data, 140 * 140); - //double check - if (!previewing) { - qDebug() << "Preview data reader long sleep!"; - QThread::sleep(3); - continue; - } - qDebug() << "Preview data response event start!"; - TRIGGER_EVENT(GUIEvents::ResponsePreviewData, nullptr, (QObject*)(&bytes)); - qDebug() << "Preview data response event end!"; - } - else{ -// lastStatus = READY; - previewing = false; - AppGlobalValues::setInProcessing(false); - QThread::sleep(3); - } - QThread::msleep(100); - } - }); - previewDataCaller->start(); - - + initPreviewThread(); } -const char * getPhaseName(int phase){ - const char* names[3] = {"Initializing","Scanning", "CE Measuring"}; - return names[phase-1]; -} - -void DeviceManager::timerEvent(QTimerEvent* event) { - if (event->timerId() == deviceInfTimerID) { - QString temp = QString(GetDeviceInfo(MEAN_TEMPERATURE)); - TRIGGER_EVENT(GUIEvents::ResponseDeviceTemperature, nullptr, (QObject *) &temp); +void DeviceManager::startScan(const char* json, bool empty) { + if (!json) return; + //clear last error state first + mErrorOccurred = false; + // check device status========================================= + qDebug() << "GetStatus"; + StatusInfo inf = GetStatus(); + qDebug() << "Scan start request status, status:" << getStatusString(inf.status); + if (inf.status != READY) { + QString errMsg("Device is not ready, start scan operation fail!status is %1"); + errMsg = errMsg.arg(getStatusString(inf.status)); + THROW_ERROR(errMsg) return; } - //scanning progress timer - //error exit, callback error - if (errorOccurred) { - timerID = event->timerId(); - exitScanTimer(); + static QString msg = "Start scan..."; + AppGlobalValues::setInProcessing(true); + TRIGGER_EVENT(GUIEvents::InvokeOperationStart, nullptr, (QObject*)&msg); + qDebug() << "SetScanInfo>>>>>>>>>>>>>>>>>>>>"; + AppGlobalValues::setEmptyScanFlag(empty); + int ret = SetScanInfo(json, empty ? 1 : 0); + if (ret) { + qDebug() << ">>>>>>>>>>>>>>>>>>>>SetScanInfo failed"; + THROW_ERROR("Transfer patient information fail!") return; } - // previewing exit - if (previewing) { - QString msg("Device is previewing, exit current operation!"); - THROW_ERROR(msg); - } else { - // check device status========================================= - qDebug() << "GetStatus"; - StatusInfo inf = GetStatus(); - qDebug() << "Scanning request status, status:" << getStatusString(inf.status); - //设备正常扫描中 - if (inf.status == SCANNING) { - scanProcess(inf.progress); - return; - } else { - //未发生错误并且,之前状态是扫描,代表正常扫描完成 - if (lastStatus == SCANNING && ! errorOccurred) { - prepareFinishScan(); - } - //一般不会出现其他情况 -// else { -// QString msg("Unknown error in scanning progress timer"); -// THROW_ERROR(msg); -// } - } - } - exitScanTimer(); + qDebug() << ">>>>>>>>>>>>>>>>>>>>SetScanInfo success"; + postScanCommand(); } -void DeviceManager::scanProcess(int sProgress) { +void DeviceManager::scanProcess(int aProgress) { qDebug() << "current output path:" << getScanOutputPath(); - lastStatus = SCANNING; + mLastStatus = SCANNING; //normal scan pending - int phase = sProgress / 100 + 1; - int progress = sProgress % 100; + int phase = aProgress / 100 + 1; + int progress = aProgress % 100; // scan with phase 3 has a different message QString extraMsg = (AppGlobalValues::EmptyScanFlag().toBool() || - (scanPhase != 3)) ? "": ", patient can leave"; - QVariant var(QString("%1%3\r\n progress:%2%").arg(getPhaseName(scanPhase)).arg(progress).arg(extraMsg)); + (mScanPhase != 3)) ? "" : ", patient can leave"; + QVariant var(QString("%1%3\r\n progress:%2%").arg(getPhaseName(mScanPhase)).arg(progress).arg(extraMsg)); TRIGGER_EVENT(InvokeOperationProgress, nullptr, (QObject *) &var); // 300 means finished - if (sProgress == 300) return; + if (aProgress == 300) return; //phase control //no change return - if (scanPhase == phase) return; + if (mScanPhase == phase) return; // error phase - if (phase > 3 || scanPhase > phase) { + if (phase > 3 || mScanPhase > phase) { QString errorMsg = QString("Error Scan Phase code, current Phase code:%1, new Phase code:%2!").arg( - scanPhase).arg(phase); + mScanPhase).arg(phase); THROW_ERROR(errorMsg) exitScanTimer(); return; } // enter phase 2 - if ((scanPhase = phase) == 2) { + if ((mScanPhase = phase) == 2) { if (!AppGlobalValues::EmptyScanFlag().toBool() && JsonObject::Instance()->getScanConfirm()) { var.setValue(QString("Waiting for operator to start scan!\r\n Click \"Next\" to continue!")); TRIGGER_EVENT(InvokeOperationPending, nullptr, (QObject *) &var); exitScanTimer(); } - //empty scan no pending, auto continue + //empty scan no pending, auto continue else { postContinueCommand(); } @@ -279,12 +149,30 @@ void DeviceManager::scanProcess(int sProgress) { } -void DeviceManager::exitScanTimer() { - qDebug() << "Scanning progress Timer exit"; - if (timerID>0)killTimer(timerID); - timerID = -1; - lastStatus = -1; - previewing = false; +void DeviceManager::postScanCommand() { + qDebug() << "ScanControl start>>>>>>>>>>>>>>>>>>>>>"; + if (!ScanControl(SCAN)) { + qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl success"; + //set current state + mLastStatus = SCANNING; + mPreviewing = false; + mScanPhase = 1; + qDebug() << "Start progress timer"; + mTimerID = startTimer(500); + return; + } + //ScanControl fail + THROW_ERROR("ScanControl start fail!") + qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl failed"; +} + +void DeviceManager::postContinueCommand(bool useTimer) { + if (!ScanControl(SCAN_CONTINUE)) { + if (useTimer)mTimerID = startTimer(500); + return; + } + //ScanControl fail + THROW_ERROR("ScanControl start fail!") } void DeviceManager::prepareFinishScan() { @@ -294,10 +182,6 @@ void DeviceManager::prepareFinishScan() { // stop normal scan with prompt TRIGGER_EVENT(InvokeOperationEnd, nullptr, (QObject *) &var); AppGlobalValues::setInProcessing(false); -// log, no need -// QString s("%1 %2"); -// s = s.arg(QDateTime::currentDateTime().toString("yyyy/MM/dd HH:mm:ss")).arg("Scan finished"); -// TRIGGER_EVENT(GlobalBannerMessage, nullptr, (QObject *) &s); // get output data path QString outputPath = GetDeviceInfo(DEV_OUTPATH); @@ -314,76 +198,185 @@ void DeviceManager::prepareFinishScan() { // save json ScanJson::Current()->save(); } else { - QString msg("Scan Output Path error!"); - THROW_ERROR(msg); + THROW_ERROR("Scan Output Path error!") } } -void DeviceManager::startScan(const char* json, bool empty) { - //clear last error state first - errorOccurred = false; - // check device status========================================= - qDebug() << "GetStatus"; - StatusInfo inf = GetStatus(); - qDebug() << "Scan start request status, status:" << getStatusString(inf.status); - if (inf.status != READY) { - QString errmsg("Device is not ready, start scan operation fail!status is %1"); - errmsg = errmsg.arg(getStatusString(inf.status)); - THROW_ERROR(errmsg); - return; - } - static QString msg = "Start scan..."; - AppGlobalValues::setInProcessing(true); - TRIGGER_EVENT(GUIEvents::InvokeOperationStart, nullptr, (QObject*)&msg); - qDebug() << "SetScanInfo>>>>>>>>>>>>>>>>>>>>"; - AppGlobalValues::setEmptyScanFlag(empty); - int ret = SetScanInfo(json, empty ? 1 : 0); - if (ret) { - qDebug() << ">>>>>>>>>>>>>>>>>>>>SetScanInfo failed"; - QString errmsg("Transfer patient information fail!"); - qDebug() << "Error thrown"; - THROW_ERROR(errmsg); - return; - } - qDebug() << ">>>>>>>>>>>>>>>>>>>>SetScanInfo success"; +void DeviceManager::stopScan() { + qDebug() << "GetStatus"; + StatusInfo inf = GetStatus(); + qDebug() << "Stop request status, status:%s" << getStatusString(inf.status); - postScanCommand(); -} - -void DeviceManager::postScanCommand() { - qDebug() << "ScanControl start>>>>>>>>>>>>>>>>>>>>>"; - if (!ScanControl(SCAN)) { - qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl success"; - //set current state - lastStatus = SCANNING; - previewing = false; - scanPhase = 1; - qDebug() << "Start progress timer"; - timerID = startTimer(500); + // check device status========================================= + //device is ready return + if (inf.status != SCANNING) { + //double check + QThread::msleep(100); + inf = GetStatus(); + if (inf.status != SCANNING) { + TRIGGER_EVENT(ResponseStop, nullptr, nullptr); + return; + } + } + AppGlobalValues::setInProcessing(true); + TRIGGER_EVENT(InvokeOperationStart, nullptr, nullptr); + //ScanControl fail + qDebug() << "Request stop!"; + if (mTimerID != -1)killTimer(mTimerID); + if (ScanControl(STOP)) { + qDebug() << "Stop fail!"; + QString msg("Stop operation fail!"); + THROW_ERROR(msg) + qDebug() << "Error thrown!"; + mLastStatus = -1; + mPreviewing = false; + QString s("%1 %2"); + s = s.arg(QDateTime::currentDateTime().toString("yyyy/MM/dd HH:mm:ss"), msg); + TRIGGER_EVENT(GlobalBannerMessage, nullptr, (QObject *) &msg); return; } - //ScanControl fail - QString errmsg("ScanControl start fail!"); - THROW_ERROR(errmsg); - qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl failed"; + mLastStatus = -1; + mPreviewing = false; + QString s("%1 %2"); + s = s.arg(QDateTime::currentDateTime().toString("yyyy/MM/dd HH:mm:ss"), ("Scan Stopped!")); + TRIGGER_EVENT(GlobalBannerMessage, nullptr, (QObject *) &s); + // preview end + TRIGGER_EVENT(InvokeOperationEnd, nullptr, nullptr); + TRIGGER_EVENT(ResponseStop, nullptr, nullptr); + AppGlobalValues::setInProcessing(false); + } -void DeviceManager::postContinueCommand(bool useTimer) { - if (!ScanControl(SCAN_CONTINUE)) { - if (useTimer)timerID = startTimer(500); - return; - } - //ScanControl fail - QString errmsg("ScanControl start fail!"); - THROW_ERROR(errmsg); +void DeviceManager::exitScanTimer() { + qDebug() << "Scanning progress Timer exit"; + if (mTimerID > 0)killTimer(mTimerID); + mTimerID = -1; + mLastStatus = -1; + mPreviewing = false; } void DeviceManager::close() { #ifdef _WIN32 StopDevice(); #endif - previewDataCaller->terminate(); - delete previewDataCaller; + mPreviewDataCaller->terminate(); + delete mPreviewDataCaller; +} + +void DeviceManager::initPreviewThread() { + mPreviewDataCaller = QThread::create([=]() { + while (!mEndLoop) { + if (!mPreviewing) { + QThread::sleep(3); + continue; + } + // check device status========================================= + qDebug() << "GetStatus"; + StatusInfo inf = GetStatus(); + qDebug() << "GetPreviewData request status, status:" << getStatusString(inf.status); + // device is preview scanning, try get preview data + if (inf.status == SCANNING) { + qDebug() << "Preview data reader read start!"; + const char *data = GetPreviewData(); + if (!data) { + continue; + } + qDebug() << "Preview data reader read end!"; + QByteArray bytes = QByteArray::fromRawData(data, PREVIEW_IMAGE_WH * PREVIEW_IMAGE_WH); + //double check + if (!mPreviewing) { + qDebug() << "Preview data reader long sleep!"; + QThread::sleep(3); + continue; + } + qDebug() << "Preview data response event start!"; + TRIGGER_EVENT(ResponsePreviewData, nullptr, (QObject *) (&bytes)); + qDebug() << "Preview data response event end!"; + } else { + mPreviewing = false; + AppGlobalValues::setInProcessing(false); + QThread::sleep(3); + } + QThread::msleep(100); + } + }); + mPreviewDataCaller->start(); +} + +void DeviceManager::startPreview() {// check device status========================================= + qDebug() << "GetStatus"; + StatusInfo inf = GetStatus(); + qDebug() << "PreviewScan request status, status:" << getStatusString(inf.status); + if (inf.status == READY) + { + AppGlobalValues::setInProcessing(true); + TRIGGER_EVENT(InvokeOperationStart, nullptr, nullptr); + //ScanControl + qDebug() << "Request preview!"; + if (!ScanControl(PREVIEW_SCAN)) + { + qDebug() << "Preview success!"; +// lastStatus = SCANNING; + mPreviewing = true; + // timerID = startTimer(500); + TRIGGER_EVENT(ResponsePreview, nullptr, nullptr); + // end scan without prompt + TRIGGER_EVENT(InvokeOperationEnd, nullptr, nullptr); + QString s("Device Previewing!"); + TRIGGER_EVENT(GlobalBannerMessage, nullptr, (QObject*)&s); + return; + } + } + qDebug() << "Preview fail!"; + QString msg(inf.status != READY ? "Can't start preview,Device is not ready!" : "Start preview operation fail!"); + THROW_ERROR(msg) + qDebug() << "Error thrown!"; +} + +void DeviceManager::timerEvent(QTimerEvent* event) { + if (event->timerId() == mDeviceInfTimerID) { + QString temp = QString(GetDeviceInfo(MEAN_TEMPERATURE)); + TRIGGER_EVENT(GUIEvents::ResponseDeviceTemperature, nullptr, (QObject *) &temp); + return; + } + //scanning progress timer + //error exit, callback error + if (mErrorOccurred) { + mTimerID = event->timerId(); + exitScanTimer(); + return; + } + // previewing exit + if (mPreviewing) { + THROW_ERROR("Device is previewing, exit current operation!") + } else { + // check device status========================================= + qDebug() << "GetStatus"; + StatusInfo inf = GetStatus(); + qDebug() << "Scanning request status, status:" << getStatusString(inf.status); + //设备正常扫描中 + if (inf.status == SCANNING) { + scanProcess(inf.progress); + return; + } else { + //未发生错误并且,之前状态是扫描,代表正常扫描完成 + if (mLastStatus == SCANNING && ! mErrorOccurred) { + prepareFinishScan(); + } + //一般不会出现其他情况 +// else { +// QString msg("Unknown error in scanning progress timer"); +// THROW_ERROR(msg); +// } + } + } + exitScanTimer(); +} + +void DeviceManager::emitErrorCallback(const char *msg) { + mErrorOccurred = true; + QString m(msg); + emit raiseGlobalError( m); } QString DeviceManager::getSoftwareVersion() { diff --git a/src/device/DeviceManager.h b/src/device/DeviceManager.h index a9c5173..ed3a8f9 100644 --- a/src/device/DeviceManager.h +++ b/src/device/DeviceManager.h @@ -7,18 +7,24 @@ #include #include -class DeviceManager :public QObject { - Q_OBJECT + +class DeviceManager : public QObject { +Q_OBJECT public: - static DeviceManager* Default(){ + static DeviceManager *Default() { static DeviceManager manager; return &manager; } + DeviceManager() = default; - ~DeviceManager() override = default ; - DeviceManager(const DeviceManager&) = delete; - DeviceManager operator=(const DeviceManager&) = delete; + + ~DeviceManager() override = default; + + DeviceManager(const DeviceManager &) = delete; + + DeviceManager operator=(const DeviceManager &) = delete; + /** * init device, include Shimlib and it's error call back, * deviceInfTimer to get temperature of water, and the @@ -29,32 +35,36 @@ public: /** * close and release the device reference resource. */ - void close(); + void close(); /** * Get Firm ware version * @return Firm ware version */ - QString getSoftwareVersion(); + static QString getSoftwareVersion(); /** * Get Scan data output path * @return Scan data output path */ - QString getScanOutputPath(); + static QString getScanOutputPath(); - void setErrorOccurred(bool v){ - errorOccurred = v; + void setErrorOccurred(bool v) { + mErrorOccurred = v; } - bool getErrorOccurred(){ - return errorOccurred; + + bool getErrorOccurred() { + return mErrorOccurred; } - void emitErrorCallback(const char * msg); - signals: + + void emitErrorCallback(const char *msg); + +signals: + void raiseGlobalError(QString msg); protected: - void timerEvent(QTimerEvent* event) override; + void timerEvent(QTimerEvent *event) override; private: /** @@ -62,11 +72,11 @@ private: * @param json The patient information json string * @param empty Empty scan flag */ - void startScan(const char* json, bool empty = false); + void startScan(const char *json, bool empty = false); - /** - * Post Scan start command to Shimlib - */ + /** + * Post Scan start command to Shimlib + */ void postScanCommand(); /** @@ -89,16 +99,24 @@ private: * Process scan progress change * @param Scan progress */ - void scanProcess(int progress); + void scanProcess(int aProgress); + + void initPreviewThread(); + + void stopScan(); + + void startPreview(); + + int mScanPhase = 1; + volatile int mTimerID = -1; + int mDeviceInfTimerID = -1; + int mLastStatus = -1; + bool mPreviewing = false; + volatile bool mEndLoop = false; + volatile bool mErrorOccurred = false; + QThread *mPreviewDataCaller = nullptr; + - int scanPhase = 1; - volatile int timerID = -1; - int deviceInfTimerID = -1; - int lastStatus = -1; - bool previewing = false; - volatile bool endLoop = false; - volatile bool errorOccurred = false; - QThread* previewDataCaller = nullptr; }; diff --git a/src/dialogs/AccountFormDialog.cpp b/src/dialogs/AccountFormDialog.cpp index 5f69143..76c0c8c 100644 --- a/src/dialogs/AccountFormDialog.cpp +++ b/src/dialogs/AccountFormDialog.cpp @@ -2,7 +2,7 @@ // Created by Krad on 2021/11/10. // #include "AccountFormDialog.h" -#include "ChangePasswordFormDialog.h" + #include #include #include @@ -10,286 +10,294 @@ #include #include #include +#include "ChangePasswordFormDialog.h" #include "event/EventCenter.h" #include "log/UserOperationLog.h" #include "db/SQLHelper.h" #include "models/User.h" -#include "components/SlidePickerBox.h" -#include "SelectDialog.h" #include "AlertDialog.h" -AccountFormDialog::AccountFormDialog(QWidget* parent, AccountEditMode mode, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) { - m_mode = mode; - QVBoxLayout *layout = new QVBoxLayout(formWidget); +AccountFormDialog::AccountFormDialog(QWidget* parent, AccountEditMode mode, Qt::WindowFlags f) +: GUIFormBaseDialog(parent, f) +, mUserNameChanged(false) +, mCommentChanged(false) +, mRoleChanged(false) +, mMode(mode) +, mLeUserCode(new QLineEdit(this)) +, mLeUserName(new QLineEdit(this)) +, mLeComment(new QLineEdit(this)) +, mLePwd(nullptr) +, mBtnPwd(nullptr) +, mLblError(new QLabel(this)) +, mRefModel(nullptr) +{ + auto layout = new QVBoxLayout(mFormWidget); layout->setSpacing(10); - // add title - QLabel *lbl_title = new QLabel(this); - lbl_title->setAlignment(Qt::AlignCenter); - lbl_title->setText(tr("Account")); - lbl_title->setObjectName("title"); - layout->addWidget(lbl_title); - - //add usercode - QLabel *lbl_UserCode = new QLabel(this); - lbl_UserCode->setText(tr("User ID")); - le_UserCode = new QLineEdit(this); - le_UserCode->setPlaceholderText(tr("Input User ID")); - if (m_mode != New)le_UserCode->setEnabled(false); - layout->addWidget(lbl_UserCode); - layout->addWidget(le_UserCode); - QLabel *lbl_endline1 = new QLabel(this); - lbl_endline1->setObjectName("endline"); - layout->addWidget(lbl_endline1); - - //add username - QLabel *lbl_UserName = new QLabel(this); - lbl_UserName->setText(tr("Name")); - le_UserName = new QLineEdit(this); - le_UserName->setPlaceholderText(tr("Input User name")); - layout->addWidget(lbl_UserName); - layout->addWidget(le_UserName); - QLabel *lbl_endline2 = new QLabel(this); - lbl_endline2->setObjectName("endline"); - layout->addWidget(lbl_endline2); - - // add new mode - if (m_mode == New) { - //add password - QLabel *lbl_Pwd = new QLabel(this); - lbl_Pwd->setText(tr("Password")); - layout->addWidget(lbl_Pwd); - le_Pwd = new QLineEdit(this); - le_Pwd->setPlaceholderText(tr("Input password")); - le_Pwd->setEchoMode(QLineEdit::Password); - layout->addWidget(le_Pwd); - m_RoleID = User::getRoleID("doctor"); - QLabel *lbl_endline3 = new QLabel(this); - lbl_endline3->setObjectName("endline"); - layout->addWidget(lbl_endline3); - } - - - //add Comment - QLabel *lbl_Comment = new QLabel(this); - lbl_Comment->setText(tr("Comment")); - le_Comment = new QLineEdit(this); - layout->addWidget(lbl_Comment); - layout->addWidget(le_Comment); - QLabel *lbl_endline0 = new QLabel(this); - lbl_endline0->setObjectName("endline"); - layout->addWidget(lbl_endline0); - - lbl_error = new QLabel(this); - lbl_error->setObjectName("warn"); - lbl_error->setVisible(false); - layout->addWidget(lbl_error); - - - QHBoxLayout* hlayout = new QHBoxLayout; + addTitleLabel(layout); + initUserCodeUI(layout); + initUserNameUI(layout); + if (mMode == New) addNewModeUI(layout); + addCommentLabel(layout); + addWarnLabel(layout); + auto hlayout = new QHBoxLayout; layout->addLayout(hlayout); - - //add logout -// QLabel *lbl_Logout = new QLabel(this); -// lbl_Logout->setText(tr("Logout")); - if (m_mode == Self) - { - QToolButton *btn_Logout = new QToolButton(this); - btn_Logout->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - btn_Logout->setIcon(QIcon(":/icons/logout.png")); - btn_Logout->setIconSize({30, 30}); - btn_Logout->setText(tr("Logout")); - btn_Logout->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed); - btn_Logout->setObjectName("editvalBtn"); - - hlayout->addWidget(btn_Logout); - connect(btn_Logout, &QAbstractButton::clicked, [=]() { - this->accept(); - LOG_USER_OPERATION(Logout); - EventCenter::Default()->triggerEvent(GUIEvents::RequestLogin, nullptr, nullptr); - }); + if (mMode == Self)addSelfModeUI(hlayout); + if (mMode != New) { + addButtonPwd(hlayout); + addEndLine(layout); + connect(mBtnPwd, &QPushButton::clicked, this, mMode == Self ? + &AccountFormDialog::changeSelfPassword : &AccountFormDialog::resetUserPassword); } - // load current user data - if (m_mode == Self && User::Current()) { - le_UserCode->setText(User::Current()->getUserCode()); - le_UserName->setText(User::Current()->getUserName()); - m_UserID = User::Current()->getUserID(); - m_UserPwd = User::Current()->getPassword(); - } - if (m_mode != New) { - btn_Pwd = new QToolButton(this); - btn_Pwd->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - btn_Pwd->setObjectName("editvalBtn"); - btn_Pwd->setIcon(QIcon(":/icons/edit.png")); - btn_Pwd->setIconSize({30, 30}); - btn_Pwd->setText(m_mode == Self ? tr("Change Password") : tr("Reset Password")); - btn_Pwd->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - hlayout->addWidget(btn_Pwd); - QLabel *lbl_endline9 = new QLabel(this); - lbl_endline9->setFixedHeight(2); - lbl_endline9->setObjectName("endline"); - layout->addWidget(lbl_endline9); - if (m_mode == Self) { - connect(btn_Pwd, &QPushButton::clicked, [=]() { - ChangePasswordFormDialog dia(this); - dia.setGeometry(this->geometry()); - dia.setWindowModality(Qt::WindowModal); - dia.exec(); - - }); - } else { - connect(btn_Pwd, &QAbstractButton::clicked, [=]() { - AlertDialog dialog(this); - dialog.setGeometry(this->geometry()); - dialog.setButtonMode(OkAndCancel); - dialog.setWindowModality(Qt::WindowModal); - dialog.setAlertMessage(tr("Reset password to \"123456\" ?")); - if (dialog.exec() == Accepted) { - User user; - dialog.setButtonMode(OkOnly); - if (!User::getUser(m_UserID, user)) { - dialog.setAlertMessage(tr("Inner error, can't find reference user!")); - dialog.exec(); - return; - } - if (!user.resetPassword()) { - dialog.setAlertMessage(tr("Submit change to database fail!")); - dialog.exec(); - } - } - }); - } - } - - connect(le_Comment, &QLineEdit::textChanged, [=](const QString &text) { - commentChanged = true; + connect(mLeComment, &QLineEdit::textChanged, [=](const QString &text) { + mCommentChanged = true; }); - connect(le_UserName, &QLineEdit::textChanged, [=](const QString &text) { - m_NewUserName = text; - userNameChanged = true; + connect(mLeUserName, &QLineEdit::textChanged, [=](const QString &text) { + mNewUserName = text; + mUserNameChanged = true; }); } -AccountFormDialog::~AccountFormDialog() { +void AccountFormDialog::addEndLine(QVBoxLayout *layout) { + auto lblEndline = new QLabel(this); + lblEndline->setFixedHeight(2); + lblEndline->setObjectName("endline"); + layout->addWidget(lblEndline); +} +void AccountFormDialog::resetUserPassword() { + AlertDialog dialog(this); + dialog.setGeometry(geometry()); + dialog.setButtonMode(OkAndCancel); + dialog.setWindowModality(Qt::WindowModal); + dialog.setAlertMessage(tr("Reset password to \"123456\" ?")); + if (dialog.exec() == Accepted) { + User user; + dialog.setButtonMode(OkOnly); + if (!User::getUser(mUserID, user)) { + dialog.setAlertMessage(tr("Inner error, can't find reference user!")); + dialog.exec(); + return; + } + if (!user.resetPassword()) { + dialog.setAlertMessage(tr("Submit change to database fail!")); + dialog.exec(); + } + } +} + +void AccountFormDialog::changeSelfPassword() { + ChangePasswordFormDialog dia(this); + dia.setGeometry(geometry()); + dia.setWindowModality(Qt::WindowModal); + dia.exec(); +} + +void AccountFormDialog::addButtonPwd(QHBoxLayout *layout) { + mBtnPwd = new QToolButton(this); + mBtnPwd->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + mBtnPwd->setObjectName("editvalBtn"); + mBtnPwd->setIcon(QIcon(":/icons/edit.png")); + mBtnPwd->setIconSize({30, 30}); + mBtnPwd->setText(mMode == Self ? tr("Change Password") : tr("Reset Password")); + mBtnPwd->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + layout->addWidget(mBtnPwd); +} + +void AccountFormDialog::addWarnLabel(QVBoxLayout *layout) { + mLblError->setObjectName("warn"); + mLblError->setVisible(false); + layout->addWidget(mLblError); +} + +void AccountFormDialog::addCommentLabel(QVBoxLayout *layout) { + auto lblComment = new QLabel(this); + lblComment->setText(tr("Comment")); + layout->addWidget(lblComment); + layout->addWidget(mLeComment); + addEndLine(layout); +} + +void AccountFormDialog::initUserNameUI(QVBoxLayout *layout) { + auto lblUserName = new QLabel(this); + lblUserName->setText(tr("Name")); + + mLeUserName->setPlaceholderText(tr("Input User name")); + layout->addWidget(lblUserName); + layout->addWidget(mLeUserName); + addEndLine(layout); +} + +void AccountFormDialog::initUserCodeUI(QVBoxLayout *layout) { + auto lblUserCode = new QLabel(this); + lblUserCode->setText(tr("User ID")); + + mLeUserCode->setPlaceholderText(tr("Input User ID")); + if (mMode != New)mLeUserCode->setEnabled(false); + layout->addWidget(lblUserCode); + layout->addWidget(mLeUserCode); + addEndLine(layout); +} + +void AccountFormDialog::addTitleLabel(QVBoxLayout *layout) { + auto lblTitle = new QLabel(this); + lblTitle->setAlignment(Qt::AlignCenter); + lblTitle->setText(tr("Account")); + lblTitle->setObjectName("title"); + layout->addWidget(lblTitle); +} + +void AccountFormDialog::addSelfModeUI(QHBoxLayout *hlayout) { + auto btnLogout = new QToolButton(this); + btnLogout->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + btnLogout->setIcon(QIcon(":/icons/logout.png")); + btnLogout->setIconSize({30, 30}); + btnLogout->setText(tr("Logout")); + btnLogout->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + btnLogout->setObjectName("editvalBtn"); + + hlayout->addWidget(btnLogout); + connect(btnLogout, &QAbstractButton::clicked, [=]() { + accept(); + LOG_USER_OPERATION(Logout) + EventCenter::Default()->triggerEvent(RequestLogin, nullptr, nullptr); + }); + // load current user data + if (User::Current()) { + mLeUserCode->setText(User::Current()->getUserCode()); + mLeUserName->setText(User::Current()->getUserName()); + mUserID = User::Current()->getUserID(); + mUserPwd = User::Current()->getPassword(); + } +} + +void AccountFormDialog::addNewModeUI(QVBoxLayout *layout) { + auto lblPwd = new QLabel(this); + lblPwd->setText(tr("Password")); + layout->addWidget(lblPwd); + mLePwd = new QLineEdit(this); + mLePwd->setPlaceholderText(tr("Input password")); + mLePwd->setEchoMode(QLineEdit::Password); + layout->addWidget(mLePwd); + mRoleID = User::getRoleID("doctor"); + addEndLine(layout); } bool AccountFormDialog::updateReferenceData() { - if (m_mode == Self) { - if (!this->userNameChanged && !this->commentChanged) return true; - if (!this->userNameChanged) { - if (m_NewUserName.isEmpty()) { + if (mMode == Self) { + if (!this->mUserNameChanged && !this->mCommentChanged) return true; + if (!this->mUserNameChanged) { + if (mNewUserName.isEmpty()) { warn(tr("User Name can't be empty!")); return false; } - User::Current()->setUserName(m_NewUserName); + User::Current()->setUserName(mNewUserName); } - if (!this->commentChanged) User::Current()->setUserName(le_Comment->text()); + if (!this->mCommentChanged) User::Current()->setUserName(mLeComment->text()); bool ret = User::Current()->submitChange(); if (ret) { hideWarn(); - LOG_USER_OPERATION(ChangeUserName); + LOG_USER_OPERATION(ChangeUserName) } else { warn(tr("Submit change to database fail!")); } return ret; } - else if (m_mode == Admin) { - if (!this->userNameChanged && !this->roleChanged) return true; + else if (mMode == Admin) { + if (!this->mUserNameChanged && !this->mRoleChanged) return true; User user; - if (!User::getUser(m_UserID, user)) return true; - if (this->userNameChanged) { - if (m_NewUserName.isEmpty()) { + if (!User::getUser(mUserID, user)) return true; + if (this->mUserNameChanged) { + if (mNewUserName.isEmpty()) { warn(tr("User Name can't be empty!")); return false; } - user.setUserName(m_NewUserName); + user.setUserName(mNewUserName); } - if (this->roleChanged) user.setRoleID(m_RoleID); - if (!this->commentChanged) user.setComment(le_Comment->text()); + if (this->mRoleChanged) user.setRoleID(mRoleID); + if (!this->mCommentChanged) user.setComment(mLeComment->text()); bool ret = user.submitChange(); if (ret) { - LOG_USER_OPERATION(AdminChangeAcountInformation); + LOG_USER_OPERATION(AdminChangeAcountInformation) } return ret; } else { - //add new - User user; - if (le_UserCode->text().isEmpty()) { - warn(tr("User ID can't be empty!")); - return false; - } - if (le_UserName->text().isEmpty()) { - warn(tr("User Name can't be empty!")); - return false; - } - if (le_Pwd->text().isEmpty()) { - warn(tr("Password can't be empty!")); - return false; - } - if (!refmodel) { - warn(tr("Inner error ,unset data model!")); - return false; - } - if (User::existsUser(le_UserCode->text())) { - warn(tr("User Id exists!")); - return false; - } - hideWarn(); - user.setUserName(le_UserName->text()); - user.setPassword(User::getEncryptedPassword(le_Pwd->text())); - user.setRoleID(m_RoleID); - user.setComment(le_Comment->text()); - // User::insertUser(le_UserCode->text(),user); + //add new + User user; + if (mLeUserCode->text().isEmpty()) { + warn(tr("User ID can't be empty!")); + return false; + } + if (mLeUserName->text().isEmpty()) { + warn(tr("User Name can't be empty!")); + return false; + } + if (mLePwd->text().isEmpty()) { + warn(tr("Password can't be empty!")); + return false; + } + if (!mRefModel) { + warn(tr("Inner error ,unset data model!")); + return false; + } + if (User::existsUser(mLeUserCode->text())) { + warn(tr("User Id exists!")); + return false; + } + hideWarn(); + user.setUserName(mLeUserName->text()); + user.setPassword(User::getEncryptedPassword(mLePwd->text())); + user.setRoleID(mRoleID); + user.setComment(mLeComment->text()); + // User::insertUser(le_UserCode->text(),user); - refmodel->insertRow(0); - refmodel->setData(refmodel->index(0, 0), QUuid::createUuid().toString()); - refmodel->setData(refmodel->index(0, 1), le_UserCode->text()); + mRefModel->insertRow(0); + mRefModel->setData(mRefModel->index(0, 0), QUuid::createUuid().toString()); + mRefModel->setData(mRefModel->index(0, 1), mLeUserCode->text()); #define USER_READONLY_PROPERTY(name) name, #define USER_PROPERTY(name)\ USER_READONLY_PROPERTY(name) - enum user_index { - USER_PROPERTIES_MACRO() - }; + enum user_index { + USER_PROPERTIES_MACRO() + }; #undef USER_READONLY_PROPERTY #undef USER_PROPERTY #define USER_READONLY_PROPERTY(name) #define USER_PROPERTY(name)\ USER_READONLY_PROPERTY(name)\ - refmodel->setData(refmodel->index(0, name),user.get##name()); - USER_PROPERTIES_MACRO() + mRefModel->setData(mRefModel->index(0, name),user.get##name()); + USER_PROPERTIES_MACRO() #undef USER_READONLY_PROPERTY #undef USER_PROPERTY - if (refmodel->submit()) { - hideWarn(); - return true; - } - else { - warn(tr("Submit to data base fail!")); - return false; - } - } + if (mRefModel->submit()) { + hideWarn(); + return true; + } else { + warn(tr("Submit to data base fail!")); + return false; + } + } return true; } void AccountFormDialog::setAccountInformation(const QMap& values) { - le_UserCode->setText(values["UserCode"].toString()); - le_UserName->setText(values["UserName"].toString()); - le_Comment->setText(values["Comment"].toString()); - m_UserID = values["UserID"].toString(); - m_UserPwd = values["Password"].toString(); + mLeUserCode->setText(values["UserCode"].toString()); + mLeUserName->setText(values["UserName"].toString()); + mLeComment->setText(values["Comment"].toString()); + mUserID = values["UserID"].toString(); + mUserPwd = values["Password"].toString(); } -void AccountFormDialog::warn(QString msg) { - lbl_error->setText(msg); - lbl_error->setVisible(true); +void AccountFormDialog::warn(const QString& msg) { + mLblError->setText(msg); + mLblError->setVisible(true); } void AccountFormDialog::hideWarn() { - this->lbl_error->setVisible(false); + mLblError->setVisible(false); } diff --git a/src/dialogs/AccountFormDialog.h b/src/dialogs/AccountFormDialog.h index 39f2726..fdcd0f6 100644 --- a/src/dialogs/AccountFormDialog.h +++ b/src/dialogs/AccountFormDialog.h @@ -8,6 +8,8 @@ class QLabel; class QLineEdit; class QToolButton; class QSqlTableModel; + +#include #include "GUIFormBaseDialog.h" enum AccountEditMode{ @@ -17,32 +19,44 @@ class AccountFormDialog:public GUIFormBaseDialog{ Q_OBJECT public: explicit AccountFormDialog(QWidget *parent = nullptr,AccountEditMode mode = Self,Qt::WindowFlags f = Qt::WindowFlags()); - ~AccountFormDialog(); + ~AccountFormDialog() override = default; void setAccountInformation(const QMap& values); void setReferenceModel(QSqlTableModel* model){ - refmodel = model; + mRefModel = model; } protected: bool updateReferenceData() override; - void warn(QString msg); + void warn(const QString& msg); void hideWarn(); private: - QString m_UserID; - QString m_UserPwd; - QString m_RoleID; - QString m_NewUserName; - bool userNameChanged = false; - bool commentChanged = false; - bool roleChanged = false; - AccountEditMode m_mode = Self; - QLineEdit* le_UserCode = nullptr; - QLineEdit* le_UserName = nullptr; - QLineEdit* le_Comment = nullptr; - QLineEdit* le_Pwd = nullptr; - QToolButton* btn_Pwd = nullptr; + void addEndLine(QVBoxLayout *layout); + void addNewModeUI(QVBoxLayout *layout); + void addSelfModeUI(QHBoxLayout *layout); + void addTitleLabel(QVBoxLayout *layout); + void initUserCodeUI(QVBoxLayout *layout); + void initUserNameUI(QVBoxLayout *layout); + void addCommentLabel(QVBoxLayout *layout); + void addWarnLabel(QVBoxLayout *layout); + void addButtonPwd(QHBoxLayout *layout); + void changeSelfPassword(); + void resetUserPassword(); + QString mUserID; + QString mUserPwd; + QString mRoleID; + QString mNewUserName; + bool mUserNameChanged; + bool mCommentChanged; + bool mRoleChanged; + AccountEditMode mMode; + QLineEdit* mLeUserCode; + QLineEdit* mLeUserName; + QLineEdit* mLeComment; + QLineEdit* mLePwd; + QToolButton* mBtnPwd; + + QLabel* mLblError; + QSqlTableModel* mRefModel; - QLabel* lbl_error = nullptr; - QSqlTableModel* refmodel = nullptr; }; diff --git a/src/dialogs/AlertDialog.cpp b/src/dialogs/AlertDialog.cpp index f1f20a0..fc86c69 100644 --- a/src/dialogs/AlertDialog.cpp +++ b/src/dialogs/AlertDialog.cpp @@ -2,33 +2,31 @@ // Created by Krad on 2021/12/8. // -#include -#include #include "AlertDialog.h" -AlertDialog::AlertDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) { +#include +#include + +AlertDialog::AlertDialog(QWidget *parent, Qt::WindowFlags f) +: GUIFormBaseDialog(parent, f) +, mLblMsg(new QLabel(this)) +, mLblTitle (new QLabel(this)) +{ this->setFixedHeight(180); this->setFixedWidth(400); - QVBoxLayout* layout = new QVBoxLayout(formWidget); + auto layout = new QVBoxLayout(mFormWidget); layout->setSpacing(10); // add title - lbl_title = new QLabel(this); - lbl_title->setAlignment(Qt::AlignCenter); - lbl_title->setText(tr("Warning")); - lbl_title->setObjectName("title"); - layout->addWidget(lbl_title); - lbl_msg = new QLabel(this); - layout->addWidget(lbl_msg); -} - -AlertDialog::~AlertDialog() { - -} + mLblTitle->setAlignment(Qt::AlignCenter); + mLblTitle->setText(tr("Warning")); + mLblTitle->setObjectName("title"); + layout->addWidget(mLblTitle); + layout->addWidget(mLblMsg);} void AlertDialog::setAlertMessage(const QString &msg) { - this->lbl_msg->setText(msg); + mLblMsg->setText(msg); } void AlertDialog::setTitle(const QString &msg) { - lbl_title->setText(msg); + mLblTitle->setText(msg); } diff --git a/src/dialogs/AlertDialog.h b/src/dialogs/AlertDialog.h index b816451..5f0df99 100644 --- a/src/dialogs/AlertDialog.h +++ b/src/dialogs/AlertDialog.h @@ -10,15 +10,15 @@ class AlertDialog :public GUIFormBaseDialog{ Q_OBJECT public: explicit AlertDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); - ~AlertDialog(); + ~AlertDialog() override = default; void setAlertMessage(const QString& msg); void setTitle(const QString& msg); protected: bool updateReferenceData() override{return true;} private: - QLabel* lbl_msg; - QLabel* lbl_title; + QLabel* mLblMsg; + QLabel* mLblTitle; }; diff --git a/src/dialogs/ChangePasswordFormDialog.cpp b/src/dialogs/ChangePasswordFormDialog.cpp index b6f0b14..d33efb8 100644 --- a/src/dialogs/ChangePasswordFormDialog.cpp +++ b/src/dialogs/ChangePasswordFormDialog.cpp @@ -9,82 +9,88 @@ #include "log/UserOperationLog.h" #include "ChangePasswordFormDialog.h" -ChangePasswordFormDialog::ChangePasswordFormDialog(QWidget* parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) { - QVBoxLayout* layout = new QVBoxLayout(formWidget); - layout->setSpacing(10); - // add title - QLabel* lbl_title = new QLabel(this); - lbl_title->setAlignment(Qt::AlignCenter); - lbl_title->setText(tr("Change Password")); - lbl_title->setObjectName("title"); - layout->addWidget(lbl_title); - - //add old password - QLabel* lbl_Old = new QLabel(this); - lbl_Old->setText(tr("Current Password")); - pwd = new QLineEdit(this); - pwd->setEchoMode(QLineEdit::Password); - layout->addWidget(lbl_Old); - layout->addWidget(pwd); - QLabel* lbl_endline1 = new QLabel(this); - lbl_endline1->setObjectName("endline"); - layout->addWidget(lbl_endline1); - - //add new password - QLabel* lbl_New = new QLabel(this); - lbl_New->setText(tr("New Password")); - new_pwd = new QLineEdit(this); - new_pwd->setEchoMode(QLineEdit::Password); - layout->addWidget(lbl_New); - layout->addWidget(new_pwd); - QLabel* lbl_endline2 = new QLabel(this); - lbl_endline2->setObjectName("endline"); - layout->addWidget(lbl_endline2); - - //add confirm password - QLabel* lbl_Confirm = new QLabel(this); - lbl_Confirm->setText(tr("Confirm Password")); - confirm_pwd = new QLineEdit(this); - confirm_pwd->setEchoMode(QLineEdit::Password); - layout->addWidget(lbl_Confirm); - layout->addWidget(confirm_pwd); - QLabel* lbl_endline3 = new QLabel(this); - lbl_endline3->setObjectName("endline"); - layout->addWidget(lbl_endline3); - - lbl_error = new QLabel(this); - lbl_error->setObjectName("warn"); - layout->addWidget(lbl_error); +ChangePasswordFormDialog::ChangePasswordFormDialog(QWidget* parent, Qt::WindowFlags f) +: GUIFormBaseDialog(parent, f) +, mLEPasswd(new QLineEdit(this)) +, mLENewPasswd(new QLineEdit(this)) +, mLEConfirmPasswd(new QLineEdit(this)) +, mLblError(new QLabel(this)) +{ + initLayout(); } -ChangePasswordFormDialog::~ChangePasswordFormDialog() { +void ChangePasswordFormDialog::initLayout() { + auto layout = new QVBoxLayout(mFormWidget); + layout->setSpacing(10); + // add title + auto lblTitle = new QLabel(this); + lblTitle->setAlignment(Qt::AlignCenter); + lblTitle->setText(tr("Change Password")); + lblTitle->setObjectName("title"); + layout->addWidget(lblTitle); + //add old password + auto lblOld = new QLabel(this); + lblOld->setText(tr("Current Password")); + + mLEPasswd->setEchoMode(QLineEdit::Password); + layout->addWidget(lblOld); + layout->addWidget(mLEPasswd); + auto lblEndline1 = new QLabel(this); + lblEndline1->setObjectName("endline"); + layout->addWidget(lblEndline1); + + //add new password + auto lblNewPasswd = new QLabel(this); + lblNewPasswd->setText(tr("New Password")); + + mLENewPasswd->setEchoMode(QLineEdit::Password); + layout->addWidget(lblNewPasswd); + layout->addWidget(mLENewPasswd); + auto lblEndline2 = new QLabel(this); + lblEndline2->setObjectName("endline"); + layout->addWidget(lblEndline2); + + //add confirm password + auto lblConfirm = new QLabel(this); + lblConfirm->setText(tr("Confirm Password")); + + mLEConfirmPasswd->setEchoMode(QLineEdit::Password); + layout->addWidget(lblConfirm); + layout->addWidget(mLEConfirmPasswd); + auto lblEndline3 = new QLabel(this); + lblEndline3->setObjectName("endline"); + layout->addWidget(lblEndline3); + + mLblError->setObjectName("warn"); + layout->addWidget(mLblError); } + bool ChangePasswordFormDialog::updateReferenceData() { - if (pwd->text().isEmpty()) + if (mLEPasswd->text().isEmpty()) { - lbl_error->setText(tr("Please enter your old password!")); + mLblError->setText(tr("Please enter your old password!")); return false; } - if (new_pwd->text().length() < 6) { - lbl_error->setText(tr("New password should at least 6 characters!")); + if (mLENewPasswd->text().length() < 6) { + mLblError->setText(tr("New password should at least 6 characters!")); return false; } - QString encryptPwd = User::getEncryptedPassword(pwd->text()); + QString encryptPwd = User::getEncryptedPassword(mLEPasswd->text()); if (encryptPwd != User::Current()->getPassword()) { - lbl_error->setText(tr("Wrong password!")); + mLblError->setText(tr("Wrong password!")); return false; } - if (new_pwd->text() != confirm_pwd->text()) + if (mLENewPasswd->text() != mLEConfirmPasswd->text()) { - lbl_error->setText(tr("Your new password does not match!")); + mLblError->setText(tr("Your new password does not match!")); return false; } - User::Current()->setPassword(User::getEncryptedPassword(new_pwd->text())); + User::Current()->setPassword(User::getEncryptedPassword(mLENewPasswd->text())); if (!User::Current()->submitChange()) { - lbl_error->setText(tr("Database update error!")); + mLblError->setText(tr("Database update error!")); User::Current()->restorePassword(encryptPwd); return false; } diff --git a/src/dialogs/ChangePasswordFormDialog.h b/src/dialogs/ChangePasswordFormDialog.h index a1aa557..a385ccd 100644 --- a/src/dialogs/ChangePasswordFormDialog.h +++ b/src/dialogs/ChangePasswordFormDialog.h @@ -12,16 +12,19 @@ class ChangePasswordFormDialog:public GUIFormBaseDialog{ Q_OBJECT public: explicit ChangePasswordFormDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); - ~ChangePasswordFormDialog(); + ~ChangePasswordFormDialog() override = default; protected: bool updateReferenceData() override; private: - QLineEdit* pwd = nullptr; - QLineEdit* new_pwd = nullptr; - QLineEdit* confirm_pwd = nullptr; - QLabel* lbl_error = nullptr; + void initLayout(); + QLineEdit* mLEPasswd; + QLineEdit* mLENewPasswd; + QLineEdit* mLEConfirmPasswd; + QLabel* mLblError; + + }; diff --git a/src/dialogs/GUIFormBaseDialog.cpp b/src/dialogs/GUIFormBaseDialog.cpp index 96644b0..cacb05a 100644 --- a/src/dialogs/GUIFormBaseDialog.cpp +++ b/src/dialogs/GUIFormBaseDialog.cpp @@ -3,63 +3,52 @@ // #include "GUIFormBaseDialog.h" + #include #include #include -GUIFormBaseDialog::GUIFormBaseDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f) { +GUIFormBaseDialog::GUIFormBaseDialog(QWidget* parent, Qt::WindowFlags f) +: QDialog(parent, f) +, mFormWidget(new QWidget(this)) +, mBtnWidget(new QWidget(this)) +, mBtnCancel(new QPushButton(tr("Cancel"), mBtnWidget)) +, mBtnOk(new QPushButton(tr("OK"), mBtnWidget)) +{ this->setObjectName("formDialog"); this->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog); - // this->setFixedSize(500,600); this->setFixedWidth(500); - this->formWidget = new QWidget(this); - this->formWidget->setObjectName("formWidget"); - - QVBoxLayout* vLayout = new QVBoxLayout(this); - // vLayout->setContentsMargins(680,100,680,100); - vLayout->addWidget(formWidget); - - QWidget* btnWidget = new QWidget(this); - vLayout->addWidget(btnWidget); - QHBoxLayout* hLayout = new QHBoxLayout(btnWidget); - btnOk = new QPushButton(btnWidget); - btnOk->setText(tr("OK")); - btnCancel = new QPushButton(btnWidget); - btnCancel->setText(tr("Cancel")); - hLayout->addWidget(btnOk); - hLayout->addWidget(btnCancel); - btnOk->setObjectName("btnOK"); - connect(btnOk, &QPushButton::clicked, [t = this]() { - if (t->updateReferenceData()) - t->accept(); - }); - connect(btnCancel, &QPushButton::clicked, [t = this]() { - t->reject(); - }); -} - -GUIFormBaseDialog::~GUIFormBaseDialog() { - + this->mFormWidget->setObjectName("formWidget"); + auto vLayout = new QVBoxLayout(this); + vLayout->addWidget(mFormWidget); + vLayout->addWidget(mBtnWidget); + auto hLayout = new QHBoxLayout(mBtnWidget); + hLayout->addWidget(mBtnOk); + hLayout->addWidget(mBtnCancel); + mBtnOk->setObjectName("btnOK"); + connect(mBtnOk, &QPushButton::clicked, [=]() { + if (updateReferenceData()) accept(); + }); + connect(mBtnCancel, &QPushButton::clicked, [=]() { + reject(); + }); } void GUIFormBaseDialog::setButtonMode(DialogButtonMode mode) { switch (mode) { - case OkOnly: - { - btnOk->setVisible(true); - btnCancel->setVisible(false); - return; - } - case OkAndCancel: - { - btnOk->setVisible(true); - btnCancel->setVisible(true); - return; - } - case None: - default: - { - btnOk->setVisible(false); - btnCancel->setVisible(false); - } - } + case OkOnly: { + mBtnOk->setVisible(true); + mBtnCancel->setVisible(false); + return; + } + case OkAndCancel: { + mBtnOk->setVisible(true); + mBtnCancel->setVisible(true); + return; + } + case None: + default: { + mBtnOk->setVisible(false); + mBtnCancel->setVisible(false); + } + } } diff --git a/src/dialogs/GUIFormBaseDialog.h b/src/dialogs/GUIFormBaseDialog.h index a57a7f2..64cbdb9 100644 --- a/src/dialogs/GUIFormBaseDialog.h +++ b/src/dialogs/GUIFormBaseDialog.h @@ -13,15 +13,16 @@ class GUIFormBaseDialog: public QDialog { Q_OBJECT public: explicit GUIFormBaseDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); - ~GUIFormBaseDialog(); + ~GUIFormBaseDialog() override = default; void setButtonMode(DialogButtonMode mode); protected: virtual bool updateReferenceData(){ return false; }; - QWidget* formWidget = nullptr; - QPushButton* btnCancel = nullptr; - QPushButton* btnOk = nullptr; + QWidget* mFormWidget; + QWidget* mBtnWidget; + QPushButton* mBtnCancel; + QPushButton* mBtnOk; }; diff --git a/src/dialogs/SelectDialog.cpp b/src/dialogs/SelectDialog.cpp index 06a4c92..d1c3da5 100644 --- a/src/dialogs/SelectDialog.cpp +++ b/src/dialogs/SelectDialog.cpp @@ -3,20 +3,19 @@ // #include "SelectDialog.h" + #include "components/SlidePickerBox.h" #include #include -SelectDialog::SelectDialog(QWidget* parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) { +SelectDialog::SelectDialog(QWidget* parent, Qt::WindowFlags f) +: GUIFormBaseDialog(parent, f) +, mPickBox(new SlidePickerBox(mFormWidget)) +{ this->setFixedSize(360, 380); - QVBoxLayout* layout = new QVBoxLayout(formWidget); - box = new SlidePickerBox(formWidget); - box->setObjectName("slider_one"); - layout->addWidget(box); - -} - -SelectDialog::~SelectDialog() { + auto layout = new QVBoxLayout(mFormWidget); + mPickBox->setObjectName("slider_one"); + layout->addWidget(mPickBox); } @@ -25,13 +24,13 @@ bool SelectDialog::updateReferenceData() { } void SelectDialog::setValues(const QStringList& dates) { - box->setItems(dates); + mPickBox->setItems(dates); } QString SelectDialog::getSelectedValue() { - return box->getSelectedValue(); + return mPickBox->getSelectedValue(); } void SelectDialog::setSelectedValue(const QString& val) { - box->setSelectedValue(val); + mPickBox->setSelectedValue(val); } diff --git a/src/dialogs/SelectDialog.h b/src/dialogs/SelectDialog.h index fb0576c..2625900 100644 --- a/src/dialogs/SelectDialog.h +++ b/src/dialogs/SelectDialog.h @@ -11,13 +11,13 @@ class SelectDialog :public GUIFormBaseDialog{ Q_OBJECT public: explicit SelectDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); - ~SelectDialog() override; + ~SelectDialog() override = default; void setValues(const QStringList& values); QString getSelectedValue(); void setSelectedValue(const QString& val); protected: bool updateReferenceData() override; - SlidePickerBox* box = nullptr; + SlidePickerBox* mPickBox; }; diff --git a/src/dialogs/guimessagedialog.cpp b/src/dialogs/guimessagedialog.cpp index f597e87..3c851ae 100644 --- a/src/dialogs/guimessagedialog.cpp +++ b/src/dialogs/guimessagedialog.cpp @@ -4,40 +4,51 @@ #include "event/EventCenter.h" #include #include -GUIMessageDialog::GUIMessageDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::GUIMessageDialog) +GUIMessageDialog::GUIMessageDialog(QWidget *parent) +: QDialog(parent) +, mUI(new Ui::GUIMessageDialog) +, mBtnMain(new QToolButton(this)) +, mBtnAppend(new QToolButton(this)) +, mFrameIndex(0) +, mTimerID(-1) +, mPending(false) { - ui->setupUi(this); + mUI->setupUi(this); this->setObjectName("MessageDialog"); this->setWindowFlags (Qt :: FramelessWindowHint | Qt :: Dialog); this->showFullScreen (); - ui->lbl_msg->setVisible(false); - ui->lbl_progressicon->setVisible(false); - btn_main = new QToolButton(this); - btn_main->setObjectName("btn_main"); - btn_main->setVisible(false); - btn_main->setText("OK"); - btn_Append = new QToolButton(this); - btn_Append->setObjectName("btn_main"); - btn_Append->setVisible(false); - btn_Append->setText("Stop"); - QWidget* btnContainer = new QWidget(this); - QHBoxLayout* hlayout = new QHBoxLayout(btnContainer); - hlayout->setMargin(0); - hlayout->addWidget(btn_main); - hlayout->addWidget(btn_Append); - - ui->widget_2->layout()->addWidget(btnContainer); + initBaseLayout(); this->setWindowOpacity(0.6); - for (int i=1; i<=6;i++) + initLoadingFrameString(); +} + +void GUIMessageDialog::initBaseLayout() { + mUI->lblMsg->setVisible(false); + mUI->lblProgressIcon->setVisible(false); + mBtnMain->setObjectName("btn_main"); + mBtnMain->setVisible(false); + mBtnMain->setText("OK"); + mBtnAppend->setObjectName("btn_main"); + mBtnAppend->setVisible(false); + mBtnAppend->setText("Stop"); + auto btnContainer = new QWidget(this); + auto hLayout = new QHBoxLayout(btnContainer); + hLayout->setMargin(0); + hLayout->addWidget(mBtnMain); + hLayout->addWidget(mBtnAppend); + + mUI->btnContainerWidget->layout()->addWidget(btnContainer); +} + +void GUIMessageDialog::initLoadingFrameString(){ + for (int i=1; i <= 6; i++) { QString str(" "); for(int j=0;j11) frameIndex = frameIndex % 12; - ui->lbl_progressicon->setText(frame[frameIndex++]); + if (mFrameIndex > 11) mFrameIndex = mFrameIndex % 12; + mUI->lblProgressIcon->setText(mFrame[mFrameIndex++]); this->update(); } void GUIMessageDialog::stopLoading() { - if (timerID!=-1){ - killTimer(timerID); - timerID=-1; + if (mTimerID != -1){ + killTimer(mTimerID); + mTimerID=-1; } - disconnect(btn_main,0,0,0); - ui->lbl_progressicon->setVisible(false); + disconnect(mBtnMain, nullptr, nullptr, nullptr); + mUI->lblProgressIcon->setVisible(false); } void GUIMessageDialog::startLoading() { - ui->lbl_progressicon->setVisible(true); - disconnect(btn_main,0,0,0); - connect(btn_main,&QToolButton::clicked,[=](){ - if (timerID != -1){ - killTimer(timerID); - timerID = -1; + mUI->lblProgressIcon->setVisible(true); + disconnect(mBtnMain, nullptr, nullptr, nullptr); + connect(mBtnMain, &QToolButton::clicked, [=](){ + if (mTimerID != -1){ + killTimer(mTimerID); + mTimerID = -1; } accept(); EventCenter::Default()->triggerEvent(GUIEvents::RequestStop, nullptr, nullptr); LOG_USER_OPERATION(Stop); }); - timerID = startTimer(100); - btn_main->setText("Stop"); - btn_main->setVisible(true); + mTimerID = startTimer(100); + mBtnMain->setText("Stop"); + mBtnMain->setVisible(true); } -void GUIMessageDialog::showMessage(QString msg) { - ui->lbl_msg->setVisible(true); - ui->lbl_msg->setText(msg); +void GUIMessageDialog::showMessage(const QString& msg) { + mUI->lblMsg->setVisible(true); + mUI->lblMsg->setText(msg); } void GUIMessageDialog::showExitButton() { - btn_main->setText("OK"); - btn_main->setVisible(true); - disconnect(btn_main,0,0,0); - connect(btn_main,&QToolButton::clicked,[=](){ - if (timerID != -1){ - killTimer(timerID); - timerID = -1; + mBtnMain->setText("OK"); + mBtnMain->setVisible(true); + disconnect(mBtnMain, nullptr, nullptr, nullptr); + connect(mBtnMain, &QToolButton::clicked, [=](){ + if (mTimerID != -1){ + killTimer(mTimerID); + mTimerID = -1; } accept(); LOG_USER_OPERATION(ConfirmError); @@ -107,13 +118,13 @@ void GUIMessageDialog::showExitButton() { } void GUIMessageDialog::hideMessage() { - ui->lbl_msg->setVisible(false); - ui->lbl_msg->setText(""); + mUI->lblMsg->setVisible(false); + mUI->lblMsg->setText(""); } void GUIMessageDialog::hideExitButton() { - btn_main->setVisible(false); - disconnect(btn_main,0,0,0); + mBtnMain->setVisible(false); + disconnect(mBtnMain, nullptr, nullptr, nullptr); } void GUIMessageDialog::setOpacity(double opacity) { @@ -121,18 +132,18 @@ void GUIMessageDialog::setOpacity(double opacity) { } void GUIMessageDialog::startPending() { - disconnect(btn_Append,0,0,0); - connect(btn_Append,&QToolButton::clicked,[=](){ + disconnect(mBtnAppend, nullptr, nullptr, nullptr); + connect(mBtnAppend, &QToolButton::clicked, [=](){ EventCenter::Default()->triggerEvent(GUIEvents::RequestContinueScan, nullptr, nullptr); stopPending(); }); - btn_Append->setText("Next"); - btn_Append->setVisible(true); - pending = true; + mBtnAppend->setText("Next"); + mBtnAppend->setVisible(true); + mPending = true; } void GUIMessageDialog::stopPending() { - disconnect(btn_Append,0,0,0); - btn_Append->setVisible(false); - pending = false; + disconnect(mBtnAppend, nullptr, nullptr, nullptr); + mBtnAppend->setVisible(false); + mPending = false; } diff --git a/src/dialogs/guimessagedialog.h b/src/dialogs/guimessagedialog.h index ecb8dfc..1a905a6 100644 --- a/src/dialogs/guimessagedialog.h +++ b/src/dialogs/guimessagedialog.h @@ -13,8 +13,8 @@ class GUIMessageDialog : public QDialog public: explicit GUIMessageDialog(QWidget *parent = nullptr); - ~GUIMessageDialog(); - void showMessage(QString msg); + ~GUIMessageDialog() override; + void showMessage(const QString& msg); void hideMessage(); void showExitButton(); void hideExitButton(); @@ -23,19 +23,21 @@ public: void startPending(); void stopPending(); bool Pending(){ - return pending; + return mPending; } void setOpacity(double); protected: void timerEvent(QTimerEvent* event) override ; private: - Ui::GUIMessageDialog *ui; - QList frame; - QToolButton *btn_main; - QToolButton *btn_Append; - int frameIndex=0; - int timerID = -1; - bool pending = false; + void initBaseLayout(); + void initLoadingFrameString(); + Ui::GUIMessageDialog *mUI; + QList mFrame; + QToolButton *mBtnMain; + QToolButton *mBtnAppend; + int mFrameIndex; + int mTimerID; + bool mPending; }; #endif // GUIMESSAGEDIALOG_H diff --git a/src/dialogs/guimessagedialog.ui b/src/dialogs/guimessagedialog.ui index 186aad8..4159e62 100644 --- a/src/dialogs/guimessagedialog.ui +++ b/src/dialogs/guimessagedialog.ui @@ -36,7 +36,7 @@ - + @@ -58,7 +58,7 @@ - + @@ -71,7 +71,7 @@ - + diff --git a/src/forms/scan/patientinformationform.cpp b/src/forms/scan/patientinformationform.cpp index fbc2d1e..b010948 100644 --- a/src/forms/scan/patientinformationform.cpp +++ b/src/forms/scan/patientinformationform.cpp @@ -4,61 +4,62 @@ #include "event/EventCenter.h" #include "json/ScanJson.h" -PatientInformationForm::PatientInformationForm(QWidget* parent) : - QWidget(parent), - ui(new Ui::PatientInformationForm) +PatientInformationForm::PatientInformationForm(QWidget* parent) +: QWidget(parent) +, mUI(new Ui::PatientInformationForm) +, mInfo(nullptr) +, mJsonStr(nullptr) { - ui->setupUi(this); - + mUI->setupUi(this); connect(EventCenter::Default(), &EventCenter::ReloadLanguage, [=]() { - ui->retranslateUi(this); - }); + mUI->retranslateUi(this); + }); } PatientInformationForm::~PatientInformationForm() { - delete ui; - delete inf; - delete jsonstr; + delete mUI; + delete mInfo; + delete mJsonStr; } void PatientInformationForm::setPatientInformation(PatientInformation* information) { - ui->lbl_ID->setText(information->ID); - ui->lbl_Date->setText(information->BirthDate); - ui->lbl_Name->setText(information->Name); - ui->lbl_Sex->setText(information->Sex); - inf = information; + mUI->lbl_ID->setText(information->ID); + mUI->lbl_Date->setText(information->BirthDate); + mUI->lbl_Name->setText(information->Name); + mUI->lbl_Sex->setText(information->Sex); + mInfo = information; } void PatientInformationForm::setProtocol(int type) { - currentProtocol = type; + mCurrentProtocol = type; switch (type) { case 0: - ui->lbl_Protocol->setText(tr("LEFT ONLY")); + mUI->lbl_Protocol->setText(tr("LEFT ONLY")); break; case 1: default: - ui->lbl_Protocol->setText(tr("RIGHT ONLY")); + mUI->lbl_Protocol->setText(tr("RIGHT ONLY")); break; } } const char* PatientInformationForm::getCurrentPatientJsonString(bool empty) { cJSON* root = cJSON_CreateObject(); - cJSON_AddItemToObject(root, "PatientName", cJSON_CreateString(ui->lbl_Name->text().replace(' ', '_').toStdString().data())); - cJSON_AddItemToObject(root, "PatientID", cJSON_CreateString(ui->lbl_ID->text().replace(' ', '_').toStdString().data())); - cJSON_AddItemToObject(root, "PatientSex", cJSON_CreateString(ui->lbl_Sex->text().toStdString().data())); + cJSON_AddItemToObject(root, "PatientName", cJSON_CreateString(mUI->lbl_Name->text().replace(' ', '_').toStdString().data())); + cJSON_AddItemToObject(root, "PatientID", cJSON_CreateString(mUI->lbl_ID->text().replace(' ', '_').toStdString().data())); + cJSON_AddItemToObject(root, "PatientSex", cJSON_CreateString(mUI->lbl_Sex->text().toStdString().data())); cJSON_AddItemToObject(root, "PatientBirthDate", - cJSON_CreateString(ui->lbl_Date->text().replace("/", "").replace("-", "").replace(' ', '.').toStdString().data())); - cJSON_AddItemToObject(root, "Laterality", cJSON_CreateString(currentProtocol ? "R" : "L")); + cJSON_CreateString(mUI->lbl_Date->text().replace("/", "").replace("-", "").replace(' ', '.').toStdString().data())); + cJSON_AddItemToObject(root, "Laterality", cJSON_CreateString(mCurrentProtocol ? "R" : "L")); cJSON_AddItemToObject(root, "IsEmptyData", cJSON_CreateNumber(empty ? 1 : 0)); cJSON_AddItemToObject(root, "OperatorName", cJSON_CreateString("Bob")); cJSON_AddItemToObject(root, "ReferringPhysicianName", cJSON_CreateString("XX")); cJSON_AddItemToObject(root, "InstitutionName", cJSON_CreateString("EQ9")); cJSON_AddItemToObject(root, "InstitutionAddress", cJSON_CreateString("HZ")); - delete jsonstr; - jsonstr = cJSON_Print(root); + delete mJsonStr; + mJsonStr = cJSON_Print(root); ScanJson::Current()->store(root); - return jsonstr; + return mJsonStr; } diff --git a/src/forms/scan/patientinformationform.h b/src/forms/scan/patientinformationform.h index 02cc2f9..1f1df85 100644 --- a/src/forms/scan/patientinformationform.h +++ b/src/forms/scan/patientinformationform.h @@ -13,15 +13,15 @@ class PatientInformationForm : public QWidget public: explicit PatientInformationForm(QWidget *parent = nullptr); - ~PatientInformationForm(); + ~PatientInformationForm() override; void setPatientInformation(PatientInformation* information); void setProtocol(int type); const char * getCurrentPatientJsonString(bool emptyScan); private: - Ui::PatientInformationForm *ui; - PatientInformation* inf = nullptr; - int currentProtocol = 0; - char * jsonstr = nullptr; + Ui::PatientInformationForm *mUI; + PatientInformation* mInfo = nullptr; + int mCurrentProtocol = 0; + char * mJsonStr = nullptr; }; #endif // PATIENTINFORMATIONFORM_H diff --git a/src/models/User.cpp b/src/models/User.cpp index e2a48e4..06a4e2c 100644 --- a/src/models/User.cpp +++ b/src/models/User.cpp @@ -36,7 +36,7 @@ bool User::submitChange() { #undef USER_READONLY_PROPERTY if (!needUpdate) return true; QString whereString = " where "+getIndexName()+" = '"+getIndexValue()+"'"; - bool result = 1 == SQLHelper::ExecuteNoQuery(updateSQL.arg(setString,whereString),¶ms); + bool result = 1 == SQLHelper::ExecuteNoQuery(updateSQL.arg(setString,whereString),params); if (result) { #define USER_READONLY_PROPERTY(name) @@ -55,7 +55,7 @@ bool User::QueryUser(const QString& userID, const QString& Pwd) { QMap params; params[":userID"] = userID; params[":pwd"] = Pwd; - SQLHelper::QueryFirst(sql, map, ¶ms); + SQLHelper::QueryFirst(sql, map, params); if(!map.isEmpty()) { // first login @@ -87,7 +87,7 @@ bool User::existsUser(const QString& userCode) { QMap map; QMap params; params[":userID"] = userCode; - SQLHelper::QueryFirst(sql, map, ¶ms); + SQLHelper::QueryFirst(sql, map, params); return !map.isEmpty(); } @@ -96,7 +96,7 @@ bool User::getUser(const QString& userUID, User& user) { QMap map; QMap params; params[":userUID"] = userUID; - SQLHelper::QueryFirst(sql, map, ¶ms); + SQLHelper::QueryFirst(sql, map, params); if(!map.isEmpty()) { #define USER_READONLY_PROPERTY(name) user.m_##name = map[#name].toString(); @@ -119,7 +119,7 @@ QString User::getRoleName(const QString& RoleID) { QMap map; QMap params; params[":RoleID"] = RoleID; - SQLHelper::QueryFirst(sql, map, ¶ms); + SQLHelper::QueryFirst(sql, map, params); roleCache[RoleID] = map["RoleName"].toString(); return map["RoleName"].toString(); } @@ -133,7 +133,7 @@ QString User::getRoleID(const QString& RoleName) { QMap map; QMap params; params[":RoleName"] = RoleName; - SQLHelper::QueryFirst(sql, map, ¶ms); + SQLHelper::QueryFirst(sql, map, params); roleCache[map["RoleID"].toString()] = RoleName; return map["RoleID"].toString(); } @@ -171,7 +171,7 @@ bool User::insertUser(const QString& UserCode, User &user) { USER_PROPERTIES_MACRO() #undef USER_PROPERTY #undef USER_READONLY_PROPERTY - bool result = 1 == SQLHelper::ExecuteNoQuery(updateSQL.arg(namesString,valuesString),¶ms); + bool result = 1 == SQLHelper::ExecuteNoQuery(updateSQL.arg(namesString,valuesString),params); return result; } diff --git a/src/network/DicomCfgDialog.h b/src/network/DicomCfgDialog.h index 58256d2..b22e756 100644 --- a/src/network/DicomCfgDialog.h +++ b/src/network/DicomCfgDialog.h @@ -14,7 +14,7 @@ class DicomCfgDialog : public QDialog public: explicit DicomCfgDialog(QWidget* aParent = nullptr); - ~DicomCfgDialog(); + ~DicomCfgDialog() override; private: Ui::DicomCfgDialog* mUi; diff --git a/src/network/GetAdminPsw.cpp b/src/network/GetAdminPsw.cpp index dad44f9..12acfaf 100644 --- a/src/network/GetAdminPsw.cpp +++ b/src/network/GetAdminPsw.cpp @@ -17,7 +17,7 @@ GetAdminPsw::GetAdminPsw(QWidget* parent, Qt::WindowFlags f) , mLabelError(new QLabel(this)) { setWindowModality(Qt::WindowModal); - QFormLayout* formLayout = new QFormLayout(formWidget); + QFormLayout* formLayout = new QFormLayout(mFormWidget); QString value1 = QString(tr("Admin Password")); mPsw->setEchoMode(QLineEdit::Password); formLayout->addRow(value1, mPsw); diff --git a/src/network/GetIPDialog.cpp b/src/network/GetIPDialog.cpp index b0b8547..925f8a3 100644 --- a/src/network/GetIPDialog.cpp +++ b/src/network/GetIPDialog.cpp @@ -17,7 +17,7 @@ GetIPDialog::GetIPDialog(QWidget* parent, Qt::WindowFlags f) , mLabelError(new QLabel(this)) { setWindowModality(Qt::WindowModal); - QFormLayout* formLayout = new QFormLayout(formWidget); + QFormLayout* formLayout = new QFormLayout(mFormWidget); QLabel* IpValue = new QLabel(tr("IP Address")); formLayout->addRow(IpValue, mIp); diff --git a/src/network/GetRouteDialog.cpp b/src/network/GetRouteDialog.cpp index 43e2dcf..80663ae 100644 --- a/src/network/GetRouteDialog.cpp +++ b/src/network/GetRouteDialog.cpp @@ -18,7 +18,7 @@ GetRouteDialog::GetRouteDialog(QWidget* parent, Qt::WindowFlags f) , mLabelError(new QLabel(this)) { setWindowModality(Qt::WindowModal); - QFormLayout* formLayout = new QFormLayout(formWidget); + QFormLayout* formLayout = new QFormLayout(mFormWidget); formLayout->addRow(QString(tr("Destination")), mDestination); formLayout->addRow(QString(tr("Netmask")), mNetmask); formLayout->addRow(QString(tr("Gateway")), mGateway); diff --git a/src/network/NetworkCfgDialog.h b/src/network/NetworkCfgDialog.h index 24c2630..fe7cdae 100644 --- a/src/network/NetworkCfgDialog.h +++ b/src/network/NetworkCfgDialog.h @@ -19,7 +19,7 @@ class NetworkCfgDialog : public QDialog public: //static void setShadow(QDialog* dialog); explicit NetworkCfgDialog(QWidget* parent = nullptr); - ~NetworkCfgDialog(); + ~NetworkCfgDialog() override; void loadData(); void applyData();