QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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 
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
Registry of color schemes.
void schemes(QList< T * > &schemeList)
Returns color schemes of a specific type.
QgsColorSchemeRegistry()=default
Constructor for an empty color scheme registry.
Abstract base class for color schemes.
SchemeFlag
Flags for controlling behavior of color scheme.
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
#define SIP_TRANSFER
Definition: qgis_sip.h:36