QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgscolorschemeregistry.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscolorschemeregistry.h
3  ------------------------
4  begin : July 2014
5  copyright : (C) 2014 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSCOLORSCHEMEREGISTRY_H
19 #define QGSCOLORSCHEMEREGISTRY_H
20 
21 #include "qgis_core.h"
22 #include "qgscolorscheme.h"
23 #include <QList>
24 
34 class CORE_EXPORT QgsColorSchemeRegistry
35 {
36 
37  public:
38 
42  QgsColorSchemeRegistry() = default;
43 
44  virtual ~QgsColorSchemeRegistry();
45 
51  void populateFromInstance();
52 
59  void addDefaultSchemes();
60 
65  void initStyleScheme();
66 
73  void addUserSchemes();
74 
82  void addColorScheme( QgsColorScheme *scheme SIP_TRANSFER );
83 
90  bool removeColorScheme( QgsColorScheme *scheme );
91 
96  QList<QgsColorScheme *> schemes() const;
97 
103  QList<QgsColorScheme *> schemes( QgsColorScheme::SchemeFlag flag ) const;
104 
105 
111 #ifndef SIP_RUN
112  template<class T> void schemes( QList<T *> &schemeList )
113  {
114  schemeList.clear();
115  QList<QgsColorScheme *> schemeInstanceList = schemes();
116  QList<QgsColorScheme *>::iterator schemeIt = schemeInstanceList.begin();
117  for ( ; schemeIt != schemeInstanceList.end(); ++schemeIt )
118  {
119  T *scheme = dynamic_cast<T *>( *schemeIt );
120  if ( scheme )
121  {
122  schemeList.push_back( scheme );
123  }
124  }
125  }
126 #endif
127 
144  void setRandomStyleColorScheme( QgsColorScheme *scheme );
145 
156  QgsColorScheme *randomStyleColorScheme();
157 
179  QColor fetchRandomStyleColor() const;
180 
181  private:
182 
183  QList< QgsColorScheme * > mColorSchemeList;
184 
185  QgsColorScheme *mRandomStyleColorScheme = nullptr;
186  QgsNamedColorList mRandomStyleColors;
187 
188  mutable int mNextRandomStyleColorIndex = 0;
189 
190  int mNextRandomStyleColorDirection = 1;
191 
192 };
193 
194 
195 
196 #endif
qgscolorscheme.h
QgsNamedColorList
QList< QPair< QColor, QString > > QgsNamedColorList
Definition: qgscolorscheme.h:34
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsColorSchemeRegistry
Registry of color schemes.
Definition: qgscolorschemeregistry.h:34
QgsColorScheme
Abstract base class for color schemes.
Definition: qgscolorscheme.h:46
QgsColorScheme::SchemeFlag
SchemeFlag
Flags for controlling behavior of color scheme.
Definition: qgscolorscheme.h:71
QgsColorSchemeRegistry::schemes
void schemes(QList< T * > &schemeList)
Returns color schemes of a specific type.
Definition: qgscolorschemeregistry.h:112