@@ -33,6 +33,26 @@ class QDomElement;
33
33
34
34
typedef QMap<QString, QgsVectorColorRampV2* > QgsVectorColorRampV2Map;
35
35
typedef QMap<int , QString> QgsSymbolGroupMap;
36
+
37
+ /* !
38
+ * A multimap to hold the smart group conditions as constraint and parameter pairs.
39
+ * Both the key and the value of the map are QString. The key is the constraint of the condition and the value is the parameter which is applied for the constraint.
40
+ *
41
+ * The supported constraints are:
42
+ * tag -> symbol has the tag matching the parameter
43
+ * !tag -> symbol doesnot have the tag matching the parameter
44
+ * group -> symbol belongs to group specified by the parameter
45
+ * !group -> symbol doesn't belong to the group specified by the parameter
46
+ * name -> symbol has a part of its name matching the parameter
47
+ * !name -> symbol doesn't have any part of the name matching the parameter
48
+ *
49
+ * Example Usage:
50
+ * QgsSmartConditionMap conditions;
51
+ * conditions.insert( "tag", "red" ); // adds the condition: Symbol has the tag red
52
+ * conditions.insert( "!name", "way" ); // add the condition: Symbol doesn't have any part of its name matching `way`
53
+ *
54
+ * \note This is a Multimap, which means it will contain multiple values for the same key.
55
+ */
36
56
typedef QMultiMap<QString, QString> QgsSmartConditionMap;
37
57
38
58
// enumerators representing sqlite DB columns
@@ -43,7 +63,12 @@ enum TagmapTable { TagmapTagId, TagmapSymbolId };
43
63
enum ColorrampTable { ColorrampId, ColorrampName, ColorrampXML, ColorrampGroupId };
44
64
enum SmartgroupTable { SmartgroupId, SmartgroupName, SmartgroupXML };
45
65
46
- // Enums for types
66
+ // ! Enum for Entities involved in a style
67
+ /* !
68
+ The enumarator is used for identifying the entity being operated on when generic
69
+ database functions are being run.
70
+ \sa group(), rename(), remove(), symbolsOfGroup(), symbolsWithTag(), symbolsOfSmartgroup()
71
+ */
47
72
enum StyleEntity { SymbolEntity, GroupEntity, TagEntity, ColorrampEntity, SmartgroupEntity };
48
73
49
74
class CORE_EXPORT QgsStyleV2
@@ -53,14 +78,93 @@ class CORE_EXPORT QgsStyleV2
53
78
QgsStyleV2 ();
54
79
~QgsStyleV2 ();
55
80
56
- // ! return default application-wide style
57
- static QgsStyleV2* defaultStyle ();
81
+ // ! add color ramp to style. takes ramp's ownership
82
+ /* !
83
+ * \note Adding a color ramp with the name of existing one replaces it.
84
+ * \param name is the name of the color ramp being added or updated
85
+ * \param colorRamp is the Vector color ramp
86
+ * \param update set to true when the style DB has to be updated, by default it is false
87
+ * \return sucess status of the operation
88
+ */
89
+ bool addColorRamp ( QString name, QgsVectorColorRampV2* colorRamp, bool update = false );
90
+
91
+ // ! adds a new group and returns the group's id
92
+ /* !
93
+ * \param groupname the name of the new group as QString
94
+ * \param parent is the id of the parent group when a subgrouo is to be created. By default it is 0 indicating it is not a sub-group
95
+ * \return returns an int, which is the DB id of the new group created, 0 if the group couldn't be created
96
+ */
97
+ int addGroup ( QString groupName, int parent = 0 );
98
+
99
+ // ! adds new smartgroup to the database and returns the id
100
+ /* !
101
+ * \param name is the name of the new Smart Group to be added
102
+ * \param op is the operator between the conditions; AND/OR as QString
103
+ * \param conditions are the smart group conditions
104
+ */
105
+ int addSmartgroup ( QString name, QString op, QgsSmartConditionMap conditions );
106
+
107
+ // ! add symbol to style. takes symbol's ownership
108
+ /* !
109
+ * \note Adding a symbol with the name of existing one replaces it.
110
+ * \param name is the name of the symbol being added or updated
111
+ * \param symbol is the Vector symbol
112
+ * \param update set to true when the style DB has to be updated, by default it is false
113
+ * \return sucess status of the operation
114
+ */
115
+ bool addSymbol ( QString name, QgsSymbolV2* symbol, bool update = false );
116
+
117
+ // ! adds a new tag and returns the tag's id
118
+ /* !
119
+ * \param tagName the name of the new tag to be created
120
+ * \return returns an int, which is the DB id of the new tag created, 0 if the tag couldn't be created
121
+ */
122
+ int addTag ( QString tagName );
123
+
124
+ // ! return a map of groupid and names for the given parent group
125
+ QgsSymbolGroupMap childGroupNames ( QString parent = " " );
58
126
59
127
// ! remove all contents of the style
60
128
void clear ();
61
129
62
- // ! add symbol to style. takes symbol's ownership
63
- bool addSymbol ( QString name, QgsSymbolV2* symbol );
130
+ // ! return a NEW copy of color ramp
131
+ QgsVectorColorRampV2* colorRamp ( QString name );
132
+
133
+ // ! return count of color ramps
134
+ int colorRampCount ();
135
+
136
+ // ! return a list of names of color ramps
137
+ QStringList colorRampNames ();
138
+
139
+ // ! return a const pointer to a symbol (doesn't create new instance)
140
+ const QgsVectorColorRampV2* colorRampRef ( QString name ) const ;
141
+
142
+ // ! return the id in the style database for the given colorramp name
143
+ // ! returns 0 if not found
144
+ int colorrampId ( QString name );
145
+
146
+ // ! return default application-wide style
147
+ static QgsStyleV2* defaultStyle ();
148
+
149
+ // ! tags the symbol with the tags in the list
150
+ /* !
151
+ * Applies the given tags to the given symbol or colorramp
152
+ * \param type is either SymbolEntity or ColorrampEntity
153
+ * \param symbol is the name of the symbol or colorramp as QString
154
+ * \param tags is the list of the tags that are to be applied as QStringList
155
+ * \return returns the success state of the operation
156
+ */
157
+ bool tagSymbol ( StyleEntity type, QString symbol, QStringList tags );
158
+
159
+ // ! detags the symbol with the given list
160
+ /* !
161
+ * Removes the given tags for the specified symbol or colorramp
162
+ * \param type is either SymbolEntity or ColorrampEntity
163
+ * \param symbol is the name of the symbol or colorramp
164
+ * \param tags is the list of tags that are to be removed as QStringList
165
+ * \return returns the sucess state of the operation
166
+ */
167
+ bool detagSymbol ( StyleEntity type, QString symbol, QStringList tags );
64
168
65
169
// ! remove symbol from style (and delete it)
66
170
bool removeSymbol ( QString name );
@@ -84,63 +188,83 @@ class CORE_EXPORT QgsStyleV2
84
188
// ! return the id in the style database for the given symbol name
85
189
// ! returns 0 if not found
86
190
int symbolId ( QString name );
87
- int colorrampId ( QString name );
88
-
89
- // ! return the id in the style database for the given group name
191
+ // ! return the DB id for the given group name
90
192
int groupId ( QString group );
193
+ // ! return the DB id for the given tag name
91
194
int tagId ( QString tag );
195
+ // ! return the DB id for the given smartgroup name
92
196
int smartgroupId ( QString smartgroup );
93
197
94
198
// ! return the all the groups in the style
95
199
QStringList groupNames ();
96
200
97
- // ! return a map of groupid and names for the given parent
98
- QgsSymbolGroupMap childGroupNames ( QString parent = " " );
99
-
100
201
// ! returns the symbolnames of a given groupid
202
+ /* !
203
+ * \param type is either SymbolEntity or ColorampEntity
204
+ * \param groupid is id of the group to which the symbols belong to, as int
205
+ * \return A QStringList of the symbol or colorramp names for the given group id
206
+ */
101
207
QStringList symbolsOfGroup ( StyleEntity type, int groupid );
208
+
102
209
// ! returns the symbol names with which have the given tag
210
+ /* !
211
+ * \param type is either SymbolEntity or ColorampEntity
212
+ * \param tagid is id of the tag which has been applied over the symbol as int
213
+ * \return A QStringList of the symbol or colorramp names for the given tag id
214
+ */
103
215
QStringList symbolsWithTag ( StyleEntity type, int tagid );
104
- // ! adds a new group and returns the group's id
105
- int addGroup ( QString groupName, int parent = 0 );
106
- // ! adds a new tag and returns the tag's id
107
- int addTag ( QString tagName );
108
216
109
217
// ! applies the specifed group to the symbol or colorramp specified by StyleEntity
218
+ /* !
219
+ * \param type is either SymbolEntity of ColorrampEntity
220
+ * \param name is the name of the symbol or coloramp whose group is to be set
221
+ * \param groupid is the id of the group to which the entity is assigned
222
+ * \return returns the success state as bool
223
+ */
110
224
bool group ( StyleEntity type, QString name, int groupid );
111
225
112
226
// ! rename the given entity with the specified id
227
+ /* !
228
+ * \param type is any of the style entites. Refer enum StyleEntity.
229
+ * \param id is the DB id of the entity which is to be renamed
230
+ * \param newName is the new name of the entity
231
+ */
113
232
void rename ( StyleEntity type, int id, QString newName );
233
+
114
234
// ! remove the specified entity from the db
235
+ /* !
236
+ * \param type is any of the style entites. Refer enum StyleEntity.
237
+ * \param id is the DB id of the entity to be removed
238
+ */
115
239
void remove ( StyleEntity type, int id );
116
240
117
241
// ! add the symbol to the DB with the tags
242
+ /* !
243
+ * \param name is the name of the symbol as QString
244
+ * \param symbol is the pointer to the new QgsSymbolV2 being saved
245
+ * \param groupid is the id of the group to which the symbol belongs. Pass 0 if it doesn't belong to any group or not known.
246
+ * \param tags is a list of tags that are associated with the symbol as a QStringList.
247
+ * \return returns the sucess state of the save operation
248
+ */
118
249
bool saveSymbol ( QString name, QgsSymbolV2* symbol, int groupid, QStringList tags );
250
+
119
251
// ! add the colorramp to the DB
252
+ /* !
253
+ * \param name is the name of the colorramp as QString
254
+ * \param ramp is the pointer to the new QgsVectorColorRampV2 being saved
255
+ * \param groupid is the id of the group to which the Color Ramp belongs. Pass 0 if it doesn't belong to any group or not known.
256
+ * \param tags is a list of tags that are associated with the color ramp as a QStringList.
257
+ * \return returns the sucess state of the save operation
258
+ */
120
259
bool saveColorRamp ( QString name, QgsVectorColorRampV2* ramp, int groupid, QStringList tags );
121
260
122
- // ! add color ramp to style. takes ramp's ownership
123
- bool addColorRamp ( QString name, QgsVectorColorRampV2* colorRamp );
124
-
125
261
// ! remove color ramp from style (and delete it)
126
262
bool removeColorRamp ( QString name );
127
263
128
264
// ! change ramp's name
129
265
// ! @note added in v1.7
130
266
bool renameColorRamp ( QString oldName, QString newName );
131
267
132
- // ! return a NEW copy of color ramp
133
- QgsVectorColorRampV2* colorRamp ( QString name );
134
-
135
- // ! return a const pointer to a symbol (doesn't create new instance)
136
- const QgsVectorColorRampV2* colorRampRef ( QString name ) const ;
137
-
138
- // ! return count of color ramps
139
- int colorRampCount ();
140
-
141
- // ! return a list of names of color ramps
142
- QStringList colorRampNames ();
143
-
144
268
145
269
// ! load a file into the style
146
270
bool load ( QString filename );
@@ -157,19 +281,15 @@ class CORE_EXPORT QgsStyleV2
157
281
// ! return the names of the symbols which have a matching 'substring' in its defintion
158
282
QStringList findSymbols ( QString qword );
159
283
160
- // ! tags the symbol with the tags in the list, the remove flag DE-TAGS
161
- bool tagSymbol ( StyleEntity type, QString symbol, QStringList tags );
162
-
163
- // ! detags the symbol with the given list
164
- bool detagSymbol ( StyleEntity type, QString symbol, QStringList tags );
165
-
166
284
// ! return the tags associated with the symbol
285
+ /* !
286
+ * \param type is either SymbolEntity or ColorrampEntity
287
+ * \param symbol is the name of the symbol or color ramp
288
+ * \return A QStringList of the tags that have been applied to that symbol/colorramp
289
+ */
167
290
QStringList tagsOfSymbol ( StyleEntity type, QString symbol );
168
291
169
- // ! adds the smartgroup to the database and returns the id
170
- int addSmartgroup ( QString name, QString op, QgsSmartConditionMap conditions );
171
-
172
- // ! returns the smart groups map
292
+ // ! returns the smart groups map with id as key and name as value
173
293
QgsSymbolGroupMap smartgroupsListMap ();
174
294
175
295
// ! returns the smart groups list
@@ -179,7 +299,7 @@ class CORE_EXPORT QgsStyleV2
179
299
QgsSmartConditionMap smartgroup ( int id );
180
300
181
301
// ! returns the operator for the smartgroup
182
- // ! @note: clumsy implementation TODO create a class for smartgroups
302
+ // clumsy implementation TODO create a class for smartgroups
183
303
QString smartgroupOperator ( int id );
184
304
185
305
// ! returns the symbols for the smartgroup
@@ -205,15 +325,27 @@ class CORE_EXPORT QgsStyleV2
205
325
206
326
// ! convenience function to open the DB and return a sqlite3 object
207
327
bool openDB ( QString filename );
328
+
208
329
// ! convenience function that would run queries which don't generate return values
209
- // ! @ param query query to run
210
- // ! @ param freeQuery release query memory
211
- // ! @ return success true on success
330
+ // ! \ param query query to run
331
+ // ! \ param freeQuery release query memory
332
+ // ! \ return success true on success
212
333
bool runEmptyQuery ( char * query, bool freeQuery = true );
334
+
213
335
// ! prepares the complex query for removing a group, so that the children are not abandoned
214
336
char * getGroupRemoveQuery ( int id );
337
+
215
338
// ! gets the id from the table for the given name from the database, 0 if not found
216
339
int getId ( QString table, QString name );
340
+
341
+ // ! updates the properties of an existing symbol/colorramp
342
+ /* !
343
+ * \note This should not be called seperately, only called through addSymbol or addColorRamp
344
+ * \param type is either SymbolEntity or ColorrampEntity
345
+ * \param name is the name of an existing symbol or a color ramp
346
+ * \return Success state of the update operation
347
+ */
348
+ bool updateSymbol ( StyleEntity type, QString name );
217
349
};
218
350
219
351
0 commit comments