Mon, 05 Mar 2018 23:59:47 +0200
migrated model swapping to mvc and made Model::swapObjects to emit dataChanged signals as a temporary solution
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 |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
3 | * Copyright (C) 2013 - 2017 Teemu Piippo |
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" |
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
|
21 | #include "documentmanager.h" |
1141
7dc2c981937e
Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
1139
diff
changeset
|
22 | #include "linetypes/comment.h" |
7dc2c981937e
Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
1139
diff
changeset
|
23 | #include "linetypes/conditionaledge.h" |
7dc2c981937e
Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
1139
diff
changeset
|
24 | #include "linetypes/edgeline.h" |
1117
efcb47c64a72
Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents:
1113
diff
changeset
|
25 | #include "linetypes/empty.h" |
1149
502c866b8512
Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
1148
diff
changeset
|
26 | #include "linetypes/quadrilateral.h" |
1148
96cb15a7611f
Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
1147
diff
changeset
|
27 | #include "linetypes/triangle.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
|
28 | #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
|
29 | |
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
|
30 | 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
|
31 | 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
|
32 | _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
|
33 | |
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 | 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
|
35 | { |
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
|
36 | 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
|
37 | 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
|
38 | } |
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
|
39 | |
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
|
40 | 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
|
41 | { |
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
|
42 | connect(object, SIGNAL(codeChanged(LDObjectState, LDObjectState)), this, SLOT(recountTriangles())); |
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
|
43 | 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
|
44 | _objects.insert(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
|
45 | recountTriangles(); |
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
|
46 | 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
|
47 | 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
|
48 | } |
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
|
49 | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
50 | /* |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
51 | * Returns the amount of objects in this model. |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
52 | */ |
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
|
53 | 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
|
54 | { |
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
|
55 | 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
|
56 | } |
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 | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
58 | /* |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
59 | * Returns the vector of objects in this model. |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
60 | */ |
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
|
61 | 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
|
62 | { |
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
|
63 | 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
|
64 | } |
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 | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
66 | /* |
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
|
67 | * 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
|
68 | */ |
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
|
69 | 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
|
70 | { |
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
|
71 | 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
|
72 | } |
1261
5d2c9d36da9d
Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents:
1258
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 | 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
|
75 | { |
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
|
76 | 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
|
77 | |
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
|
78 | 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
|
79 | 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
|
80 | } |
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
|
81 | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
82 | /* |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
83 | * Swaps one object with another, assuming they both are in this model. |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
84 | */ |
1272
bf0ac547b934
migrated model swapping to mvc and made Model::swapObjects to emit dataChanged signals as a temporary solution
Santeri Piippo
parents:
1269
diff
changeset
|
85 | bool Model::swapObjects(const QModelIndex& index_1, const QModelIndex& index_2) |
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
|
86 | { |
1272
bf0ac547b934
migrated model swapping to mvc and made Model::swapObjects to emit dataChanged signals as a temporary solution
Santeri Piippo
parents:
1269
diff
changeset
|
87 | if (index_1.isValid() and index_2.isValid() and index_1 != index_2) |
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
|
88 | { |
1272
bf0ac547b934
migrated model swapping to mvc and made Model::swapObjects to emit dataChanged signals as a temporary solution
Santeri Piippo
parents:
1269
diff
changeset
|
89 | qSwap(_objects[index_1.row()], _objects[index_2.row()]); |
bf0ac547b934
migrated model swapping to mvc and made Model::swapObjects to emit dataChanged signals as a temporary solution
Santeri Piippo
parents:
1269
diff
changeset
|
90 | emit objectsSwapped(index_1, index_2); |
bf0ac547b934
migrated model swapping to mvc and made Model::swapObjects to emit dataChanged signals as a temporary solution
Santeri Piippo
parents:
1269
diff
changeset
|
91 | emit dataChanged(index_1, index_1); |
bf0ac547b934
migrated model swapping to mvc and made Model::swapObjects to emit dataChanged signals as a temporary solution
Santeri Piippo
parents:
1269
diff
changeset
|
92 | emit dataChanged(index_2, index_2); |
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
|
93 | 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
|
94 | } |
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
|
95 | 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
|
96 | { |
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
|
97 | 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
|
98 | } |
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
|
99 | } |
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 | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
101 | /* |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
102 | * 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
|
103 | */ |
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
|
104 | 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
|
105 | { |
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
|
106 | 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
|
107 | |
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
|
108 | 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
|
109 | { |
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
|
110 | 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
|
111 | 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
|
112 | 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
|
113 | } |
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
|
114 | 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
|
115 | { |
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
|
116 | 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
|
117 | } |
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
|
118 | } |
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
|
119 | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
120 | /* |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
121 | * 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
|
122 | */ |
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
|
123 | 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
|
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 | 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
|
126 | 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
|
127 | 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
|
128 | 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
|
129 | } |
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 | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
131 | /* |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
132 | * Removes the given object from the model. |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
133 | */ |
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
|
134 | 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
|
135 | { |
1258 | 136 | int position = indexOf(object).row(); |
137 | ||
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
|
138 | 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
|
139 | 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
|
140 | } |
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 | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
142 | /* |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
143 | * Removes the object at the provided position. |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
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 | 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
|
146 | { |
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
|
147 | 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
|
148 | 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
|
149 | 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
|
150 | _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
|
151 | _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
|
152 | 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
|
153 | 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
|
154 | } |
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
|
155 | |
1249 | 156 | void Model::removeAt(const QModelIndex& index) |
157 | { | |
158 | removeAt(index.row()); | |
159 | } | |
160 | ||
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
161 | /* |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
162 | * 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
|
163 | */ |
1258 | 164 | 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
|
165 | { |
1258 | 166 | QModelIndex index = this->indexOf(object); |
167 | ||
168 | 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
|
169 | { |
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
|
170 | 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
|
171 | |
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
|
172 | 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
|
173 | 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
|
174 | } |
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
|
175 | } |
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 | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
177 | /* |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
178 | * Signals the model to recount its triangles. |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
179 | */ |
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
|
180 | 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
|
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 | _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
|
183 | } |
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
|
184 | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
185 | /* |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
186 | * Returns the triangle count in the model. |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
187 | */ |
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
|
188 | 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
|
189 | { |
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 | 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
|
191 | { |
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
|
192 | _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
|
193 | |
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
|
194 | 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
|
195 | _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
|
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 | _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
|
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 | |
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 | 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
|
201 | } |
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
|
202 | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
203 | /* |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
204 | * 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
|
205 | */ |
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
|
206 | 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
|
207 | { |
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 | 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
|
209 | 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
|
210 | |
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
|
211 | // 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
|
212 | 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
|
213 | |
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 | // 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
|
215 | 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
|
216 | { |
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
|
217 | 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
|
218 | 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
|
219 | } |
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 | 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
|
222 | } |
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 | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
224 | /* |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
225 | * 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
|
226 | */ |
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
|
227 | 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
|
228 | { |
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 | 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
|
230 | } |
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
|
231 | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
232 | /* |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
233 | * 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
|
234 | */ |
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
|
235 | 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
|
236 | { |
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 | 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
|
238 | } |
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
|
239 | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
240 | /* |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
241 | * Removes all objects in this model. |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
242 | */ |
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
|
243 | 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
|
244 | { |
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 | 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
|
246 | 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
|
247 | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
248 | _triangleCount = 0; |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
249 | _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
|
250 | } |
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 | /* |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
253 | * Returns whether or not this model is empty. |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
254 | */ |
1077
952d6b3e7d11
Replaced uses of LDSpawn with the Model class in edit modes
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
255 | 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
|
256 | { |
952d6b3e7d11
Replaced uses of LDSpawn with the Model class in edit modes
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
257 | return _objects.isEmpty(); |
952d6b3e7d11
Replaced uses of LDSpawn with the Model class in edit modes
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
258 | } |
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
|
259 | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
260 | /* |
1258 | 261 | * Returns an index that corresponds to the given object |
262 | */ | |
263 | QModelIndex Model::indexOf(LDObject* object) const | |
264 | { | |
265 | for (int i = 0; i < this->size(); ++i) | |
266 | { | |
267 | if (this->getObject(i) == object) | |
268 | return index(i); | |
269 | } | |
270 | ||
271 | return {}; | |
272 | } | |
273 | ||
274 | /* | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
275 | * 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
|
276 | */ |
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
|
277 | 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
|
278 | { |
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
|
279 | 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
|
280 | } |
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
|
281 | |
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
|
282 | // ============================================================================= |
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
|
283 | // |
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 | static void CheckTokenCount (const QStringList& tokens, int num) |
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 | if (countof(tokens) != num) |
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 | throw QString (format ("Bad amount of tokens, expected %1, got %2", num, countof(tokens))); |
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 | } |
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
|
289 | |
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
|
290 | // ============================================================================= |
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
|
291 | // |
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
|
292 | static void CheckTokenNumbers (const QStringList& tokens, int min, int max) |
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
|
293 | { |
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
|
294 | bool ok; |
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
|
295 | QRegExp scientificRegex ("\\-?[0-9]+\\.[0-9]+e\\-[0-9]+"); |
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
|
296 | |
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
|
297 | for (int i = min; i <= max; ++i) |
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
|
298 | { |
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
|
299 | // Check for floating point |
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
|
300 | tokens[i].toDouble (&ok); |
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
|
301 | if (ok) |
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
|
302 | return; |
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
|
303 | |
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
|
304 | // Check hex |
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
|
305 | if (tokens[i].startsWith ("0x")) |
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
|
306 | { |
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
|
307 | tokens[i].mid (2).toInt (&ok, 16); |
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
|
308 | |
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
|
309 | if (ok) |
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
|
310 | return; |
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
|
311 | } |
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
|
312 | |
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
|
313 | // Check scientific notation, e.g. 7.99361e-15 |
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
|
314 | if (scientificRegex.exactMatch (tokens[i])) |
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
|
315 | return; |
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
|
316 | |
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
|
317 | throw QString (format ("Token #%1 was `%2`, expected a number (matched length: %3)", |
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
|
318 | (i + 1), tokens[i], scientificRegex.matchedLength())); |
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
|
319 | } |
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
|
320 | } |
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
|
321 | |
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
|
322 | // ============================================================================= |
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
|
323 | // |
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
|
324 | static Vertex ParseVertex (QStringList& s, const int n) |
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
|
325 | { |
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
|
326 | Vertex v; |
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
|
327 | v.apply ([&] (Axis ax, double& a) { a = s[n + ax].toDouble(); }); |
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
|
328 | return v; |
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
|
329 | } |
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
|
330 | |
1135
8e0691be0b6f
Removed the intXX type aliases and removed uses of intXX_t in favor of qintXX
Teemu Piippo <teemu@hecknology.net>
parents:
1117
diff
changeset
|
331 | static qint32 StringToNumber (QString a, bool* ok = nullptr) |
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
|
332 | { |
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
|
333 | int base = 10; |
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
|
334 | |
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
|
335 | if (a.startsWith ("0x")) |
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
|
336 | { |
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
|
337 | a.remove (0, 2); |
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
|
338 | base = 16; |
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
|
339 | } |
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
|
340 | |
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
|
341 | return a.toLong (ok, base); |
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
|
342 | } |
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
|
343 | |
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
|
344 | // ============================================================================= |
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
|
345 | // This is the LDraw code parser function. It takes in a string containing LDraw |
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
|
346 | // code and returns the object parsed from it. parseLine never returns null, |
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
|
347 | // the object will be LDError if it could not be parsed properly. |
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
|
348 | // ============================================================================= |
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
|
349 | LDObject* Model::insertFromString(int position, QString line) |
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
|
350 | { |
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
|
351 | try |
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
|
352 | { |
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
|
353 | QStringList tokens = line.split(" ", QString::SkipEmptyParts); |
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
|
354 | |
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
|
355 | if (countof(tokens) <= 0) |
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
|
356 | { |
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
|
357 | // Line was empty, or only consisted of whitespace |
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
|
358 | return emplaceAt<LDEmpty>(position); |
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
|
359 | } |
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
|
360 | |
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
|
361 | if (countof(tokens[0]) != 1 or not tokens[0][0].isDigit()) |
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
|
362 | throw QString ("Illogical line code"); |
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
|
363 | |
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
|
364 | int num = tokens[0][0].digitValue(); |
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
|
365 | |
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
|
366 | switch (num) |
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
|
367 | { |
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
|
368 | case 0: |
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
|
369 | { |
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
|
370 | // Comment |
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
|
371 | QString commentText = line.mid (line.indexOf ("0") + 2); |
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
|
372 | QString commentTextSimplified = commentText.simplified(); |
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
|
373 | |
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
|
374 | // Handle BFC statements |
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
|
375 | if (countof(tokens) > 2 and tokens[1] == "BFC") |
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
|
376 | { |
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
|
377 | for (BfcStatement statement : iterateEnum<BfcStatement>()) |
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
|
378 | { |
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
|
379 | if (commentTextSimplified == format("BFC %1", LDBfc::statementToString (statement))) |
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
|
380 | return emplaceAt<LDBfc>(position, statement); |
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
|
381 | } |
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
|
382 | |
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
|
383 | // MLCAD is notorious for stuffing these statements in parts it |
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
|
384 | // creates. The above block only handles valid statements, so we |
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
|
385 | // need to handle MLCAD-style invertnext, clip and noclip separately. |
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
|
386 | if (commentTextSimplified == "BFC CERTIFY INVERTNEXT") |
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
|
387 | return emplaceAt<LDBfc>(position, BfcStatement::InvertNext); |
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
|
388 | else if (commentTextSimplified == "BFC CERTIFY CLIP") |
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
|
389 | return emplaceAt<LDBfc>(position, BfcStatement::Clip); |
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
|
390 | else if (commentTextSimplified == "BFC CERTIFY NOCLIP") |
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
|
391 | return emplaceAt<LDBfc>(position, BfcStatement::NoClip); |
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
|
392 | } |
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
|
393 | |
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
|
394 | if (countof(tokens) > 2 and tokens[1] == "!LDFORGE") |
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
|
395 | { |
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
|
396 | // Handle LDForge-specific types, they're embedded into comments too |
1100
9b2797729c82
Removed all overlay support. It's a messy pile of mess and I will reimplement it later as background images and it will be much better then.
Teemu Piippo <teemu@hecknology.net>
parents:
1091
diff
changeset
|
397 | if (tokens[2] == "BEZIER_CURVE") |
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
|
398 | { |
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
|
399 | CheckTokenCount (tokens, 16); |
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
|
400 | CheckTokenNumbers (tokens, 3, 15); |
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
|
401 | LDBezierCurve* obj = emplaceAt<LDBezierCurve>(position); |
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
|
402 | obj->setColor (StringToNumber (tokens[3])); |
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
|
403 | |
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
|
404 | for (int i = 0; i < 4; ++i) |
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
|
405 | obj->setVertex (i, ParseVertex (tokens, 4 + (i * 3))); |
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
|
406 | |
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
|
407 | return obj; |
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
|
408 | } |
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
|
409 | } |
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
|
410 | |
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
|
411 | // Just a regular comment: |
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
|
412 | return emplaceAt<LDComment>(position, commentText); |
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
|
413 | } |
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
|
414 | |
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
|
415 | case 1: |
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
|
416 | { |
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
|
417 | // Subfile |
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
|
418 | CheckTokenCount (tokens, 15); |
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
|
419 | CheckTokenNumbers (tokens, 1, 13); |
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
|
420 | |
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
|
421 | Vertex referncePosition = ParseVertex (tokens, 2); // 2 - 4 |
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
|
422 | Matrix transform; |
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
|
423 | |
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
|
424 | for (int i = 0; i < 9; ++i) |
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
|
425 | transform.value(i) = tokens[i + 5].toDouble(); // 5 - 13 |
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
|
426 | |
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
|
427 | LDSubfileReference* obj = emplaceAt<LDSubfileReference>(position, tokens[14], transform, referncePosition); |
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
|
428 | obj->setColor (StringToNumber (tokens[1])); |
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
|
429 | return obj; |
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
|
430 | } |
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
|
431 | |
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
|
432 | case 2: |
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
|
433 | { |
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
|
434 | CheckTokenCount (tokens, 8); |
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
|
435 | CheckTokenNumbers (tokens, 1, 7); |
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
|
436 | |
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
|
437 | // Line |
1139
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1135
diff
changeset
|
438 | LDEdgeLine* obj = emplaceAt<LDEdgeLine>(position); |
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
|
439 | obj->setColor (StringToNumber (tokens[1])); |
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
|
440 | |
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
|
441 | for (int i = 0; i < 2; ++i) |
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
|
442 | obj->setVertex (i, ParseVertex (tokens, 2 + (i * 3))); // 2 - 7 |
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
|
443 | |
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
|
444 | return obj; |
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
|
445 | } |
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
|
446 | |
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
|
447 | case 3: |
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
|
448 | { |
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
|
449 | CheckTokenCount (tokens, 11); |
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
|
450 | CheckTokenNumbers (tokens, 1, 10); |
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
|
451 | |
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
|
452 | // Triangle |
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
|
453 | LDTriangle* obj = emplaceAt<LDTriangle>(position); |
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
|
454 | obj->setColor (StringToNumber (tokens[1])); |
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
|
455 | |
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
|
456 | for (int i = 0; i < 3; ++i) |
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
|
457 | obj->setVertex (i, ParseVertex (tokens, 2 + (i * 3))); // 2 - 10 |
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
|
458 | |
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
|
459 | return obj; |
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
|
460 | } |
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
|
461 | |
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
|
462 | case 4: |
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
|
463 | case 5: |
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
|
464 | { |
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
|
465 | CheckTokenCount (tokens, 14); |
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
|
466 | CheckTokenNumbers (tokens, 1, 13); |
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
|
467 | |
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
|
468 | // Quadrilateral / Conditional line |
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
|
469 | LDObject* obj; |
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
|
470 | |
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
|
471 | if (num == 4) |
1139
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1135
diff
changeset
|
472 | obj = emplaceAt<LDQuadrilateral>(position); |
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
|
473 | else |
1139
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1135
diff
changeset
|
474 | obj = emplaceAt<LDConditionalEdge>(position); |
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
|
475 | |
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
|
476 | obj->setColor (StringToNumber (tokens[1])); |
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
|
477 | |
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
|
478 | for (int i = 0; i < 4; ++i) |
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
|
479 | obj->setVertex (i, ParseVertex (tokens, 2 + (i * 3))); // 2 - 13 |
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
|
480 | |
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
|
481 | return obj; |
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
|
482 | } |
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
|
483 | |
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
|
484 | default: |
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
|
485 | throw QString {"Unknown line code number"}; |
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
|
486 | } |
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
|
487 | } |
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
|
488 | catch (QString& errorMessage) |
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
|
489 | { |
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
|
490 | // Strange line we couldn't parse |
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
|
491 | return emplaceAt<LDError>(position, line, errorMessage); |
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
|
492 | } |
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
|
493 | } |
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
|
494 | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
495 | /* |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
496 | * Given an LDraw object string, parses it and inserts it into the model. |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
497 | */ |
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
|
498 | LDObject* Model::addFromString(QString line) |
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
|
499 | { |
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
|
500 | return insertFromString(size(), line); |
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
|
501 | } |
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
|
502 | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
503 | /* |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
504 | * Replaces the given object with a new one that is parsed from the given LDraw object string. |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
505 | * If the parsing fails, the object is replaced with an error object. |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
506 | */ |
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
|
507 | LDObject* Model::replaceWithFromString(LDObject* object, QString line) |
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
|
508 | { |
1258 | 509 | QModelIndex index = this->indexOf(object); |
510 | ||
511 | if (index.isValid()) | |
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
|
512 | { |
1258 | 513 | removeAt(index.row()); |
514 | return insertFromString(index.row(), line); | |
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
|
515 | } |
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
|
516 | else |
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
|
517 | return nullptr; |
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
|
518 | } |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1082
diff
changeset
|
519 | |
1244 | 520 | IndexGenerator Model::indices() const |
521 | { | |
522 | return {this}; | |
523 | } | |
524 | ||
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
|
525 | 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
|
526 | { |
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
|
527 | 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
|
528 | } |
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
|
529 | |
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
|
530 | 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
|
531 | { |
1244 | 532 | if (index.row() < 0 or index.row() >= size()) |
533 | return {}; | |
534 | ||
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
|
535 | 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
|
536 | |
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
|
537 | 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
|
538 | { |
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
|
539 | 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
|
540 | { |
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
|
541 | 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
|
542 | |
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
|
543 | 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
|
544 | 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
|
545 | |
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
|
546 | 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
|
547 | } |
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
|
548 | |
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
|
549 | 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
|
550 | 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
|
551 | |
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
|
552 | 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
|
553 | 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
|
554 | 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
|
555 | 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
|
556 | 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
|
557 | |
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
|
558 | 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
|
559 | 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
|
560 | { |
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
|
561 | 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
|
562 | } |
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
|
563 | 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
|
564 | 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
|
565 | 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
|
566 | 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
|
567 | 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
|
568 | ) { |
1244 | 569 | // If the object isn't in the main or edge color, draw this list |
570 | // 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
|
571 | 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
|
572 | } |
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
|
573 | 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
|
574 | { |
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
|
575 | 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
|
576 | } |
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
|
577 | |
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
|
578 | 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
|
579 | 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
|
580 | { |
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
|
581 | 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
|
582 | 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
|
583 | 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
|
584 | } |
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
|
585 | 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
|
586 | { |
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
|
587 | 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
|
588 | } |
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
|
589 | |
1245 | 590 | case ObjectIdRole: |
591 | return object->id(); | |
1244 | 592 | |
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
|
593 | 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
|
594 | 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
|
595 | } |
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
|
596 | } |
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
|
597 | |
1245 | 598 | /* |
1244 | 599 | bool Model::removeRows(int row, int count, const QModelIndex& parent) |
600 | { | |
601 | if (row >= 0 and row < size() and count <= size() - row) | |
602 | { | |
603 | beginRemoveRows(parent, row, row + count - 1); | |
604 | ||
605 | for (signed int i = row + count - 1; i >= row; i -= 1) | |
606 | this->removeAt(i); | |
607 | ||
608 | endRemoveRows(); | |
609 | return true; | |
610 | } | |
611 | else | |
612 | { | |
613 | return false; | |
614 | } | |
615 | } | |
1245 | 616 | */ |
617 | ||
618 | /* | |
619 | * Looks up an object by the given index. | |
620 | */ | |
621 | LDObject* Model::lookup(const QModelIndex &index) const | |
622 | { | |
623 | if (index.row() >= 0 and index.row() < size()) | |
624 | return this->objects()[index.row()]; | |
625 | else | |
626 | return nullptr; | |
627 | } | |
1244 | 628 | |
1247 | 629 | QModelIndex Model::indexFromId(qint32 id) const |
630 | { | |
631 | for (int row = 0; row < this->size(); ++row) | |
632 | { | |
633 | if (this->objects()[row]->id() == id) | |
634 | return index(row); | |
635 | } | |
636 | ||
637 | return {}; | |
638 | } | |
639 | ||
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1082
diff
changeset
|
640 | int countof(Model& model) |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1082
diff
changeset
|
641 | { |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1082
diff
changeset
|
642 | return model.size(); |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1082
diff
changeset
|
643 | } |