Debian Codegraph @

src/editor/editordata.hpp

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2015 Jussi Lind <[email protected]>
3 //
4 // Dust Racing 2D is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 // Dust Racing 2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
15
16 #ifndef EDITORDATA_HPP
17 #define EDITORDATA_HPP
18
19 #include <memory>
20 #include <vector>
21
22 #include <QPointF>
23 #include <QString>
24
25 #include "draganddropstore.hpp"
26 #include "editormode.hpp"
27 #include "trackdata.hpp"
28 #include "trackio.hpp"
29 #include "undostack.hpp"
30
31 class Mediator;
32 class Object;
33 class ObjectModelLoader;
34 class TargetNode;
35 class TargetNodeBase;
36 class TrackTile;
37 class QGraphicsLineItem;
38
39 //! Editor data includes data and functionality related to the current
40 //! race track and editing session.
41 class EditorData
42 {
43 public:
44 //! Constructor.
45 explicit EditorData(Mediator & mediator);
46
47 DragAndDropStore & dadStore();
48
49 //! Load track from the given file.
50 bool loadTrackData(QString fileName);
51
52 bool isUndoable() const;
53
54 //! Load track from undo point.
55 void undo();
56
57 bool isRedoable() const;
58
59 //! Load track from redo point.
60 void redo();
61
62 //! Save track data.
63 bool saveTrackData();
64
65 //! Sava track data to the given file.
66 bool saveTrackDataAs(QString fileName);
67
68 //! Save undo point.
69 void saveUndoPoint();
70
71 //! Save redo point.
72 void saveRedoPoint();
73
74 //! Set track data as the given data.
75 void setTrackData(TrackDataPtr newTrackData);
76
77 //! Check if it's possible to set route.
78 bool canRouteBeSet() const;
79
80 //! This should be called before user starts
81 //! setting the route.
82 void beginSetRoute();
83
84 //! Adds current target node objects to the scene.
85 void addExistingRouteToScene();
86
87 //! Push a new target node.
88 void pushNewTargetNodeToRoute(QPointF pos);
89
90 //! Removes target node and line objects from the scene.
91 void removeRouteFromScene();
92
93 //! Removes given tile from the scene.
94 void removeTileFromScene(TrackTileBasePtr trackTile);
95
96 //! Returns current track data object. Returns NULL if not set.
97 TrackDataPtr trackData();
98
99 //! Set selected object.
100 void setSelectedObject(Object * object);
101
102 //! Returns the selected object or nullptr.
103 Object * selectedObject() const;
104
105 //! Set selected target node.
106 void setSelectedTargetNode(TargetNode * tnode);
107
108 //! Returns the selected target node or nullptr.
109 TargetNode * selectedTargetNode() const;
110
111 //! Add tiles in current track data object to the scene.
112 void addTilesToScene();
113
114 //! Add objects in current track data object to the scene.
115 void addObjectsToScene();
116
117 //! Clear the current route only.
118 void clearRoute();
119
120 void setActiveColumn(unsigned int column);
121
122 unsigned int activeColumn() const;
123
124 void setActiveRow(unsigned int row);
125
126 unsigned int activeRow() const;
127
128 void setCurrentScale(int currentScale);
129
130 int currentScale() const;
131
132 private:
133 EditorData(const EditorData & e);
134 EditorData & operator=(const EditorData & e);
135
136 void clearScene();
137
138 void pushTargetNodeToRoute(TargetNodeBasePtr tnode);
139
140 void removeTilesFromScene();
141
142 void removeObjectsFromScene();
143
144 void removeTargetNodesFromScene();
145
146 DragAndDropStore m_dadStore;
147
148 TrackIO m_trackIO;
149
150 TrackDataPtr m_trackData;
151
152 UndoStack m_undoStack;
153
154 Object * m_selectedObject = nullptr;
155
156 TargetNode * m_selectedTargetNode = nullptr;
157
158 Mediator & m_mediator;
159
160 std::vector<QGraphicsLineItem *> m_targetNodes;
161
162 unsigned int m_activeColumn = 0;
163
164 unsigned int m_activeRow = 0;
165
166 // Scale percentage
167 int m_currentScale = 50;
168 };
169
170 #endif // EDITORDATA_HPP