QGIS API Documentation  2.2.0-Valmiera
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsstylev2.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsstylev2.h
3  ---------------------
4  begin : November 2009
5  copyright : (C) 2009 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSSTYLEV2_H
17 #define QGSSTYLEV2_H
18 
19 #include <QMap>
20 #include <QMultiMap>
21 #include <QString>
22 
23 #include <sqlite3.h>
24 
25 #include "qgssymbollayerv2utils.h" // QgsStringMap
26 
27 class QgsSymbolV2;
28 class QgsSymbolLayerV2;
30 
31 class QDomDocument;
32 class QDomElement;
33 
34 typedef QMap<QString, QgsVectorColorRampV2* > QgsVectorColorRampV2Map;
35 typedef QMap<int, QString> QgsSymbolGroupMap;
36 
56 typedef QMultiMap<QString, QString> QgsSmartConditionMap;
57 
58 // enumerators representing sqlite DB columns
65 
66 class CORE_EXPORT QgsStyleV2
67 {
68  public:
69  QgsStyleV2();
70  ~QgsStyleV2();
71 
73 
78  enum StyleEntity { SymbolEntity, GroupEntity, TagEntity, ColorrampEntity, SmartgroupEntity };
79 
81 
88  bool addColorRamp( QString name, QgsVectorColorRampV2* colorRamp, bool update = false );
89 
91 
96  int addGroup( QString groupName, int parent = 0 );
97 
99 
104  int addSmartgroup( QString name, QString op, QgsSmartConditionMap conditions );
105 
107 
114  bool addSymbol( QString name, QgsSymbolV2* symbol, bool update = false );
115 
117 
121  int addTag( QString tagName );
122 
124  QgsSymbolGroupMap childGroupNames( QString parent = "" );
125 
127  void clear();
128 
130  QgsVectorColorRampV2* colorRamp( QString name );
131 
133  int colorRampCount();
134 
136  QStringList colorRampNames();
137 
139  const QgsVectorColorRampV2* colorRampRef( QString name ) const;
140 
143  int colorrampId( QString name );
144 
146  static QgsStyleV2* defaultStyle();
147 
149 
156  bool tagSymbol( StyleEntity type, QString symbol, QStringList tags );
157 
159 
166  bool detagSymbol( StyleEntity type, QString symbol, QStringList tags );
167 
169  bool removeSymbol( QString name );
170 
173  bool renameSymbol( QString oldName, QString newName );
174 
176  QgsSymbolV2* symbol( QString name );
177 
179  const QgsSymbolV2* symbolRef( QString name ) const;
180 
182  int symbolCount();
183 
185  QStringList symbolNames();
186 
189  int symbolId( QString name );
191  int groupId( QString group );
193  int tagId( QString tag );
195  int smartgroupId( QString smartgroup );
196 
198  QStringList groupNames();
199 
201 
206  QStringList symbolsOfGroup( StyleEntity type, int groupid );
207 
209 
214  QStringList symbolsWithTag( StyleEntity type, int tagid );
215 
217 
223  bool group( StyleEntity type, QString name, int groupid );
224 
226 
231  void rename( StyleEntity type, int id, QString newName );
232 
234 
238  void remove( StyleEntity type, int id );
239 
241 
248  bool saveSymbol( QString name, QgsSymbolV2* symbol, int groupid, QStringList tags );
249 
251 
258  bool saveColorRamp( QString name, QgsVectorColorRampV2* ramp, int groupid, QStringList tags );
259 
261  bool removeColorRamp( QString name );
262 
265  bool renameColorRamp( QString oldName, QString newName );
266 
267 
269  bool load( QString filename );
270 
272  bool save( QString filename = QString() );
273 
275  QString errorString() { return mErrorString; }
276 
278  QString fileName() { return mFileName; }
279 
281 
286  QStringList findSymbols( StyleEntity type, QString qword );
287 
289 
294  QStringList tagsOfSymbol( StyleEntity type, QString symbol );
295 
297  QgsSymbolGroupMap smartgroupsListMap();
298 
300  QStringList smartgroupNames();
301 
303  QgsSmartConditionMap smartgroup( int id );
304 
306  //clumsy implementation TODO create a class for smartgroups
307  QString smartgroupOperator( int id );
308 
310  QStringList symbolsOfSmartgroup( StyleEntity type, int id );
311 
313  bool exportXML( QString filename );
314 
316  bool importXML( QString filename );
317 
318  protected:
319 
322 
323  QString mErrorString;
324  QString mFileName;
325 
327 
329 
331  bool openDB( QString filename );
332 
337  bool runEmptyQuery( char* query, bool freeQuery = true );
338 
340  char* getGroupRemoveQuery( int id );
341 
343  int getId( QString table, QString name );
344 
346 
352  bool updateSymbol( StyleEntity type, QString name );
353 };
354 
355 
356 #endif