QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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;
33 
36 
57 
58 // enumerators representing sqlite DB columns
65 
69 class CORE_EXPORT QgsStyleV2 : public QObject
70 {
71  Q_OBJECT
72 
73  public:
74  QgsStyleV2();
75  ~QgsStyleV2();
76 
78 
83  enum StyleEntity { SymbolEntity, GroupEntity, TagEntity, ColorrampEntity, SmartgroupEntity };
84 
86 
93  bool addColorRamp( const QString& name, QgsVectorColorRampV2* colorRamp, bool update = false );
94 
96 
101  int addGroup( const QString& groupName, int parent = 0 );
102 
104 
109  int addSmartgroup( const QString& name, const QString& op, const QgsSmartConditionMap& conditions );
110 
112 
119  bool addSymbol( const QString& name, QgsSymbolV2* symbol, bool update = false );
120 
122 
126  int addTag( const QString& tagName );
127 
132  QStringList tags() const;
133 
135  QgsSymbolGroupMap childGroupNames( const QString& parent = "" );
136 
138  void clear();
139 
141  QgsVectorColorRampV2* colorRamp( const QString& name );
142 
144  int colorRampCount();
145 
147  QStringList colorRampNames();
148 
150  const QgsVectorColorRampV2* colorRampRef( const QString& name ) const;
151 
154  int colorrampId( const QString& name );
155 
157  static QgsStyleV2* defaultStyle();
158 
160 
167  bool tagSymbol( StyleEntity type, const QString& symbol, const QStringList& tags );
168 
170 
177  bool detagSymbol( StyleEntity type, const QString& symbol, const QStringList& tags );
178 
180  bool removeSymbol( const QString& name );
181 
183  bool renameSymbol( const QString& oldName, const QString& newName );
184 
186  QgsSymbolV2* symbol( const QString& name );
187 
189  const QgsSymbolV2* symbolRef( const QString& name ) const;
190 
192  int symbolCount();
193 
195  QStringList symbolNames();
196 
199  int symbolId( const QString& name );
201  int groupId( const QString& group );
203  QString groupName( int groupId ) const;
205  int tagId( const QString& tag );
207  int smartgroupId( const QString& smartgroup );
208 
210  QStringList groupNames();
211 
213  QList<int> groupIds() const;
214 
216 
221  QStringList symbolsOfGroup( StyleEntity type, int groupid );
222 
224 
229  QStringList symbolsWithTag( StyleEntity type, int tagid );
230 
232 
238  bool group( StyleEntity type, const QString& name, int groupid );
239 
241 
246  void rename( StyleEntity type, int id, const QString& newName );
247 
249 
253  void remove( StyleEntity type, int id );
254 
256 
263  bool saveSymbol( const QString& name, QgsSymbolV2* symbol, int groupid, const QStringList& tags );
264 
266 
273  bool saveColorRamp( const QString& name, QgsVectorColorRampV2* ramp, int groupid, const QStringList& tags );
274 
276  bool removeColorRamp( const QString& name );
277 
279  bool renameColorRamp( const QString& oldName, const QString& newName );
280 
282  bool load( const QString& filename );
283 
285  bool save( QString filename = QString() );
286 
288  QString errorString() { return mErrorString; }
289 
291  QString fileName() { return mFileName; }
292 
294 
299  QStringList findSymbols( StyleEntity type, const QString& qword );
300 
302 
307  QStringList tagsOfSymbol( StyleEntity type, const QString& symbol );
308 
310  QgsSymbolGroupMap smartgroupsListMap();
311 
313  QStringList smartgroupNames();
314 
316  QgsSmartConditionMap smartgroup( int id );
317 
319  //clumsy implementation TODO create a class for smartgroups
320  QString smartgroupOperator( int id );
321 
323  QStringList symbolsOfSmartgroup( StyleEntity type, int id );
324 
326  bool exportXML( const QString& filename );
327 
329  bool importXML( const QString& filename );
330 
331  signals:
332  void symbolSaved( const QString& name, QgsSymbolV2* symbol );
333 
334  protected:
335 
338 
341 
343 
345 
347  bool openDB( const QString& filename );
348 
353  bool runEmptyQuery( char* query, bool freeQuery = true );
354 
356  char* getGroupRemoveQuery( int id );
357 
359  int getId( const QString& table, const QString& name );
360 
362  QString getName( const QString& table, int id ) const;
363 
365 
371  bool updateSymbol( StyleEntity type, const QString& name );
372 
373  private:
374  Q_DISABLE_COPY( QgsStyleV2 )
375 };
376 
377 
378 #endif
QString mErrorString
Definition: qgsstylev2.h:339
QString mFileName
Definition: qgsstylev2.h:340
ColorrampTable
Definition: qgsstylev2.h:63
QString fileName()
return current file name of the style
Definition: qgsstylev2.h:291
static QgsStyleV2 * mDefaultStyle
Definition: qgsstylev2.h:344
sqlite3 * mCurrentDB
Definition: qgsstylev2.h:342
QMap< int, QString > QgsSymbolGroupMap
Definition: qgsstylev2.h:35
SymbolTable
Definition: qgsstylev2.h:59
struct sqlite3 sqlite3
QgsSymbolV2Map mSymbols
Definition: qgsstylev2.h:336
QMap< QString, QgsVectorColorRampV2 *> QgsVectorColorRampV2Map
Definition: qgsstylev2.h:32
QgsVectorColorRampV2Map mColorRamps
Definition: qgsstylev2.h:337
TagTable
Definition: qgsstylev2.h:61
TagmapTable
Definition: qgsstylev2.h:62
StyleEntity
Enum for Entities involved in a style.
Definition: qgsstylev2.h:83
Abstract base class for color ramps.
SmartgroupTable
Definition: qgsstylev2.h:64
QString errorString()
return last error from load/save operation
Definition: qgsstylev2.h:288
QMultiMap< QString, QString > QgsSmartConditionMap
A multimap to hold the smart group conditions as constraint and parameter pairs.
Definition: qgsstylev2.h:56
SymgroupTable
Definition: qgsstylev2.h:60