src/model.cpp

Sat, 31 Mar 2018 18:41:24 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 31 Mar 2018 18:41:24 +0300
changeset 1366
69087b1e123b
parent 1326
69a90bd2dba2
permissions
-rw-r--r--

start rework

1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
1 /*
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
2 * LDForge: LDraw parts authoring CAD
1326
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1306
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
4 *
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
5 * This program is free software: you can redistribute it and/or modify
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
6 * it under the terms of the GNU General Public License as published by
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
8 * (at your option) any later version.
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
9 *
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
10 * This program is distributed in the hope that it will be useful,
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
13 * GNU General Public License for more details.
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
14 *
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
15 * You should have received a copy of the GNU General Public License
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
17 */
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
18
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 #include "model.h"
1147
a26568aa3cce Renamed ldObject.cpp → linetypes/modelobject.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1141
diff changeset
20 #include "linetypes/modelobject.h"
1366
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
21 #include "linetypes/comment.h"
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1077
diff changeset
22 #include "documentmanager.h"
1273
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
23 #include "generics/migrate.h"
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
24 #include "editHistory.h"
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1077
diff changeset
26 Model::Model(DocumentManager* manager) :
1240
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
27 QAbstractListModel {manager},
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1077
diff changeset
28 _manager {manager} {}
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 Model::~Model()
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 {
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 for (int i = 0; i < countof(_objects); ++i)
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 delete _objects[i];
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
36 void Model::installObject(int row, LDObject* object)
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 {
1279
0f6a4a7cafec renamed signal
Santeri Piippo
parents: 1278
diff changeset
38 connect(object, SIGNAL(modified(LDObjectState, LDObjectState)), this, SLOT(recountTriangles()));
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
39 beginInsertRows({}, row, row);
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
40 _objects.insert(row, object);
1278
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
41
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
42 if (this->pickingColorCursor <= 0xffffff)
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
43 {
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
44 this->pickingColors[object] = this->pickingColorCursor;
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
45 this->pickingColorCursor += 1;
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
46 }
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
47
1281
f9c01b455594 optimized triangle count
Santeri Piippo
parents: 1279
diff changeset
48 _triangleCount += object->triangleCount(documentManager());
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
49 emit objectAdded(index(row));
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
50 endInsertRows();
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
53 /*
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
54 * Returns the amount of objects in this model.
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
55 */
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 int Model::size() const
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57 {
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58 return _objects.size();
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
59 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
60
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
61 /*
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
62 * Returns the vector of objects in this model.
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
63 */
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
64 const QVector<LDObject*>& Model::objects() const
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65 {
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
66 return _objects;
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
67 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
68
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
69 /*
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
70 * Takes an existing object and copies it to this model, at the specified position.
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
71 */
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
72 void Model::insertCopy(int position, LDObject* object)
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
73 {
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
74 installObject(position, Serializer::clone(object));
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
75 }
1261
5d2c9d36da9d Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents: 1258
diff changeset
76
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
77 void Model::insertFromArchive(int row, Serializer::Archive& archive)
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
78 {
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
79 LDObject* object = Serializer::restore(archive);
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
80
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
81 if (object)
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
82 installObject(row, object);
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
83 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
84
1273
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
85 bool Model::moveRows(
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
86 const QModelIndex&,
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
87 int sourceRow,
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
88 int count,
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
89 const QModelIndex&,
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
90 int destinationRow
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
91 ) {
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
92 int sourceRowLast = sourceRow + count - 1;
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
93
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
94 if (range(0, 1, size() - count).contains(sourceRow)
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
95 and range(0, 1, size()).contains(destinationRow)
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
96 ) {
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
97 beginMoveRows({}, sourceRow, sourceRowLast, {}, destinationRow);
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
98 migrate(_objects, sourceRow, sourceRowLast, destinationRow);
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
99 endMoveRows();
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
100 return true;
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
101 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
102 else
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
103 {
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
104 return false;
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
105 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
106 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
107
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
108 /*
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
109 * Assigns a new object to the specified position in the model. The object that already is in the position is deleted in the process.
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
110 */
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
111 bool Model::setObjectAt(int row, Serializer::Archive& archive)
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
112 {
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
113 LDObject* object = Serializer::restore(archive);
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
114
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
115 if (object and row >= 0 and row < countof(_objects))
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
116 {
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
117 removeAt(row);
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
118 insertCopy(row, object);
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
119 return true;
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
120 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
121 else
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
122 {
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
123 return false;
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
124 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
125 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
126
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
127 /*
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
128 * Returns the object at the specified position, or null if not found.
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
129 */
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
130 LDObject* Model::getObject(int position) const
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
131 {
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
132 if (position >= 0 and position < countof(_objects))
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
133 return _objects[position];
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
134 else
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
135 return nullptr;
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
136 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
137
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
138 /*
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
139 * Removes the given object from the model.
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
140 */
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
141 void Model::remove(LDObject* object)
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
142 {
1258
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
143 int position = indexOf(object).row();
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
144
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
145 if (_objects[position] == object)
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
146 removeAt(position);
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
147 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
148
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
149 /*
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
150 * Removes the object at the provided position.
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
151 */
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
152 void Model::removeAt(int position)
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
153 {
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
154 beginRemoveRows({}, position, position);
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
155 LDObject* object = _objects[position];
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
156 emit aboutToRemoveObject(this->index(position));
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
157 _objects.removeAt(position);
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
158 _needsTriangleRecount = true;
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
159 endRemoveRows();
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
160 delete object;
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
161 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
162
1249
6a8f76f0f4d1 convert MainWindow::deleteSelection to mvc
Santeri Piippo
parents: 1247
diff changeset
163 void Model::removeAt(const QModelIndex& index)
6a8f76f0f4d1 convert MainWindow::deleteSelection to mvc
Santeri Piippo
parents: 1247
diff changeset
164 {
6a8f76f0f4d1 convert MainWindow::deleteSelection to mvc
Santeri Piippo
parents: 1247
diff changeset
165 removeAt(index.row());
6a8f76f0f4d1 convert MainWindow::deleteSelection to mvc
Santeri Piippo
parents: 1247
diff changeset
166 }
6a8f76f0f4d1 convert MainWindow::deleteSelection to mvc
Santeri Piippo
parents: 1247
diff changeset
167
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
168 /*
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
169 * Replaces the given object with the contents of a model.
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
170 */
1258
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
171 void Model::replace(LDObject* object, Model& model)
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
172 {
1258
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
173 QModelIndex index = this->indexOf(object);
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
174
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
175 if (index.isValid())
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
176 {
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
177 removeAt(index.row());
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
178
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
179 for (signed int i = countof(model.objects()) - 1; i >= 0; i -= 1)
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
180 insertCopy(index.row() + i, model.objects()[i]);
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
181 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
182 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
183
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
184 /*
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
185 * Signals the model to recount its triangles.
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
186 */
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
187 void Model::recountTriangles()
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
188 {
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
189 _needsTriangleRecount = true;
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
190 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
191
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
192 /*
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
193 * Returns the triangle count in the model.
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
194 */
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
195 int Model::triangleCount() const
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
196 {
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
197 if (_needsTriangleRecount)
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
198 {
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
199 _triangleCount = 0;
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
200
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
201 for (LDObject* object : objects())
1263
0256edecda54 LDSubfileReference now contains the name of the subfile and not a pointer anymore. Some methods now require a DocumentManager* for context on resolving the name.
Santeri Piippo
parents: 1261
diff changeset
202 _triangleCount += object->triangleCount(documentManager());
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
203
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
204 _needsTriangleRecount = false;
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
205 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
206
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
207 return _triangleCount;
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
208 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
209
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
210 /*
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
211 * Merges the given model into this model, starting at the given position. The other model is emptied in the process.
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
212 */
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
213 void Model::merge(Model& other, int position)
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
214 {
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
215 if (position < 0)
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
216 position = countof(_objects);
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
217
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
218 // Copy the vector of objects to copy, so that we don't change the vector while iterating over it.
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
219 QVector<LDObject*> objectsCopy = other._objects;
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
220
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
221 // Inform the contents of their new owner
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
222 for (LDObject* object : objectsCopy)
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
223 {
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
224 insertCopy(position, object);
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
225 position += 1;
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
226 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
227
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
228 other.clear();
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
229 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
230
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
231 /*
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
232 * Returns the begin-iterator into this model, so that models can be used in foreach-loops.
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
233 */
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
234 QVector<LDObject*>::iterator Model::begin()
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
235 {
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
236 return _objects.begin();
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
237 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
238
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
239 /*
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
240 * Returns the end-iterator into this mode, so that models can be used in foreach-loops.
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
241 */
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
242 QVector<LDObject*>::iterator Model::end()
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
243 {
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
244 return _objects.end();
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
245 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
246
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
247 /*
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
248 * Removes all objects in this model.
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
249 */
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
250 void Model::clear()
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
251 {
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
252 for (int i = _objects.size() - 1; i >= 0; i -= 1)
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
253 removeAt(i);
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
254
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
255 _triangleCount = 0;
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
256 _needsTriangleRecount = false;
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
257 }
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
258
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
259 /*
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
260 * Returns whether or not this model is empty.
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
261 */
1077
952d6b3e7d11 Replaced uses of LDSpawn with the Model class in edit modes
Teemu Piippo <teemu@hecknology.net>
parents: 1073
diff changeset
262 bool Model::isEmpty() const
952d6b3e7d11 Replaced uses of LDSpawn with the Model class in edit modes
Teemu Piippo <teemu@hecknology.net>
parents: 1073
diff changeset
263 {
952d6b3e7d11 Replaced uses of LDSpawn with the Model class in edit modes
Teemu Piippo <teemu@hecknology.net>
parents: 1073
diff changeset
264 return _objects.isEmpty();
952d6b3e7d11 Replaced uses of LDSpawn with the Model class in edit modes
Teemu Piippo <teemu@hecknology.net>
parents: 1073
diff changeset
265 }
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1077
diff changeset
266
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
267 /*
1258
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
268 * Returns an index that corresponds to the given object
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
269 */
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
270 QModelIndex Model::indexOf(LDObject* object) const
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
271 {
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
272 for (int i = 0; i < this->size(); ++i)
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
273 {
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
274 if (this->getObject(i) == object)
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
275 return index(i);
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
276 }
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
277
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
278 return {};
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
279 }
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
280
f5921a474d57 removed LDObject::lineNumber
Santeri Piippo
parents: 1249
diff changeset
281 /*
1091
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
282 * Returns the model's associated document manager. This pointer is used to resolve subfile references.
4a754362f660 Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents: 1087
diff changeset
283 */
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1077
diff changeset
284 DocumentManager* Model::documentManager() const
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1077
diff changeset
285 {
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1077
diff changeset
286 return _manager;
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1077
diff changeset
287 }
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1077
diff changeset
288
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
289 IndexGenerator Model::indices() const
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
290 {
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
291 return {this};
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
292 }
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
293
1240
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
294 int Model::rowCount(const QModelIndex&) const
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
295 {
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
296 return this->objects().size();
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
297 }
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
298
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
299 QVariant Model::data(const QModelIndex& index, int role) const
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
300 {
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
301 if (index.row() < 0 or index.row() >= size())
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
302 return {};
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
303
1240
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
304 LDObject* object = this->objects()[index.row()];
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
305
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
306 switch (role)
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
307 {
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
308 case Qt::DisplayRole:
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
309 {
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
310 QString result = object->objectListText();
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
311
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
312 if (object->isInverted())
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
313 result.prepend("↺ ");
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
314
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
315 return result;
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
316 }
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
317
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
318 case Qt::DecorationRole:
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
319 return MainWindow::getIcon(object->typeName());
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
320
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
321 case Qt::BackgroundColorRole:
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
322 if (object->type() == LDObjectType::Error)
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
323 return QColor {"#AA0000"};
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
324 else
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
325 return {};
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
326
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
327 case Qt::ForegroundRole:
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
328 if (object->type() == LDObjectType::Error)
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
329 {
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
330 return QColor {"#FFAA00"};
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
331 }
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
332 else if (
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
333 object->isColored()
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
334 and object->color().isValid()
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
335 and object->color() != MainColor
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
336 and object->color() != EdgeColor
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
337 ) {
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
338 // If the object isn't in the main or edge color, draw this list
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
339 // entry in that color.
1240
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
340 return object->color().faceColor();
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
341 }
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
342 else
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
343 {
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
344 return {};
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
345 }
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
346
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
347 case Qt::FontRole:
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
348 if (object->isHidden())
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
349 {
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
350 QFont font;
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
351 font.setItalic(true);
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
352 return font;
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
353 }
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
354 else
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
355 {
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
356 return {};
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
357 }
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
358
1366
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
359 case LDObjectTypeRole:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
360 return object->type();
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
361
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
362 case Vertex0Role:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
363 case Vertex1Role:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
364 case Vertex2Role:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
365 case Vertex3Role:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
366 return this->map(object->vertex(role - Vertex0Role));
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
367
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
368 case ColorRole:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
369 return object->color();
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
370
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
371 case PositionRole:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
372 if (object->type() == LDObjectType::SubfileReference)
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
373 return static_cast<LDSubfileReference*>(object)->position();
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
374 else
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
375 return Vertex {};
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
376
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
377 case TransformationMatrixRole:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
378 if (object->type() == LDObjectType::SubfileReference)
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
379 {
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
380 return static_cast<LDSubfileReference*>(object)->transformationMatrix()
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
381 * this->transformationMatrix().toGenericMatrix<3, 3>();
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
382 }
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
383 else
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
384 {
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
385 return Matrix {};
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
386 }
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
387
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
388 case ReferenceNameRole:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
389 if (object->type() == LDObjectType::SubfileReference)
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
390 return static_cast<LDSubfileReference*>(object)->referenceName();
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
391 else
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
392 return "";
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
393
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
394 case CommentTextRole:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
395 if (object->type() == LDObjectType::Comment)
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
396 return static_cast<LDComment*>(object)->text();
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
397 else
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
398 return "";
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
399
1240
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
400 default:
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
401 return {};
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
402 }
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
403 }
cebb7ef54f41 changed Model into an MVC list model and replaced the objects list with a view into the model
Santeri Piippo
parents: 1149
diff changeset
404
1366
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
405 bool Model::setData(const QModelIndex& index, const QVariant& value, int role)
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
406 {
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
407 LDObject* object = this->objects()[index.row()];
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
408
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
409 switch (role)
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
410 {
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
411 case Vertex0Role:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
412 case Vertex1Role:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
413 case Vertex2Role:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
414 case Vertex3Role:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
415 object->setVertex(role - Vertex0Role, this->unmap(value.value<Vertex>()));
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
416 return true;
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
417
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
418 case ColorRole:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
419 object->setColor(value.value<LDColor>());
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
420 return true;
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
421
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
422 case PositionRole:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
423 if (object->type() == LDObjectType::SubfileReference)
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
424 {
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
425 LDSubfileReference* reference = static_cast<LDSubfileReference*>(object);
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
426 reference->setPosition(this->unmap(value.value<Vertex>()));
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
427 return true;
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
428 }
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
429 else
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
430 {
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
431 return false;
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
432 }
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
433
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
434 case TransformationMatrixRole:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
435 if (object->type() == LDObjectType::SubfileReference)
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
436 {
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
437 LDSubfileReference* reference = static_cast<LDSubfileReference*>(object);
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
438 reference->setTransformationMatrix(
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
439 value.value<Matrix>()
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
440 * this->invertedTransformationmatrix.toGenericMatrix<3, 3>()
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
441 );
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
442 return true;
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
443 }
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
444 else
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
445 {
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
446 return false;
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
447 }
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
448
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
449 case ReferenceNameRole:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
450 if (object->type() == LDObjectType::SubfileReference)
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
451 return static_cast<LDSubfileReference*>(object)->referenceName();
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
452 else
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
453 return "";
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
454
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
455 case CommentTextRole:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
456 if (object->type() == LDObjectType::Comment)
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
457 {
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
458 static_cast<LDComment*>(object)->setText(value.toString());
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
459 return true;
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
460 }
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
461 else
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
462 {
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
463 return false;
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
464 }
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
465
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
466 default:
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
467 return false;
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
468 }
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
469 }
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
470
1245
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
471 /*
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
472 bool Model::removeRows(int row, int count, const QModelIndex& parent)
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
473 {
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
474 if (row >= 0 and row < size() and count <= size() - row)
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
475 {
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
476 beginRemoveRows(parent, row, row + count - 1);
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
477
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
478 for (signed int i = row + count - 1; i >= row; i -= 1)
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
479 this->removeAt(i);
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
480
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
481 endRemoveRows();
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
482 return true;
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
483 }
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
484 else
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
485 {
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
486 return false;
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
487 }
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
488 }
1245
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
489 */
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
490
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
491 /*
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
492 * Looks up an object by the given index.
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
493 */
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
494 LDObject* Model::lookup(const QModelIndex &index) const
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
495 {
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
496 if (index.row() >= 0 and index.row() < size())
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
497 return this->objects()[index.row()];
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
498 else
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
499 return nullptr;
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
500 }
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1240
diff changeset
501
1278
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
502 QColor Model::pickingColorForObject(const QModelIndex& objectIndex) const
1247
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1245
diff changeset
503 {
1278
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
504 return QColor::fromRgba(this->pickingColors.value(this->lookup(objectIndex)) | 0xff000000);
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
505 }
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
506
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
507 QModelIndex Model::objectByPickingColor(const QColor& color) const
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
508 {
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
509 if (color != qRgb(0, 0, 0))
1247
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1245
diff changeset
510 {
1278
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
511 for (int row = 0; row < this->size(); row += 1)
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
512 {
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
513 if (this->pickingColorForObject(this->index(row)) == color)
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
514 return this->index(row);
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
515 }
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
516
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
517 return {};
1247
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1245
diff changeset
518 }
1278
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
519 else
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
520 {
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
521 return {};
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1277
diff changeset
522 }
1247
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1245
diff changeset
523 }
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1245
diff changeset
524
1306
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
525 Winding Model::winding() const
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
526 {
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
527 return this->_winding;
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
528 }
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
529
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
530 void Model::setWinding(Winding winding)
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
531 {
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
532 this->_winding = winding;
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
533 emit windingChanged(this->_winding);
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
534 }
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
535
1366
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
536 const GLRotationMatrix& Model::transformationMatrix() const
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
537 {
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
538 return this->storedTransformationmatrix;
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
539 }
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
540
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
541 void Model::setTransformationMatrix(const GLRotationMatrix& matrix)
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
542 {
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
543 if (matrix != this->storedTransformationmatrix)
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
544 {
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
545 this->storedTransformationmatrix = matrix;
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
546 this->invertedTransformationmatrix = matrix.inverted();
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
547 emit this->transformationMatrixChanged(matrix);
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
548 }
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
549 }
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
550
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
551 Vertex Model::map(const Vertex& global) const
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
552 {
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
553 return global.transformed(this->transformationMatrix());
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
554 }
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
555
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
556 Vertex Model::unmap(const Vertex& local) const
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
557 {
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
558 return local.transformed(this->invertedTransformationmatrix);
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
559 }
69087b1e123b start rework
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
560
1087
80e25f6b0bb0 Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
561 int countof(Model& model)
80e25f6b0bb0 Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
562 {
80e25f6b0bb0 Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
563 return model.size();
80e25f6b0bb0 Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents: 1082
diff changeset
564 }

mercurial