You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AppFlowPost/GUIDialog/GUIDialogManager.cpp

54 lines
1.6 KiB
C++

#include "GUIDialogManager.h"
#include "GUIDialogBase.h"
namespace GUI
{
// GUIDialogManager的单例实例初始化为nullptr
GUIDialogManager *GUIDialogManager::_instance = nullptr;
// 当对话框创建时调用此函数,将其添加到管理列表中
void GUIDialogManager::dialogCreated(GUIDialogBase *dlg, QString uniqueFlag)
{
if (_dialogList.contains(dlg))
return;
_dialogList.append(dlg);
if (uniqueFlag.isEmpty()) return;
if (!_dialogHash.contains(uniqueFlag)) {
_dialogHash.insert(uniqueFlag, nullptr);
}
auto dialog = _dialogHash.value(uniqueFlag, nullptr);
if (dialog != nullptr) {
dialog->setAttribute(Qt::WA_DeleteOnClose, false);
dialog->close();
delete dialog;
dialog = nullptr;
}
_dialogHash[uniqueFlag] = dlg;
}
// 当对话框销毁时调用此函数,将其从管理列表中移除
void GUIDialogManager::dialogDestoried(GUIDialogBase *dlg)
{
if (!_dialogList.contains(dlg))
return;
_dialogList.removeOne(dlg);
// 删除对话框的时候将hash中的value设置nullptr
auto it = _dialogHash.constBegin();
while (it != _dialogHash.constEnd()) {
if (it.value() == dlg) {
_dialogHash[it.key()] = nullptr;
}
++it;
}
}
// 获取当前所有存活的对话框列表
QList<GUIDialogBase *> GUIDialogManager::getAllDialogs()
{
return _dialogList;
}
} // namespace GUI