QGIS API Documentation  3.2.0-Bonn (bc43194)
qgsstyle.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsstyle.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 "qgis_core.h"
20 #include "qgis.h"
21 #include <QMap>
22 #include <QMultiMap>
23 #include <QString>
24 
25 #include <sqlite3.h>
26 
27 #include "qgssqliteutils.h"
28 #include "qgssymbollayerutils.h" // QgsStringMap
29 
30 class QgsSymbol;
31 class QgsSymbolLayer;
32 class QgsColorRamp;
33 
34 class QDomDocument;
35 class QDomElement;
36 
37 typedef QMap<QString, QgsColorRamp * > QgsVectorColorRampMap;
38 typedef QMap<int, QString> QgsSymbolGroupMap;
39 
40 /*
41  * Constants used to describe copy-paste MIME types
42  */
43 #define QGSCLIPBOARD_STYLE_MIME "application/qgis.style"
44 
63 typedef QMultiMap<QString, QString> QgsSmartConditionMap;
64 
65 // enumerators representing sqlite DB columns
71 
76 class CORE_EXPORT QgsStyle : public QObject
77 {
78  Q_OBJECT
79 
80  public:
81 
85  QgsStyle() = default;
86  ~QgsStyle() override;
87 
95  enum StyleEntity { SymbolEntity, TagEntity, ColorrampEntity, SmartgroupEntity };
96 
106  bool addSymbol( const QString &name, QgsSymbol *symbol SIP_TRANSFER, bool update = false );
107 
116  bool addColorRamp( const QString &name, QgsColorRamp *colorRamp SIP_TRANSFER, bool update = false );
117 
124  int addTag( const QString &tagName );
125 
133  int addSmartgroup( const QString &name, const QString &op, const QgsSmartConditionMap &conditions );
134 
141  QStringList tags() const;
142 
144  void clear();
145 
150  QgsColorRamp *colorRamp( const QString &name ) const SIP_FACTORY;
151 
153  int colorRampCount();
154 
156  QStringList colorRampNames();
157 
159  const QgsColorRamp *colorRampRef( const QString &name ) const;
160 
165  int colorrampId( const QString &name );
166 
168  static QgsStyle *defaultStyle();
169 
171  static void cleanDefaultStyle() SIP_SKIP;
172 
182  bool tagSymbol( StyleEntity type, const QString &symbol, const QStringList &tags );
183 
193  bool detagSymbol( StyleEntity type, const QString &symbol, const QStringList &tags );
194 
203  bool detagSymbol( StyleEntity type, const QString &symbol );
204 
206  bool removeSymbol( const QString &name );
207 
209  bool renameSymbol( const QString &oldName, const QString &newName );
210 
212  QgsSymbol *symbol( const QString &name ) SIP_FACTORY;
213 
215  const QgsSymbol *symbolRef( const QString &name ) const;
216 
218  int symbolCount();
219 
221  QStringList symbolNames();
222 
227  int symbolId( const QString &name );
229  int tagId( const QString &tag );
231  int smartgroupId( const QString &smartgroup );
232 
239  QStringList symbolsOfFavorite( StyleEntity type ) const;
240 
248  QStringList symbolsWithTag( StyleEntity type, int tagid ) const;
249 
257  bool addFavorite( StyleEntity type, const QString &name );
258 
266  bool removeFavorite( StyleEntity type, const QString &name );
267 
275  void rename( StyleEntity type, int id, const QString &newName );
276 
283  void remove( StyleEntity type, int id );
284 
294  bool saveSymbol( const QString &name, QgsSymbol *symbol, bool favorite, const QStringList &tags );
295 
305  bool saveColorRamp( const QString &name, QgsColorRamp *ramp, bool favorite, const QStringList &tags );
306 
308  bool removeColorRamp( const QString &name );
309 
311  bool renameColorRamp( const QString &oldName, const QString &newName );
312 
321  bool createDatabase( const QString &filename );
322 
331  bool createMemoryDatabase();
332 
342  void createTables();
343 
351  bool load( const QString &filename );
352 
354  bool save( QString filename = QString() );
355 
357  QString errorString() { return mErrorString; }
358 
360  QString fileName() { return mFileName; }
361 
369  QStringList findSymbols( StyleEntity type, const QString &qword );
370 
378  QStringList tagsOfSymbol( StyleEntity type, const QString &symbol );
379 
388  bool symbolHasTag( StyleEntity type, const QString &symbol, const QString &tag );
389 
391  QString tag( int id ) const;
392 
394  QgsSymbolGroupMap smartgroupsListMap();
395 
397  QStringList smartgroupNames();
398 
400  QgsSmartConditionMap smartgroup( int id );
401 
406  QString smartgroupOperator( int id );
407 
409  QStringList symbolsOfSmartgroup( StyleEntity type, int id );
410 
412  bool exportXml( const QString &filename );
413 
415  bool importXml( const QString &filename );
416 
417  signals:
419  void symbolSaved( const QString &name, QgsSymbol *symbol );
421  void groupsModified();
422 
423  private:
424 
425  QgsSymbolMap mSymbols;
426  QgsVectorColorRampMap mColorRamps;
427 
428  QString mErrorString;
429  QString mFileName;
430 
431  sqlite3_database_unique_ptr mCurrentDB;
432 
433  static QgsStyle *sDefaultStyle;
434 
436  bool openDatabase( const QString &filename );
437 
444  bool runEmptyQuery( const QString &query );
445 
447  int getId( const QString &table, const QString &name );
448 
450  QString getName( const QString &table, int id ) const;
451 
460  bool updateSymbol( StyleEntity type, const QString &name );
461 
462  Q_DISABLE_COPY( QgsStyle )
463 };
464 
465 #endif
TagmapTable
Definition: qgsstyle.h:68
Abstract base class for color ramps.
Definition: qgscolorramp.h:31
QMap< int, QString > QgsSymbolGroupMap
Definition: qgsstyle.h:38
SmartgroupTable
Definition: qgsstyle.h:70
StyleEntity
Enum for Entities involved in a style.
Definition: qgsstyle.h:95
#define SIP_SKIP
Definition: qgis_sip.h:119
#define SIP_TRANSFER
Definition: qgis_sip.h:36
TagTable
Definition: qgsstyle.h:67
#define SIP_FACTORY
Definition: qgis_sip.h:69
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
ColorrampTable
Definition: qgsstyle.h:69
QMap< QString, QgsColorRamp *> QgsVectorColorRampMap
Definition: qgsstyle.h:35
QString fileName()
Returns current file name of the style.
Definition: qgsstyle.h:360
QMap< QString, QgsSymbol *> QgsSymbolMap
Definition: qgsrenderer.h:44
Definition: qgsstyle.h:67
SymbolTable
Definition: qgsstyle.h:66
QString errorString()
Returns last error from load/save operation.
Definition: qgsstyle.h:357
QMultiMap< QString, QString > QgsSmartConditionMap
A multimap to hold the smart group conditions as constraint and parameter pairs.
Definition: qgsstyle.h:63