QGIS API Documentation  2.5.0-Master
 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 : public QObject
67 {
68  Q_OBJECT
69 
70  public:
71  QgsStyleV2();
72  ~QgsStyleV2();
73 
75 
80  enum StyleEntity { SymbolEntity, GroupEntity, TagEntity, ColorrampEntity, SmartgroupEntity };
81 
83 
90  bool addColorRamp( QString name, QgsVectorColorRampV2* colorRamp, bool update = false );
91 
93 
98  int addGroup( QString groupName, int parent = 0 );
99 
101 
106  int addSmartgroup( QString name, QString op, QgsSmartConditionMap conditions );
107 
109 
116  bool addSymbol( QString name, QgsSymbolV2* symbol, bool update = false );
117 
119 
123  int addTag( QString tagName );
124 
126  QgsSymbolGroupMap childGroupNames( QString parent = "" );
127 
129  void clear();
130 
132  QgsVectorColorRampV2* colorRamp( QString name );
133 
135  int colorRampCount();
136 
138  QStringList colorRampNames();
139 
141  const QgsVectorColorRampV2* colorRampRef( QString name ) const;
142 
145  int colorrampId( QString name );
146 
148  static QgsStyleV2* defaultStyle();
149 
151 
158  bool tagSymbol( StyleEntity type, QString symbol, QStringList tags );
159 
161 
168  bool detagSymbol( StyleEntity type, QString symbol, QStringList tags );
169 
171  bool removeSymbol( QString name );
172 
175  bool renameSymbol( QString oldName, QString newName );
176 
178  QgsSymbolV2* symbol( QString name );
179 
181  const QgsSymbolV2* symbolRef( QString name ) const;
182 
184  int symbolCount();
185 
187  QStringList symbolNames();
188 
191  int symbolId( QString name );
193  int groupId( QString group );
195  int tagId( QString tag );
197  int smartgroupId( QString smartgroup );
198 
200  QStringList groupNames();
201 
203 
208  QStringList symbolsOfGroup( StyleEntity type, int groupid );
209 
211 
216  QStringList symbolsWithTag( StyleEntity type, int tagid );
217 
219 
225  bool group( StyleEntity type, QString name, int groupid );
226 
228 
233  void rename( StyleEntity type, int id, QString newName );
234 
236 
240  void remove( StyleEntity type, int id );
241 
243 
250  bool saveSymbol( QString name, QgsSymbolV2* symbol, int groupid, QStringList tags );
251 
253 
260  bool saveColorRamp( QString name, QgsVectorColorRampV2* ramp, int groupid, QStringList tags );
261 
263  bool removeColorRamp( QString name );
264 
267  bool renameColorRamp( QString oldName, QString newName );
268 
269 
271  bool load( QString filename );
272 
274  bool save( QString filename = QString() );
275 
277  QString errorString() { return mErrorString; }
278 
280  QString fileName() { return mFileName; }
281 
283 
288  QStringList findSymbols( StyleEntity type, QString qword );
289 
291 
296  QStringList tagsOfSymbol( StyleEntity type, QString symbol );
297 
299  QgsSymbolGroupMap smartgroupsListMap();
300 
302  QStringList smartgroupNames();
303 
305  QgsSmartConditionMap smartgroup( int id );
306 
308  //clumsy implementation TODO create a class for smartgroups
309  QString smartgroupOperator( int id );
310 
312  QStringList symbolsOfSmartgroup( StyleEntity type, int id );
313 
315  bool exportXML( QString filename );
316 
318  bool importXML( QString filename );
319 
320  signals:
321  void symbolSaved( QString name, QgsSymbolV2* symbol );
322 
323  protected:
324 
327 
328  QString mErrorString;
329  QString mFileName;
330 
332 
334 
336  bool openDB( QString filename );
337 
342  bool runEmptyQuery( char* query, bool freeQuery = true );
343 
345  char* getGroupRemoveQuery( int id );
346 
348  int getId( QString table, QString name );
349 
351 
357  bool updateSymbol( StyleEntity type, QString name );
358 
359  private:
360  Q_DISABLE_COPY( QgsStyleV2 )
361 };
362 
363 
364 #endif
QString mErrorString
Definition: qgsstylev2.h:328
QMap< QString, QgsSymbolV2 * > QgsSymbolV2Map
Definition: qgsrendererv2.h:38
QString mFileName
Definition: qgsstylev2.h:329
QMultiMap< QString, QString > QgsSmartConditionMap
Definition: qgsstylev2.h:56
ColorrampTable
Definition: qgsstylev2.h:63
QString fileName()
return current file name of the style
Definition: qgsstylev2.h:280
static QgsStyleV2 * mDefaultStyle
Definition: qgsstylev2.h:333
sqlite3 * mCurrentDB
Definition: qgsstylev2.h:331
QMap< int, QString > QgsSymbolGroupMap
Definition: qgsstylev2.h:35
SymbolTable
Definition: qgsstylev2.h:59
struct sqlite3 sqlite3
QgsSymbolV2Map mSymbols
Definition: qgsstylev2.h:325
QMap< QString, QgsVectorColorRampV2 * > QgsVectorColorRampV2Map
Definition: qgsstylev2.h:32
QgsVectorColorRampV2Map mColorRamps
Definition: qgsstylev2.h:326
TagTable
Definition: qgsstylev2.h:61
TagmapTable
Definition: qgsstylev2.h:62
StyleEntity
Enum for Entities involved in a style.
Definition: qgsstylev2.h:80
SmartgroupTable
Definition: qgsstylev2.h:64
QString errorString()
return last error from load/save operation
Definition: qgsstylev2.h:277
SymgroupTable
Definition: qgsstylev2.h:60