QGIS API Documentation  2.15.0-Master (af20121)
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 
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( const QString& name, QgsVectorColorRampV2* colorRamp, bool update = false );
91 
93 
98  int addGroup( const QString& groupName, int parent = 0 );
99 
101 
106  int addSmartgroup( const QString& name, const QString& op, const QgsSmartConditionMap& conditions );
107 
109 
116  bool addSymbol( const QString& name, QgsSymbolV2* symbol, bool update = false );
117 
119 
123  int addTag( const QString& tagName );
124 
129  QStringList tags() const;
130 
132  QgsSymbolGroupMap childGroupNames( const QString& parent = "" );
133 
135  void clear();
136 
138  QgsVectorColorRampV2* colorRamp( const QString& name );
139 
141  int colorRampCount();
142 
144  QStringList colorRampNames();
145 
147  const QgsVectorColorRampV2* colorRampRef( const QString& name ) const;
148 
151  int colorrampId( const QString& name );
152 
154  static QgsStyleV2* defaultStyle();
155 
157 
164  bool tagSymbol( StyleEntity type, const QString& symbol, const QStringList& tags );
165 
167 
174  bool detagSymbol( StyleEntity type, const QString& symbol, const QStringList& tags );
175 
177  bool removeSymbol( const QString& name );
178 
180  bool renameSymbol( const QString& oldName, const QString& newName );
181 
183  QgsSymbolV2* symbol( const QString& name );
184 
186  const QgsSymbolV2* symbolRef( const QString& name ) const;
187 
189  int symbolCount();
190 
192  QStringList symbolNames();
193 
196  int symbolId( const QString& name );
198  int groupId( const QString& group );
200  QString groupName( int groupId ) const;
202  int tagId( const QString& tag );
204  int smartgroupId( const QString& smartgroup );
205 
207  QStringList groupNames();
208 
210  QList<int> groupIds() const;
211 
213 
218  QStringList symbolsOfGroup( StyleEntity type, int groupid );
219 
221 
226  QStringList symbolsWithTag( StyleEntity type, int tagid );
227 
229 
235  bool group( StyleEntity type, const QString& name, int groupid );
236 
238 
243  void rename( StyleEntity type, int id, const QString& newName );
244 
246 
250  void remove( StyleEntity type, int id );
251 
253 
260  bool saveSymbol( const QString& name, QgsSymbolV2* symbol, int groupid, const QStringList& tags );
261 
263 
270  bool saveColorRamp( const QString& name, QgsVectorColorRampV2* ramp, int groupid, const QStringList& tags );
271 
273  bool removeColorRamp( const QString& name );
274 
276  bool renameColorRamp( const QString& oldName, const QString& newName );
277 
279  bool load( const QString& filename );
280 
282  bool save( QString filename = QString() );
283 
285  QString errorString() { return mErrorString; }
286 
288  QString fileName() { return mFileName; }
289 
291 
296  QStringList findSymbols( StyleEntity type, const QString& qword );
297 
299 
304  QStringList tagsOfSymbol( StyleEntity type, const QString& symbol );
305 
307  QgsSymbolGroupMap smartgroupsListMap();
308 
310  QStringList smartgroupNames();
311 
313  QgsSmartConditionMap smartgroup( int id );
314 
316  //clumsy implementation TODO create a class for smartgroups
317  QString smartgroupOperator( int id );
318 
320  QStringList symbolsOfSmartgroup( StyleEntity type, int id );
321 
323  bool exportXML( const QString& filename );
324 
326  bool importXML( const QString& filename );
327 
328  signals:
329  void symbolSaved( const QString& name, QgsSymbolV2* symbol );
330 
331  protected:
332 
335 
338 
340 
342 
344  bool openDB( const QString& filename );
345 
350  bool runEmptyQuery( char* query, bool freeQuery = true );
351 
353  char* getGroupRemoveQuery( int id );
354 
356  int getId( const QString& table, const QString& name );
357 
359  QString getName( const QString& table, int id ) const;
360 
362 
368  bool updateSymbol( StyleEntity type, const QString& name );
369 
370  private:
371  Q_DISABLE_COPY( QgsStyleV2 )
372 };
373 
374 
375 #endif
QString mErrorString
Definition: qgsstylev2.h:336
QString mFileName
Definition: qgsstylev2.h:337
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:288
static QgsStyleV2 * mDefaultStyle
Definition: qgsstylev2.h:341
sqlite3 * mCurrentDB
Definition: qgsstylev2.h:339
QMap< int, QString > QgsSymbolGroupMap
Definition: qgsstylev2.h:35
SymbolTable
Definition: qgsstylev2.h:59
struct sqlite3 sqlite3
QgsSymbolV2Map mSymbols
Definition: qgsstylev2.h:333
QMap< QString, QgsVectorColorRampV2 * > QgsVectorColorRampV2Map
Definition: qgsstylev2.h:32
QgsVectorColorRampV2Map mColorRamps
Definition: qgsstylev2.h:334
TagTable
Definition: qgsstylev2.h:61
TagmapTable
Definition: qgsstylev2.h:62
StyleEntity
Enum for Entities involved in a style.
Definition: qgsstylev2.h:80
Abstract base class for color ramps.
SmartgroupTable
Definition: qgsstylev2.h:64
QString errorString()
return last error from load/save operation
Definition: qgsstylev2.h:285
SymgroupTable
Definition: qgsstylev2.h:60