QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
96  {
100  SmartgroupEntity
101  };
102 
112  bool addSymbol( const QString &name, QgsSymbol *symbol SIP_TRANSFER, bool update = false );
113 
122  bool addColorRamp( const QString &name, QgsColorRamp *colorRamp SIP_TRANSFER, bool update = false );
123 
130  int addTag( const QString &tagName );
131 
141  int addSmartgroup( const QString &name, const QString &op, const QgsSmartConditionMap &conditions ) SIP_SKIP;
142 
155  int addSmartgroup( const QString &name, const QString &op, const QStringList &matchTag, const QStringList &noMatchTag,
156  const QStringList &matchName, const QStringList &noMatchName );
157 
164  QStringList tags() const;
165 
167  void clear();
168 
173  QgsColorRamp *colorRamp( const QString &name ) const SIP_FACTORY;
174 
176  int colorRampCount();
177 
179  QStringList colorRampNames();
180 
182  const QgsColorRamp *colorRampRef( const QString &name ) const;
183 
188  int colorrampId( const QString &name );
189 
191  static QgsStyle *defaultStyle();
192 
194  static void cleanDefaultStyle() SIP_SKIP;
195 
205  bool tagSymbol( StyleEntity type, const QString &symbol, const QStringList &tags );
206 
216  bool detagSymbol( StyleEntity type, const QString &symbol, const QStringList &tags );
217 
226  bool detagSymbol( StyleEntity type, const QString &symbol );
227 
229  bool removeSymbol( const QString &name );
230 
236  bool renameSymbol( const QString &oldName, const QString &newName );
237 
239  QgsSymbol *symbol( const QString &name ) SIP_FACTORY;
240 
242  const QgsSymbol *symbolRef( const QString &name ) const;
243 
245  int symbolCount();
246 
248  QStringList symbolNames();
249 
254  int symbolId( const QString &name );
256  int tagId( const QString &tag );
258  int smartgroupId( const QString &smartgroup );
259 
266  QStringList symbolsOfFavorite( StyleEntity type ) const;
267 
275  QStringList symbolsWithTag( StyleEntity type, int tagid ) const;
276 
284  bool addFavorite( StyleEntity type, const QString &name );
285 
293  bool removeFavorite( StyleEntity type, const QString &name );
294 
302  bool rename( StyleEntity type, int id, const QString &newName );
303 
310  bool remove( StyleEntity type, int id );
311 
321  bool saveSymbol( const QString &name, QgsSymbol *symbol, bool favorite, const QStringList &tags );
322 
332  bool saveColorRamp( const QString &name, QgsColorRamp *ramp, bool favorite, const QStringList &tags );
333 
335  bool removeColorRamp( const QString &name );
336 
338  bool renameColorRamp( const QString &oldName, const QString &newName );
339 
348  bool createDatabase( const QString &filename );
349 
358  bool createMemoryDatabase();
359 
369  void createTables();
370 
378  bool load( const QString &filename );
379 
381  bool save( QString filename = QString() );
382 
384  QString errorString() { return mErrorString; }
385 
387  QString fileName() { return mFileName; }
388 
396  QStringList findSymbols( StyleEntity type, const QString &qword );
397 
405  QStringList tagsOfSymbol( StyleEntity type, const QString &symbol );
406 
415  bool symbolHasTag( StyleEntity type, const QString &symbol, const QString &tag );
416 
418  QString tag( int id ) const;
419 
421  QgsSymbolGroupMap smartgroupsListMap();
422 
424  QStringList smartgroupNames();
425 
427  QgsSmartConditionMap smartgroup( int id );
428 
433  QString smartgroupOperator( int id );
434 
436  QStringList symbolsOfSmartgroup( StyleEntity type, int id );
437 
439  bool exportXml( const QString &filename );
440 
442  bool importXml( const QString &filename );
443 
452  static bool isXmlStyleFile( const QString &path );
453 
454  signals:
455 
464  void symbolSaved( const QString &name, QgsSymbol *symbol );
465 
474  void symbolChanged( const QString &name );
475 
477  void groupsModified();
478 
484  void entityTagsChanged( QgsStyle::StyleEntity entity, const QString &name, const QStringList &newTags );
485 
491  void favoritedChanged( QgsStyle::StyleEntity entity, const QString &name, bool isFavorite );
492 
500  void symbolRemoved( const QString &name );
501 
507  void symbolRenamed( const QString &oldName, const QString &newName );
508 
514  void rampRenamed( const QString &oldName, const QString &newName );
515 
523  void rampAdded( const QString &name );
524 
532  void rampRemoved( const QString &name );
533 
542  void rampChanged( const QString &name );
543 
544  private:
545 
546  QgsSymbolMap mSymbols;
547  QgsVectorColorRampMap mColorRamps;
548 
549  QHash< QString, QStringList > mCachedSymbolTags;
550  QHash< QString, QStringList > mCachedColorRampTags;
551 
552  QString mErrorString;
553  QString mFileName;
554 
555  sqlite3_database_unique_ptr mCurrentDB;
556 
557  static QgsStyle *sDefaultStyle;
558 
560  bool openDatabase( const QString &filename );
561 
568  bool runEmptyQuery( const QString &query );
569 
571  int getId( const QString &table, const QString &name );
572 
574  QString getName( const QString &table, int id ) const;
575 
584  bool updateSymbol( StyleEntity type, const QString &name );
585 
586  void clearCachedTags( StyleEntity type, const QString &name );
587 
588  Q_DISABLE_COPY( QgsStyle )
589 };
590 
591 #endif
TagmapTable
Definition: qgsstyle.h:68
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
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:387
QMap< QString, QgsSymbol * > QgsSymbolMap
Definition: qgsrenderer.h:44
Definition: qgsstyle.h:67
SymbolTable
Definition: qgsstyle.h:66
QMultiMap< QString, QString > QgsSmartConditionMap
A multimap to hold the smart group conditions as constraint and parameter pairs.
Definition: qgsstyle.h:63