src/mainwindow.cpp

changeset 96
165777a20dc7
parent 94
164f53fb5921
child 97
d9a3b153f679
--- 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<typename BaseType, typename MemberType, typename DataType>
 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<BaseTool*>(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

mercurial