src/main.cpp

changeset 243
959469a7e149
parent 241
c4e2afabcb90
child 249
37d3c819cafa
equal deleted inserted replaced
242:16855456992d 243:959469a7e149
47 std::unique_ptr<EditTools> tools; 47 std::unique_ptr<EditTools> tools;
48 std::unique_ptr<AxesLayer> axesLayer; 48 std::unique_ptr<AxesLayer> axesLayer;
49 std::unique_ptr<GridLayer> gridLayer; 49 std::unique_ptr<GridLayer> gridLayer;
50 Model* model; 50 Model* model;
51 }; 51 };
52
53 class Signal final : public QObject
54 {
55 Q_OBJECT
56 public:
57 Signal() : QObject{}{}
58 virtual ~Signal(){}
59 void emit()
60 {
61 Q_EMIT this->triggered();
62 }
63 Q_SIGNALS:
64 void triggered();
65 };
52 #include "main.moc" 66 #include "main.moc"
53 67
54 static void doQtRegistrations() 68 static void doQtRegistrations()
55 { 69 {
56 QCoreApplication::setApplicationName(::appName); 70 QCoreApplication::setApplicationName(::appName);
357 LibrariesModel libraries{&mainWindow}; 371 LibrariesModel libraries{&mainWindow};
358 QStringList recentlyOpenedFiles; 372 QStringList recentlyOpenedFiles;
359 ColorTable colorTable; 373 ColorTable colorTable;
360 gl::RenderPreferences renderPreferences; 374 gl::RenderPreferences renderPreferences;
361 MessageLog messageLog; 375 MessageLog messageLog;
376 Signal settingsChanged;
362 ui.setupUi(&mainWindow); 377 ui.setupUi(&mainWindow);
363 const uiutilities::KeySequenceMap defaultKeyboardShortcuts = 378 const uiutilities::KeySequenceMap defaultKeyboardShortcuts =
364 uiutilities::makeKeySequenceMap(uiutilities::collectActions(&mainWindow)); 379 uiutilities::makeKeySequenceMap(uiutilities::collectActions(&mainWindow));
365 const auto saveSettings = [&]{ 380 const auto saveSettings = [&]{
366 setSetting<Setting::MainWindowGeometry>(mainWindow.saveGeometry()); 381 setSetting<Setting::MainWindowGeometry>(mainWindow.saveGeometry());
368 setSetting<Setting::RecentFiles>(recentlyOpenedFiles); 383 setSetting<Setting::RecentFiles>(recentlyOpenedFiles);
369 setSetting<Setting::RenderStyle>(renderPreferences.style); 384 setSetting<Setting::RenderStyle>(renderPreferences.style);
370 setSetting<Setting::DrawAxes>(renderPreferences.drawAxes); 385 setSetting<Setting::DrawAxes>(renderPreferences.drawAxes);
371 setSetting<Setting::Wireframe>(renderPreferences.wireframe); 386 setSetting<Setting::Wireframe>(renderPreferences.wireframe);
372 libraries.storeToSettings(); 387 libraries.storeToSettings();
388 settingsChanged.emit();
373 }; 389 };
374 const auto updateRecentlyOpenedDocumentsMenu = [&]{ 390 const auto updateRecentlyOpenedDocumentsMenu = [&]{
375 rebuildRecentFilesMenu(ui.menuRecentFiles, recentlyOpenedFiles, &mainWindow); 391 rebuildRecentFilesMenu(ui.menuRecentFiles, recentlyOpenedFiles, &mainWindow);
376 for (QAction* action : ui.menuRecentFiles->findChildren<QAction*>()) { 392 for (QAction* action : ui.menuRecentFiles->findChildren<QAction*>()) {
377 QString path = action->data().toString(); 393 QString path = action->data().toString();
404 updateRecentlyOpenedDocumentsMenu(); 420 updateRecentlyOpenedDocumentsMenu();
405 colorTable = loadColors(&libraries); 421 colorTable = loadColors(&libraries);
406 updateRenderPreferences(&ui, &renderPreferences, &documents); 422 updateRenderPreferences(&ui, &renderPreferences, &documents);
407 ui.mdiArea->setViewMode(setting<Setting::ViewMode>()); 423 ui.mdiArea->setViewMode(setting<Setting::ViewMode>());
408 ui.retranslateUi(&mainWindow); 424 ui.retranslateUi(&mainWindow);
425 settingsChanged.emit();
409 }; 426 };
410 const auto addRecentlyOpenedFile = [&](const QString& path){ 427 const auto addRecentlyOpenedFile = [&](const QString& path){
411 constexpr int maxRecentlyOpenedFiles = 10; 428 constexpr int maxRecentlyOpenedFiles = 10;
412 recentlyOpenedFiles.removeAll(path); 429 recentlyOpenedFiles.removeAll(path);
413 recentlyOpenedFiles.insert(0, path); 430 recentlyOpenedFiles.insert(0, path);
478 data->itemSelectionModel->select(qindex, QItemSelectionModel::Select); 495 data->itemSelectionModel->select(qindex, QItemSelectionModel::Select);
479 } 496 }
480 } 497 }
481 } 498 }
482 }); 499 });
500 QObject::connect(&settingsChanged, &Signal::triggered, [modelId, &documents]{
501 ModelData* data = findModelData(&documents, modelId);
502 if (data != nullptr) {
503 data->gridLayer->settingsChanged();
504 }
505 });
483 QObject::connect(data->canvas.get(), &PartRenderer::message, &messageLog, &MessageLog::addMessage); 506 QObject::connect(data->canvas.get(), &PartRenderer::message, &messageLog, &MessageLog::addMessage);
484 const QFileInfo fileInfo{*documents.modelPath(modelId)}; 507 const QFileInfo fileInfo{*documents.modelPath(modelId)};
485 ModelSubWindow* subWindow = new ModelSubWindow{modelId, ui.mdiArea}; 508 ModelSubWindow* subWindow = new ModelSubWindow{modelId, ui.mdiArea};
486 subWindow->setWidget(data->canvas.get()); 509 subWindow->setWidget(data->canvas.get());
487 subWindow->setWindowTitle(tabName(fileInfo)); 510 subWindow->setWindowTitle(tabName(fileInfo));

mercurial