QGIS API Documentation  3.0.2-Girona (307d082)
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 
179  bool tagSymbol( StyleEntity type, const QString &symbol, const QStringList &tags );
180 
190  bool detagSymbol( StyleEntity type, const QString &symbol, const QStringList &tags );
191 
200  bool detagSymbol( StyleEntity type, const QString &symbol );
201 
203  bool removeSymbol( const QString &name );
204 
206  bool renameSymbol( const QString &oldName, const QString &newName );
207 
209  QgsSymbol *symbol( const QString &name ) SIP_FACTORY;
210 
212  const QgsSymbol *symbolRef( const QString &name ) const;
213 
215  int symbolCount();
216 
218  QStringList symbolNames();
219 
224  int symbolId( const QString &name );
226  int tagId( const QString &tag );
228  int smartgroupId( const QString &smartgroup );
229 
236  QStringList symbolsOfFavorite( StyleEntity type ) const;
237 
245  QStringList symbolsWithTag( StyleEntity type, int tagid ) const;
246 
254  bool addFavorite( StyleEntity type, const QString &name );
255 
263  bool removeFavorite( StyleEntity type, const QString &name );
264 
272  void rename( StyleEntity type, int id, const QString &newName );
273 
280  void remove( StyleEntity type, int id );
281 
291  bool saveSymbol( const QString &name, QgsSymbol *symbol, bool favorite, const QStringList &tags );
292 
302  bool saveColorRamp( const QString &name, QgsColorRamp *ramp, bool favorite, const QStringList &tags );
303 
305  bool removeColorRamp( const QString &name );
306 
308  bool renameColorRamp( const QString &oldName, const QString &newName );
309 
318  bool createDatabase( const QString &filename );
319 
328  bool createMemoryDatabase();
329 
338  void createTables();
339 
347  bool load( const QString &filename );
348 
350  bool save( QString filename = QString() );
351 
353  QString errorString() { return mErrorString; }
354 
356  QString fileName() { return mFileName; }
357 
365  QStringList findSymbols( StyleEntity type, const QString &qword );
366 
374  QStringList tagsOfSymbol( StyleEntity type, const QString &symbol );
375 
384  bool symbolHasTag( StyleEntity type, const QString &symbol, const QString &tag );
385 
387  QString tag( int id ) const;
388 
390  QgsSymbolGroupMap smartgroupsListMap();
391 
393  QStringList smartgroupNames();
394 
396  QgsSmartConditionMap smartgroup( int id );
397 
402  QString smartgroupOperator( int id );
403 
405  QStringList symbolsOfSmartgroup( StyleEntity type, int id );
406 
408  bool exportXml( const QString &filename );
409 
411  bool importXml( const QString &filename );
412 
413  signals:
415  void symbolSaved( const QString &name, QgsSymbol *symbol );
417  void groupsModified();
418 
419  protected:
420 
423 
424  QString mErrorString;
425  QString mFileName;
426 
428 
430 
432  bool openDatabase( const QString &filename );
433 
441  bool runEmptyQuery( char *query, bool freeQuery = true );
442 
444  int getId( const QString &table, const QString &name );
445 
447  QString getName( const QString &table, int id ) const;
448 
457  bool updateSymbol( StyleEntity type, const QString &name );
458 
459  private:
460  Q_DISABLE_COPY( QgsStyle )
461 };
462 
463 
464 #endif
TagmapTable
Definition: qgsstyle.h:68
QString mFileName
Definition: qgsstyle.h:425
QgsSymbolMap mSymbols
Definition: qgsstyle.h:421
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
static QgsStyle * sDefaultStyle
Definition: qgsstyle.h:429
#define SIP_TRANSFER
Definition: qgis_sip.h:36
TagTable
Definition: qgsstyle.h:67
#define SIP_FACTORY
Definition: qgis_sip.h:69
QgsVectorColorRampMap mColorRamps
Definition: qgsstyle.h:422
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:356
sqlite3_database_unique_ptr mCurrentDB
Definition: qgsstyle.h:427
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:353
QMultiMap< QString, QString > QgsSmartConditionMap
A multimap to hold the smart group conditions as constraint and parameter pairs.
Definition: qgsstyle.h:63
QString mErrorString
Definition: qgsstyle.h:424