--- a/src/main.cpp Wed Jun 22 16:53:35 2022 +0300 +++ b/src/main.cpp Wed Jun 22 20:10:57 2022 +0300 @@ -288,10 +288,14 @@ }; } -void initializeTools(Ui_MainWindow* ui, DocumentManager* documents, QWidget* parent) +struct ToolWidgets { - CircleToolOptionsWidget* circleToolOptions = new CircleToolOptionsWidget{parent}; - ObjectEditor* objectEditor = new ObjectEditor{parent}; + CircleToolOptionsWidget* circleToolOptions; + ObjectEditor* objectEditor; +}; + +void initializeTools(Ui_MainWindow* ui, ToolWidgets* toolWidgets, QWidget* parent) +{ const struct { QString name, tooltip; @@ -302,7 +306,7 @@ .name = QObject::tr("Select"), .tooltip = QObject::tr("Select elements from the model."), .icon = {":/icons/navigate-outline.png"}, - .widget = objectEditor, + .widget = toolWidgets->objectEditor, }, { .name = QObject::tr("Draw"), @@ -314,7 +318,7 @@ .name = QObject::tr("Circle"), .tooltip = QObject::tr("Draw circular primitives."), .icon = {":/icons/linetype-circularprimitive.png"}, - .widget = circleToolOptions, + .widget = toolWidgets->circleToolOptions, }, }; for (int i = 0; i < countof(editingModesInfo); ++i) { @@ -335,14 +339,6 @@ ui->toolWidgetStack->setCurrentIndex(i); }); } - QObject::connect( - circleToolOptions, - &CircleToolOptionsWidget::optionsChanged, - [ui, documents](const CircleToolOptions& options) { - if (ModelData* data = currentModelData(ui, documents)) { - data->tools->setCircleToolOptions(options); - } - }); } constexpr bool sortModelIndexesByRow(const QModelIndex& a, const QModelIndex& b) @@ -377,6 +373,10 @@ MessageLog messageLog; Signal settingsChanged; ui.setupUi(&mainWindow); + ToolWidgets toolWidgets{ + .circleToolOptions = new CircleToolOptionsWidget{&mainWindow}, + .objectEditor = new ObjectEditor{&mainWindow}, + }; const uiutilities::KeySequenceMap defaultKeyboardShortcuts = uiutilities::makeKeySequenceMap(uiutilities::collectActions(&mainWindow)); const auto saveSettings = [&]{ @@ -463,7 +463,7 @@ QObject::connect( data->itemSelectionModel.get(), &QItemSelectionModel::selectionChanged, - [modelId, &documents]{ + [modelId, &documents, &toolWidgets]{ ModelData* data = findModelData(&documents, modelId); if (data != nullptr) { auto resolveIndex = [&data](const QModelIndex& index){ @@ -472,6 +472,17 @@ const auto selection = data->itemSelectionModel->selection(); const auto indices = fn::map<QSet<ModelId>>(selection.indexes(), resolveIndex); data->canvas->setSelection(indices); + /* + if (indices.size() == 1) { + opt<std::size_t> index = data->model->find(*indices.begin()); + if (index.has_value()) { + toolWidgets.objectEditor->setObject((*data->model)[*index]); + } + } + else { + toolWidgets.objectEditor->reset(); + } + */ } }); data->canvas->setRenderPreferences(renderPreferences); @@ -633,7 +644,7 @@ action->setChecked(action->data().value<EditingMode>() == mode); } }; - initializeTools(&ui, &documents, &mainWindow); + initializeTools(&ui, &toolWidgets, &mainWindow); for (QAction* action : ui.editingModesToolBar->actions()) { QObject::connect(action, &QAction::triggered, [&, action]{ if (ModelData* data = currentModelData(&ui, &documents)) { @@ -669,6 +680,14 @@ ui.messageLog->scrollToBottom(); } }); + QObject::connect( + toolWidgets.circleToolOptions, + &CircleToolOptionsWidget::optionsChanged, + [&ui, &documents](const CircleToolOptions& options) { + if (ModelData* data = currentModelData(&ui, &documents)) { + data->tools->setCircleToolOptions(options); + } + }); mainWindow.setWindowTitle(title()); mainWindow.tabifyDockWidget(ui.messageLogDock, ui.toolOptionsDock); mainWindow.restoreGeometry(setting<Setting::MainWindowGeometry>());