Debian Codegraph @

plugins/dm.stimresponse/SREntity.h

raw
1 #pragma once
2
3 #include <vector>
4 #include <list>
5 #include <string>
6 #include "wxutil/dataview/TreeModel.h"
7 #include <memory>
8
9 #include "StimResponse.h"
10 #include "StimTypes.h"
11
12 // Forward declaration
13 class Entity;
14
15 namespace
16 {
17 const std::string ICON_STIM = "sr_stim";
18 const std::string ICON_RESPONSE = "sr_response";
19 const std::string ICON_CUSTOM_STIM = "sr_icon_custom.png";
20
21 const std::string SUFFIX_INHERITED = "_inherited";
22 const std::string SUFFIX_INACTIVE = "_inactive";
23 const std::string SUFFIX_EXTENSION = ".png";
24 }
25
26 // Tree model definition for a Stim/Response list
27 struct SRListColumns :
28 public wxutil::TreeModel::ColumnRecord
29 {
30 SRListColumns() :
31 index(add(wxutil::TreeModel::Column::Integer)),
32 srClass(add(wxutil::TreeModel::Column::Icon)),
33 caption(add(wxutil::TreeModel::Column::IconText)),
34 inherited(add(wxutil::TreeModel::Column::Boolean))
35 {}
36
37 wxutil::TreeModel::Column index; // S/R index
38 wxutil::TreeModel::Column srClass; // Type icon
39 wxutil::TreeModel::Column caption; // Caption String
40 wxutil::TreeModel::Column inherited; // Inheritance flag
41 };
42
43 /**
44 * greebo: This is the representation of an entity holding S/R keys.
45 * Use the load() and save() methods to load/save the spawnargs.
46 *
47 * The getStimStore() and getResponseStore() methods are available
48 * to retrieve the TreeModel for association with a TreeView.
49 * The liststore is maintained automatically when the set() method is
50 * used to manipulate the data. The SREntity class will hold a reference
51 * of the liststore, so client code should not DecRef() it.
52 */
53 class SREntity
54 {
55 public:
56 // These are the possible key names
57 typedef std::vector<SRKey> KeyList;
58
59 // These are the int-indexed Stims/Responses belonging to an entity
60 typedef std::list<StimResponse> StimsAndResponses;
61
62 private:
63 // The local lists of S/R and possible keys
64 StimsAndResponses _list;
65 KeyList _keys;
66
67 // The liststore representation
68 wxutil::TreeModel::Ptr _stimStore;
69 wxutil::TreeModel::Ptr _responseStore;
70
71 // A collection of warnings regarding the parsing of the spawnargs
72 std::string _warnings;
73
74 // The helper class managing the various stim types
75 StimTypes& _stimTypes;
76
77 // An empty stim
78 StimResponse _emptyStimResponse;
79
80 public:
81 SREntity(Entity* source, StimTypes& stimTypes);
82
83 void load(Entity* source);
84 void save(Entity* target);
85
86 /** greebo: Removes all the stim/response-relevant spawnargs
87 * from the <target> entity.
88 */
89 void cleanEntity(Entity* target);
90
91 /** greebo: Retrieves the reference to the StimResponse object
92 * having the given integer <index>.
93 *
94 * @returns: The ref to the StimResponse or an empty StimResponse object,
95 * if the index was not found.
96 */
97 StimResponse& get(int index);
98
99 /** greebo: Adds a new StimResponse and returns the index of the new object.
100 * The ListStore is NOT updated with this call to allow setting of
101 * the properties before refreshing the treeview.
102 */
103 int add();
104
105 /** greebo: Adds a new StimResponse and returns the index of the new object.
106 * The ListStore is NOT updated with this call to allow setting of
107 * the properties before refreshing the treeview.
108 */
109 StimResponse& add(int index);
110
111 /** greebo: Removes the StimResponse object with the given index.
112 * This triggers a refresh of the liststores.
113 */
114 void remove(int index);
115
116 /** greebo: Duplicates the stim/response with the given index.
117 *
118 * @fromId: The index of the SR to copy from.
119 * @returns: the index of the new duplicate.
120 */
121 int duplicate(int fromIndex);
122
123 // Static column definition
124 static const SRListColumns& getColumns();
125
126 /**
127 * greebo: Returns the list store containing the stim/response data.
128 * Use this to add the data to a treeview or a combobox.
129 * Don't call DecRef() on this model, just associate it to a TreeView.
130 */
131 wxutil::TreeModel::Ptr getStimStore();
132 wxutil::TreeModel::Ptr getResponseStore();
133
134 /** greebo: Sets the <key> of the SR with the given <index> to <value>
135 */
136 void setProperty(int index, const std::string& key, const std::string& value);
137
138 /** greebo: Updates the ListStore according to the
139 * values of the current StimResponseMap <_list>
140 */
141 void updateListStores();
142
143 /** greebo: Helper to load the possible key names
144 * from the registry into the _keys list.
145 */
146 void loadKeys();
147
148 /**
149 * greebo: Returns the treeIter pointing to the row containing the
150 * StimResponse with the given <index>
151 *
152 * @targetStore: The liststore where the iter should be searched
153 */
154 wxDataViewItem getIterForIndex(wxutil::TreeModel& targetStore, int index);
155
156 StimsAndResponses::iterator findByIndex(int index);
157
158 private:
159
160 /** greebo: Write the values of the passed StimResponse to the
161 * TreeModel using the passed Row.
162 * The index stays untouched.
163 *
164 * @row: The row where the data should be inserted to
165 * @sr: the StimResponse object containing the source data
166 */
167 void writeToListRow(wxutil::TreeModel::Row& row, StimResponse& sr);
168
169 // Returns the highest Stim/Response index number
170 int getHighestIndex();
171
172 // Returns the highest number used by inherited S/R, or 0 if no inherited S/R are present
173 int getHighestInheritedIndex();
174 };
175 typedef std::shared_ptr<SREntity> SREntityPtr;