Refactor DialogManager.1
This commit is contained in:
@@ -6,10 +6,24 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QWidget>
|
||||
#include <QThread>
|
||||
|
||||
#include "event/EventCenter.h"
|
||||
#include "dialogs/GUIMessageDialog.h"
|
||||
#include "dialogs/ChangePasswordFormDialog.h"
|
||||
#include "dialogs/AccountFormDialog.h"
|
||||
#include "appvals/AppGlobalValues.h"
|
||||
#include "windows/LoginDialog.h"
|
||||
|
||||
|
||||
|
||||
DialogManager::DialogManager()
|
||||
: QObject()
|
||||
, mFunctionDialog(nullptr)
|
||||
, mMessageDialog(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DialogManager::init() {
|
||||
connect(EventCenter::Default(), &EventCenter::DeviceErrorRaise,this,&DialogManager::raiseDeviceError);
|
||||
@@ -24,36 +38,86 @@ QWidget *DialogManager::getTopWidget() {
|
||||
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) {
|
||||
if (!this->getTopWidget()->isVisible()) return;
|
||||
clearMessageDialog();
|
||||
//new dialog
|
||||
auto dialog = new GUIMessageDialog(this->getTopWidget());
|
||||
if (msg)
|
||||
{
|
||||
QString* str = (QString*)msg;
|
||||
if (msg) {
|
||||
QString *str = (QString *) msg;
|
||||
dialog->showMessage(*str);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dialog->showMessage("Something went error!");
|
||||
}
|
||||
dialog->stopLoading();
|
||||
dialog->showExitButton();
|
||||
if (dialog->isHidden())
|
||||
{
|
||||
topWidgetStore.push(dialog);
|
||||
dialog->setWindowModality(Qt::NonModal);
|
||||
dialog->exec();
|
||||
topWidgetStore.pop();
|
||||
}
|
||||
topWidgetStore.push(dialog);
|
||||
dialog->setWindowModality(Qt::NonModal);
|
||||
dialog->exec();
|
||||
mErrorCount.fetch_sub(1);
|
||||
auto lastDialog = topWidgetStore.pop();
|
||||
lastDialog->deleteLater();
|
||||
}
|
||||
|
||||
// 扫描过程 dialog 只能为最底层,并且会被error dialog 清除!
|
||||
void DialogManager::invokeOperationStart(QObject *parent, QObject *msg) {
|
||||
if (mMessageDialog)
|
||||
{
|
||||
mMessageDialog->hide();
|
||||
delete mMessageDialog;
|
||||
}
|
||||
//没有目标parent 撤销操作
|
||||
if (!QApplication::activeWindow()) return;
|
||||
//只能在最底层窗口上模态
|
||||
if (!topWidgetStore.isEmpty()) return;
|
||||
clearMessageDialog();
|
||||
mMessageDialog = new GUIMessageDialog(this->getTopWidget());
|
||||
if (msg)
|
||||
{
|
||||
@@ -74,7 +138,8 @@ void DialogManager::invokeOperationStart(QObject *parent, QObject *msg) {
|
||||
}
|
||||
|
||||
void DialogManager::invokeOperationProgress(QObject *parent, QObject *msg) {
|
||||
if (!mMessageDialog) mMessageDialog = new GUIMessageDialog(this->getTopWidget());
|
||||
//窗口不存在,撤销操作
|
||||
if (!mMessageDialog) return;
|
||||
if (msg)
|
||||
{
|
||||
QVariant* var = (QVariant*)msg;
|
||||
@@ -95,6 +160,7 @@ void DialogManager::invokeOperationProgress(QObject *parent, QObject *msg) {
|
||||
}
|
||||
|
||||
void DialogManager::invokeOperationPending(QObject *parent, QObject *msg) {
|
||||
//窗口不存在,撤销操作
|
||||
if (!mMessageDialog) return;
|
||||
if (!mMessageDialog->Pending())
|
||||
{
|
||||
@@ -105,10 +171,8 @@ void DialogManager::invokeOperationPending(QObject *parent, QObject *msg) {
|
||||
}
|
||||
|
||||
void DialogManager::invokeOperationEnd(QObject *parent, QObject *msg) {
|
||||
if (!mMessageDialog)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//窗口不存在,撤销操作
|
||||
if (!mMessageDialog) return;
|
||||
if (!mMessageDialog->isHidden())
|
||||
{
|
||||
if (msg && ((QVariant*)msg)->toBool())
|
||||
@@ -128,3 +192,15 @@ void DialogManager::invokeOperationEnd(QObject *parent, QObject *msg) {
|
||||
AppGlobalValues::setInProcessing(false);
|
||||
}
|
||||
}
|
||||
|
||||
void DialogManager::clearMessageDialog() {
|
||||
if (mMessageDialog){
|
||||
if (!mMessageDialog->isHidden()) mMessageDialog->hide();
|
||||
delete mMessageDialog;
|
||||
mMessageDialog = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
DialogManager::~DialogManager() {
|
||||
clearMessageDialog();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user