Refactor dialog package.

This commit is contained in:
Krad
2022-06-13 11:21:44 +08:00
parent 9a233251dc
commit 69a506ff94
27 changed files with 870 additions and 828 deletions

View File

@@ -9,8 +9,8 @@
#include "components/DateSlidePickerBox.h" #include "components/DateSlidePickerBox.h"
DateSelectDialog::DateSelectDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) { DateSelectDialog::DateSelectDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
this->setFixedSize(460, 380); this->setFixedSize(460, 380);
QVBoxLayout* layout = new QVBoxLayout(formWidget); QVBoxLayout* layout = new QVBoxLayout(mFormWidget);
box = new DateSlidePickerBox(formWidget); box = new DateSlidePickerBox(mFormWidget);
box->setObjectName("slider_one"); box->setObjectName("slider_one");
box->setSelectedValue("1990-01-01"); box->setSelectedValue("1990-01-01");
lbl_error = new QLabel(this); lbl_error = new QLabel(this);

View File

@@ -23,7 +23,7 @@ int queryValue(QSqlTableModel* model, int colID, const QVariant& var)
} }
EditPatientDialog::EditPatientDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) { EditPatientDialog::EditPatientDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
QVBoxLayout* layout = new QVBoxLayout(formWidget); QVBoxLayout* layout = new QVBoxLayout(mFormWidget);
layout->setSpacing(10); layout->setSpacing(10);
// add title // add title
QLabel* lbl_title = new QLabel(this); QLabel* lbl_title = new QLabel(this);

View File

@@ -10,7 +10,7 @@
#include <QSqlRecord> #include <QSqlRecord>
#include <qdebug.h> #include <qdebug.h>
QSqlDatabase* SQLHelper::defaultDatabase= nullptr; QSqlDatabase* SQLHelper::defaultDatabase= nullptr;
QHash<QString,QSqlQueryModel*>* SQLHelper::cache= new QHash<QString,QSqlQueryModel*>; static QHash<QString,QSqlQueryModel*> cache;
bool SQLHelper::Open() { bool SQLHelper::Open() {
if (defaultDatabase) return true; if (defaultDatabase) return true;
defaultDatabase= new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE", "USCTDB")); defaultDatabase= new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE", "USCTDB"));
@@ -26,11 +26,11 @@ bool SQLHelper::Open(QSqlDatabase *base) {
} }
void SQLHelper::Close() { void SQLHelper::Close() {
for(auto item : cache->values()) for(auto item : cache.values())
{ {
delete item; delete item;
} }
cache->clear(); cache.clear();
if(defaultDatabase->isValid() && defaultDatabase->isOpen()) if(defaultDatabase->isValid() && defaultDatabase->isOpen())
{ {
defaultDatabase->close(); defaultDatabase->close();
@@ -39,25 +39,25 @@ void SQLHelper::Close() {
} }
} }
void prepareSQL(QSqlQuery& query,QMap<QString,QVariant>* params) void prepareSQL(QSqlQuery& query,const QMap<QString,QVariant>& params)
{ {
if (!params) return; if (params.empty()) return;
for (auto key : params->keys()) for (const auto & key : params.keys())
{ {
query.bindValue(key,params->value(key)); query.bindValue(key,params.value(key));
} }
} }
QSqlTableModel* SQLHelper::getTable(const QString &tableName) { 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); CenterAlignSqlTableModel *model = new CenterAlignSqlTableModel(nullptr,*defaultDatabase);
model->setTable(tableName); model->setTable(tableName);
(*cache)[tableName] = model; cache[tableName] = model;
return (QSqlTableModel*)(*cache)[tableName]; return (QSqlTableModel*)(cache)[tableName];
} }
int SQLHelper::QueryCount(QString sql, QMap<QString,QVariant>* params) { int SQLHelper::QueryCount(const QString& sql, const QMap<QString,QVariant>& params) {
QSqlQuery query(*defaultDatabase); QSqlQuery query(*defaultDatabase);
prepareSQL(query, params); prepareSQL(query, params);
if (query.exec(sql)) if (query.exec(sql))
@@ -68,7 +68,7 @@ int SQLHelper::QueryCount(QString sql, QMap<QString,QVariant>* params) {
return 0; return 0;
} }
int SQLHelper::ExecuteNoQuery(QString sql, QMap<QString,QVariant>* params) { int SQLHelper::ExecuteNoQuery(const QString& sql, const QMap<QString,QVariant>& params) {
QSqlQuery query(*defaultDatabase); QSqlQuery query(*defaultDatabase);
query.prepare(sql); query.prepare(sql);
prepareSQL(query, params); prepareSQL(query, params);
@@ -79,7 +79,7 @@ int SQLHelper::ExecuteNoQuery(QString sql, QMap<QString,QVariant>* params) {
return 0; return 0;
} }
void SQLHelper::QueryFirst(QString sql, QMap<QString,QVariant>& result, QMap<QString,QVariant>* params) { void SQLHelper::QueryFirst(const QString &sql, QMap<QString,QVariant>& result, const QMap<QString,QVariant>& params) {
QSqlQuery query(*defaultDatabase); QSqlQuery query(*defaultDatabase);
query.prepare(sql); query.prepare(sql);
prepareSQL(query, params); prepareSQL(query, params);
@@ -95,8 +95,8 @@ void SQLHelper::QueryFirst(QString sql, QMap<QString,QVariant>& result, QMap<QSt
} }
} }
QSqlQueryModel *SQLHelper::QueryModel(QString queryName, QString sql, QMap<QString, QVariant> *params) { QSqlQueryModel *SQLHelper::QueryModel(const QString& queryName, const QString& sql, const QMap<QString, QVariant> &params) {
if (cache->contains(queryName)) return (*cache)[queryName]; if (cache.contains(queryName)) return cache[queryName];
QSqlQueryModel* model = new QSqlQueryModel; QSqlQueryModel* model = new QSqlQueryModel;
QSqlQuery query(*defaultDatabase); QSqlQuery query(*defaultDatabase);
@@ -108,16 +108,16 @@ QSqlQueryModel *SQLHelper::QueryModel(QString queryName, QString sql, QMap<QStri
delete model; delete model;
return nullptr; return nullptr;
} }
(*cache)[queryName] = model; cache[queryName] = model;
return model; return model;
} }
QSqlQueryModel *SQLHelper::QueryModel(QString queryName) { QSqlQueryModel *SQLHelper::QueryModel(const QString& queryName) {
if (cache->contains(queryName)) return (*cache)[queryName]; if (cache.contains(queryName)) return cache[queryName];
return nullptr; return nullptr;
} }
void SQLHelper::QueryMap(QString sql, QMap<QString, QVariant> &result, QMap<QString, QVariant> *params) { void SQLHelper::QueryMap(const QString& sql, QMap<QString, QVariant> &result, const QMap<QString, QVariant> &params) {
QSqlQuery query(*defaultDatabase); QSqlQuery query(*defaultDatabase);
query.prepare(sql); query.prepare(sql);
prepareSQL(query, params); prepareSQL(query, params);

View File

@@ -16,16 +16,15 @@ public:
static bool Open(); static bool Open();
static bool Open(QSqlDatabase* base); static bool Open(QSqlDatabase* base);
static void Close(); static void Close();
static void QueryFirst(QString sql, QMap<QString,QVariant>& result, QMap<QString,QVariant>* params = nullptr); static void QueryFirst(const QString &sql, QMap<QString,QVariant>& result, const QMap<QString, QVariant> &params = QMap<QString, QVariant>());
static int QueryCount(QString sql, QMap<QString,QVariant>* params = nullptr); static int QueryCount(const QString &sql, const QMap<QString, QVariant> &params = QMap<QString, QVariant>());
static int ExecuteNoQuery(QString sql, QMap<QString,QVariant>* params = nullptr); static int ExecuteNoQuery(const QString &sql,const QMap<QString, QVariant> &params = QMap<QString, QVariant>());
static void QueryMap(QString sql, QMap<QString,QVariant>& result, QMap<QString,QVariant>* params = nullptr); static void QueryMap(const QString& sql, QMap<QString,QVariant>& result, const QMap<QString, QVariant> &params = QMap<QString, QVariant>());
static QSqlQueryModel* QueryModel(QString queryName); static QSqlQueryModel* QueryModel(const QString &queryName);
static QSqlQueryModel* QueryModel(QString queryName, QString sql, QMap<QString,QVariant>* params = nullptr); static QSqlQueryModel* QueryModel(const QString &queryName, const QString &sql, const QMap<QString, QVariant> &params = QMap<QString, QVariant>());
static QSqlTableModel* getTable(const QString & tableName); static QSqlTableModel* getTable(const QString & tableName);
private: private:
static QSqlDatabase* defaultDatabase; static QSqlDatabase* defaultDatabase;
static QHash<QString,QSqlQueryModel*>* cache;
}; };

View File

@@ -1,22 +1,30 @@
// //
// Created by Krad on 2021/10/12. // Created by Krad on 2021/10/12.
// //
#include "ShimLib/ShimLib.h"
#include "DeviceManager.h" #include "DeviceManager.h"
#include "../event/EventCenter.h"
#include <QVariant> #include <QVariant>
#include <QTimerEvent> #include <QTimerEvent>
#include <QDate> #include <QDate>
#include <qdebug.h> #include <qdebug.h>
#include "appvals/AppGlobalValues.h" #include "appvals/AppGlobalValues.h"
#include "json/ScanJson.h" #include "json/ScanJson.h"
#include "json/jsonobject.h" #include "ShimLib/ShimLib.h"
#include "event/EventCenter.h"
#define TRIGGER_EVENT EventCenter::Default()->triggerEvent #define TRIGGER_EVENT EventCenter::Default()->triggerEvent
#define THROW_ERROR(errormsg)\ #define THROW_ERROR(errormsg)\
TRIGGER_EVENT(GUIEvents::GUIErrorRaise, nullptr, (QObject*)&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) const char* getStatusString(int status)
{ {
switch (status) { switch (status) {
@@ -28,8 +36,9 @@ const char* getStatusString(int status)
return "BUSY"; return "BUSY";
case ERROR: case ERROR:
return "ERROR"; return "ERROR";
default:
return nullptr;
} }
return "";
} }
std::string getJsonFromPatInf(QObject* obj) std::string getJsonFromPatInf(QObject* obj)
@@ -37,235 +46,96 @@ std::string getJsonFromPatInf(QObject* obj)
return ((QString*)obj)->toStdString(); return ((QString*)obj)->toStdString();
} }
void ErrorCallback(const char* msg) void errorCallback(const char* msg)
{ {
DeviceManager::Default()->emitErrorCallback(msg); DeviceManager::Default()->emitErrorCallback(msg);
} }
void DeviceManager::emitErrorCallback(const char *msg) { const char * getPhaseName(int phase){
errorOccurred=true; return names[phase-1];
printf("Error Callback , message:%s\r\n", msg);
QString m(msg);
emit raiseGlobalError( m);
} }
void DeviceManager::initDevice() { void DeviceManager::initDevice() {
InitLib(ErrorCallback); InitLib(errorCallback);
deviceInfTimerID = startTimer(10000); mDeviceInfTimerID = startTimer(10000);
// empty scan // empty scan
connect(EventCenter::Default(), &EventCenter::RequestEmptyScan, [=](QObject* sender, QObject* detail) { connect(EventCenter::Default(), &EventCenter::RequestEmptyScan, [=](QObject* sender, QObject* detail) {
std::string json = getJsonFromPatInf(detail); startScan(getJsonFromPatInf(detail).c_str(), true);
startScan(json.c_str(), true);
}); });
// Patient scan // Patient scan
connect(EventCenter::Default(), &EventCenter::RequestPatientScan, [=](QObject* sender, QObject* detail) { connect(EventCenter::Default(), &EventCenter::RequestPatientScan, [=](QObject* sender, QObject* detail) {
std::string json = getJsonFromPatInf(detail); startScan(getJsonFromPatInf(detail).c_str());
qDebug() << json.c_str();
if (!json.empty())
{
startScan(json.c_str());
}
}); });
// Continue Scan // Continue Scan
connect(EventCenter::Default(), &EventCenter::RequestContinueScan, [=](QObject* sender, QObject* detail) { connect(EventCenter::Default(), &EventCenter::RequestContinueScan, [=](QObject* sender, QObject* detail) {
postContinueCommand(true); postContinueCommand(true);
}); });
// stop // stop
connect(EventCenter::Default(), &EventCenter::RequestStop, [=]() { connect(EventCenter::Default(), &EventCenter::RequestStop,this, &DeviceManager::stopScan);
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);
});
// preview // preview
connect(EventCenter::Default(), &EventCenter::RequestPreviewScan, [=]() { connect(EventCenter::Default(), &EventCenter::RequestPreviewScan,this, &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(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!";
});
// init the preview data caller thread // init the preview data caller thread
previewDataCaller = QThread::create([=]() { initPreviewThread();
while (!endLoop)
{
if (!previewing) {
QThread::sleep(3);
continue;
} }
void DeviceManager::startScan(const char* json, bool empty) {
if (!json) return;
//clear last error state first
mErrorOccurred = false;
// check device status========================================= // check device status=========================================
qDebug() << "GetStatus"; qDebug() << "GetStatus";
StatusInfo inf = GetStatus(); StatusInfo inf = GetStatus();
qDebug() << "GetPreviewData request status, status:" << getStatusString(inf.status); qDebug() << "Scan start request status, status:" << getStatusString(inf.status);
// device is preview scanning, try get preview data if (inf.status != READY) {
if (inf.status == SCANNING) { QString errMsg("Device is not ready, start scan operation fail!status is %1");
qDebug() << "Preview data reader read start!"; errMsg = errMsg.arg(getStatusString(inf.status));
const char* data = GetPreviewData(); THROW_ERROR(errMsg)
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();
}
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);
return; return;
} }
//scanning progress timer static QString msg = "Start scan...";
//error exit, callback error AppGlobalValues::setInProcessing(true);
if (errorOccurred) { TRIGGER_EVENT(GUIEvents::InvokeOperationStart, nullptr, (QObject*)&msg);
timerID = event->timerId(); qDebug() << "SetScanInfo>>>>>>>>>>>>>>>>>>>>";
exitScanTimer(); AppGlobalValues::setEmptyScanFlag(empty);
int ret = SetScanInfo(json, empty ? 1 : 0);
if (ret) {
qDebug() << ">>>>>>>>>>>>>>>>>>>>SetScanInfo failed";
THROW_ERROR("Transfer patient information fail!")
return; return;
} }
// previewing exit qDebug() << ">>>>>>>>>>>>>>>>>>>>SetScanInfo success";
if (previewing) { postScanCommand();
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();
} }
void DeviceManager::scanProcess(int sProgress) { void DeviceManager::scanProcess(int aProgress) {
qDebug() << "current output path:" << getScanOutputPath(); qDebug() << "current output path:" << getScanOutputPath();
lastStatus = SCANNING; mLastStatus = SCANNING;
//normal scan pending //normal scan pending
int phase = sProgress / 100 + 1; int phase = aProgress / 100 + 1;
int progress = sProgress % 100; int progress = aProgress % 100;
// scan with phase 3 has a different message // scan with phase 3 has a different message
QString extraMsg = (AppGlobalValues::EmptyScanFlag().toBool() || QString extraMsg = (AppGlobalValues::EmptyScanFlag().toBool() ||
(scanPhase != 3)) ? "": ", patient can leave"; (mScanPhase != 3)) ? "" : ", patient can leave";
QVariant var(QString("%1%3\r\n progress:%2%").arg(getPhaseName(scanPhase)).arg(progress).arg(extraMsg)); QVariant var(QString("%1%3\r\n progress:%2%").arg(getPhaseName(mScanPhase)).arg(progress).arg(extraMsg));
TRIGGER_EVENT(InvokeOperationProgress, nullptr, (QObject *) &var); TRIGGER_EVENT(InvokeOperationProgress, nullptr, (QObject *) &var);
// 300 means finished // 300 means finished
if (sProgress == 300) return; if (aProgress == 300) return;
//phase control //phase control
//no change return //no change return
if (scanPhase == phase) return; if (mScanPhase == phase) return;
// error phase // 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( 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) THROW_ERROR(errorMsg)
exitScanTimer(); exitScanTimer();
return; return;
} }
// enter phase 2 // enter phase 2
if ((scanPhase = phase) == 2) { if ((mScanPhase = phase) == 2) {
if (!AppGlobalValues::EmptyScanFlag().toBool() && JsonObject::Instance()->getScanConfirm()) { if (!AppGlobalValues::EmptyScanFlag().toBool() && JsonObject::Instance()->getScanConfirm()) {
var.setValue(QString("Waiting for operator to start scan!\r\n Click \"Next\" to continue!")); var.setValue(QString("Waiting for operator to start scan!\r\n Click \"Next\" to continue!"));
TRIGGER_EVENT(InvokeOperationPending, nullptr, (QObject *) &var); TRIGGER_EVENT(InvokeOperationPending, nullptr, (QObject *) &var);
@@ -279,12 +149,30 @@ void DeviceManager::scanProcess(int sProgress) {
} }
void DeviceManager::exitScanTimer() { void DeviceManager::postScanCommand() {
qDebug() << "Scanning progress Timer exit"; qDebug() << "ScanControl start>>>>>>>>>>>>>>>>>>>>>";
if (timerID>0)killTimer(timerID); if (!ScanControl(SCAN)) {
timerID = -1; qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl success";
lastStatus = -1; //set current state
previewing = false; 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() { void DeviceManager::prepareFinishScan() {
@@ -294,10 +182,6 @@ void DeviceManager::prepareFinishScan() {
// stop normal scan with prompt // stop normal scan with prompt
TRIGGER_EVENT(InvokeOperationEnd, nullptr, (QObject *) &var); TRIGGER_EVENT(InvokeOperationEnd, nullptr, (QObject *) &var);
AppGlobalValues::setInProcessing(false); 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 // get output data path
QString outputPath = GetDeviceInfo(DEV_OUTPATH); QString outputPath = GetDeviceInfo(DEV_OUTPATH);
@@ -314,76 +198,185 @@ void DeviceManager::prepareFinishScan() {
// save json // save json
ScanJson::Current()->save(); ScanJson::Current()->save();
} else { } else {
QString msg("Scan Output Path error!"); THROW_ERROR("Scan Output Path error!")
THROW_ERROR(msg);
} }
} }
void DeviceManager::startScan(const char* json, bool empty) { void DeviceManager::stopScan() {
//clear last error state first
errorOccurred = false;
// check device status=========================================
qDebug() << "GetStatus"; qDebug() << "GetStatus";
StatusInfo inf = GetStatus(); StatusInfo inf = GetStatus();
qDebug() << "Scan start request status, status:" << getStatusString(inf.status); qDebug() << "Stop request status, status:%s" << getStatusString(inf.status);
if (inf.status != READY) {
QString errmsg("Device is not ready, start scan operation fail!status is %1"); // check device status=========================================
errmsg = errmsg.arg(getStatusString(inf.status)); //device is ready return
THROW_ERROR(errmsg); if (inf.status != SCANNING) {
//double check
QThread::msleep(100);
inf = GetStatus();
if (inf.status != SCANNING) {
TRIGGER_EVENT(ResponseStop, nullptr, nullptr);
return; return;
} }
static QString msg = "Start scan..."; }
AppGlobalValues::setInProcessing(true); AppGlobalValues::setInProcessing(true);
TRIGGER_EVENT(GUIEvents::InvokeOperationStart, nullptr, (QObject*)&msg); TRIGGER_EVENT(InvokeOperationStart, nullptr, nullptr);
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";
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);
return;
}
//ScanControl fail //ScanControl fail
QString errmsg("ScanControl start fail!"); qDebug() << "Request stop!";
THROW_ERROR(errmsg); if (mTimerID != -1)killTimer(mTimerID);
qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl failed"; if (ScanControl(STOP)) {
} qDebug() << "Stop fail!";
QString msg("Stop operation fail!");
void DeviceManager::postContinueCommand(bool useTimer) { THROW_ERROR(msg)
if (!ScanControl(SCAN_CONTINUE)) { qDebug() << "Error thrown!";
if (useTimer)timerID = startTimer(500); 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; return;
} }
//ScanControl fail mLastStatus = -1;
QString errmsg("ScanControl start fail!"); mPreviewing = false;
THROW_ERROR(errmsg); 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::exitScanTimer() {
qDebug() << "Scanning progress Timer exit";
if (mTimerID > 0)killTimer(mTimerID);
mTimerID = -1;
mLastStatus = -1;
mPreviewing = false;
} }
void DeviceManager::close() { void DeviceManager::close() {
#ifdef _WIN32 #ifdef _WIN32
StopDevice(); StopDevice();
#endif #endif
previewDataCaller->terminate(); mPreviewDataCaller->terminate();
delete previewDataCaller; 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() { QString DeviceManager::getSoftwareVersion() {

View File

@@ -7,6 +7,7 @@
#include <QObject> #include <QObject>
#include <QThread> #include <QThread>
class DeviceManager : public QObject { class DeviceManager : public QObject {
Q_OBJECT Q_OBJECT
@@ -15,10 +16,15 @@ public:
static DeviceManager manager; static DeviceManager manager;
return &manager; return &manager;
} }
DeviceManager() = default; DeviceManager() = default;
~DeviceManager() override = default; ~DeviceManager() override = default;
DeviceManager(const DeviceManager &) = delete; DeviceManager(const DeviceManager &) = delete;
DeviceManager operator=(const DeviceManager &) = delete; DeviceManager operator=(const DeviceManager &) = delete;
/** /**
* init device, include Shimlib and it's error call back, * init device, include Shimlib and it's error call back,
* deviceInfTimer to get temperature of water, and the * deviceInfTimer to get temperature of water, and the
@@ -35,22 +41,26 @@ public:
* Get Firm ware version * Get Firm ware version
* @return Firm ware version * @return Firm ware version
*/ */
QString getSoftwareVersion(); static QString getSoftwareVersion();
/** /**
* Get Scan data output path * Get Scan data output path
* @return Scan data output path * @return Scan data output path
*/ */
QString getScanOutputPath(); static QString getScanOutputPath();
void setErrorOccurred(bool v) { void setErrorOccurred(bool v) {
errorOccurred = v; mErrorOccurred = v;
} }
bool getErrorOccurred() { bool getErrorOccurred() {
return errorOccurred; return mErrorOccurred;
} }
void emitErrorCallback(const char *msg); void emitErrorCallback(const char *msg);
signals: signals:
void raiseGlobalError(QString msg); void raiseGlobalError(QString msg);
protected: protected:
@@ -89,16 +99,24 @@ private:
* Process scan progress change * Process scan progress change
* @param Scan progress * @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;
}; };

View File

@@ -2,7 +2,7 @@
// Created by Krad on 2021/11/10. // Created by Krad on 2021/11/10.
// //
#include "AccountFormDialog.h" #include "AccountFormDialog.h"
#include "ChangePasswordFormDialog.h"
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QLabel> #include <QLabel>
#include <QUuid> #include <QUuid>
@@ -10,144 +10,71 @@
#include <QToolButton> #include <QToolButton>
#include <QPushButton> #include <QPushButton>
#include <QLineEdit> #include <QLineEdit>
#include "ChangePasswordFormDialog.h"
#include "event/EventCenter.h" #include "event/EventCenter.h"
#include "log/UserOperationLog.h" #include "log/UserOperationLog.h"
#include "db/SQLHelper.h" #include "db/SQLHelper.h"
#include "models/User.h" #include "models/User.h"
#include "components/SlidePickerBox.h"
#include "SelectDialog.h"
#include "AlertDialog.h" #include "AlertDialog.h"
AccountFormDialog::AccountFormDialog(QWidget* parent, AccountEditMode mode, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) { AccountFormDialog::AccountFormDialog(QWidget* parent, AccountEditMode mode, Qt::WindowFlags f)
m_mode = mode; : GUIFormBaseDialog(parent, f)
QVBoxLayout *layout = new QVBoxLayout(formWidget); , mUserNameChanged(false)
layout->setSpacing(10); , mCommentChanged(false)
// add title , mRoleChanged(false)
QLabel *lbl_title = new QLabel(this); , mMode(mode)
lbl_title->setAlignment(Qt::AlignCenter); , mLeUserCode(new QLineEdit(this))
lbl_title->setText(tr("Account")); , mLeUserName(new QLineEdit(this))
lbl_title->setObjectName("title"); , mLeComment(new QLineEdit(this))
layout->addWidget(lbl_title); , mLePwd(nullptr)
, mBtnPwd(nullptr)
//add usercode , mLblError(new QLabel(this))
QLabel *lbl_UserCode = new QLabel(this); , mRefModel(nullptr)
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;
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); auto layout = new QVBoxLayout(mFormWidget);
btn_Logout->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); layout->setSpacing(10);
btn_Logout->setIcon(QIcon(":/icons/logout.png")); addTitleLabel(layout);
btn_Logout->setIconSize({30, 30}); initUserCodeUI(layout);
btn_Logout->setText(tr("Logout")); initUserNameUI(layout);
btn_Logout->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed); if (mMode == New) addNewModeUI(layout);
btn_Logout->setObjectName("editvalBtn"); addCommentLabel(layout);
addWarnLabel(layout);
auto hlayout = new QHBoxLayout;
layout->addLayout(hlayout);
if (mMode == Self)addSelfModeUI(hlayout);
if (mMode != New) {
addButtonPwd(hlayout);
addEndLine(layout);
connect(mBtnPwd, &QPushButton::clicked, this, mMode == Self ?
&AccountFormDialog::changeSelfPassword : &AccountFormDialog::resetUserPassword);
}
hlayout->addWidget(btn_Logout); connect(mLeComment, &QLineEdit::textChanged, [=](const QString &text) {
connect(btn_Logout, &QAbstractButton::clicked, [=]() { mCommentChanged = true;
this->accept(); });
LOG_USER_OPERATION(Logout); connect(mLeUserName, &QLineEdit::textChanged, [=](const QString &text) {
EventCenter::Default()->triggerEvent(GUIEvents::RequestLogin, nullptr, nullptr); mNewUserName = text;
mUserNameChanged = true;
}); });
} }
// load current user data void AccountFormDialog::addEndLine(QVBoxLayout *layout) {
if (m_mode == Self && User::Current()) { auto lblEndline = new QLabel(this);
le_UserCode->setText(User::Current()->getUserCode()); lblEndline->setFixedHeight(2);
le_UserName->setText(User::Current()->getUserName()); lblEndline->setObjectName("endline");
m_UserID = User::Current()->getUserID(); layout->addWidget(lblEndline);
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();
}); void AccountFormDialog::resetUserPassword() {
} else {
connect(btn_Pwd, &QAbstractButton::clicked, [=]() {
AlertDialog dialog(this); AlertDialog dialog(this);
dialog.setGeometry(this->geometry()); dialog.setGeometry(geometry());
dialog.setButtonMode(OkAndCancel); dialog.setButtonMode(OkAndCancel);
dialog.setWindowModality(Qt::WindowModal); dialog.setWindowModality(Qt::WindowModal);
dialog.setAlertMessage(tr("Reset password to \"123456\" ?")); dialog.setAlertMessage(tr("Reset password to \"123456\" ?"));
if (dialog.exec() == Accepted) { if (dialog.exec() == Accepted) {
User user; User user;
dialog.setButtonMode(OkOnly); dialog.setButtonMode(OkOnly);
if (!User::getUser(m_UserID, user)) { if (!User::getUser(mUserID, user)) {
dialog.setAlertMessage(tr("Inner error, can't find reference user!")); dialog.setAlertMessage(tr("Inner error, can't find reference user!"));
dialog.exec(); dialog.exec();
return; return;
@@ -157,96 +84,178 @@ AccountFormDialog::AccountFormDialog(QWidget* parent, AccountEditMode mode, Qt::
dialog.exec(); 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();
} }
} }
connect(le_Comment, &QLineEdit::textChanged, [=](const QString &text) { void AccountFormDialog::addNewModeUI(QVBoxLayout *layout) {
commentChanged = true; auto lblPwd = new QLabel(this);
}); lblPwd->setText(tr("Password"));
connect(le_UserName, &QLineEdit::textChanged, [=](const QString &text) { layout->addWidget(lblPwd);
m_NewUserName = text; mLePwd = new QLineEdit(this);
userNameChanged = true; mLePwd->setPlaceholderText(tr("Input password"));
}); mLePwd->setEchoMode(QLineEdit::Password);
} layout->addWidget(mLePwd);
mRoleID = User::getRoleID("doctor");
AccountFormDialog::~AccountFormDialog() { addEndLine(layout);
} }
bool AccountFormDialog::updateReferenceData() { bool AccountFormDialog::updateReferenceData() {
if (m_mode == Self) { if (mMode == Self) {
if (!this->userNameChanged && !this->commentChanged) return true; if (!this->mUserNameChanged && !this->mCommentChanged) return true;
if (!this->userNameChanged) { if (!this->mUserNameChanged) {
if (m_NewUserName.isEmpty()) { if (mNewUserName.isEmpty()) {
warn(tr("User Name can't be empty!")); warn(tr("User Name can't be empty!"));
return false; 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(); bool ret = User::Current()->submitChange();
if (ret) { if (ret) {
hideWarn(); hideWarn();
LOG_USER_OPERATION(ChangeUserName); LOG_USER_OPERATION(ChangeUserName)
} }
else { else {
warn(tr("Submit change to database fail!")); warn(tr("Submit change to database fail!"));
} }
return ret; return ret;
} }
else if (m_mode == Admin) { else if (mMode == Admin) {
if (!this->userNameChanged && !this->roleChanged) return true; if (!this->mUserNameChanged && !this->mRoleChanged) return true;
User user; User user;
if (!User::getUser(m_UserID, user)) return true; if (!User::getUser(mUserID, user)) return true;
if (this->userNameChanged) { if (this->mUserNameChanged) {
if (m_NewUserName.isEmpty()) { if (mNewUserName.isEmpty()) {
warn(tr("User Name can't be empty!")); warn(tr("User Name can't be empty!"));
return false; return false;
} }
user.setUserName(m_NewUserName); user.setUserName(mNewUserName);
} }
if (this->roleChanged) user.setRoleID(m_RoleID); if (this->mRoleChanged) user.setRoleID(mRoleID);
if (!this->commentChanged) user.setComment(le_Comment->text()); if (!this->mCommentChanged) user.setComment(mLeComment->text());
bool ret = user.submitChange(); bool ret = user.submitChange();
if (ret) { if (ret) {
LOG_USER_OPERATION(AdminChangeAcountInformation); LOG_USER_OPERATION(AdminChangeAcountInformation)
} }
return ret; return ret;
} }
else { else {
//add new //add new
User user; User user;
if (le_UserCode->text().isEmpty()) { if (mLeUserCode->text().isEmpty()) {
warn(tr("User ID can't be empty!")); warn(tr("User ID can't be empty!"));
return false; return false;
} }
if (le_UserName->text().isEmpty()) { if (mLeUserName->text().isEmpty()) {
warn(tr("User Name can't be empty!")); warn(tr("User Name can't be empty!"));
return false; return false;
} }
if (le_Pwd->text().isEmpty()) { if (mLePwd->text().isEmpty()) {
warn(tr("Password can't be empty!")); warn(tr("Password can't be empty!"));
return false; return false;
} }
if (!refmodel) { if (!mRefModel) {
warn(tr("Inner error ,unset data model!")); warn(tr("Inner error ,unset data model!"));
return false; return false;
} }
if (User::existsUser(le_UserCode->text())) { if (User::existsUser(mLeUserCode->text())) {
warn(tr("User Id exists!")); warn(tr("User Id exists!"));
return false; return false;
} }
hideWarn(); hideWarn();
user.setUserName(le_UserName->text()); user.setUserName(mLeUserName->text());
user.setPassword(User::getEncryptedPassword(le_Pwd->text())); user.setPassword(User::getEncryptedPassword(mLePwd->text()));
user.setRoleID(m_RoleID); user.setRoleID(mRoleID);
user.setComment(le_Comment->text()); user.setComment(mLeComment->text());
// User::insertUser(le_UserCode->text(),user); // User::insertUser(le_UserCode->text(),user);
refmodel->insertRow(0); mRefModel->insertRow(0);
refmodel->setData(refmodel->index(0, 0), QUuid::createUuid().toString()); mRefModel->setData(mRefModel->index(0, 0), QUuid::createUuid().toString());
refmodel->setData(refmodel->index(0, 1), le_UserCode->text()); mRefModel->setData(mRefModel->index(0, 1), mLeUserCode->text());
#define USER_READONLY_PROPERTY(name) name, #define USER_READONLY_PROPERTY(name) name,
#define USER_PROPERTY(name)\ #define USER_PROPERTY(name)\
USER_READONLY_PROPERTY(name) USER_READONLY_PROPERTY(name)
@@ -260,16 +269,15 @@ bool AccountFormDialog::updateReferenceData() {
#define USER_READONLY_PROPERTY(name) #define USER_READONLY_PROPERTY(name)
#define USER_PROPERTY(name)\ #define USER_PROPERTY(name)\
USER_READONLY_PROPERTY(name)\ USER_READONLY_PROPERTY(name)\
refmodel->setData(refmodel->index(0, name),user.get##name()); mRefModel->setData(mRefModel->index(0, name),user.get##name());
USER_PROPERTIES_MACRO() USER_PROPERTIES_MACRO()
#undef USER_READONLY_PROPERTY #undef USER_READONLY_PROPERTY
#undef USER_PROPERTY #undef USER_PROPERTY
if (refmodel->submit()) { if (mRefModel->submit()) {
hideWarn(); hideWarn();
return true; return true;
} } else {
else {
warn(tr("Submit to data base fail!")); warn(tr("Submit to data base fail!"));
return false; return false;
} }
@@ -278,18 +286,18 @@ bool AccountFormDialog::updateReferenceData() {
} }
void AccountFormDialog::setAccountInformation(const QMap<QString, QVariant>& values) { void AccountFormDialog::setAccountInformation(const QMap<QString, QVariant>& values) {
le_UserCode->setText(values["UserCode"].toString()); mLeUserCode->setText(values["UserCode"].toString());
le_UserName->setText(values["UserName"].toString()); mLeUserName->setText(values["UserName"].toString());
le_Comment->setText(values["Comment"].toString()); mLeComment->setText(values["Comment"].toString());
m_UserID = values["UserID"].toString(); mUserID = values["UserID"].toString();
m_UserPwd = values["Password"].toString(); mUserPwd = values["Password"].toString();
} }
void AccountFormDialog::warn(QString msg) { void AccountFormDialog::warn(const QString& msg) {
lbl_error->setText(msg); mLblError->setText(msg);
lbl_error->setVisible(true); mLblError->setVisible(true);
} }
void AccountFormDialog::hideWarn() { void AccountFormDialog::hideWarn() {
this->lbl_error->setVisible(false); mLblError->setVisible(false);
} }

View File

@@ -8,6 +8,8 @@ class QLabel;
class QLineEdit; class QLineEdit;
class QToolButton; class QToolButton;
class QSqlTableModel; class QSqlTableModel;
#include <QtWidgets/QVBoxLayout>
#include "GUIFormBaseDialog.h" #include "GUIFormBaseDialog.h"
enum AccountEditMode{ enum AccountEditMode{
@@ -17,32 +19,44 @@ class AccountFormDialog:public GUIFormBaseDialog{
Q_OBJECT Q_OBJECT
public: public:
explicit AccountFormDialog(QWidget *parent = nullptr,AccountEditMode mode = Self,Qt::WindowFlags f = Qt::WindowFlags()); explicit AccountFormDialog(QWidget *parent = nullptr,AccountEditMode mode = Self,Qt::WindowFlags f = Qt::WindowFlags());
~AccountFormDialog(); ~AccountFormDialog() override = default;
void setAccountInformation(const QMap<QString,QVariant>& values); void setAccountInformation(const QMap<QString,QVariant>& values);
void setReferenceModel(QSqlTableModel* model){ void setReferenceModel(QSqlTableModel* model){
refmodel = model; mRefModel = model;
} }
protected: protected:
bool updateReferenceData() override; bool updateReferenceData() override;
void warn(QString msg); void warn(const QString& msg);
void hideWarn(); void hideWarn();
private: private:
QString m_UserID; void addEndLine(QVBoxLayout *layout);
QString m_UserPwd; void addNewModeUI(QVBoxLayout *layout);
QString m_RoleID; void addSelfModeUI(QHBoxLayout *layout);
QString m_NewUserName; void addTitleLabel(QVBoxLayout *layout);
bool userNameChanged = false; void initUserCodeUI(QVBoxLayout *layout);
bool commentChanged = false; void initUserNameUI(QVBoxLayout *layout);
bool roleChanged = false; void addCommentLabel(QVBoxLayout *layout);
AccountEditMode m_mode = Self; void addWarnLabel(QVBoxLayout *layout);
QLineEdit* le_UserCode = nullptr; void addButtonPwd(QHBoxLayout *layout);
QLineEdit* le_UserName = nullptr; void changeSelfPassword();
QLineEdit* le_Comment = nullptr; void resetUserPassword();
QLineEdit* le_Pwd = nullptr; QString mUserID;
QToolButton* btn_Pwd = nullptr; 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;
}; };

View File

@@ -2,33 +2,31 @@
// Created by Krad on 2021/12/8. // Created by Krad on 2021/12/8.
// //
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QLabel>
#include "AlertDialog.h" #include "AlertDialog.h"
AlertDialog::AlertDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) { #include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QLabel>
AlertDialog::AlertDialog(QWidget *parent, Qt::WindowFlags f)
: GUIFormBaseDialog(parent, f)
, mLblMsg(new QLabel(this))
, mLblTitle (new QLabel(this))
{
this->setFixedHeight(180); this->setFixedHeight(180);
this->setFixedWidth(400); this->setFixedWidth(400);
QVBoxLayout* layout = new QVBoxLayout(formWidget); auto layout = new QVBoxLayout(mFormWidget);
layout->setSpacing(10); layout->setSpacing(10);
// add title // add title
lbl_title = new QLabel(this); mLblTitle->setAlignment(Qt::AlignCenter);
lbl_title->setAlignment(Qt::AlignCenter); mLblTitle->setText(tr("Warning"));
lbl_title->setText(tr("Warning")); mLblTitle->setObjectName("title");
lbl_title->setObjectName("title"); layout->addWidget(mLblTitle);
layout->addWidget(lbl_title); layout->addWidget(mLblMsg);}
lbl_msg = new QLabel(this);
layout->addWidget(lbl_msg);
}
AlertDialog::~AlertDialog() {
}
void AlertDialog::setAlertMessage(const QString &msg) { void AlertDialog::setAlertMessage(const QString &msg) {
this->lbl_msg->setText(msg); mLblMsg->setText(msg);
} }
void AlertDialog::setTitle(const QString &msg) { void AlertDialog::setTitle(const QString &msg) {
lbl_title->setText(msg); mLblTitle->setText(msg);
} }

View File

@@ -10,15 +10,15 @@ class AlertDialog :public GUIFormBaseDialog{
Q_OBJECT Q_OBJECT
public: public:
explicit AlertDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); explicit AlertDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
~AlertDialog(); ~AlertDialog() override = default;
void setAlertMessage(const QString& msg); void setAlertMessage(const QString& msg);
void setTitle(const QString& msg); void setTitle(const QString& msg);
protected: protected:
bool updateReferenceData() override{return true;} bool updateReferenceData() override{return true;}
private: private:
QLabel* lbl_msg; QLabel* mLblMsg;
QLabel* lbl_title; QLabel* mLblTitle;
}; };

View File

@@ -9,82 +9,88 @@
#include "log/UserOperationLog.h" #include "log/UserOperationLog.h"
#include "ChangePasswordFormDialog.h" #include "ChangePasswordFormDialog.h"
ChangePasswordFormDialog::ChangePasswordFormDialog(QWidget* parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) { ChangePasswordFormDialog::ChangePasswordFormDialog(QWidget* parent, Qt::WindowFlags f)
QVBoxLayout* layout = new QVBoxLayout(formWidget); : GUIFormBaseDialog(parent, f)
, mLEPasswd(new QLineEdit(this))
, mLENewPasswd(new QLineEdit(this))
, mLEConfirmPasswd(new QLineEdit(this))
, mLblError(new QLabel(this))
{
initLayout();
}
void ChangePasswordFormDialog::initLayout() {
auto layout = new QVBoxLayout(mFormWidget);
layout->setSpacing(10); layout->setSpacing(10);
// add title // add title
QLabel* lbl_title = new QLabel(this); auto lblTitle = new QLabel(this);
lbl_title->setAlignment(Qt::AlignCenter); lblTitle->setAlignment(Qt::AlignCenter);
lbl_title->setText(tr("Change Password")); lblTitle->setText(tr("Change Password"));
lbl_title->setObjectName("title"); lblTitle->setObjectName("title");
layout->addWidget(lbl_title); layout->addWidget(lblTitle);
//add old password //add old password
QLabel* lbl_Old = new QLabel(this); auto lblOld = new QLabel(this);
lbl_Old->setText(tr("Current Password")); lblOld->setText(tr("Current Password"));
pwd = new QLineEdit(this);
pwd->setEchoMode(QLineEdit::Password); mLEPasswd->setEchoMode(QLineEdit::Password);
layout->addWidget(lbl_Old); layout->addWidget(lblOld);
layout->addWidget(pwd); layout->addWidget(mLEPasswd);
QLabel* lbl_endline1 = new QLabel(this); auto lblEndline1 = new QLabel(this);
lbl_endline1->setObjectName("endline"); lblEndline1->setObjectName("endline");
layout->addWidget(lbl_endline1); layout->addWidget(lblEndline1);
//add new password //add new password
QLabel* lbl_New = new QLabel(this); auto lblNewPasswd = new QLabel(this);
lbl_New->setText(tr("New Password")); lblNewPasswd->setText(tr("New Password"));
new_pwd = new QLineEdit(this);
new_pwd->setEchoMode(QLineEdit::Password); mLENewPasswd->setEchoMode(QLineEdit::Password);
layout->addWidget(lbl_New); layout->addWidget(lblNewPasswd);
layout->addWidget(new_pwd); layout->addWidget(mLENewPasswd);
QLabel* lbl_endline2 = new QLabel(this); auto lblEndline2 = new QLabel(this);
lbl_endline2->setObjectName("endline"); lblEndline2->setObjectName("endline");
layout->addWidget(lbl_endline2); layout->addWidget(lblEndline2);
//add confirm password //add confirm password
QLabel* lbl_Confirm = new QLabel(this); auto lblConfirm = new QLabel(this);
lbl_Confirm->setText(tr("Confirm Password")); lblConfirm->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); mLEConfirmPasswd->setEchoMode(QLineEdit::Password);
lbl_error->setObjectName("warn"); layout->addWidget(lblConfirm);
layout->addWidget(lbl_error); layout->addWidget(mLEConfirmPasswd);
auto lblEndline3 = new QLabel(this);
lblEndline3->setObjectName("endline");
layout->addWidget(lblEndline3);
mLblError->setObjectName("warn");
layout->addWidget(mLblError);
} }
ChangePasswordFormDialog::~ChangePasswordFormDialog() {
}
bool ChangePasswordFormDialog::updateReferenceData() { 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; return false;
} }
if (new_pwd->text().length() < 6) { if (mLENewPasswd->text().length() < 6) {
lbl_error->setText(tr("New password should at least 6 characters!")); mLblError->setText(tr("New password should at least 6 characters!"));
return false; return false;
} }
QString encryptPwd = User::getEncryptedPassword(pwd->text()); QString encryptPwd = User::getEncryptedPassword(mLEPasswd->text());
if (encryptPwd != User::Current()->getPassword()) if (encryptPwd != User::Current()->getPassword())
{ {
lbl_error->setText(tr("Wrong password!")); mLblError->setText(tr("Wrong password!"));
return false; 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; return false;
} }
User::Current()->setPassword(User::getEncryptedPassword(new_pwd->text())); User::Current()->setPassword(User::getEncryptedPassword(mLENewPasswd->text()));
if (!User::Current()->submitChange()) { if (!User::Current()->submitChange()) {
lbl_error->setText(tr("Database update error!")); mLblError->setText(tr("Database update error!"));
User::Current()->restorePassword(encryptPwd); User::Current()->restorePassword(encryptPwd);
return false; return false;
} }

View File

@@ -12,16 +12,19 @@ class ChangePasswordFormDialog:public GUIFormBaseDialog{
Q_OBJECT Q_OBJECT
public: public:
explicit ChangePasswordFormDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); explicit ChangePasswordFormDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
~ChangePasswordFormDialog(); ~ChangePasswordFormDialog() override = default;
protected: protected:
bool updateReferenceData() override; bool updateReferenceData() override;
private: private:
QLineEdit* pwd = nullptr; void initLayout();
QLineEdit* new_pwd = nullptr; QLineEdit* mLEPasswd;
QLineEdit* confirm_pwd = nullptr; QLineEdit* mLENewPasswd;
QLabel* lbl_error = nullptr; QLineEdit* mLEConfirmPasswd;
QLabel* mLblError;
}; };

View File

@@ -3,63 +3,52 @@
// //
#include "GUIFormBaseDialog.h" #include "GUIFormBaseDialog.h"
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QPushButton> #include <QPushButton>
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->setObjectName("formDialog");
this->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog); this->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
// this->setFixedSize(500,600);
this->setFixedWidth(500); this->setFixedWidth(500);
this->formWidget = new QWidget(this); this->mFormWidget->setObjectName("formWidget");
this->formWidget->setObjectName("formWidget"); auto vLayout = new QVBoxLayout(this);
vLayout->addWidget(mFormWidget);
QVBoxLayout* vLayout = new QVBoxLayout(this); vLayout->addWidget(mBtnWidget);
// vLayout->setContentsMargins(680,100,680,100); auto hLayout = new QHBoxLayout(mBtnWidget);
vLayout->addWidget(formWidget); hLayout->addWidget(mBtnOk);
hLayout->addWidget(mBtnCancel);
QWidget* btnWidget = new QWidget(this); mBtnOk->setObjectName("btnOK");
vLayout->addWidget(btnWidget); connect(mBtnOk, &QPushButton::clicked, [=]() {
QHBoxLayout* hLayout = new QHBoxLayout(btnWidget); if (updateReferenceData()) accept();
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]() { connect(mBtnCancel, &QPushButton::clicked, [=]() {
t->reject(); reject();
}); });
} }
GUIFormBaseDialog::~GUIFormBaseDialog() {
}
void GUIFormBaseDialog::setButtonMode(DialogButtonMode mode) { void GUIFormBaseDialog::setButtonMode(DialogButtonMode mode) {
switch (mode) { switch (mode) {
case OkOnly: case OkOnly: {
{ mBtnOk->setVisible(true);
btnOk->setVisible(true); mBtnCancel->setVisible(false);
btnCancel->setVisible(false);
return; return;
} }
case OkAndCancel: case OkAndCancel: {
{ mBtnOk->setVisible(true);
btnOk->setVisible(true); mBtnCancel->setVisible(true);
btnCancel->setVisible(true);
return; return;
} }
case None: case None:
default: default: {
{ mBtnOk->setVisible(false);
btnOk->setVisible(false); mBtnCancel->setVisible(false);
btnCancel->setVisible(false);
} }
} }
} }

View File

@@ -13,15 +13,16 @@ class GUIFormBaseDialog: public QDialog {
Q_OBJECT Q_OBJECT
public: public:
explicit GUIFormBaseDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); explicit GUIFormBaseDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
~GUIFormBaseDialog(); ~GUIFormBaseDialog() override = default;
void setButtonMode(DialogButtonMode mode); void setButtonMode(DialogButtonMode mode);
protected: protected:
virtual bool updateReferenceData(){ virtual bool updateReferenceData(){
return false; return false;
}; };
QWidget* formWidget = nullptr; QWidget* mFormWidget;
QPushButton* btnCancel = nullptr; QWidget* mBtnWidget;
QPushButton* btnOk = nullptr; QPushButton* mBtnCancel;
QPushButton* mBtnOk;
}; };

View File

@@ -3,20 +3,19 @@
// //
#include "SelectDialog.h" #include "SelectDialog.h"
#include "components/SlidePickerBox.h" #include "components/SlidePickerBox.h"
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QLabel> #include <QLabel>
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); this->setFixedSize(360, 380);
QVBoxLayout* layout = new QVBoxLayout(formWidget); auto layout = new QVBoxLayout(mFormWidget);
box = new SlidePickerBox(formWidget); mPickBox->setObjectName("slider_one");
box->setObjectName("slider_one"); layout->addWidget(mPickBox);
layout->addWidget(box);
}
SelectDialog::~SelectDialog() {
} }
@@ -25,13 +24,13 @@ bool SelectDialog::updateReferenceData() {
} }
void SelectDialog::setValues(const QStringList& dates) { void SelectDialog::setValues(const QStringList& dates) {
box->setItems(dates); mPickBox->setItems(dates);
} }
QString SelectDialog::getSelectedValue() { QString SelectDialog::getSelectedValue() {
return box->getSelectedValue(); return mPickBox->getSelectedValue();
} }
void SelectDialog::setSelectedValue(const QString& val) { void SelectDialog::setSelectedValue(const QString& val) {
box->setSelectedValue(val); mPickBox->setSelectedValue(val);
} }

View File

@@ -11,13 +11,13 @@ class SelectDialog :public GUIFormBaseDialog{
Q_OBJECT Q_OBJECT
public: public:
explicit SelectDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); explicit SelectDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
~SelectDialog() override; ~SelectDialog() override = default;
void setValues(const QStringList& values); void setValues(const QStringList& values);
QString getSelectedValue(); QString getSelectedValue();
void setSelectedValue(const QString& val); void setSelectedValue(const QString& val);
protected: protected:
bool updateReferenceData() override; bool updateReferenceData() override;
SlidePickerBox* box = nullptr; SlidePickerBox* mPickBox;
}; };

View File

@@ -4,32 +4,43 @@
#include "event/EventCenter.h" #include "event/EventCenter.h"
#include <QToolButton> #include <QToolButton>
#include <QHBoxLayout> #include <QHBoxLayout>
GUIMessageDialog::GUIMessageDialog(QWidget *parent) : GUIMessageDialog::GUIMessageDialog(QWidget *parent)
QDialog(parent), : QDialog(parent)
ui(new Ui::GUIMessageDialog) , 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->setObjectName("MessageDialog");
this->setWindowFlags (Qt :: FramelessWindowHint | Qt :: Dialog); this->setWindowFlags (Qt :: FramelessWindowHint | Qt :: Dialog);
this->showFullScreen (); this->showFullScreen ();
ui->lbl_msg->setVisible(false); initBaseLayout();
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);
this->setWindowOpacity(0.6); this->setWindowOpacity(0.6);
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++) for (int i=1; i <= 6; i++)
{ {
QString str(" "); QString str(" ");
@@ -37,7 +48,7 @@ GUIMessageDialog::GUIMessageDialog(QWidget *parent) :
{ {
str[j]='.'; str[j]='.';
} }
frame.append(str); mFrame.append(str);
} }
for (int i=1; i<=6;i++) for (int i=1; i<=6;i++)
{ {
@@ -46,60 +57,60 @@ GUIMessageDialog::GUIMessageDialog(QWidget *parent) :
{ {
str[j]=' '; str[j]=' ';
} }
frame.append(str); mFrame.append(str);
} }
} }
GUIMessageDialog::~GUIMessageDialog() GUIMessageDialog::~GUIMessageDialog()
{ {
delete ui; delete mUI;
} }
void GUIMessageDialog::timerEvent(QTimerEvent *event) { void GUIMessageDialog::timerEvent(QTimerEvent *event) {
if (frameIndex>11) frameIndex = frameIndex % 12; if (mFrameIndex > 11) mFrameIndex = mFrameIndex % 12;
ui->lbl_progressicon->setText(frame[frameIndex++]); mUI->lblProgressIcon->setText(mFrame[mFrameIndex++]);
this->update(); this->update();
} }
void GUIMessageDialog::stopLoading() { void GUIMessageDialog::stopLoading() {
if (timerID!=-1){ if (mTimerID != -1){
killTimer(timerID); killTimer(mTimerID);
timerID=-1; mTimerID=-1;
} }
disconnect(btn_main,0,0,0); disconnect(mBtnMain, nullptr, nullptr, nullptr);
ui->lbl_progressicon->setVisible(false); mUI->lblProgressIcon->setVisible(false);
} }
void GUIMessageDialog::startLoading() { void GUIMessageDialog::startLoading() {
ui->lbl_progressicon->setVisible(true); mUI->lblProgressIcon->setVisible(true);
disconnect(btn_main,0,0,0); disconnect(mBtnMain, nullptr, nullptr, nullptr);
connect(btn_main,&QToolButton::clicked,[=](){ connect(mBtnMain, &QToolButton::clicked, [=](){
if (timerID != -1){ if (mTimerID != -1){
killTimer(timerID); killTimer(mTimerID);
timerID = -1; mTimerID = -1;
} }
accept(); accept();
EventCenter::Default()->triggerEvent(GUIEvents::RequestStop, nullptr, nullptr); EventCenter::Default()->triggerEvent(GUIEvents::RequestStop, nullptr, nullptr);
LOG_USER_OPERATION(Stop); LOG_USER_OPERATION(Stop);
}); });
timerID = startTimer(100); mTimerID = startTimer(100);
btn_main->setText("Stop"); mBtnMain->setText("Stop");
btn_main->setVisible(true); mBtnMain->setVisible(true);
} }
void GUIMessageDialog::showMessage(QString msg) { void GUIMessageDialog::showMessage(const QString& msg) {
ui->lbl_msg->setVisible(true); mUI->lblMsg->setVisible(true);
ui->lbl_msg->setText(msg); mUI->lblMsg->setText(msg);
} }
void GUIMessageDialog::showExitButton() { void GUIMessageDialog::showExitButton() {
btn_main->setText("OK"); mBtnMain->setText("OK");
btn_main->setVisible(true); mBtnMain->setVisible(true);
disconnect(btn_main,0,0,0); disconnect(mBtnMain, nullptr, nullptr, nullptr);
connect(btn_main,&QToolButton::clicked,[=](){ connect(mBtnMain, &QToolButton::clicked, [=](){
if (timerID != -1){ if (mTimerID != -1){
killTimer(timerID); killTimer(mTimerID);
timerID = -1; mTimerID = -1;
} }
accept(); accept();
LOG_USER_OPERATION(ConfirmError); LOG_USER_OPERATION(ConfirmError);
@@ -107,13 +118,13 @@ void GUIMessageDialog::showExitButton() {
} }
void GUIMessageDialog::hideMessage() { void GUIMessageDialog::hideMessage() {
ui->lbl_msg->setVisible(false); mUI->lblMsg->setVisible(false);
ui->lbl_msg->setText(""); mUI->lblMsg->setText("");
} }
void GUIMessageDialog::hideExitButton() { void GUIMessageDialog::hideExitButton() {
btn_main->setVisible(false); mBtnMain->setVisible(false);
disconnect(btn_main,0,0,0); disconnect(mBtnMain, nullptr, nullptr, nullptr);
} }
void GUIMessageDialog::setOpacity(double opacity) { void GUIMessageDialog::setOpacity(double opacity) {
@@ -121,18 +132,18 @@ void GUIMessageDialog::setOpacity(double opacity) {
} }
void GUIMessageDialog::startPending() { void GUIMessageDialog::startPending() {
disconnect(btn_Append,0,0,0); disconnect(mBtnAppend, nullptr, nullptr, nullptr);
connect(btn_Append,&QToolButton::clicked,[=](){ connect(mBtnAppend, &QToolButton::clicked, [=](){
EventCenter::Default()->triggerEvent(GUIEvents::RequestContinueScan, nullptr, nullptr); EventCenter::Default()->triggerEvent(GUIEvents::RequestContinueScan, nullptr, nullptr);
stopPending(); stopPending();
}); });
btn_Append->setText("Next"); mBtnAppend->setText("Next");
btn_Append->setVisible(true); mBtnAppend->setVisible(true);
pending = true; mPending = true;
} }
void GUIMessageDialog::stopPending() { void GUIMessageDialog::stopPending() {
disconnect(btn_Append,0,0,0); disconnect(mBtnAppend, nullptr, nullptr, nullptr);
btn_Append->setVisible(false); mBtnAppend->setVisible(false);
pending = false; mPending = false;
} }

View File

@@ -13,8 +13,8 @@ class GUIMessageDialog : public QDialog
public: public:
explicit GUIMessageDialog(QWidget *parent = nullptr); explicit GUIMessageDialog(QWidget *parent = nullptr);
~GUIMessageDialog(); ~GUIMessageDialog() override;
void showMessage(QString msg); void showMessage(const QString& msg);
void hideMessage(); void hideMessage();
void showExitButton(); void showExitButton();
void hideExitButton(); void hideExitButton();
@@ -23,19 +23,21 @@ public:
void startPending(); void startPending();
void stopPending(); void stopPending();
bool Pending(){ bool Pending(){
return pending; return mPending;
} }
void setOpacity(double); void setOpacity(double);
protected: protected:
void timerEvent(QTimerEvent* event) override ; void timerEvent(QTimerEvent* event) override ;
private: private:
Ui::GUIMessageDialog *ui; void initBaseLayout();
QList<QString> frame; void initLoadingFrameString();
QToolButton *btn_main; Ui::GUIMessageDialog *mUI;
QToolButton *btn_Append; QList<QString> mFrame;
int frameIndex=0; QToolButton *mBtnMain;
int timerID = -1; QToolButton *mBtnAppend;
bool pending = false; int mFrameIndex;
int mTimerID;
bool mPending;
}; };
#endif // GUIMESSAGEDIALOG_H #endif // GUIMESSAGEDIALOG_H

View File

@@ -36,7 +36,7 @@
<widget class="QWidget" name="innerWidget" native="true"> <widget class="QWidget" name="innerWidget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QWidget" name="widget_2" native="true"> <widget class="QWidget" name="btnContainerWidget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<widget class="QWidget" name="widget" native="true"> <widget class="QWidget" name="widget" native="true">
@@ -58,7 +58,7 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QLabel" name="lbl_msg"> <widget class="QLabel" name="lblMsg">
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
@@ -71,7 +71,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="lbl_progressicon"> <widget class="QLabel" name="lblProgressIcon">
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>

View File

@@ -4,61 +4,62 @@
#include "event/EventCenter.h" #include "event/EventCenter.h"
#include "json/ScanJson.h" #include "json/ScanJson.h"
PatientInformationForm::PatientInformationForm(QWidget* parent) : PatientInformationForm::PatientInformationForm(QWidget* parent)
QWidget(parent), : QWidget(parent)
ui(new Ui::PatientInformationForm) , mUI(new Ui::PatientInformationForm)
, mInfo(nullptr)
, mJsonStr(nullptr)
{ {
ui->setupUi(this); mUI->setupUi(this);
connect(EventCenter::Default(), &EventCenter::ReloadLanguage, [=]() { connect(EventCenter::Default(), &EventCenter::ReloadLanguage, [=]() {
ui->retranslateUi(this); mUI->retranslateUi(this);
}); });
} }
PatientInformationForm::~PatientInformationForm() PatientInformationForm::~PatientInformationForm()
{ {
delete ui; delete mUI;
delete inf; delete mInfo;
delete jsonstr; delete mJsonStr;
} }
void PatientInformationForm::setPatientInformation(PatientInformation* information) { void PatientInformationForm::setPatientInformation(PatientInformation* information) {
ui->lbl_ID->setText(information->ID); mUI->lbl_ID->setText(information->ID);
ui->lbl_Date->setText(information->BirthDate); mUI->lbl_Date->setText(information->BirthDate);
ui->lbl_Name->setText(information->Name); mUI->lbl_Name->setText(information->Name);
ui->lbl_Sex->setText(information->Sex); mUI->lbl_Sex->setText(information->Sex);
inf = information; mInfo = information;
} }
void PatientInformationForm::setProtocol(int type) { void PatientInformationForm::setProtocol(int type) {
currentProtocol = type; mCurrentProtocol = type;
switch (type) switch (type)
{ {
case 0: case 0:
ui->lbl_Protocol->setText(tr("LEFT ONLY")); mUI->lbl_Protocol->setText(tr("LEFT ONLY"));
break; break;
case 1: case 1:
default: default:
ui->lbl_Protocol->setText(tr("RIGHT ONLY")); mUI->lbl_Protocol->setText(tr("RIGHT ONLY"));
break; break;
} }
} }
const char* PatientInformationForm::getCurrentPatientJsonString(bool empty) { const char* PatientInformationForm::getCurrentPatientJsonString(bool empty) {
cJSON* root = cJSON_CreateObject(); cJSON* root = cJSON_CreateObject();
cJSON_AddItemToObject(root, "PatientName", cJSON_CreateString(ui->lbl_Name->text().replace(' ', '_').toStdString().data())); cJSON_AddItemToObject(root, "PatientName", cJSON_CreateString(mUI->lbl_Name->text().replace(' ', '_').toStdString().data()));
cJSON_AddItemToObject(root, "PatientID", cJSON_CreateString(ui->lbl_ID->text().replace(' ', '_').toStdString().data())); cJSON_AddItemToObject(root, "PatientID", cJSON_CreateString(mUI->lbl_ID->text().replace(' ', '_').toStdString().data()));
cJSON_AddItemToObject(root, "PatientSex", cJSON_CreateString(ui->lbl_Sex->text().toStdString().data())); cJSON_AddItemToObject(root, "PatientSex", cJSON_CreateString(mUI->lbl_Sex->text().toStdString().data()));
cJSON_AddItemToObject(root, "PatientBirthDate", cJSON_AddItemToObject(root, "PatientBirthDate",
cJSON_CreateString(ui->lbl_Date->text().replace("/", "").replace("-", "").replace(' ', '.').toStdString().data())); cJSON_CreateString(mUI->lbl_Date->text().replace("/", "").replace("-", "").replace(' ', '.').toStdString().data()));
cJSON_AddItemToObject(root, "Laterality", cJSON_CreateString(currentProtocol ? "R" : "L")); cJSON_AddItemToObject(root, "Laterality", cJSON_CreateString(mCurrentProtocol ? "R" : "L"));
cJSON_AddItemToObject(root, "IsEmptyData", cJSON_CreateNumber(empty ? 1 : 0)); cJSON_AddItemToObject(root, "IsEmptyData", cJSON_CreateNumber(empty ? 1 : 0));
cJSON_AddItemToObject(root, "OperatorName", cJSON_CreateString("Bob")); cJSON_AddItemToObject(root, "OperatorName", cJSON_CreateString("Bob"));
cJSON_AddItemToObject(root, "ReferringPhysicianName", cJSON_CreateString("XX")); cJSON_AddItemToObject(root, "ReferringPhysicianName", cJSON_CreateString("XX"));
cJSON_AddItemToObject(root, "InstitutionName", cJSON_CreateString("EQ9")); cJSON_AddItemToObject(root, "InstitutionName", cJSON_CreateString("EQ9"));
cJSON_AddItemToObject(root, "InstitutionAddress", cJSON_CreateString("HZ")); cJSON_AddItemToObject(root, "InstitutionAddress", cJSON_CreateString("HZ"));
delete jsonstr; delete mJsonStr;
jsonstr = cJSON_Print(root); mJsonStr = cJSON_Print(root);
ScanJson::Current()->store(root); ScanJson::Current()->store(root);
return jsonstr; return mJsonStr;
} }

View File

@@ -13,15 +13,15 @@ class PatientInformationForm : public QWidget
public: public:
explicit PatientInformationForm(QWidget *parent = nullptr); explicit PatientInformationForm(QWidget *parent = nullptr);
~PatientInformationForm(); ~PatientInformationForm() override;
void setPatientInformation(PatientInformation* information); void setPatientInformation(PatientInformation* information);
void setProtocol(int type); void setProtocol(int type);
const char * getCurrentPatientJsonString(bool emptyScan); const char * getCurrentPatientJsonString(bool emptyScan);
private: private:
Ui::PatientInformationForm *ui; Ui::PatientInformationForm *mUI;
PatientInformation* inf = nullptr; PatientInformation* mInfo = nullptr;
int currentProtocol = 0; int mCurrentProtocol = 0;
char * jsonstr = nullptr; char * mJsonStr = nullptr;
}; };
#endif // PATIENTINFORMATIONFORM_H #endif // PATIENTINFORMATIONFORM_H

View File

@@ -36,7 +36,7 @@ bool User::submitChange() {
#undef USER_READONLY_PROPERTY #undef USER_READONLY_PROPERTY
if (!needUpdate) return true; if (!needUpdate) return true;
QString whereString = " where "+getIndexName()+" = '"+getIndexValue()+"'"; QString whereString = " where "+getIndexName()+" = '"+getIndexValue()+"'";
bool result = 1 == SQLHelper::ExecuteNoQuery(updateSQL.arg(setString,whereString),&params); bool result = 1 == SQLHelper::ExecuteNoQuery(updateSQL.arg(setString,whereString),params);
if (result) if (result)
{ {
#define USER_READONLY_PROPERTY(name) #define USER_READONLY_PROPERTY(name)
@@ -55,7 +55,7 @@ bool User::QueryUser(const QString& userID, const QString& Pwd) {
QMap<QString,QVariant> params; QMap<QString,QVariant> params;
params[":userID"] = userID; params[":userID"] = userID;
params[":pwd"] = Pwd; params[":pwd"] = Pwd;
SQLHelper::QueryFirst(sql, map, &params); SQLHelper::QueryFirst(sql, map, params);
if(!map.isEmpty()) if(!map.isEmpty())
{ {
// first login // first login
@@ -87,7 +87,7 @@ bool User::existsUser(const QString& userCode) {
QMap<QString,QVariant> map; QMap<QString,QVariant> map;
QMap<QString,QVariant> params; QMap<QString,QVariant> params;
params[":userID"] = userCode; params[":userID"] = userCode;
SQLHelper::QueryFirst(sql, map, &params); SQLHelper::QueryFirst(sql, map, params);
return !map.isEmpty(); return !map.isEmpty();
} }
@@ -96,7 +96,7 @@ bool User::getUser(const QString& userUID, User& user) {
QMap<QString,QVariant> map; QMap<QString,QVariant> map;
QMap<QString,QVariant> params; QMap<QString,QVariant> params;
params[":userUID"] = userUID; params[":userUID"] = userUID;
SQLHelper::QueryFirst(sql, map, &params); SQLHelper::QueryFirst(sql, map, params);
if(!map.isEmpty()) if(!map.isEmpty())
{ {
#define USER_READONLY_PROPERTY(name) user.m_##name = map[#name].toString(); #define USER_READONLY_PROPERTY(name) user.m_##name = map[#name].toString();
@@ -119,7 +119,7 @@ QString User::getRoleName(const QString& RoleID) {
QMap<QString,QVariant> map; QMap<QString,QVariant> map;
QMap<QString,QVariant> params; QMap<QString,QVariant> params;
params[":RoleID"] = RoleID; params[":RoleID"] = RoleID;
SQLHelper::QueryFirst(sql, map, &params); SQLHelper::QueryFirst(sql, map, params);
roleCache[RoleID] = map["RoleName"].toString(); roleCache[RoleID] = map["RoleName"].toString();
return map["RoleName"].toString(); return map["RoleName"].toString();
} }
@@ -133,7 +133,7 @@ QString User::getRoleID(const QString& RoleName) {
QMap<QString,QVariant> map; QMap<QString,QVariant> map;
QMap<QString,QVariant> params; QMap<QString,QVariant> params;
params[":RoleName"] = RoleName; params[":RoleName"] = RoleName;
SQLHelper::QueryFirst(sql, map, &params); SQLHelper::QueryFirst(sql, map, params);
roleCache[map["RoleID"].toString()] = RoleName; roleCache[map["RoleID"].toString()] = RoleName;
return map["RoleID"].toString(); return map["RoleID"].toString();
} }
@@ -171,7 +171,7 @@ bool User::insertUser(const QString& UserCode, User &user) {
USER_PROPERTIES_MACRO() USER_PROPERTIES_MACRO()
#undef USER_PROPERTY #undef USER_PROPERTY
#undef USER_READONLY_PROPERTY #undef USER_READONLY_PROPERTY
bool result = 1 == SQLHelper::ExecuteNoQuery(updateSQL.arg(namesString,valuesString),&params); bool result = 1 == SQLHelper::ExecuteNoQuery(updateSQL.arg(namesString,valuesString),params);
return result; return result;
} }

View File

@@ -14,7 +14,7 @@ class DicomCfgDialog : public QDialog
public: public:
explicit DicomCfgDialog(QWidget* aParent = nullptr); explicit DicomCfgDialog(QWidget* aParent = nullptr);
~DicomCfgDialog(); ~DicomCfgDialog() override;
private: private:
Ui::DicomCfgDialog* mUi; Ui::DicomCfgDialog* mUi;

View File

@@ -17,7 +17,7 @@ GetAdminPsw::GetAdminPsw(QWidget* parent, Qt::WindowFlags f)
, mLabelError(new QLabel(this)) , mLabelError(new QLabel(this))
{ {
setWindowModality(Qt::WindowModal); setWindowModality(Qt::WindowModal);
QFormLayout* formLayout = new QFormLayout(formWidget); QFormLayout* formLayout = new QFormLayout(mFormWidget);
QString value1 = QString(tr("Admin Password")); QString value1 = QString(tr("Admin Password"));
mPsw->setEchoMode(QLineEdit::Password); mPsw->setEchoMode(QLineEdit::Password);
formLayout->addRow(value1, mPsw); formLayout->addRow(value1, mPsw);

View File

@@ -17,7 +17,7 @@ GetIPDialog::GetIPDialog(QWidget* parent, Qt::WindowFlags f)
, mLabelError(new QLabel(this)) , mLabelError(new QLabel(this))
{ {
setWindowModality(Qt::WindowModal); setWindowModality(Qt::WindowModal);
QFormLayout* formLayout = new QFormLayout(formWidget); QFormLayout* formLayout = new QFormLayout(mFormWidget);
QLabel* IpValue = new QLabel(tr("IP Address")); QLabel* IpValue = new QLabel(tr("IP Address"));
formLayout->addRow(IpValue, mIp); formLayout->addRow(IpValue, mIp);

View File

@@ -18,7 +18,7 @@ GetRouteDialog::GetRouteDialog(QWidget* parent, Qt::WindowFlags f)
, mLabelError(new QLabel(this)) , mLabelError(new QLabel(this))
{ {
setWindowModality(Qt::WindowModal); setWindowModality(Qt::WindowModal);
QFormLayout* formLayout = new QFormLayout(formWidget); QFormLayout* formLayout = new QFormLayout(mFormWidget);
formLayout->addRow(QString(tr("Destination")), mDestination); formLayout->addRow(QString(tr("Destination")), mDestination);
formLayout->addRow(QString(tr("Netmask")), mNetmask); formLayout->addRow(QString(tr("Netmask")), mNetmask);
formLayout->addRow(QString(tr("Gateway")), mGateway); formLayout->addRow(QString(tr("Gateway")), mGateway);

View File

@@ -19,7 +19,7 @@ class NetworkCfgDialog : public QDialog
public: public:
//static void setShadow(QDialog* dialog); //static void setShadow(QDialog* dialog);
explicit NetworkCfgDialog(QWidget* parent = nullptr); explicit NetworkCfgDialog(QWidget* parent = nullptr);
~NetworkCfgDialog(); ~NetworkCfgDialog() override;
void loadData(); void loadData();
void applyData(); void applyData();