src/mainwindow.cpp

changeset 96
165777a20dc7
parent 94
164f53fb5921
child 97
d9a3b153f679
equal deleted inserted replaced
95:06a1aef170aa 96:165777a20dc7
26 #include "settingseditor/settingseditor.h" 26 #include "settingseditor/settingseditor.h"
27 #include "version.h" 27 #include "version.h"
28 #include "document.h" 28 #include "document.h"
29 #include "uiutilities.h" 29 #include "uiutilities.h"
30 #include "widgets/colorselectdialog.h" 30 #include "widgets/colorselectdialog.h"
31 #include "tools/basetool.h"
32 #include "tools/drawtool.h"
33 #include "tools/selecttool.h"
34
35 static const QMetaObject* const toolMetaObjects[] = {
36 &SelectTool::staticMetaObject,
37 &DrawTool::staticMetaObject,
38 };
31 39
32 template<typename BaseType, typename MemberType, typename DataType> 40 template<typename BaseType, typename MemberType, typename DataType>
33 struct MemberData 41 struct MemberData
34 { 42 {
35 std::size_t member; 43 std::size_t member;
76 this->updateTitle(); 84 this->updateTitle();
77 this->restoreStartupSettings(); 85 this->restoreStartupSettings();
78 this->restoreSettings(); 86 this->restoreSettings();
79 this->updateRenderPreferences(); 87 this->updateRenderPreferences();
80 this->newModel(); 88 this->newModel();
89
90 for (const QMetaObject* const metaObject : ::toolMetaObjects)
91 {
92 QObject* const objectInstance = metaObject->newInstance(Q_ARG(QObject*, this));
93 BaseTool* const toolInstance = qobject_cast<BaseTool*>(objectInstance);
94 if (toolInstance)
95 {
96 this->selectedTool = coalesce(this->selectedTool, toolInstance);
97 this->tools.append(toolInstance);
98 qInfo() << toolInstance->name();
99 }
100 else
101 {
102 QMessageBox::critical(this, tr("Error"), tr("Unable to construct %1").arg(metaObject->className()));
103 }
104 }
81 } 105 }
82 106
83 // MainWindow needs a destructor even if it is empty because otherwise the destructor of the 107 // MainWindow needs a destructor even if it is empty because otherwise the destructor of the
84 // std::unique_ptr is resolved in the header file, where it will complain about Ui_MainWindow 108 // std::unique_ptr is resolved in the header file, where it will complain about Ui_MainWindow
85 // being incomplete. 109 // being incomplete.

mercurial