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 |
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 |
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 |
bool addColorRamp( QString name, QgsVectorColorRampV2* colorRamp );
|
58 |
83 |
|
59 |
|
//! remove all contents of the style
|
60 |
|
void clear();
|
|
84 |
//! adds a new group and returns the group's id
|
|
85 |
/*!
|
|
86 |
* \param groupname the name of the new group as QString
|
|
87 |
* \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
|
|
88 |
* \return returns an int, which is the DB id of the new group created, 0 if the group couldn't be created
|
|
89 |
*/
|
|
90 |
int addGroup( QString groupName, int parent = 0 );
|
|
91 |
|
|
92 |
//! adds new smartgroup to the database and returns the id
|
|
93 |
/*!
|
|
94 |
* \param name is the name of the new Smart Group to be added
|
|
95 |
* \param op is the operator between the conditions; AND/OR as QString
|
|
96 |
* \param conditions are the smart group conditions
|
|
97 |
*/
|
|
98 |
int addSmartgroup( QString name, QString op, QgsSmartConditionMap conditions );
|
61 |
99 |
|
62 |
100 |
//! add symbol to style. takes symbol's ownership
|
63 |
101 |
bool addSymbol( QString name, QgsSymbolV2* symbol );
|
64 |
102 |
|
|
103 |
//! adds a new tag and returns the tag's id
|
|
104 |
/*!
|
|
105 |
* \param tagName the name of the new tag to be created
|
|
106 |
* \return returns an int, which is the DB id of the new tag created, 0 if the tag couldn't be created
|
|
107 |
*/
|
|
108 |
int addTag( QString tagName );
|
|
109 |
|
|
110 |
//! return a map of groupid and names for the given parent
|
|
111 |
QgsSymbolGroupMap childGroupNames( QString parent = "" );
|
|
112 |
|
|
113 |
//! remove all contents of the style
|
|
114 |
void clear();
|
|
115 |
|
|
116 |
//! return a NEW copy of color ramp
|
|
117 |
QgsVectorColorRampV2* colorRamp( QString name );
|
|
118 |
|
|
119 |
//! return count of color ramps
|
|
120 |
int colorRampCount();
|
|
121 |
|
|
122 |
//! return a list of names of color ramps
|
|
123 |
QStringList colorRampNames();
|
|
124 |
|
|
125 |
//! return a const pointer to a symbol (doesn't create new instance)
|
|
126 |
const QgsVectorColorRampV2* colorRampRef( QString name ) const;
|
|
127 |
|
|
128 |
//! return the id in the style database for the given colorramp name
|
|
129 |
//! returns 0 if not found
|
|
130 |
int colorrampId( QString name );
|
|
131 |
|
|
132 |
//! return default application-wide style
|
|
133 |
static QgsStyleV2* defaultStyle();
|
|
134 |
|
|
135 |
//! tags the symbol with the tags in the list
|
|
136 |
/*!
|
|
137 |
* Applies the given tags to the given symbol or colorramp
|
|
138 |
* \param type is either SymbolEntity or ColorrampEntity
|
|
139 |
* \param symbol is the name of the symbol or colorramp as QString
|
|
140 |
* \param tags is the list of the tags that are to be applied as QStringList
|
|
141 |
* \return returns the success state of the operation
|
|
142 |
*/
|
|
143 |
bool tagSymbol( StyleEntity type, QString symbol, QStringList tags );
|
|
144 |
|
|
145 |
//! detags the symbol with the given list
|
|
146 |
/*!
|
|
147 |
* Removes the given tags for the specified symbol or colorramp
|
|
148 |
* \param type is either SymbolEntity or ColorrampEntity
|
|
149 |
* \param symbol is the name of the symbol or colorramp
|
|
150 |
* \param tags is the list of tags that are to be removed as QStringList
|
|
151 |
* \return returns the sucess state of the operation
|
|
152 |
*/
|
|
153 |
bool detagSymbol( StyleEntity type, QString symbol, QStringList tags );
|
|
154 |
|
65 |
155 |
//! remove symbol from style (and delete it)
|
66 |
156 |
bool removeSymbol( QString name );
|
67 |
157 |
|
... | ... | |
84 |
174 |
//! return the id in the style database for the given symbol name
|
85 |
175 |
//! returns 0 if not found
|
86 |
176 |
int symbolId( QString name );
|
87 |
|
int colorrampId( QString name );
|
88 |
|
|
89 |
|
//! return the id in the style database for the given group name
|
|
177 |
//! return the DB id for the given group name
|
90 |
178 |
int groupId( QString group );
|
|
179 |
//! return the DB id for the given tag name
|
91 |
180 |
int tagId( QString tag );
|
|
181 |
//! return the DB id for the given smartgroup name
|
92 |
182 |
int smartgroupId( QString smartgroup );
|
93 |
183 |
|
94 |
184 |
//! return the all the groups in the style
|
95 |
185 |
QStringList groupNames();
|
96 |
186 |
|
97 |
|
//! return a map of groupid and names for the given parent
|
98 |
|
QgsSymbolGroupMap childGroupNames( QString parent = "" );
|
99 |
|
|
100 |
187 |
//! returns the symbolnames of a given groupid
|
|
188 |
/*!
|
|
189 |
* \param type is either SymbolEntity or ColorampEntity
|
|
190 |
* \param groupid is id of the group to which the symbols belong to, as int
|
|
191 |
* \return A QStringList of the symbol or colorramp names for the given group id
|
|
192 |
*/
|
101 |
193 |
QStringList symbolsOfGroup( StyleEntity type, int groupid );
|
|
194 |
|
102 |
195 |
//! returns the symbol names with which have the given tag
|
|
196 |
/*!
|
|
197 |
* \param type is either SymbolEntity or ColorampEntity
|
|
198 |
* \param tagid is id of the tag which has been applied over the symbol as int
|
|
199 |
* \return A QStringList of the symbol or colorramp names for the given tag id
|
|
200 |
*/
|
103 |
201 |
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 |
202 |
|
109 |
203 |
//! applies the specifed group to the symbol or colorramp specified by StyleEntity
|
|
204 |
/*!
|
|
205 |
* \param type is either SymbolEntity of ColorrampEntity
|
|
206 |
* \param name is the name of the symbol or coloramp whose group is to be set
|
|
207 |
* \param groupid is the id of the group to which the entity is assigned
|
|
208 |
* \return returns the success state as bool
|
|
209 |
*/
|
110 |
210 |
bool group( StyleEntity type, QString name, int groupid );
|
111 |
211 |
|
112 |
212 |
//! rename the given entity with the specified id
|
|
213 |
/*!
|
|
214 |
* \param type is any of the style entites. Refer enum StyleEntity.
|
|
215 |
* \param id is the DB id of the entity which is to be renamed
|
|
216 |
* \param newName is the new name of the entity
|
|
217 |
*/
|
113 |
218 |
void rename( StyleEntity type, int id, QString newName );
|
|
219 |
|
114 |
220 |
//! remove the specified entity from the db
|
|
221 |
/*!
|
|
222 |
* \param type is any of the style entites. Refer enum StyleEntity.
|
|
223 |
* \param id is the DB id of the entity to be removed
|
|
224 |
*/
|
115 |
225 |
void remove( StyleEntity type, int id );
|
116 |
226 |
|
117 |
227 |
//! add the symbol to the DB with the tags
|
|
228 |
/*!
|
|
229 |
* \param name is the name of the symbol as QString
|
|
230 |
* \param symbol is the pointer to the new QgsSymbolV2 being saved
|
|
231 |
* \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.
|
|
232 |
* \param tags is a list of tags that are associated with the symbol as a QStringList.
|
|
233 |
* \return returns the sucess state of the save operation
|
|
234 |
*/
|
118 |
235 |
bool saveSymbol( QString name, QgsSymbolV2* symbol, int groupid, QStringList tags );
|
|
236 |
|
119 |
237 |
//! add the colorramp to the DB
|
|
238 |
/*!
|
|
239 |
* \param name is the name of the colorramp as QString
|
|
240 |
* \param ramp is the pointer to the new QgsVectorColorRampV2 being saved
|
|
241 |
* \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.
|
|
242 |
* \param tags is a list of tags that are associated with the color ramp as a QStringList.
|
|
243 |
* \return returns the sucess state of the save operation
|
|
244 |
*/
|
120 |
245 |
bool saveColorRamp( QString name, QgsVectorColorRampV2* ramp, int groupid, QStringList tags );
|
121 |
246 |
|
122 |
|
//! add color ramp to style. takes ramp's ownership
|
123 |
|
bool addColorRamp( QString name, QgsVectorColorRampV2* colorRamp );
|
124 |
|
|
125 |
247 |
//! remove color ramp from style (and delete it)
|
126 |
248 |
bool removeColorRamp( QString name );
|
127 |
249 |
|
... | ... | |
129 |
251 |
//! @note added in v1.7
|
130 |
252 |
bool renameColorRamp( QString oldName, QString newName );
|
131 |
253 |
|
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 |
254 |
|
145 |
255 |
//! load a file into the style
|
146 |
256 |
bool load( QString filename );
|
... | ... | |
157 |
267 |
//! return the names of the symbols which have a matching 'substring' in its defintion
|
158 |
268 |
QStringList findSymbols( QString qword );
|
159 |
269 |
|
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 |
270 |
//! return the tags associated with the symbol
|
|
271 |
/*!
|
|
272 |
* \param type is either SymbolEntity or ColorrampEntity
|
|
273 |
* \param symbol is the name of the symbol or color ramp
|
|
274 |
* \return A QStringList of the tags that have been applied to that symbol/colorramp
|
|
275 |
*/
|
167 |
276 |
QStringList tagsOfSymbol( StyleEntity type, QString symbol );
|
168 |
277 |
|
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
|
|
278 |
//! returns the smart groups map with id as key and name as value
|
173 |
279 |
QgsSymbolGroupMap smartgroupsListMap();
|
174 |
280 |
|
175 |
281 |
//! returns the smart groups list
|
... | ... | |
179 |
285 |
QgsSmartConditionMap smartgroup( int id );
|
180 |
286 |
|
181 |
287 |
//! returns the operator for the smartgroup
|
182 |
|
//! @note: clumsy implementation TODO create a class for smartgroups
|
|
288 |
//clumsy implementation TODO create a class for smartgroups
|
183 |
289 |
QString smartgroupOperator( int id );
|
184 |
290 |
|
185 |
291 |
//! returns the symbols for the smartgroup
|
... | ... | |
205 |
311 |
|
206 |
312 |
//! convenience function to open the DB and return a sqlite3 object
|
207 |
313 |
bool openDB( QString filename );
|
|
314 |
|
208 |
315 |
//! 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
|
|
316 |
//! \param query query to run
|
|
317 |
//! \param freeQuery release query memory
|
|
318 |
//! \return success true on success
|
212 |
319 |
bool runEmptyQuery( char* query, bool freeQuery = true );
|
|
320 |
|
213 |
321 |
//! prepares the complex query for removing a group, so that the children are not abandoned
|
214 |
322 |
char* getGroupRemoveQuery( int id );
|
|
323 |
|
215 |
324 |
//! gets the id from the table for the given name from the database, 0 if not found
|
216 |
325 |
int getId( QString table, QString name );
|
217 |
326 |
};
|
218 |
|
-
|