src/main.cpp

changeset 338
719b909a7d2b
parent 337
5bb26aa33ad5
child 350
676d0b43b577
equal deleted inserted replaced
337:5bb26aa33ad5 338:719b909a7d2b
51 std::unique_ptr<PartRenderer> canvas; 51 std::unique_ptr<PartRenderer> canvas;
52 std::unique_ptr<EditTools> tools; 52 std::unique_ptr<EditTools> tools;
53 std::unique_ptr<AxesLayer> axesLayer; 53 std::unique_ptr<AxesLayer> axesLayer;
54 std::unique_ptr<GridLayer> gridLayer; 54 std::unique_ptr<GridLayer> gridLayer;
55 std::unique_ptr<QTextCursor> textcursor; 55 std::unique_ptr<QTextCursor> textcursor;
56 Model* model; 56 QTextDocument* model;
57 }; 57 };
58 58
59 class Signal final : public QObject 59 class Signal final : public QObject
60 { 60 {
61 Q_OBJECT 61 Q_OBJECT
161 161
162 static ModelData* currentModelData(Ui_MainWindow* ui, const DocumentManager* documents) 162 static ModelData* currentModelData(Ui_MainWindow* ui, const DocumentManager* documents)
163 { 163 {
164 if (auto* const activeSubWindow = currentModelSubWindow(ui)) { 164 if (auto* const activeSubWindow = currentModelSubWindow(ui)) {
165 return findModelData(documents, activeSubWindow->modelId); 165 return findModelData(documents, activeSubWindow->modelId);
166 }
167 else {
168 return nullptr;
169 }
170 }
171
172 static Model* currentModelBody(Ui_MainWindow* ui, DocumentManager* documents)
173 {
174 if (auto* const activeSubWindow = currentModelSubWindow(ui)) {
175 return documents->getModelById(activeSubWindow->modelId);
176 } 166 }
177 else { 167 else {
178 return nullptr; 168 return nullptr;
179 } 169 }
180 } 170 }
330 ui->toolWidgetStack->setCurrentIndex(i); 320 ui->toolWidgetStack->setCurrentIndex(i);
331 }); 321 });
332 } 322 }
333 } 323 }
334 324
335 static QFont monospace()
336 {
337 QFont font{"Monospace"};
338 font.setStyleHint(QFont::TypeWriter);
339 font.setPointSize(10);
340 font.setFixedPitch(true);
341 return font;
342 }
343
344 constexpr bool sortModelIndexesByRow(const QModelIndex& a, const QModelIndex& b) 325 constexpr bool sortModelIndexesByRow(const QModelIndex& a, const QModelIndex& b)
345 { 326 {
346 return a.row() < b.row(); 327 return a.row() < b.row();
347 } 328 }
348 329
407 SubWindow* subWindow = new SubWindow{args..., nullptr}; 388 SubWindow* subWindow = new SubWindow{args..., nullptr};
408 mdiArea->addSubWindow(subWindow); 389 mdiArea->addSubWindow(subWindow);
409 return subWindow; 390 return subWindow;
410 } 391 }
411 392
412 static QSet<ElementId> resolveIdsFromSelection(const ModelData* data)
413 {
414 // const auto selection = data->itemSelectionModel->selection();
415 QSet<ElementId> selectedIndexes;
416 /* for (const QModelIndex& qindex : selection.indexes()) {
417 const std::size_t row = unsigned_cast(qindex.row());
418 selectedIndexes.insert(data->model->idAt(row));
419 }
420 */ return selectedIndexes;
421 }
422
423 int main(int argc, char *argv[]) 393 int main(int argc, char *argv[])
424 { 394 {
425 doQtRegistrations(); 395 doQtRegistrations();
426 QApplication app{argc, argv}; 396 QApplication app{argc, argv};
427 QApplication::setWindowIcon(QIcon{":/icons/appicon.png"}); 397 QApplication::setWindowIcon(QIcon{":/icons/appicon.png"});
467 } 437 }
468 ); 438 );
469 } 439 }
470 }; 440 };
471 const auto executeAction = [&]( 441 const auto executeAction = [&](
472 Model* model, const ModelAction& action 442 QTextDocument* model, const ModelAction& action
473 ) { 443 ) {
474 std::visit(overloaded{ 444 std::visit(overloaded{
475 [model](const AppendToModel& action){ 445 [model](const AppendToModel& action){
476 QTextCursor cursor{model}; 446 QTextCursor cursor{model};
477 cursor.movePosition(QTextCursor::End); 447 cursor.movePosition(QTextCursor::End);
517 } 487 }
518 saveSettings(); 488 saveSettings();
519 updateRecentlyOpenedDocumentsMenu(); 489 updateRecentlyOpenedDocumentsMenu();
520 }; 490 };
521 const auto openModelForEditing = [&](const ModelId modelId){ 491 const auto openModelForEditing = [&](const ModelId modelId){
522 Model* model = documents.getModelById(modelId); 492 QTextDocument* model = documents.getModelById(modelId);
523 if (model != nullptr) { 493 if (model != nullptr) {
524 ModelData* data = new ModelData(&documents); 494 ModelData* data = new ModelData(&documents);
525 data->tools = std::make_unique<EditTools>(); 495 data->tools = std::make_unique<EditTools>();
526 data->canvas = std::make_unique<PartRenderer>(model, &documents, colorTable); 496 data->canvas = std::make_unique<PartRenderer>(model, &documents, colorTable);
527 data->axesLayer = std::make_unique<AxesLayer>(); 497 data->axesLayer = std::make_unique<AxesLayer>();
754 QObject::connect( 724 QObject::connect(
755 ui.actionMakeUnofficial, 725 ui.actionMakeUnofficial,
756 &QAction::triggered, 726 &QAction::triggered,
757 [&]{ 727 [&]{
758 if (ModelData* data = currentModelData(&ui, &documents)) { 728 if (ModelData* data = currentModelData(&ui, &documents)) {
759 Model* const model = data->model; 729 QTextDocument* const model = data->model;
760 for (const ModelAction& action : ldraw::makeUnofficial(model)) { 730 for (const ModelAction& action : ldraw::makeUnofficial(model)) {
761 executeAction(model, action); 731 executeAction(model, action);
762 } 732 }
763 } 733 }
764 }); 734 });

mercurial