Debian Codegraph @

plugins/dm.stimresponse/StimTypes.h

raw
1 #pragma once
2
3 #include <map>
4 #include <string>
5 #include "ientity.h"
6 #include "wxutil/dataview/TreeModel.h"
7
8 class wxBitmapComboBox;
9 class wxComboBox;
10
11 /** greebo: A simple StimType representation.
12 */
13 struct StimType {
14 std::string name; // The name (STIM_FIRE)
15 std::string caption; // Nice format ("Fire")
16 std::string description; // Unused at the moment
17 std::string icon; // The icon to display
18 bool custom; // is TRUE for custom stims
19 };
20 typedef std::map<int, StimType> StimTypeMap;
21
22 class StimTypes
23 {
24 public:
25 // Tree model definition for a Stim/Response list
26 struct Columns :
27 public wxutil::TreeModel::ColumnRecord
28 {
29 Columns() :
30 id(add(wxutil::TreeModel::Column::Integer)),
31 caption(add(wxutil::TreeModel::Column::IconText)),
32 name(add(wxutil::TreeModel::Column::String)),
33 captionPlusID(add(wxutil::TreeModel::Column::String)),
34 isCustom(add(wxutil::TreeModel::Column::Boolean))
35 {}
36
37 wxutil::TreeModel::Column id; // ID
38 wxutil::TreeModel::Column caption; // Caption String
39 wxutil::TreeModel::Column name; // Name
40 wxutil::TreeModel::Column captionPlusID; // The caption plus ID in brackets
41 wxutil::TreeModel::Column isCustom; // TRUE if the row is a custom stim type
42 };
43
44 private:
45 // The list of available stims
46 StimTypeMap _stimTypes;
47
48 // The empty stim.
49 StimType _emptyStimType;
50
51 // The list store for use in combo boxes
52 Columns _columns;
53 wxutil::TreeModel::Ptr _listStore;
54
55 public:
56 /** greebo: Constructor, loads the Stim types from the registry.
57 */
58 StimTypes();
59
60 // Releases the TreeModel reference
61 ~StimTypes();
62
63 /** greebo: Saves the custom stim types to the storage entity
64 */
65 void save();
66
67 /** greebo: Reloads the custom stim types from the map entities.
68 */
69 void reload();
70
71 /** greebo: Returns the reference to the internal stim type map
72 */
73 StimTypeMap& getStimMap();
74
75 /** greebo: Returns the StimType with the given ID
76 */
77 StimType get(int id) const;
78
79 /** greebo: Returns the StimType for the given name (STIM_FIRE)
80 */
81 StimType get(const std::string& name) const;
82
83 // Returns the numeric ID for the given stim type name
84 // Returns -1 if nothing found
85 int getIdForName(const std::string& name) const;
86
87 /** greebo: Returns the name of the first available stimtype name.
88 */
89 std::string getFirstName();
90
91 /** greebo: Returns the GtkTreeIter pointing to the element
92 * named <name> located in the member _listStore.
93 */
94 wxDataViewItem getIterForName(const std::string& name);
95
96 // Get the liststore for use in combo boxes and treeviews
97 const Columns& getColumns() const;
98 wxutil::TreeModel::Ptr getListStore() const;
99
100 // Load the stim type list into the choice array of the given combo box
101 void populateComboBox(wxComboBox* combo) const;
102 void populateComboBox(wxBitmapComboBox* combo) const;
103
104 /** greebo: Visitor function implementation. This parses the keyvalues
105 * for custom stim definitions.
106 */
107 void visitKeyValue(const std::string& key, const std::string& value);
108
109 /** greebo: Retrieves the lowest available custom stim id.
110 */
111 int getFreeCustomStimId();
112
113 /** greebo: Adds a new stim type to the list and updates the liststore.
114 * Pass the relevant string properties like "name" as arguments.
115 */
116 void add(int id,
117 const std::string& name,
118 const std::string& caption,
119 const std::string& description,
120 const std::string& icon,
121 bool custom);
122
123 /** greebo: Updates the caption of the stimtype with the given id
124 * to <caption> and updates the internal list store.
125 */
126 void setStimTypeCaption(int id, const std::string& caption);
127
128 /** greebo: Removes the stim type with the given id.
129 * This works for custom stims only.
130 */
131 void remove(int id);
132
133 /**
134 * greebo: Retrieves the GtkTreeIter pointing at the row with the
135 * stim type with the given ID
136 */
137 wxDataViewItem getIterForId(int id);
138 };