Deduplicate mainwindow code
This commit is contained in:
+32
-38
@@ -238,21 +238,8 @@ void MainWindow::openPropertiesWindowFor(T &entry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto dialog = new PropertiesDialogFor<T>{entry, *m_projectTreeModel, *this};
|
auto dialog = new PropertiesDialogFor<T>{entry, *m_projectTreeModel, *this};
|
||||||
auto subwindow = m_ui->mdiArea->addSubWindow(dialog);
|
auto subwindow = addSubWindow(dialog);
|
||||||
auto action = m_ui->menuWindow->addAction(dialog->windowTitle());
|
|
||||||
m_actionGroupWindows->addAction(action);
|
|
||||||
action->setCheckable(true);
|
|
||||||
connect(action, &QAction::triggered,
|
|
||||||
m_ui->mdiArea, [mdiArea=m_ui->mdiArea,subwindow,action](){
|
|
||||||
mdiArea->setActiveSubWindow(subwindow);
|
|
||||||
action->setChecked(subwindow->windowState().testFlag(Qt::WindowActive));
|
|
||||||
});
|
|
||||||
connect(subwindow, &QMdiSubWindow::windowStateChanged,
|
|
||||||
action, [action](Qt::WindowStates oldState, Qt::WindowStates newState){
|
|
||||||
Q_UNUSED(oldState)
|
|
||||||
action->setChecked(newState.testFlag(Qt::WindowActive));
|
|
||||||
});
|
|
||||||
connect(dialog, &QWidget::windowTitleChanged, action, &QAction::setText);
|
|
||||||
connect(dialog, &QDialog::finished,
|
connect(dialog, &QDialog::finished,
|
||||||
this, [this,&propertyWindows,subwindow](int result){
|
this, [this,&propertyWindows,subwindow](int result){
|
||||||
if (result == QDialog::Accepted)
|
if (result == QDialog::Accepted)
|
||||||
@@ -265,11 +252,9 @@ void MainWindow::openPropertiesWindowFor(T &entry)
|
|||||||
iter++;
|
iter++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connect(dialog, &QDialog::finished,
|
|
||||||
subwindow, &QObject::deleteLater);
|
|
||||||
connect(dialog, &QDialog::finished,
|
|
||||||
action, &QObject::deleteLater);
|
|
||||||
propertyWindows[&entry] = subwindow;
|
propertyWindows[&entry] = subwindow;
|
||||||
|
|
||||||
dialog->show();
|
dialog->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -954,6 +939,30 @@ void MainWindow::updateTitle()
|
|||||||
.arg(m_unsavedChanges ? tr("*") : QString{}));
|
.arg(m_unsavedChanges ? tr("*") : QString{}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMdiSubWindow *MainWindow::addSubWindow(QDialog *dialog)
|
||||||
|
{
|
||||||
|
auto subwindow = m_ui->mdiArea->addSubWindow(dialog);
|
||||||
|
auto action = m_ui->menuWindow->addAction(dialog->windowTitle());
|
||||||
|
m_actionGroupWindows->addAction(action);
|
||||||
|
action->setCheckable(true);
|
||||||
|
connect(action, &QAction::triggered,
|
||||||
|
m_ui->mdiArea, [mdiArea=m_ui->mdiArea,subwindow,action](){
|
||||||
|
mdiArea->setActiveSubWindow(subwindow);
|
||||||
|
action->setChecked(subwindow->windowState().testFlag(Qt::WindowActive));
|
||||||
|
});
|
||||||
|
connect(subwindow, &QMdiSubWindow::windowStateChanged,
|
||||||
|
action, [action](Qt::WindowStates oldState, Qt::WindowStates newState){
|
||||||
|
Q_UNUSED(oldState)
|
||||||
|
action->setChecked(newState.testFlag(Qt::WindowActive));
|
||||||
|
});
|
||||||
|
connect(dialog, &QWidget::windowTitleChanged, action, &QAction::setText);
|
||||||
|
connect(dialog, &QDialog::finished,
|
||||||
|
subwindow, &QObject::deleteLater);
|
||||||
|
connect(dialog, &QDialog::finished,
|
||||||
|
action, &QObject::deleteLater);
|
||||||
|
return subwindow;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T, typename ...Targs>
|
template<typename T, typename ...Targs>
|
||||||
void MainWindow::openOrActivateWindow(QMdiSubWindow * &ptr, Targs &&...args)
|
void MainWindow::openOrActivateWindow(QMdiSubWindow * &ptr, Targs &&...args)
|
||||||
{
|
{
|
||||||
@@ -962,30 +971,15 @@ void MainWindow::openOrActivateWindow(QMdiSubWindow * &ptr, Targs &&...args)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto dialog = new T{std::forward<Targs>(args)...};
|
auto dialog = new T{std::forward<Targs>(args)...};
|
||||||
auto subwindow = m_ui->mdiArea->addSubWindow(dialog);
|
auto subwindow = addSubWindow(dialog);
|
||||||
auto action = m_ui->menuWindow->addAction(dialog->windowTitle());
|
|
||||||
m_actionGroupWindows->addAction(action);
|
|
||||||
action->setCheckable(true);
|
|
||||||
connect(action, &QAction::triggered,
|
|
||||||
m_ui->mdiArea, [mdiArea=m_ui->mdiArea,subwindow,action](){
|
|
||||||
mdiArea->setActiveSubWindow(subwindow);
|
|
||||||
action->setChecked(subwindow->windowState().testFlag(Qt::WindowActive));
|
|
||||||
});
|
|
||||||
connect(subwindow, &QMdiSubWindow::windowStateChanged,
|
|
||||||
action, [action](Qt::WindowStates oldState, Qt::WindowStates newState){
|
|
||||||
Q_UNUSED(oldState)
|
|
||||||
action->setChecked(newState.testFlag(Qt::WindowActive));
|
|
||||||
});
|
|
||||||
connect(dialog, &QWidget::windowTitleChanged, action, &QAction::setText);
|
|
||||||
connect(dialog, &QDialog::finished,
|
connect(dialog, &QDialog::finished,
|
||||||
this, [&ptr](){
|
this, [&ptr](){
|
||||||
ptr = nullptr;
|
ptr = nullptr;
|
||||||
});
|
});
|
||||||
connect(dialog, &QDialog::finished,
|
|
||||||
subwindow, &QObject::deleteLater);
|
|
||||||
connect(dialog, &QDialog::finished,
|
|
||||||
action, &QObject::deleteLater);
|
|
||||||
ptr = subwindow;
|
ptr = subwindow;
|
||||||
|
|
||||||
dialog->show();
|
dialog->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,8 @@ private:
|
|||||||
void loadFile(const QString &path);
|
void loadFile(const QString &path);
|
||||||
void updateTitle();
|
void updateTitle();
|
||||||
|
|
||||||
|
QMdiSubWindow *addSubWindow(QDialog *dialog);
|
||||||
|
|
||||||
template<typename T, typename ...Targs>
|
template<typename T, typename ...Targs>
|
||||||
void openOrActivateWindow(QMdiSubWindow * &ptr, Targs &&...args);
|
void openOrActivateWindow(QMdiSubWindow * &ptr, Targs &&...args);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user