src/document.cpp

Wed, 25 May 2022 17:47:06 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 25 May 2022 17:47:06 +0300
changeset 194
be056e87c8ca
parent 191
d355d4c52d51
child 197
0e729e681a2c
permissions
-rw-r--r--

simplify further

24
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
1 /*
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
2 * LDForge: LDraw parts authoring CAD
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
3 * Copyright (C) 2013 - 2020 Teemu Piippo
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
4 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
5 * This program is free software: you can redistribute it and/or modify
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
6 * it under the terms of the GNU General Public License as published by
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
8 * (at your option) any later version.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
9 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
10 * This program is distributed in the hope that it will be useful,
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
13 * GNU General Public License for more details.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
14 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
15 * You should have received a copy of the GNU General Public License
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
17 */
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
18
47
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents: 39
diff changeset
19 #include <QMouseEvent>
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
20 #include <QMessageBox>
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 #include "document.h"
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 #include "ui_document.h"
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 #include "model.h"
153
2f79053c2e9a Renamed modeleditcontext.cpp -> modeleditor.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
24 #include "modeleditor.h"
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
25 #include "ui/objecteditor.h"
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
26
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
27 Document::Document(
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
28 Model* model,
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
29 DocumentManager* documents,
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
30 const ldraw::ColorTable& colorTable,
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
31 QWidget* parent) :
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 QWidget{parent},
178
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents: 169
diff changeset
33 colorTable{colorTable},
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
34 canvas{new Canvas{model, this, documents, colorTable, this}},
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 model{model},
21
Teemu Piippo <teemu@hecknology.net>
parents: 9
diff changeset
36 documents{documents},
118
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
37 vertexMap{model},
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
38 ui{*new Ui_Document},
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
39 toolsBar{new QToolBar{this}},
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
40 objectEditor{new ObjectEditor{this}}
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 {
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 this->ui.setupUi(this);
187
30204975694a work on circle tool
Teemu Piippo <teemu@hecknology.net>
parents: 185
diff changeset
43 const int listWidth = static_cast<int>(this->width() / 3);
30204975694a work on circle tool
Teemu Piippo <teemu@hecknology.net>
parents: 185
diff changeset
44 this->ui.viewportListSplitter->setSizes({listWidth * 2, listWidth});
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
45 this->ui.toolsBarContainer->setLayout(new QVBoxLayout{this->ui.toolsBarContainer});
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
46 this->ui.toolsBarContainer->layout()->addWidget(this->toolsBar);
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 this->ui.listView->setModel(model);
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
48 this->ui.viewportFrame->setLayout(new QVBoxLayout{this->ui.listView});
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
49 this->ui.viewportFrame->layout()->addWidget(this->canvas);
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
50 this->toolsBar->setOrientation(Qt::Vertical);
47
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents: 39
diff changeset
51 this->setMouseTracking(true);
187
30204975694a work on circle tool
Teemu Piippo <teemu@hecknology.net>
parents: 185
diff changeset
52 connect(this->ui.viewportListSplitter, &QSplitter::splitterMoved, this, &Document::splitterChanged);
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
53 connect(this->canvas, &Canvas::newStatusText, this, &Document::newStatusText);
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
54 connect(this->canvas, &Canvas::selectionChanged, [&](const QSet<ldraw::id_t>& newSelection)
51
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
55 {
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
56 QItemSelectionModel* selectionModel = this->ui.listView->selectionModel();
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
57 QItemSelection selection;
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
58 for (const ldraw::id_t id : newSelection)
51
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
59 {
150
b6cbba6e29a1 extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
60 QModelIndex index = this->model->find(id);
51
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
61 if (index != QModelIndex{})
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
62 {
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
63 selection.select(index, index);
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
64 }
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
65 }
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
66 QSignalBlocker blocker{this};
51
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
67 selectionModel->select(selection, QItemSelectionModel::ClearAndSelect);
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
68 });
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
69 connect(this->ui.listView->selectionModel(), &QItemSelectionModel::selectionChanged,
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
70 [&](const QItemSelection& selected, const QItemSelection& deselected)
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
71 {
150
b6cbba6e29a1 extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
72 auto resolveIndex = [this](const QModelIndex& index){ return (*this->model)[index.row()]->id; };
63
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents: 51
diff changeset
73 auto resolve = [resolveIndex](const QItemSelection& selection)
51
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
74 {
73
97df974b5ed5 ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents: 63
diff changeset
75 return fn::map<QSet<ldraw::id_t>>(selection.indexes(), resolveIndex);
63
f7dd937667a5 omg functional programming
Teemu Piippo <teemu@hecknology.net>
parents: 51
diff changeset
76 };
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
77 this->canvas->handleSelectionChange(resolve(selected), resolve(deselected));
51
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
78 });
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
79 connect(this->model, &Model::dataChanged, this->canvas, qOverload<>(&Canvas::update));
118
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
80 connect(&this->vertexMap, &VertexMap::verticesChanged, [&]()
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
81 {
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
82 this->canvas->rebuildVertices(this);
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
83 });
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
84 this->initializeTools();
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
85 }
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
86
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
87 Document::~Document()
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
88 {
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
89 delete &this->ui;
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
90 }
9
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
91
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
92 QByteArray Document::saveSplitterState() const
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
93 {
187
30204975694a work on circle tool
Teemu Piippo <teemu@hecknology.net>
parents: 185
diff changeset
94 return this->ui.viewportListSplitter->saveState();
9
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
95 }
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
96
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
97 void Document::restoreSplitterState(const QByteArray& state)
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
98 {
187
30204975694a work on circle tool
Teemu Piippo <teemu@hecknology.net>
parents: 185
diff changeset
99 this->ui.viewportListSplitter->restoreState(state);
9
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
100 }
36
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
101
152
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 150
diff changeset
102 std::unique_ptr<ModelEditor> Document::editModel()
111
1f42c03fafca Draw tool actually adds objects now
Teemu Piippo <teemu@hecknology.net>
parents: 109
diff changeset
103 {
152
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 150
diff changeset
104 std::unique_ptr<ModelEditor> editorPointer = std::make_unique<ModelEditor>(*this->model);
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 150
diff changeset
105 connect(editorPointer.get(), &ModelEditor::objectModified, [&](int position){
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 150
diff changeset
106 this->model->emitDataChangedSignal(position);
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 150
diff changeset
107 });
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 150
diff changeset
108 return editorPointer;
111
1f42c03fafca Draw tool actually adds objects now
Teemu Piippo <teemu@hecknology.net>
parents: 109
diff changeset
109 }
1f42c03fafca Draw tool actually adds objects now
Teemu Piippo <teemu@hecknology.net>
parents: 109
diff changeset
110
118
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
111 void Document::applyToVertices(VertexMap::ApplyFunction fn) const
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
112 {
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
113 this->vertexMap.apply(fn);
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
114 }
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
115
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
116 const char INDEX_PROPERTY[] = "_editing_mode_index";
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
117
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
118 void Document::initializeTools()
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
119 {
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
120 const struct
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
121 {
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
122 QString name, tooltip;
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
123 QPixmap icon;
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
124 QWidget* widget;
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
125 } editingModesInfo[] = {
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
126 {
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
127 .name = tr("Select"),
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
128 .tooltip = tr("Select elements from the model."),
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
129 .icon = {":/icons/navigate-outline.png"},
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
130 .widget = this->objectEditor,
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
131 },
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
132 {
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
133 .name = tr("Draw"),
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
134 .tooltip = tr("Draw new elements into the model."),
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
135 .icon = {":/icons/pencil-outline.png"},
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
136 .widget = nullptr,
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
137 },
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
138 };
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
139 for (int i = 0; i < countof(editingModesInfo); ++i) {
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
140 const auto& editingModeInfo = editingModesInfo[i];
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
141 QAction* action = new QAction{editingModeInfo.name, this};
143
7b62c52835a1 Fix memory corruption involving document tools.
Teemu Piippo <teemu@hecknology.net>
parents: 141
diff changeset
142 action->setCheckable(true);
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
143 action->setChecked(i == 0);
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
144 action->setToolTip(editingModeInfo.tooltip);
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
145 action->setIcon(QPixmap{editingModeInfo.icon});
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
146 action->setProperty(INDEX_PROPERTY, i);
143
7b62c52835a1 Fix memory corruption involving document tools.
Teemu Piippo <teemu@hecknology.net>
parents: 141
diff changeset
147 this->toolsBar->addAction(action);
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
148 QWidget* widget = editingModeInfo.widget;
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
149 if (widget == nullptr) {
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
150 widget = new QWidget{this};
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
151 }
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
152 this->ui.toolWidgetStack->addWidget(widget);
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
153 this->toolActions.push_back(action);
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
154 connect(action, &QAction::triggered, this, &Document::editingModeTriggered);
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
155 }
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
156 }
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
157
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
158 void Document::editingModeTriggered()
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
159 {
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
160 QAction* triggeredAction = qobject_cast<QAction*>(this->sender());
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
161 if (triggeredAction != nullptr)
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
162 {
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
163 const int index = triggeredAction->property(INDEX_PROPERTY).toInt();
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
164 this->canvas->mode = static_cast<EditingMode>(index);
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
165 this->ui.toolWidgetStack->setCurrentIndex(index);
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
166 for (QAction* action : this->toolActions) {
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
167 action->setChecked(action == triggeredAction);
126
a7c720aff97c moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents: 125
diff changeset
168 }
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
169 }
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
170 }
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
171
178
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents: 169
diff changeset
172 const Model &Document::getModel() const
152
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 150
diff changeset
173 {
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 150
diff changeset
174 return *this->model;
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 150
diff changeset
175 }
169
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 163
diff changeset
176
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 163
diff changeset
177 const QSet<ldraw::id_t> Document::selectedObjects() const
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 163
diff changeset
178 {
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 188
diff changeset
179 return this->canvas->selectedObjects();
169
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 163
diff changeset
180 }

mercurial