Files
QtGameMaker/src/editor/mainwindow.cpp
T

1228 lines
43 KiB
C++
Raw Normal View History

2022-01-09 06:42:13 +01:00
#include "mainwindow.h"
#include "ui_mainwindow.h"
2022-01-15 01:52:55 +01:00
#include <QApplication>
#include <QActionGroup>
#include <QStyleFactory>
2022-01-09 06:42:13 +01:00
#include <QMdiSubWindow>
#include <QMessageBox>
#include <QCloseEvent>
#include <QFileDialog>
2022-01-09 21:07:41 +01:00
#include <QInputDialog>
2022-01-10 21:49:06 +01:00
#include <QDebug>
#include <QPersistentModelIndex>
#include <QPointer>
#include <algorithm>
#include <vector>
2022-01-09 06:42:13 +01:00
2025-11-30 19:43:05 +01:00
#include "editorsettings.h"
2024-01-04 20:22:39 +01:00
#include "projectserialization.h"
#include "models/projecttreemodel.h"
2022-01-10 21:49:06 +01:00
#include "dialogs/preferencesdialog.h"
2022-01-09 06:42:13 +01:00
#include "dialogs/spritepropertiesdialog.h"
#include "dialogs/soundpropertiesdialog.h"
#include "dialogs/backgroundpropertiesdialog.h"
#include "dialogs/pathpropertiesdialog.h"
#include "dialogs/scriptpropertiesdialog.h"
#include "dialogs/fontpropertiesdialog.h"
#include "dialogs/timelinepropertiesdialog.h"
#include "dialogs/objectpropertiesdialog.h"
#include "dialogs/roompropertiesdialog.h"
#include "dialogs/projectchangesapplier.h"
2022-01-10 21:49:06 +01:00
#include "dialogs/objectinformationdialog.h"
#include "dialogs/transparentbackgroundsettingsdialog.h"
2022-01-09 06:42:13 +01:00
#include "dialogs/gameinformationdialog.h"
#include "dialogs/globalgamesettingsdialog.h"
#include "dialogs/extensionpackagesdialog.h"
2022-01-10 21:49:06 +01:00
#include "dialogs/userdefinedconstantsdialog.h"
#include "dialogs/triggersdialog.h"
#include "dialogs/includedfilesdialog.h"
2022-01-15 08:57:28 +01:00
#include "engine/gameengine.h"
2022-01-09 06:42:13 +01:00
namespace {
template<typename T> struct PropertiesDialogForDetail;
template<> struct PropertiesDialogForDetail<Sprite> { using Type = SpritePropertiesDialog; };
template<> struct PropertiesDialogForDetail<Sound> { using Type = SoundPropertiesDialog; };
template<> struct PropertiesDialogForDetail<Background> { using Type = BackgroundPropertiesDialog; };
template<> struct PropertiesDialogForDetail<Path> { using Type = PathPropertiesDialog; };
template<> struct PropertiesDialogForDetail<Script> { using Type = ScriptPropertiesDialog; };
template<> struct PropertiesDialogForDetail<Font> { using Type = FontPropertiesDialog; };
template<> struct PropertiesDialogForDetail<TimeLine> { using Type = TimeLinePropertiesDialog; };
template<> struct PropertiesDialogForDetail<Object> { using Type = ObjectPropertiesDialog; };
template<> struct PropertiesDialogForDetail<Room> { using Type = RoomPropertiesDialog; };
template<typename T> using PropertiesDialogFor = typename PropertiesDialogForDetail<T>::Type;
}
2025-11-30 19:43:05 +01:00
MainWindow::MainWindow(const QString &filePath, EditorSettings &settings, QWidget *parent) :
2022-01-09 06:42:13 +01:00
QMainWindow{parent},
m_ui{std::make_unique<Ui::MainWindow>()},
2025-11-30 19:43:05 +01:00
m_settings{settings},
2022-01-09 21:07:41 +01:00
m_projectTreeModel{std::make_unique<ProjectTreeModel>(m_project, this)}
2022-01-09 06:42:13 +01:00
{
m_ui->setupUi(this);
//m_ui->splitter->setSizes({
// m_ui->splitter->width() / 2,
// m_ui->splitter->width() / 2
//});
m_ui->splitter->setStretchFactor(0, 0);
m_ui->splitter->setStretchFactor(1, 1);
2022-01-09 06:42:13 +01:00
m_ui->actionNew->setShortcut(QKeySequence::New);
m_ui->actionOpen->setShortcut(QKeySequence::Open);
m_ui->actionSave->setShortcut(QKeySequence::Save);
m_ui->actionSaveAs->setShortcut(QKeySequence::SaveAs);
m_ui->actionExit->setShortcut(QKeySequence::Quit);
m_ui->actionDelete->setShortcut(QKeySequence::Delete);
m_ui->actionDelete->setShortcutContext(Qt::WidgetShortcut);
m_ui->treeView->addAction(m_ui->actionDelete);
2022-01-09 06:42:13 +01:00
m_ui->actionFindResource->setShortcut(QKeySequence::Find);
m_ui->actionPrevious->setShortcut(QKeySequence::PreviousChild);
m_ui->actionNext->setShortcut(QKeySequence::NextChild);
m_ui->actionContents->setShortcut(QKeySequence::HelpContents);
{
const auto updateViewActions = [this](){
m_ui->actionSubWindowedView->setChecked(m_ui->mdiArea->viewMode() == QMdiArea::SubWindowView);
m_ui->actionTabbedView->setChecked(m_ui->mdiArea->viewMode() == QMdiArea::TabbedView);
};
updateViewActions();
connect(m_ui->actionSubWindowedView, &QAction::triggered, m_ui->mdiArea, [mdiArea=m_ui->mdiArea,updateViewActions](){
mdiArea->setViewMode(QMdiArea::SubWindowView);
updateViewActions();
});
connect(m_ui->actionTabbedView, &QAction::triggered, m_ui->mdiArea, [mdiArea=m_ui->mdiArea,updateViewActions](){
mdiArea->setViewMode(QMdiArea::TabbedView);
updateViewActions();
});
}
connect(m_ui->actionNew, &QAction::triggered, this, &MainWindow::newFile);
connect(m_ui->actionOpen, &QAction::triggered, this, &MainWindow::openFile);
connect(m_ui->actionSave, &QAction::triggered, this, &MainWindow::saveFile);
connect(m_ui->actionSaveAs, &QAction::triggered, this, &MainWindow::saveFileAs);
connect(m_ui->actionCreateExecutable, &QAction::triggered, this, &MainWindow::createExecutable);
connect(m_ui->actionPublishGame, &QAction::triggered, this, &MainWindow::publishGame);
connect(m_ui->actionImportResources, &QAction::triggered, this, &MainWindow::importResources);
connect(m_ui->actionExportResources, &QAction::triggered, this, &MainWindow::exportResources);
connect(m_ui->actionPreferences, &QAction::triggered, this, &MainWindow::preferences);
connect(m_ui->actionCreate, &QAction::triggered, this, &MainWindow::create);
connect(m_ui->actionDuplicate, &QAction::triggered, this, &MainWindow::duplicate);
connect(m_ui->actionCreateGroup, &QAction::triggered, this, &MainWindow::createGroup);
connect(m_ui->actionSortByName, &QAction::triggered, this, &MainWindow::sortByName);
connect(m_ui->actionDelete, &QAction::triggered, this, &MainWindow::delete_);
connect(m_ui->actionRename, &QAction::triggered, this, &MainWindow::rename);
connect(m_ui->actionProperties, &QAction::triggered, this, &MainWindow::showProperties);
2022-01-09 21:07:41 +01:00
connect(m_ui->actionFindResource, &QAction::triggered, this, &MainWindow::findResource);
connect(m_ui->actionShowObjectInformation, &QAction::triggered, this, &MainWindow::showObjectInformation);
connect(m_ui->actionTransparentBackgroundSettings, &QAction::triggered, this, &MainWindow::transparentBackgroundSettings);
connect(m_ui->actionCreateSprite, &QAction::triggered, this, &MainWindow::createFor<Sprite>);
connect(m_ui->actionCreateSound, &QAction::triggered, this, &MainWindow::createFor<Sound>);
connect(m_ui->actionCreateBackground, &QAction::triggered, this, &MainWindow::createFor<Background>);
connect(m_ui->actionCreatePath, &QAction::triggered, this, &MainWindow::createFor<Path>);
connect(m_ui->actionCreateScript, &QAction::triggered, this, &MainWindow::createFor<Script>);
connect(m_ui->actionCreateFont, &QAction::triggered, this, &MainWindow::createFor<Font>);
connect(m_ui->actionCreateTimeLine, &QAction::triggered, this, &MainWindow::createFor<TimeLine>);
connect(m_ui->actionCreateObject, &QAction::triggered, this, &MainWindow::createFor<Object>);
connect(m_ui->actionCreateRoom, &QAction::triggered, this, &MainWindow::createFor<Room>);
2022-01-09 06:42:13 +01:00
connect(m_ui->actionGameInformation, &QAction::triggered, this, &MainWindow::showGameInformation);
connect(m_ui->actionGlobalGameSettings, &QAction::triggered, this, &MainWindow::showGlobalGameSettings);
connect(m_ui->actionExtensionPackages, &QAction::triggered, this, &MainWindow::showExtensionPackages);
2022-01-10 21:49:06 +01:00
connect(m_ui->actionDefineConstants, &QAction::triggered, this, &MainWindow::showDefineConstants);
connect(m_ui->actionDefineTriggers, &QAction::triggered, this, &MainWindow::showDefineTriggers);
connect(m_ui->actionIncludedFiles, &QAction::triggered, this, &MainWindow::showIncludedFiles);
2022-01-15 01:52:55 +01:00
connect(m_ui->actionRunNormally, &QAction::triggered, this, &MainWindow::runGame);
connect(m_ui->actionRunInDebugMode, &QAction::triggered, this, &MainWindow::debugGame);
2022-01-09 06:42:13 +01:00
connect(m_ui->actionAbout, &QAction::triggered, this, &MainWindow::about);
connect(m_ui->actionAboutQt, &QAction::triggered, qApp, &QApplication::aboutQt);
2022-01-15 01:52:55 +01:00
setupStylesMenu();
m_actionGroupViewMode = new QActionGroup{this};
m_actionGroupViewMode->setExclusive(true);
m_actionGroupViewMode->addAction(m_ui->actionSubWindowedView);
m_actionGroupViewMode->addAction(m_ui->actionTabbedView);
m_actionGroupWindows = new QActionGroup{this};
m_actionGroupWindows->setExclusive(true);
2022-01-09 06:42:13 +01:00
m_ui->treeView->setModel(m_projectTreeModel.get());
2022-01-09 21:07:41 +01:00
connect(m_projectTreeModel.get(), &ProjectTreeModel::errorOccured,
this, &MainWindow::modelErrorOccured);
2022-01-09 06:42:13 +01:00
connect(m_ui->treeView, &QTreeView::customContextMenuRequested,
this, &MainWindow::contextMenuRequested);
connect(m_ui->treeView, &QTreeView::activated,
this, &MainWindow::activated);
2022-01-09 06:42:13 +01:00
connect(m_ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged,
this, &MainWindow::selectionChanged);
connect(m_projectTreeModel.get(), &ProjectTreeModel::rowsInserted,
this, &MainWindow::rowsInserted);
2022-01-10 21:49:06 +01:00
connect(m_projectTreeModel.get(), &QAbstractTableModel::rowsInserted,
this, &MainWindow::changed);
2022-01-09 06:42:13 +01:00
connect(m_projectTreeModel.get(), &ProjectTreeModel::rowsAboutToBeRemoved,
this, &MainWindow::rowsAboutToBeRemoved);
2022-01-10 21:49:06 +01:00
connect(m_projectTreeModel.get(), &QAbstractTableModel::rowsRemoved,
this, &MainWindow::changed);
connect(m_projectTreeModel.get(), &QAbstractItemModel::rowsMoved,
this, &MainWindow::changed);
2022-01-09 06:42:13 +01:00
connect(m_projectTreeModel.get(), &ProjectTreeModel::modelAboutToBeReset,
this, &MainWindow::modelAboutToBeReset);
2022-01-10 21:49:06 +01:00
connect(m_projectTreeModel.get(), &QAbstractTableModel::dataChanged,
this, &MainWindow::changed);
2022-01-09 06:42:13 +01:00
if (!filePath.isEmpty())
loadFile(filePath);
else if (const auto &recentFiles = m_settings.recentFiles(); m_settings.autoLoadLastFile() && !recentFiles.isEmpty())
loadFile(recentFiles.front());
else
updateTitle();
2025-11-30 19:43:05 +01:00
updateVisibilities();
2025-12-20 20:24:39 +01:00
m_ui->actionAdvancedMode->setChecked(m_settings.advancedMode());
connect(m_ui->actionAdvancedMode, &QAction::toggled, &m_settings, &EditorSettings::setAdvancedMode);
connect(&m_settings, &EditorSettings::advancedModeChanged, this, &MainWindow::advancedModeChanged);
advancedModeChanged(m_settings.advancedMode());
2025-11-30 19:43:05 +01:00
restoreGeometry(m_settings.mainWindowGeometry());
restoreState(m_settings.mainWindowState());
2022-01-09 06:42:13 +01:00
}
template<>
std::map<Sprite*, QMdiSubWindow*> &MainWindow::propertyWindowsFor<Sprite>()
{
return m_spritePropertiesWindows;
}
template<>
std::map<Sound*, QMdiSubWindow*> &MainWindow::propertyWindowsFor<Sound>()
{
return m_soundPropertiesWindows;
}
template<>
std::map<Background*, QMdiSubWindow*> &MainWindow::propertyWindowsFor<Background>()
{
return m_backgroundPropertiesWindows;
}
template<>
std::map<Path*, QMdiSubWindow*> &MainWindow::propertyWindowsFor<Path>()
{
return m_pathPropertiesWindows;
}
template<>
std::map<Script*, QMdiSubWindow*> &MainWindow::propertyWindowsFor<Script>()
{
return m_scriptPropertiesWindows;
}
template<>
std::map<Font*, QMdiSubWindow*> &MainWindow::propertyWindowsFor<Font>()
{
return m_fontPropertiesWindows;
}
template<>
std::map<TimeLine*, QMdiSubWindow*> &MainWindow::propertyWindowsFor<TimeLine>()
{
return m_timeLinePropertiesWindows;
}
template<>
std::map<Object*, QMdiSubWindow*> &MainWindow::propertyWindowsFor<Object>()
{
return m_objectPropertiesWindows;
}
template<>
std::map<Room*, QMdiSubWindow*> &MainWindow::propertyWindowsFor<Room>()
{
return m_roomPropertiesWindows;
}
template<typename T>
void MainWindow::openPropertiesWindowFor(T &entry)
{
auto &propertyWindows = propertyWindowsFor<T>();
if (const auto iter = propertyWindows.find(&entry); iter != std::cend(propertyWindows))
{
m_ui->mdiArea->setActiveSubWindow(iter->second);
return;
}
2024-01-07 16:49:13 +01:00
auto dialog = new PropertiesDialogFor<T>{entry, *m_projectTreeModel, *this};
2025-12-08 10:07:11 +01:00
auto subwindow = addSubWindow(dialog);
connect(dialog, &QDialog::finished,
this, [this,&propertyWindows,subwindow](int result){
if (result == QDialog::Accepted)
changed();
for (auto iter = std::begin(propertyWindows); iter != std::end(propertyWindows); )
{
if (iter->second == subwindow)
iter = propertyWindows.erase(iter);
else
iter++;
}
});
2025-12-08 10:07:11 +01:00
propertyWindows[&entry] = subwindow;
2025-12-08 10:07:11 +01:00
dialog->show();
}
template void MainWindow::openPropertiesWindowFor<Sprite>(Sprite &entry);
template void MainWindow::openPropertiesWindowFor<Sound>(Sound &entry);
template void MainWindow::openPropertiesWindowFor<Background>(Background &entry);
template void MainWindow::openPropertiesWindowFor<Path>(Path &entry);
template void MainWindow::openPropertiesWindowFor<Script>(Script &entry);
template void MainWindow::openPropertiesWindowFor<Font>(Font &entry);
template void MainWindow::openPropertiesWindowFor<TimeLine>(TimeLine &entry);
template void MainWindow::openPropertiesWindowFor<Object>(Object &entry);
template void MainWindow::openPropertiesWindowFor<Room>(Room &entry);
2022-01-09 06:42:13 +01:00
void MainWindow::closeEvent(QCloseEvent *event)
{
m_ui->mdiArea->closeAllSubWindows();
if (!m_ui->mdiArea->subWindowList().empty())
{
event->ignore();
return;
}
if (m_unsavedChanges)
{
const auto result = QMessageBox::warning(
this,
tr("The Game has been modified."),
tr("Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
QMessageBox::Save
);
switch (result)
{
case QMessageBox::Save:
saveFile();
if (m_unsavedChanges)
{
event->ignore();
return;
}
else
break;
case QMessageBox::Discard:
break;
case QMessageBox::Cancel:
event->ignore();
return;
default:
qWarning() << "unexpected dialog result" << result;
event->ignore();
return;
}
}
2025-11-30 19:43:05 +01:00
m_settings.setMainWindowGeometry(saveGeometry());
m_settings.setMainWindowState(saveState());
2022-01-09 06:42:13 +01:00
QMainWindow::closeEvent(event);
}
MainWindow::~MainWindow() = default;
void MainWindow::contextMenuRequested(const QPoint &pos)
{
if (const QModelIndex clicked = m_ui->treeView->indexAt(pos); clicked.isValid())
m_ui->treeView->setCurrentIndex(clicked);
2022-01-09 06:42:13 +01:00
QMenu menu{this};
menu.addAction(m_ui->actionCreate);
menu.addAction(m_ui->actionDuplicate);
menu.addSeparator();
menu.addAction(m_ui->actionCreateGroup);
menu.addSeparator();
menu.addAction(m_ui->actionSortByName);
menu.addSeparator();
menu.addAction(m_ui->actionDelete);
menu.addSeparator();
menu.addAction(m_ui->actionRename);
menu.addSeparator();
menu.addAction(m_ui->actionProperties);
menu.exec(m_ui->treeView->viewport()->mapToGlobal(pos));
}
void MainWindow::activated(const QModelIndex &index)
2022-01-09 06:42:13 +01:00
{
if (m_projectTreeModel->nodeType(index) == ProjectTreeModel::NodeType::Root)
2022-01-09 06:42:13 +01:00
{
if (index == m_projectTreeModel->gameInformationRoot())
showGameInformation();
else if (index == m_projectTreeModel->globalGameSettingsRoot())
showGlobalGameSettings();
else if (index == m_projectTreeModel->extensionPackagesRoot())
showExtensionPackages();
return;
2022-01-09 06:42:13 +01:00
}
if (activatedFor<Sprite>(index)) return;
if (activatedFor<Sound>(index)) return;
if (activatedFor<Background>(index)) return;
if (activatedFor<Path>(index)) return;
if (activatedFor<Script>(index)) return;
if (activatedFor<Font>(index)) return;
if (activatedFor<TimeLine>(index)) return;
if (activatedFor<Object>(index)) return;
if (activatedFor<Room>(index)) return;
2022-01-09 06:42:13 +01:00
}
void MainWindow::selectionChanged(const QModelIndex &index)
{
switch (const auto nodeType = m_projectTreeModel->nodeType(index))
{
case ProjectTreeModel::NodeType::Folder:
m_ui->actionCreate->setEnabled(true);
m_ui->actionCreate->setText(tr("&Create Resource"));
m_ui->actionCreateGroup->setEnabled(true);
m_ui->actionSortByName->setEnabled(true);
m_ui->actionDuplicate->setEnabled(false);
m_ui->actionDelete->setEnabled(true);
m_ui->actionRename->setEnabled(true);
m_ui->actionProperties->setEnabled(false);
break;
2022-01-09 06:42:13 +01:00
case ProjectTreeModel::NodeType::Root:
if (index == m_projectTreeModel->rootFor<Sprite>() ||
index == m_projectTreeModel->rootFor<Sound>() ||
index == m_projectTreeModel->rootFor<Background>() ||
index == m_projectTreeModel->rootFor<Path>() ||
index == m_projectTreeModel->rootFor<Script>() ||
index == m_projectTreeModel->rootFor<Font>() ||
index == m_projectTreeModel->rootFor<TimeLine>() ||
index == m_projectTreeModel->rootFor<Object>() ||
index == m_projectTreeModel->rootFor<Room>())
2022-01-09 06:42:13 +01:00
{
m_ui->actionCreate->setEnabled(true);
m_ui->actionCreateGroup->setText(tr("Cr&eate Group"));
m_ui->actionCreateGroup->setEnabled(true);
m_ui->actionSortByName->setEnabled(true);
if (index == m_projectTreeModel->rootFor<Sprite>()) m_ui->actionCreate->setText(tr("&Create Sprite"));
else if (index == m_projectTreeModel->rootFor<Sound>()) m_ui->actionCreate->setText(tr("&Create Sound"));
else if (index == m_projectTreeModel->rootFor<Background>()) m_ui->actionCreate->setText(tr("&Create Background"));
else if (index == m_projectTreeModel->rootFor<Path>()) m_ui->actionCreate->setText(tr("&Create Path"));
else if (index == m_projectTreeModel->rootFor<Script>()) m_ui->actionCreate->setText(tr("&Create Script"));
else if (index == m_projectTreeModel->rootFor<Font>()) m_ui->actionCreate->setText(tr("&Create Font"));
else if (index == m_projectTreeModel->rootFor<TimeLine>()) m_ui->actionCreate->setText(tr("&Create Time Line"));
else if (index == m_projectTreeModel->rootFor<Object>()) m_ui->actionCreate->setText(tr("&Create Object"));
else if (index == m_projectTreeModel->rootFor<Room>()) m_ui->actionCreate->setText(tr("&Create Room"));
2022-01-09 06:42:13 +01:00
}
else
{
m_ui->actionCreate->setEnabled(false);
m_ui->actionCreate->setText(tr("&Create"));
m_ui->actionCreateGroup->setText(tr("Cr&eate Group"));
m_ui->actionCreateGroup->setEnabled(false);
m_ui->actionSortByName->setEnabled(false);
}
m_ui->actionDuplicate->setEnabled(false);
m_ui->actionDelete->setEnabled(false);
m_ui->actionRename->setEnabled(false);
m_ui->actionProperties->setEnabled(
index == m_projectTreeModel->gameInformationRoot() ||
index == m_projectTreeModel->globalGameSettingsRoot() ||
index == m_projectTreeModel->extensionPackagesRoot());
break;
case ProjectTreeModel::NodeType::Sprite:
case ProjectTreeModel::NodeType::Sound:
case ProjectTreeModel::NodeType::Background:
case ProjectTreeModel::NodeType::Path:
case ProjectTreeModel::NodeType::Script:
case ProjectTreeModel::NodeType::Font:
case ProjectTreeModel::NodeType::TimeLine:
case ProjectTreeModel::NodeType::Object:
case ProjectTreeModel::NodeType::Room:
2022-01-09 06:42:13 +01:00
m_ui->actionCreate->setEnabled(true);
switch (nodeType)
{
case ProjectTreeModel::NodeType::Sprite: m_ui->actionCreate->setText(tr("&Insert Sprite")); break;
case ProjectTreeModel::NodeType::Sound: m_ui->actionCreate->setText(tr("&Insert Sound")); break;
case ProjectTreeModel::NodeType::Background: m_ui->actionCreate->setText(tr("&Insert Background")); break;
case ProjectTreeModel::NodeType::Path: m_ui->actionCreate->setText(tr("&Insert Path")); break;
case ProjectTreeModel::NodeType::Script: m_ui->actionCreate->setText(tr("&Insert Script")); break;
case ProjectTreeModel::NodeType::Font: m_ui->actionCreate->setText(tr("&Insert Font")); break;
case ProjectTreeModel::NodeType::TimeLine: m_ui->actionCreate->setText(tr("&Insert Time Line")); break;
case ProjectTreeModel::NodeType::Object: m_ui->actionCreate->setText(tr("&Insert Object")); break;
case ProjectTreeModel::NodeType::Room: m_ui->actionCreate->setText(tr("&Insert Room")); break;
2022-01-09 06:42:13 +01:00
default:
__builtin_unreachable();
}
m_ui->actionDuplicate->setEnabled(true);
m_ui->actionCreateGroup->setText(tr("I&nsert Group"));
m_ui->actionCreateGroup->setEnabled(true);
m_ui->actionSortByName->setEnabled(false);
m_ui->actionDelete->setEnabled(true);
m_ui->actionRename->setEnabled(true);
m_ui->actionProperties->setEnabled(true);
break;
default:
m_ui->actionCreate->setEnabled(false);
m_ui->actionCreate->setText(tr("&Create"));
m_ui->actionDuplicate->setEnabled(false);
m_ui->actionCreateGroup->setText(tr("Cr&eate Group"));
m_ui->actionCreateGroup->setEnabled(false);
m_ui->actionSortByName->setEnabled(false);
m_ui->actionDelete->setEnabled(false);
m_ui->actionRename->setEnabled(false);
m_ui->actionProperties->setEnabled(false);
}
}
2022-01-09 21:07:41 +01:00
void MainWindow::modelErrorOccured(const QString &message)
{
QMessageBox::warning(this, tr("Error occured!"), tr("Error occured!") + "\n\n" + message);
}
2022-01-10 21:49:06 +01:00
void MainWindow::changed()
{
if (!m_unsavedChanges)
{
m_unsavedChanges = true;
updateTitle();
}
}
2022-01-09 06:42:13 +01:00
void MainWindow::newFile()
{
m_ui->mdiArea->closeAllSubWindows();
if (!m_ui->mdiArea->subWindowList().empty())
return;
if (m_unsavedChanges)
{
const auto result = QMessageBox::warning(
this,
tr("The Game has been modified."),
tr("Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
QMessageBox::Save
);
switch (result)
{
case QMessageBox::Save:
saveFile();
if (m_unsavedChanges)
return;
else
break;
case QMessageBox::Discard:
break;
case QMessageBox::Cancel:
return;
default:
qWarning() << "unexpected dialog result" << result;
return;
}
}
m_project = {};
m_projectTreeModel->setProject(&m_project);
2022-01-10 21:49:06 +01:00
m_filePath = QString{};
2022-01-09 06:42:13 +01:00
m_unsavedChanges = false;
updateTitle();
}
void MainWindow::openFile()
{
auto path = QFileDialog::getOpenFileName(this, tr("Load a game"), {}, tr("GMK Files (*.gmk)"));
if (path.isEmpty())
return;
2022-01-11 02:35:26 +01:00
loadFile(path);
2022-01-09 06:42:13 +01:00
}
void MainWindow::saveFile()
{
if (m_filePath.isEmpty())
{
saveFileAs();
return;
}
{
QFile file{m_filePath};
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
QMessageBox::warning(this, tr("Could not save game!"), tr("Could not save game!") + "\n\n" + file.errorString());
saveFileAs();
return;
}
QDataStream dataStream{&file};
dataStream << m_project;
}
m_unsavedChanges = false;
updateTitle();
}
void MainWindow::saveFileAs()
{
auto path = QFileDialog::getSaveFileName(this, tr("Save the game"), "mygame.gmk", tr("GMK Files (*.gmk)"));
if (path.isEmpty())
return;
{
QFile file{path};
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
QMessageBox::warning(this, tr("Could not save game!"), tr("Could not save game!") + "\n\n" + file.errorString());
return;
}
QDataStream dataStream{&file};
dataStream << m_project;
}
2025-12-20 16:02:46 +01:00
m_settings.pushRecentFile(path);
updateRecentFiles();
2022-01-09 06:42:13 +01:00
m_filePath = path;
m_unsavedChanges = false;
updateTitle();
}
void MainWindow::createExecutable()
{
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
}
void MainWindow::publishGame()
{
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
}
void MainWindow::importResources()
{
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
}
void MainWindow::exportResources()
{
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
}
2025-12-20 20:24:39 +01:00
void MainWindow::advancedModeChanged(bool advancedMode)
{
for (const QModelIndex &index : {
m_projectTreeModel->rootFor<Path>(),
m_projectTreeModel->rootFor<Script>(),
m_projectTreeModel->rootFor<Font>(),
m_projectTreeModel->rootFor<TimeLine>(),
m_projectTreeModel->extensionPackagesRoot()
})
{
m_ui->treeView->setRowHidden(index.row(), index.parent(), !advancedMode);
}
for (QAction *action : {
m_ui->actionImportResources,
m_ui->actionExportResources,
m_ui->actionCreateGroup,
m_ui->actionFindResource,
m_ui->actionExpandResourceTree,
m_ui->actionCollapseResourceTree,
m_ui->actionShowObjectInformation,
m_ui->actionCreatePath,
m_ui->actionCreateScript,
m_ui->actionCreateFont,
m_ui->actionCreateTimeLine,
m_ui->actionExtensionPackages,
m_ui->actionDefineConstants,
m_ui->actionDefineTriggers,
m_ui->actionIncludedFiles
})
action->setVisible(advancedMode);
m_ui->menuScripts->menuAction()->setVisible(advancedMode);
}
2022-01-09 06:42:13 +01:00
void MainWindow::preferences()
{
2025-11-30 19:43:05 +01:00
PreferencesDialog dialog{m_settings, this};
if (dialog.exec() == QDialog::Accepted)
{
2025-11-30 19:43:05 +01:00
dialog.save(m_settings);
updateVisibilities();
}
2022-01-09 06:42:13 +01:00
}
void MainWindow::create()
{
const auto index = m_ui->treeView->currentIndex();
if (!index.isValid())
return;
2022-01-10 21:49:06 +01:00
if (index == m_projectTreeModel->rootFor<Sprite>()) createFor<Sprite>();
else if (index == m_projectTreeModel->rootFor<Sound>()) createFor<Sound>();
else if (index == m_projectTreeModel->rootFor<Background>()) createFor<Background>();
else if (index == m_projectTreeModel->rootFor<Path>()) createFor<Path>();
else if (index == m_projectTreeModel->rootFor<Script>()) createFor<Script>();
else if (index == m_projectTreeModel->rootFor<Font>()) createFor<Font>();
else if (index == m_projectTreeModel->rootFor<TimeLine>()) createFor<TimeLine>();
else if (index == m_projectTreeModel->rootFor<Object>()) createFor<Object>();
else if (index == m_projectTreeModel->rootFor<Room>()) createFor<Room>();
2022-01-09 06:42:13 +01:00
else
{
switch (m_projectTreeModel->nodeType(index))
{
2022-01-11 02:35:26 +01:00
using NodeType = ProjectTreeModel::NodeType;
case NodeType::Root:
break;
case NodeType::Folder:
if (!m_projectTreeModel->insertRows(m_projectTreeModel->rowCount(index), 1, index))
QMessageBox::warning(this, tr("Creating failed!"), tr("Creating failed!"));
break;
2022-01-11 02:35:26 +01:00
case NodeType::Sprite:
case NodeType::Sound:
case NodeType::Background:
case NodeType::Path:
case NodeType::Script:
case NodeType::Font:
case NodeType::TimeLine:
case NodeType::Object:
case NodeType::Room:
2022-01-09 06:42:13 +01:00
if (!m_projectTreeModel->insertRows(index.row(), 1, index.parent()))
QMessageBox::warning(this, tr("Inserting failed!"), tr("Inserting failed!"));
break;
}
}
}
void MainWindow::duplicate()
{
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
}
void MainWindow::createGroup()
{
auto parent = m_ui->treeView->currentIndex();
if (!parent.isValid()) return;
int row = -1;
if (m_projectTreeModel->nodeType(parent) != ProjectTreeModel::NodeType::Folder &&
m_projectTreeModel->nodeType(parent) != ProjectTreeModel::NodeType::Root)
{
row = parent.row();
parent = parent.parent();
}
const auto folder = m_projectTreeModel->createFolder(parent, {}, row);
if (!folder.isValid())
QMessageBox::warning(this, tr("Creating failed!"), tr("Could not create a group here."));
else
m_ui->treeView->edit(folder);
2022-01-09 06:42:13 +01:00
}
void MainWindow::sortByName()
{
const QModelIndex parent = m_ui->treeView->currentIndex();
if (!parent.isValid()) return;
if (m_projectTreeModel->nodeType(parent) != ProjectTreeModel::NodeType::Root &&
m_projectTreeModel->nodeType(parent) != ProjectTreeModel::NodeType::Folder)
return;
std::vector<QPersistentModelIndex> order;
for (int row = 0; row < m_projectTreeModel->rowCount(parent); ++row)
order.emplace_back(m_projectTreeModel->index(row, 0, parent));
std::stable_sort(order.begin(), order.end(), [this](const auto &a, const auto &b) {
return QString::localeAwareCompare(m_projectTreeModel->data(a, Qt::DisplayRole).toString(),
m_projectTreeModel->data(b, Qt::DisplayRole).toString()) < 0;
});
for (int row = 0; row < int(order.size()); ++row)
if (order[row].row() != row)
m_projectTreeModel->moveRows(parent, order[row].row(), 1, parent, row);
2022-01-09 06:42:13 +01:00
}
void MainWindow::delete_()
{
const auto index = m_ui->treeView->currentIndex();
if (!index.isValid())
return;
switch (m_projectTreeModel->nodeType(index))
{
using NodeType = ProjectTreeModel::NodeType;
case NodeType::Root:
return;
case NodeType::Folder:
case NodeType::Sprite:
case NodeType::Sound:
case NodeType::Background:
case NodeType::Path:
case NodeType::Script:
case NodeType::Font:
case NodeType::TimeLine:
case NodeType::Object:
case NodeType::Room:
if (QMessageBox::question(this,
tr("Confirm"),
tr("You are about to delete %0. This will be permanent. Continue?")
.arg(m_projectTreeModel->data(index, Qt::DisplayRole).toString())
) != QMessageBox::Yes)
return;
break;
}
2022-01-09 06:42:13 +01:00
if (!m_projectTreeModel->removeRow(index.row(), index.parent()))
QMessageBox::warning(this, tr("Deleting failed!"), tr("Deleting failed!"));
}
void MainWindow::rename()
{
m_ui->treeView->edit(m_ui->treeView->currentIndex());
}
void MainWindow::showProperties()
{
const auto index = m_ui->treeView->currentIndex();
if (!index.isValid())
{
qWarning() << "unexpected invalid index";
return;
}
activated(index);
2022-01-09 06:42:13 +01:00
}
2022-01-09 21:07:41 +01:00
void MainWindow::findResource()
{
bool ok;
const auto filter = QInputDialog::getText(this, tr("Finding a resource"), tr("Resource name:"), QLineEdit::Normal, {}, &ok);
if (!ok)
return;
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
}
void MainWindow::showObjectInformation()
{
2022-01-10 21:49:06 +01:00
openOrActivateWindow<ObjectInformationDialog>(m_objectInformationWindow, m_project);
2022-01-09 21:07:41 +01:00
}
void MainWindow::transparentBackgroundSettings()
{
2025-11-30 19:43:05 +01:00
TransparentBackgroundSettingsDialog dialog{m_settings, this};
if (dialog.exec() == QDialog::Accepted)
2025-11-30 19:43:05 +01:00
dialog.save(m_settings);
}
template<typename T>
void MainWindow::createFor()
2022-01-09 06:42:13 +01:00
{
QModelIndex parent = m_projectTreeModel->rootFor<T>();
const auto current = m_ui->treeView->currentIndex();
if (current.isValid() && m_projectTreeModel->nodeType(current) == ProjectTreeModel::NodeType::Folder)
{
auto category = current;
while (category.parent().isValid()) category = category.parent();
if (category == parent) parent = current;
}
if (!m_projectTreeModel->insertRows(m_projectTreeModel->rowCount(parent), 1, parent))
QMessageBox::warning(this, tr("Creating failed!"), tr("Creating failed!"));
2022-01-09 06:42:13 +01:00
}
template void MainWindow::createFor<Sprite>();
template void MainWindow::createFor<Sound>();
template void MainWindow::createFor<Background>();
template void MainWindow::createFor<Path>();
template void MainWindow::createFor<Script>();
template void MainWindow::createFor<Font>();
template void MainWindow::createFor<TimeLine>();
template void MainWindow::createFor<Object>();
template void MainWindow::createFor<Room>();
2022-01-09 06:42:13 +01:00
void MainWindow::showGameInformation()
{
2022-01-10 21:49:06 +01:00
GameInformationDialog dialog{this};
if (dialog.exec() /*== QDialog::Accepted*/)
2022-01-10 21:49:06 +01:00
changed();
2022-01-09 06:42:13 +01:00
}
void MainWindow::showGlobalGameSettings()
{
GlobalGameSettingsDialog dialog{m_project.globalGameSettings, this};
2022-01-10 21:49:06 +01:00
if (dialog.exec() == QDialog::Accepted)
changed();
2022-01-09 06:42:13 +01:00
}
void MainWindow::showExtensionPackages()
{
2022-01-10 21:49:06 +01:00
ExtensionPackagesDialog dialog{this};
dialog.exec();
}
void MainWindow::showDefineConstants()
{
openOrActivateWindow<UserDefinedConstantsDialog>(m_userDefinedConstantsWindow, m_project);
}
void MainWindow::showDefineTriggers()
{
openOrActivateWindow<TriggersDialog>(m_triggersWindow, m_project);
}
void MainWindow::showIncludedFiles()
{
openOrActivateWindow<IncludedFilesDialog>(m_includedFilesWindow, m_project);
2022-01-09 06:42:13 +01:00
}
2022-01-15 01:52:55 +01:00
void MainWindow::runGame()
{
if (!applyOpenPropertyWindows())
return;
2026-11-14 12:03:10 +01:00
if (m_project.rooms.empty())
{
QMessageBox::information(this, tr("No room to play"),
tr("Create a room before running the game."));
return;
}
2022-01-15 08:57:28 +01:00
GameEngine engine{m_project};
2022-01-15 01:52:55 +01:00
2022-01-15 08:57:28 +01:00
setEnabled(false);
engine.run();
setEnabled(true);
2022-01-15 01:52:55 +01:00
}
bool MainWindow::applyOpenPropertyWindows()
{
std::vector<QPointer<QMdiSubWindow>> windows;
const auto collect = [&windows](const auto &propertyWindows) {
for (const auto &entry : propertyWindows)
windows.emplace_back(entry.second);
};
collect(m_spritePropertiesWindows);
collect(m_soundPropertiesWindows);
collect(m_backgroundPropertiesWindows);
collect(m_pathPropertiesWindows);
collect(m_scriptPropertiesWindows);
collect(m_fontPropertiesWindows);
collect(m_timeLinePropertiesWindows);
collect(m_objectPropertiesWindows);
collect(m_roomPropertiesWindows);
for (const auto &window : windows)
{
if (!window) continue;
QPointer<QDialog> dialog = qobject_cast<QDialog *>(window->widget());
if (!dialog) continue;
auto *applier = dynamic_cast<ProjectChangesApplier *>(dialog.data());
Q_ASSERT(applier);
const bool hadChanges = dialog->isWindowModified();
if (!applier->applyChanges())
{
m_ui->mdiArea->setActiveSubWindow(window);
return false;
}
if (hadChanges) changed();
}
return true;
}
2022-01-15 01:52:55 +01:00
void MainWindow::debugGame()
{
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
}
2022-01-09 06:42:13 +01:00
void MainWindow::about()
{
QMessageBox::about(this, tr("About Qt Game Maker"),
tr("This <b>About-Dialog</b> is not finished."));
}
void MainWindow::rowsInserted(const QModelIndex &parent, int first, int last)
{
2022-01-11 02:35:26 +01:00
Q_UNUSED(last)
2022-01-09 06:42:13 +01:00
m_ui->treeView->expand(parent);
const auto index = m_projectTreeModel->index(first, 0, parent);
m_ui->treeView->selectionModel()->select(index, QItemSelectionModel::ClearAndSelect);
activated(index);
2022-01-09 06:42:13 +01:00
}
void MainWindow::rowsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
{
rowsAboutToBeRemovedFor<Sprite>(parent, first, last);
rowsAboutToBeRemovedFor<Sound>(parent, first, last);
rowsAboutToBeRemovedFor<Background>(parent, first, last);
rowsAboutToBeRemovedFor<Path>(parent, first, last);
rowsAboutToBeRemovedFor<Script>(parent, first, last);
rowsAboutToBeRemovedFor<Font>(parent, first, last);
rowsAboutToBeRemovedFor<TimeLine>(parent, first, last);
rowsAboutToBeRemovedFor<Object>(parent, first, last);
rowsAboutToBeRemovedFor<Room>(parent, first, last);
2022-01-09 06:42:13 +01:00
}
void MainWindow::modelAboutToBeReset()
{
modelAboutToBeResetFor<Sprite>();
modelAboutToBeResetFor<Sound>();
modelAboutToBeResetFor<Background>();
modelAboutToBeResetFor<Path>();
modelAboutToBeResetFor<Script>();
modelAboutToBeResetFor<Font>();
modelAboutToBeResetFor<TimeLine>();
modelAboutToBeResetFor<Object>();
modelAboutToBeResetFor<Room>();
2022-01-09 06:42:13 +01:00
}
2022-01-15 01:52:55 +01:00
void MainWindow::setupStylesMenu()
{
auto currentStyle = QApplication::style();
m_actionGroupStyles = new QActionGroup{this};
m_actionGroupStyles->setExclusive(true);
for (const auto &key : QStyleFactory::keys())
{
auto name = [&key](){
const std::unique_ptr<QStyle> style{QStyleFactory::create(key)};
if (!style)
{
qWarning() << "invalid style" << key;
return QString{};
}
2022-01-15 06:35:21 +01:00
return style->
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
name
#else
objectName
#endif
();
2022-01-15 01:52:55 +01:00
}();
if (name.isEmpty())
continue;
auto action = m_ui->menuStyle->addAction(tr("%0 (%1)").arg(key, name), this, [this,key](){
auto style = QStyleFactory::create(key);
if (!style)
{
QMessageBox::warning(this, tr("Could not instantiate Style!"), tr("Could not instantiate Style!"));
return;
}
QApplication::setStyle(style);
});
m_actionGroupStyles->addAction(action);
action->setCheckable(true);
2022-01-15 06:35:21 +01:00
action->setChecked(currentStyle && currentStyle->
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
name
#else
objectName
#endif
() == name);
2022-01-15 01:52:55 +01:00
}
}
2022-01-11 02:35:26 +01:00
void MainWindow::loadFile(const QString &path)
{
ProjectContainer project;
{
QFile file{path};
if (!file.open(QIODevice::ReadOnly))
{
QMessageBox::warning(this, tr("Could not load game!"), tr("Could not load game!") + "\n\n" + file.errorString());
return;
}
QDataStream dataStream{&file};
dataStream >> project;
if (dataStream.status() != QDataStream::Ok)
{
QMessageBox::warning(this, tr("Could not load game!"),
tr("This project has an unsupported or damaged format."));
return;
}
2022-01-11 02:35:26 +01:00
}
m_ui->mdiArea->closeAllSubWindows();
if (!m_ui->mdiArea->subWindowList().empty())
return;
if (m_unsavedChanges)
{
const auto result = QMessageBox::warning(
this,
tr("The Game has been modified."),
tr("Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
QMessageBox::Save
);
switch (result)
{
case QMessageBox::Save:
saveFile();
if (m_unsavedChanges)
return;
else
break;
case QMessageBox::Discard:
break;
case QMessageBox::Cancel:
return;
default:
qWarning() << "unexpected dialog result" << result;
return;
}
}
2025-12-20 16:02:46 +01:00
m_settings.pushRecentFile(path);
updateRecentFiles();
2022-01-11 02:35:26 +01:00
m_project = std::move(project);
m_projectTreeModel->setProject(&m_project);
m_filePath = path;
m_unsavedChanges = false;
updateTitle();
}
2022-01-09 06:42:13 +01:00
void MainWindow::updateTitle()
{
2022-01-10 21:49:06 +01:00
setWindowTitle(tr("%0%1 - Qt Gamemaker 1.0 Ultimate")
2022-01-09 06:42:13 +01:00
.arg(m_filePath.isEmpty() ? "<new-game>" : QFileInfo{m_filePath}.fileName())
.arg(m_unsavedChanges ? tr("*") : QString{}));
}
void MainWindow::updateVisibilities()
{
m_ui->menuRecentFiles->menuAction()->setVisible(m_settings.showRecentFiles());
m_ui->logo->setHidden(m_settings.hideWebsiteImage());
}
2025-12-20 16:02:46 +01:00
void MainWindow::updateRecentFiles()
{
m_ui->menuRecentFiles->clear();
for (const auto &path : m_settings.recentFiles())
{
QFileInfo fileInfo{path};
if (!fileInfo.exists())
continue;
m_ui->menuRecentFiles->addAction(fileInfo.fileName(), this, [path,this](){ loadFile(path); });
}
if (m_ui->menuRecentFiles->isEmpty())
m_ui->menuRecentFiles->addAction(tr("(none)"))->setEnabled(false);
else
{
m_ui->menuRecentFiles->addSeparator();
m_ui->menuRecentFiles->addAction(tr("&Clear Recent Files"), this, [this](){
m_settings.clearRecentFiles();
updateRecentFiles();
});
}
}
2025-12-08 10:07:11 +01:00
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;
}
2022-01-10 21:49:06 +01:00
template<typename T, typename ...Targs>
void MainWindow::openOrActivateWindow(QMdiSubWindow * &ptr, Targs &&...args)
{
if (ptr)
m_ui->mdiArea->setActiveSubWindow(ptr);
else
{
auto dialog = new T{std::forward<Targs>(args)...};
2025-12-08 10:07:11 +01:00
auto subwindow = addSubWindow(dialog);
2022-01-10 21:49:06 +01:00
connect(dialog, &QDialog::finished,
this, [&ptr](){
ptr = nullptr;
});
2025-12-08 10:07:11 +01:00
2022-01-10 21:49:06 +01:00
ptr = subwindow;
2025-12-08 10:07:11 +01:00
2022-01-10 21:49:06 +01:00
dialog->show();
}
}
template<typename T>
bool MainWindow::activatedFor(const QModelIndex &index)
{
if (m_projectTreeModel->nodeType(index) != ProjectTreeModel::nodeTypeFor<T>())
return false;
auto entry = m_projectTreeModel->get<T>(index);
if (!entry)
return true;
openPropertiesWindowFor(*entry);
return true;
}
template<typename T>
void MainWindow::rowsAboutToBeRemovedFor(const QModelIndex &parent, int first, int last)
{
const auto closeDescendants = [this](const auto &self, const QModelIndex &item) -> void {
if (m_projectTreeModel->nodeType(item) == ProjectTreeModel::nodeTypeFor<T>())
{
if (auto *entry = m_projectTreeModel->get<T>(item))
{
auto &windows = propertyWindowsFor<T>();
if (auto it = windows.find(entry); it != windows.end())
{
delete it->second;
windows.erase(it);
}
}
}
for (int row = 0; row < m_projectTreeModel->rowCount(item); ++row)
self(self, m_projectTreeModel->index(row, 0, item));
};
for (int row = first; row <= last; ++row)
closeDescendants(closeDescendants, m_projectTreeModel->index(row, 0, parent));
}
template<typename T>
void MainWindow::modelAboutToBeResetFor()
{
auto &propertyWindows = propertyWindowsFor<T>();
for (const auto &pair : propertyWindows)
delete pair.second;
propertyWindows.clear();
}