src/document.cpp

changeset 143
7b62c52835a1
parent 141
185eb297dc1e
child 148
e1ced2523cad
--- a/src/document.cpp	Tue Sep 28 00:21:09 2021 +0300
+++ b/src/document.cpp	Tue Sep 28 22:14:00 2021 +0300
@@ -27,12 +27,6 @@
 #include "tools/selecttool.h"
 #include "tools/transformtool.h"
 
-static const QMetaObject* const toolMetaObjects[] = {
-	&SelectTool::staticMetaObject,
-	&DrawTool::staticMetaObject,
-	&TransformTool::staticMetaObject,
-};
-
 Document::Document(
 	Model* model,
 	DocumentManager* documents,
@@ -158,32 +152,27 @@
 
 void Document::initializeTools()
 {
-	for (const QMetaObject* const metaObject : ::toolMetaObjects)
+	this->tools.clear();
+	this->tools.reserve(3);
+	this->tools.push_back(new SelectTool{this->model, this});
+	this->tools.push_back(new DrawTool{this->model, this});
+	this->tools.push_back(new TransformTool{this->model, this});
+	for (BaseTool* const toolInstance : this->tools)
 	{
-		QObject* const objectInstance = metaObject->newInstance(Q_ARG(Model*, this->model), Q_ARG(QObject*, this));
-		BaseTool* const toolInstance = qobject_cast<BaseTool*>(objectInstance);
-		if (toolInstance)
+		QAction* action = new QAction{toolInstance->name(), this};
+		action->setCheckable(true);
+		this->toolActions[toolInstance] = action;
+		action->setToolTip(toolInstance->toolTip());
+		connect(action, &QAction::triggered, this, &Document::toolActionTriggered);
+		this->toolsBar->addAction(action);
+		QWidget* const widget = toolInstance->toolWidget();
+		if (widget)
 		{
-			this->tools.append(toolInstance);
-			QAction* action = new QAction{toolInstance->name(), this};
-			action->setCheckable(true);
-			this->toolActions[toolInstance] = action;
-			action->setToolTip(toolInstance->toolTip());
-			connect(action, &QAction::triggered, this, &Document::toolActionTriggered);
-			this->toolsBar->addAction(action);
-			QWidget* const widget = toolInstance->toolWidget();
-			if (widget)
-			{
-				this->ui.toolWidgetStack->addWidget(widget);
-			}
-			else
-			{
-				this->ui.toolWidgetStack->addWidget(new QWidget{this});
-			}
+			this->ui.toolWidgetStack->addWidget(widget);
 		}
 		else
 		{
-			QMessageBox::critical(this, tr("Error"), tr("Unable to construct %1").arg(metaObject->className()));
+			this->ui.toolWidgetStack->addWidget(new QWidget{this});
 		}
 	}
 	this->selectTool(this->tools[0]);

mercurial