diff -r 06a1aef170aa -r 165777a20dc7 src/mainwindow.cpp --- a/src/mainwindow.cpp Thu Nov 05 14:29:58 2020 +0200 +++ b/src/mainwindow.cpp Sun Jan 10 15:28:44 2021 +0200 @@ -28,6 +28,14 @@ #include "document.h" #include "uiutilities.h" #include "widgets/colorselectdialog.h" +#include "tools/basetool.h" +#include "tools/drawtool.h" +#include "tools/selecttool.h" + +static const QMetaObject* const toolMetaObjects[] = { + &SelectTool::staticMetaObject, + &DrawTool::staticMetaObject, +}; template struct MemberData @@ -78,6 +86,22 @@ this->restoreSettings(); this->updateRenderPreferences(); this->newModel(); + + for (const QMetaObject* const metaObject : ::toolMetaObjects) + { + QObject* const objectInstance = metaObject->newInstance(Q_ARG(QObject*, this)); + BaseTool* const toolInstance = qobject_cast(objectInstance); + if (toolInstance) + { + this->selectedTool = coalesce(this->selectedTool, toolInstance); + this->tools.append(toolInstance); + qInfo() << toolInstance->name(); + } + else + { + QMessageBox::critical(this, tr("Error"), tr("Unable to construct %1").arg(metaObject->className())); + } + } } // MainWindow needs a destructor even if it is empty because otherwise the destructor of the