src/main.cpp

changeset 333
07e65a4c6611
parent 332
ae7f7fbb9cda
child 335
c5830bce1c23
equal deleted inserted replaced
332:ae7f7fbb9cda 333:07e65a4c6611
50 ModelData(QObject* parent) : QObject {parent} {} 50 ModelData(QObject* parent) : QObject {parent} {}
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<QTextDocument> textbuffer;
56 std::unique_ptr<QTextCursor> textcursor; 55 std::unique_ptr<QTextCursor> textcursor;
57 Model* model; 56 Model* model;
58 }; 57 };
59 58
60 class Signal final : public QObject 59 class Signal final : public QObject
482 [model](const ModifyModel& action){ 481 [model](const ModifyModel& action){
483 model->assignAt(action.position, action.newElement); 482 model->assignAt(action.position, action.newElement);
484 }, 483 },
485 }, action); 484 }, action);
486 */ 485 */
486
487 }; 487 };
488 const auto restoreSettings = [&]{ 488 const auto restoreSettings = [&]{
489 recentlyOpenedFiles = setting<Setting::RecentFiles>(); 489 recentlyOpenedFiles = setting<Setting::RecentFiles>();
490 renderPreferences = loadRenderPreferences(); 490 renderPreferences = loadRenderPreferences();
491 libraries.restoreFromSettings(); 491 libraries.restoreFromSettings();
521 data->model = model; 521 data->model = model;
522 data->canvas->addRenderLayer(data->axesLayer.get()); 522 data->canvas->addRenderLayer(data->axesLayer.get());
523 data->canvas->setLayerEnabled(data->axesLayer.get(), setting<Setting::DrawAxes>()); 523 data->canvas->setLayerEnabled(data->axesLayer.get(), setting<Setting::DrawAxes>());
524 data->canvas->addRenderLayer(data->gridLayer.get()); 524 data->canvas->addRenderLayer(data->gridLayer.get());
525 data->canvas->addRenderLayer(data->tools.get()); 525 data->canvas->addRenderLayer(data->tools.get());
526 QString modeltext; 526 new LDrawSyntaxHighlighter{model};
527 QTextStream stream{&modeltext}; 527 data->textcursor = std::make_unique<QTextCursor>(model);
528 ::save(*model, &stream);
529 data->textbuffer = std::make_unique<QTextDocument>();
530 data->textbuffer->setPlainText(modeltext);
531 data->textbuffer->setDefaultFont(monospace());
532 data->textbuffer->setDocumentLayout(new QPlainTextDocumentLayout(data->textbuffer.get()));
533 new LDrawSyntaxHighlighter{data->textbuffer.get()};
534 data->textcursor = std::make_unique<QTextCursor>(data->textbuffer.get());
535 documents.setModelPayload(modelId, data); 528 documents.setModelPayload(modelId, data);
536 QObject::connect( 529 QObject::connect(
537 data->tools.get(), 530 data->tools.get(),
538 &EditTools::modelAction, 531 &EditTools::modelAction,
539 std::bind(executeAction, model, std::placeholders::_1)); 532 std::bind(executeAction, model, std::placeholders::_1));
714 [&](QMdiSubWindow* subWindow) { 707 [&](QMdiSubWindow* subWindow) {
715 ModelSubWindow* modelSubWindow = qobject_cast<ModelSubWindow*>(subWindow); 708 ModelSubWindow* modelSubWindow = qobject_cast<ModelSubWindow*>(subWindow);
716 if (modelSubWindow != nullptr) { 709 if (modelSubWindow != nullptr) {
717 if (ModelData* data = documents.findPayload<ModelData>(modelSubWindow->modelId)) { 710 if (ModelData* data = documents.findPayload<ModelData>(modelSubWindow->modelId)) {
718 checkEditingModeAction(data->tools->currentEditingMode()); 711 checkEditingModeAction(data->tools->currentEditingMode());
719 ui.modelEdit->setDocument(data->textbuffer.get()); 712 ui.modelEdit->setDocument(data->model);
720 ui.modelEdit->setTextCursor(*data->textcursor); 713 ui.modelEdit->setTextCursor(*data->textcursor);
721 } 714 }
722 } 715 }
723 else { 716 else {
724 checkEditingModeAction(EditingMode::SelectMode); 717 checkEditingModeAction(EditingMode::SelectMode);
773 QObject::connect( 766 QObject::connect(
774 ui.modelEdit, 767 ui.modelEdit,
775 &QPlainTextEdit::textChanged, 768 &QPlainTextEdit::textChanged,
776 [&]{ 769 [&]{
777 if (ModelData* data = currentModelData(&ui, &documents)) { 770 if (ModelData* data = currentModelData(&ui, &documents)) {
778 Model* const model = data->model;
779 model->clear();
780 QString text = ui.modelEdit->toPlainText();
781 QTextStream stream{&text};
782 Parser parser(stream);
783 parser.parseBody(*data->model);
784 documents.loadDependenciesForAllModels(libraries); 771 documents.loadDependenciesForAllModels(libraries);
785 data->canvas->update(); 772 data->canvas->update();
786 } 773 }
787 }); 774 });
788 mainWindow.tabifyDockWidget(ui.messageLogDock, ui.toolOptionsDock); 775 mainWindow.tabifyDockWidget(ui.messageLogDock, ui.toolOptionsDock);

mercurial