Refactor DialogManager.1
This commit is contained in:
@@ -10,13 +10,13 @@
|
|||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
|
||||||
#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 "AlertDialog.h"
|
#include "AlertDialog.h"
|
||||||
#include "components/ULineEdit.h"
|
#include "components/ULineEdit.h"
|
||||||
|
#include "DialogManager.h"
|
||||||
|
|
||||||
AccountFormDialog::AccountFormDialog(QWidget* parent, AccountEditMode mode, Qt::WindowFlags f)
|
AccountFormDialog::AccountFormDialog(QWidget* parent, AccountEditMode mode, Qt::WindowFlags f)
|
||||||
: GUIFormBaseDialog(parent, f)
|
: GUIFormBaseDialog(parent, f)
|
||||||
@@ -95,10 +95,7 @@ void AccountFormDialog::resetUserPassword()
|
|||||||
|
|
||||||
void AccountFormDialog::changeSelfPassword()
|
void AccountFormDialog::changeSelfPassword()
|
||||||
{
|
{
|
||||||
ChangePasswordFormDialog dia(this);
|
DialogManager::Default()->requestChangePassword();
|
||||||
dia.setGeometry(geometry());
|
|
||||||
dia.setWindowModality(Qt::WindowModal);
|
|
||||||
dia.exec();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountFormDialog::addButtonPwd(QHBoxLayout* layout)
|
void AccountFormDialog::addButtonPwd(QHBoxLayout* layout)
|
||||||
|
|||||||
@@ -6,10 +6,24 @@
|
|||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
#include "event/EventCenter.h"
|
#include "event/EventCenter.h"
|
||||||
#include "dialogs/GUIMessageDialog.h"
|
#include "dialogs/GUIMessageDialog.h"
|
||||||
|
#include "dialogs/ChangePasswordFormDialog.h"
|
||||||
|
#include "dialogs/AccountFormDialog.h"
|
||||||
#include "appvals/AppGlobalValues.h"
|
#include "appvals/AppGlobalValues.h"
|
||||||
|
#include "windows/LoginDialog.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
DialogManager::DialogManager()
|
||||||
|
: QObject()
|
||||||
|
, mFunctionDialog(nullptr)
|
||||||
|
, mMessageDialog(nullptr)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void DialogManager::init() {
|
void DialogManager::init() {
|
||||||
connect(EventCenter::Default(), &EventCenter::DeviceErrorRaise,this,&DialogManager::raiseDeviceError);
|
connect(EventCenter::Default(), &EventCenter::DeviceErrorRaise,this,&DialogManager::raiseDeviceError);
|
||||||
@@ -24,36 +38,86 @@ QWidget *DialogManager::getTopWidget() {
|
|||||||
return QApplication::activeWindow();
|
return QApplication::activeWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DialogManager::requestLogin()
|
||||||
|
{
|
||||||
|
//Login 直接最顶层模态
|
||||||
|
if (!mFunctionDialog){
|
||||||
|
mFunctionDialog = new LoginDialog;
|
||||||
|
}
|
||||||
|
mFunctionDialog->exec();
|
||||||
|
while (QDialog::Accepted != mFunctionDialog->result())
|
||||||
|
{
|
||||||
|
mFunctionDialog->exec();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DialogManager::requestAddAccount(QSqlTableModel* model) {
|
||||||
|
AccountFormDialog dialog(getTopWidget(), New);
|
||||||
|
topWidgetStore.push(&dialog);
|
||||||
|
dialog.setWindowModality(Qt::WindowModal);
|
||||||
|
dialog.setReferenceModel(model);
|
||||||
|
int ret = dialog.exec();
|
||||||
|
topWidgetStore.pop();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DialogManager::requestEditSelfAccount() {
|
||||||
|
AccountFormDialog dialog(getTopWidget(), Self);
|
||||||
|
topWidgetStore.push(&dialog);
|
||||||
|
dialog.setWindowModality(Qt::WindowModal);
|
||||||
|
int ret = dialog.exec();
|
||||||
|
topWidgetStore.pop();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DialogManager::requestEditAdminAccount(const QMap<QString, QVariant>& values) {
|
||||||
|
AccountFormDialog dialog(getTopWidget(), Admin);
|
||||||
|
topWidgetStore.push(&dialog);
|
||||||
|
dialog.setAccountInformation(values);
|
||||||
|
dialog.setWindowModality(Qt::WindowModal);
|
||||||
|
int ret = dialog.exec();
|
||||||
|
topWidgetStore.pop();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DialogManager::requestChangePassword() {
|
||||||
|
ChangePasswordFormDialog dialog(getTopWidget());
|
||||||
|
topWidgetStore.push(&dialog);
|
||||||
|
dialog.setGeometry(getTopWidget()->geometry());
|
||||||
|
dialog.setWindowModality(Qt::WindowModal);
|
||||||
|
dialog.exec();
|
||||||
|
topWidgetStore.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
//考虑以后使用另外的dialog显示错误
|
||||||
void DialogManager::raiseDeviceError(QObject *parent, QObject *msg) {
|
void DialogManager::raiseDeviceError(QObject *parent, QObject *msg) {
|
||||||
if (!this->getTopWidget()->isVisible()) return;
|
if (!this->getTopWidget()->isVisible()) return;
|
||||||
|
clearMessageDialog();
|
||||||
//new dialog
|
//new dialog
|
||||||
auto dialog = new GUIMessageDialog(this->getTopWidget());
|
auto dialog = new GUIMessageDialog(this->getTopWidget());
|
||||||
if (msg)
|
if (msg) {
|
||||||
{
|
QString *str = (QString *) msg;
|
||||||
QString* str = (QString*)msg;
|
|
||||||
dialog->showMessage(*str);
|
dialog->showMessage(*str);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dialog->showMessage("Something went error!");
|
dialog->showMessage("Something went error!");
|
||||||
}
|
}
|
||||||
dialog->stopLoading();
|
dialog->stopLoading();
|
||||||
dialog->showExitButton();
|
dialog->showExitButton();
|
||||||
if (dialog->isHidden())
|
topWidgetStore.push(dialog);
|
||||||
{
|
dialog->setWindowModality(Qt::NonModal);
|
||||||
topWidgetStore.push(dialog);
|
dialog->exec();
|
||||||
dialog->setWindowModality(Qt::NonModal);
|
mErrorCount.fetch_sub(1);
|
||||||
dialog->exec();
|
auto lastDialog = topWidgetStore.pop();
|
||||||
topWidgetStore.pop();
|
lastDialog->deleteLater();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 扫描过程 dialog 只能为最底层,并且会被error dialog 清除!
|
||||||
void DialogManager::invokeOperationStart(QObject *parent, QObject *msg) {
|
void DialogManager::invokeOperationStart(QObject *parent, QObject *msg) {
|
||||||
if (mMessageDialog)
|
//没有目标parent 撤销操作
|
||||||
{
|
if (!QApplication::activeWindow()) return;
|
||||||
mMessageDialog->hide();
|
//只能在最底层窗口上模态
|
||||||
delete mMessageDialog;
|
if (!topWidgetStore.isEmpty()) return;
|
||||||
}
|
clearMessageDialog();
|
||||||
mMessageDialog = new GUIMessageDialog(this->getTopWidget());
|
mMessageDialog = new GUIMessageDialog(this->getTopWidget());
|
||||||
if (msg)
|
if (msg)
|
||||||
{
|
{
|
||||||
@@ -74,7 +138,8 @@ void DialogManager::invokeOperationStart(QObject *parent, QObject *msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DialogManager::invokeOperationProgress(QObject *parent, QObject *msg) {
|
void DialogManager::invokeOperationProgress(QObject *parent, QObject *msg) {
|
||||||
if (!mMessageDialog) mMessageDialog = new GUIMessageDialog(this->getTopWidget());
|
//窗口不存在,撤销操作
|
||||||
|
if (!mMessageDialog) return;
|
||||||
if (msg)
|
if (msg)
|
||||||
{
|
{
|
||||||
QVariant* var = (QVariant*)msg;
|
QVariant* var = (QVariant*)msg;
|
||||||
@@ -95,6 +160,7 @@ void DialogManager::invokeOperationProgress(QObject *parent, QObject *msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DialogManager::invokeOperationPending(QObject *parent, QObject *msg) {
|
void DialogManager::invokeOperationPending(QObject *parent, QObject *msg) {
|
||||||
|
//窗口不存在,撤销操作
|
||||||
if (!mMessageDialog) return;
|
if (!mMessageDialog) return;
|
||||||
if (!mMessageDialog->Pending())
|
if (!mMessageDialog->Pending())
|
||||||
{
|
{
|
||||||
@@ -105,10 +171,8 @@ void DialogManager::invokeOperationPending(QObject *parent, QObject *msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DialogManager::invokeOperationEnd(QObject *parent, QObject *msg) {
|
void DialogManager::invokeOperationEnd(QObject *parent, QObject *msg) {
|
||||||
if (!mMessageDialog)
|
//窗口不存在,撤销操作
|
||||||
{
|
if (!mMessageDialog) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!mMessageDialog->isHidden())
|
if (!mMessageDialog->isHidden())
|
||||||
{
|
{
|
||||||
if (msg && ((QVariant*)msg)->toBool())
|
if (msg && ((QVariant*)msg)->toBool())
|
||||||
@@ -128,3 +192,15 @@ void DialogManager::invokeOperationEnd(QObject *parent, QObject *msg) {
|
|||||||
AppGlobalValues::setInProcessing(false);
|
AppGlobalValues::setInProcessing(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DialogManager::clearMessageDialog() {
|
||||||
|
if (mMessageDialog){
|
||||||
|
if (!mMessageDialog->isHidden()) mMessageDialog->hide();
|
||||||
|
delete mMessageDialog;
|
||||||
|
mMessageDialog = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DialogManager::~DialogManager() {
|
||||||
|
clearMessageDialog();
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,11 +6,14 @@
|
|||||||
#define GUI_DIALOGMANAGER_H
|
#define GUI_DIALOGMANAGER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <mutex>
|
||||||
#include <QStack>
|
#include <QStack>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
class QWidget;
|
class QWidget;
|
||||||
class QDialog;
|
class QDialog;
|
||||||
class GUIMessageDialog;
|
class GUIMessageDialog;
|
||||||
|
class QSqlTableModel;
|
||||||
|
|
||||||
class DialogManager:public QObject {
|
class DialogManager:public QObject {
|
||||||
public:
|
public:
|
||||||
@@ -19,20 +22,27 @@ public:
|
|||||||
return &manager;
|
return &manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
DialogManager() = default;
|
DialogManager();
|
||||||
|
|
||||||
~DialogManager() override = default;
|
~DialogManager() override;
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
QWidget* getTopWidget();
|
QWidget* getTopWidget();
|
||||||
|
void requestLogin();
|
||||||
|
int requestAddAccount(QSqlTableModel* model);
|
||||||
|
int requestEditSelfAccount();
|
||||||
|
int requestEditAdminAccount(const QMap<QString, QVariant>& values);
|
||||||
|
void requestChangePassword();
|
||||||
void raiseDeviceError(QObject* parent, QObject* msg);
|
void raiseDeviceError(QObject* parent, QObject* msg);
|
||||||
void invokeOperationStart(QObject* parent, QObject* msg);
|
void invokeOperationStart(QObject* parent, QObject* msg);
|
||||||
void invokeOperationProgress(QObject* parent, QObject* msg);
|
void invokeOperationProgress(QObject* parent, QObject* msg);
|
||||||
void invokeOperationPending(QObject* parent, QObject* msg);
|
void invokeOperationPending(QObject* parent, QObject* msg);
|
||||||
void invokeOperationEnd(QObject* parent, QObject* msg);
|
void invokeOperationEnd(QObject* parent, QObject* msg);
|
||||||
private:
|
private:
|
||||||
QDialog* mDialog = nullptr;
|
void clearMessageDialog();
|
||||||
GUIMessageDialog* mMessageDialog = nullptr;
|
|
||||||
|
QDialog* mFunctionDialog;
|
||||||
|
GUIMessageDialog* mMessageDialog;
|
||||||
QStack<QDialog*> topWidgetStore;
|
QStack<QDialog*> topWidgetStore;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -135,10 +135,11 @@ void ScanFormWidget::initScanControlBar(QHBoxLayout *layout){
|
|||||||
mBtnPreview->setEnabled(false);
|
mBtnPreview->setEnabled(false);
|
||||||
mBtnStop->setEnabled(false);
|
mBtnStop->setEnabled(false);
|
||||||
|
|
||||||
layout->addWidget(mBtnScan);
|
|
||||||
layout->addWidget(mBtnRefresh);
|
layout->addWidget(mBtnRefresh);
|
||||||
layout->addWidget(mBtnPreview);
|
layout->addWidget(mBtnPreview);
|
||||||
layout->addWidget(mBtnStop);
|
layout->addWidget(mBtnStop);
|
||||||
|
layout->addWidget(mBtnScan);
|
||||||
connect(mBtnRefresh, &QToolButton::clicked, [=]() {
|
connect(mBtnRefresh, &QToolButton::clicked, [=]() {
|
||||||
QString patientInf(mPatInf->getCurrentPatientJsonString(true));
|
QString patientInf(mPatInf->getCurrentPatientJsonString(true));
|
||||||
LOG_USER_OPERATION(StartRefresh)
|
LOG_USER_OPERATION(StartRefresh)
|
||||||
|
|||||||
@@ -11,10 +11,10 @@
|
|||||||
|
|
||||||
#include "components/AccountRoleComboDelegate.h"
|
#include "components/AccountRoleComboDelegate.h"
|
||||||
#include "dialogs/AlertDialog.h"
|
#include "dialogs/AlertDialog.h"
|
||||||
|
#include "dialogs/DialogManager.h"
|
||||||
#include "db/SQLHelper.h"
|
#include "db/SQLHelper.h"
|
||||||
#include "models/User.h"
|
#include "models/User.h"
|
||||||
#include "components/SlideTableView.h"
|
#include "components/SlideTableView.h"
|
||||||
#include "dialogs/AccountFormDialog.h"
|
|
||||||
#include "event/EventCenter.h"
|
#include "event/EventCenter.h"
|
||||||
|
|
||||||
AccountTableForm::AccountTableForm(QWidget* aParent)
|
AccountTableForm::AccountTableForm(QWidget* aParent)
|
||||||
@@ -87,14 +87,11 @@ AccountTableForm::AccountTableForm(QWidget* aParent)
|
|||||||
|
|
||||||
//add new account
|
//add new account
|
||||||
connect(btnAdd, &QToolButton::clicked, [=]() {
|
connect(btnAdd, &QToolButton::clicked, [=]() {
|
||||||
AccountFormDialog dialog(this, New);
|
if (DialogManager::Default()->requestAddAccount(model) == QDialog::Accepted)
|
||||||
dialog.setWindowModality(Qt::WindowModal);
|
|
||||||
dialog.setReferenceModel(model);
|
|
||||||
if (dialog.exec() == QDialog::Accepted)
|
|
||||||
{
|
{
|
||||||
table->selectRow(0);
|
table->selectRow(0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(btnEdit, &QToolButton::clicked, [=]() {
|
connect(btnEdit, &QToolButton::clicked, [=]() {
|
||||||
if (mCurrentRow < 0)
|
if (mCurrentRow < 0)
|
||||||
@@ -107,16 +104,19 @@ AccountTableForm::AccountTableForm(QWidget* aParent)
|
|||||||
{
|
{
|
||||||
map[record.fieldName(i)] = record.value(i);
|
map[record.fieldName(i)] = record.value(i);
|
||||||
}
|
}
|
||||||
auto mode = map["UserID"] == User::Current()->getUserID() ? Self : Admin;
|
int ret =0;
|
||||||
AccountFormDialog dialog(this, mode);
|
if (map["UserID"] == User::Current()->getUserID()){
|
||||||
dialog.setWindowModality(Qt::WindowModal);
|
ret = DialogManager::Default()->requestEditSelfAccount();
|
||||||
if (mode == Admin)dialog.setAccountInformation(map);
|
}
|
||||||
if (dialog.exec() == QDialog::Accepted)
|
else{
|
||||||
|
ret = DialogManager::Default()->requestEditAdminAccount(map);
|
||||||
|
}
|
||||||
|
if (ret == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
model->select();
|
model->select();
|
||||||
table->selectRow(mCurrentRow);
|
table->selectRow(mCurrentRow);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(btnDelete, &QToolButton::clicked, [=]() {
|
connect(btnDelete, &QToolButton::clicked, [=]() {
|
||||||
if (mCurrentRow < 0)
|
if (mCurrentRow < 0)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#include "LoginDialog.h"
|
#include "LoginDialog.h"
|
||||||
|
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QDeskTopWidget>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QtWidgets/QLabel>
|
#include <QtWidgets/QLabel>
|
||||||
|
|
||||||
@@ -24,6 +26,7 @@ LoginDialog::LoginDialog(QWidget* aParent)
|
|||||||
{
|
{
|
||||||
initializeAllWidget();
|
initializeAllWidget();
|
||||||
setWindowFlags(windowFlags() | Qt::Window | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
|
setWindowFlags(windowFlags() | Qt::Window | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
|
||||||
|
setGeometry(QApplication::desktop()->screenGeometry());
|
||||||
mAccountEdit->setText(JsonObject::Instance()->defaultUser());
|
mAccountEdit->setText(JsonObject::Instance()->defaultUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,4 +151,9 @@ void LoginDialog::doLogin()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LoginDialog::accept() {
|
||||||
|
QDialog::accept();
|
||||||
|
clearInputData();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public:
|
|||||||
LoginDialog(QWidget* aParent = nullptr);
|
LoginDialog(QWidget* aParent = nullptr);
|
||||||
~LoginDialog() override;
|
~LoginDialog() override;
|
||||||
|
|
||||||
|
void accept() override;
|
||||||
void clearInputData();
|
void clearInputData();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "forms/settings/SettingFormWidget.h"
|
#include "forms/settings/SettingFormWidget.h"
|
||||||
#include "forms/TopBarWidget.h"
|
#include "forms/TopBarWidget.h"
|
||||||
#include "dialogs/GUIMessageDialog.h"
|
#include "dialogs/GUIMessageDialog.h"
|
||||||
|
#include "dialogs/DialogManager.h"
|
||||||
#include "device/DeviceManager.h"
|
#include "device/DeviceManager.h"
|
||||||
#include "errorhandle/GUIErrorHandle.h"
|
#include "errorhandle/GUIErrorHandle.h"
|
||||||
#include "LoginDialog.h"
|
#include "LoginDialog.h"
|
||||||
@@ -64,7 +65,7 @@ MainWindow::MainWindow(QWidget* aParent)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
mThread->start();
|
mThread->start();
|
||||||
centerWidgetHide();
|
QApplication::setActiveWindow(centralWidget());
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@@ -266,17 +267,7 @@ void MainWindow::swipeTriggered(QSwipeGesture* aSwipeGesture)
|
|||||||
|
|
||||||
void MainWindow::requestLogin()
|
void MainWindow::requestLogin()
|
||||||
{
|
{
|
||||||
mLoginDialog->clearInputData();
|
DialogManager::Default()->requestLogin();
|
||||||
mLoginDialog->setWindowModality(Qt::WindowModal);
|
|
||||||
mLoginDialog->showFullScreen();
|
|
||||||
centerWidgetHide();
|
|
||||||
QApplication::setActiveWindow(mLoginDialog);
|
|
||||||
while (QDialog::Accepted != mLoginDialog->result())
|
|
||||||
{
|
|
||||||
mLoginDialog->exec();
|
|
||||||
}
|
|
||||||
mLoginDialog->setResult(QDialog::Rejected);
|
|
||||||
centerWidgetShow();
|
|
||||||
QApplication::setActiveWindow(centralWidget());
|
QApplication::setActiveWindow(centralWidget());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user