QGIS API Documentation 4.3.0-Master (0cef2469b72)
Loading...
Searching...
No Matches
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
24#include <QList>
25#include <QPointer>
26
27class QgsProject;
28
37class CORE_EXPORT QgsColorSchemeRegistry
38{
39 public:
49
51
58
65 void addDefaultSchemes();
66
71 void initStyleScheme();
72
79 void addUserSchemes();
80
89
96 bool removeColorScheme( QgsColorScheme *scheme );
97
102 QList<QgsColorScheme *> schemes() const;
103
109 QList<QgsColorScheme *> schemes( QgsColorScheme::SchemeFlag flag ) const;
110
111
117#ifndef SIP_RUN
118 template<class T> void schemes( QList<T *> &schemeList ) const
119 {
120 schemeList.clear();
121 QList<QgsColorScheme *> schemeInstanceList = schemes();
122 QList<QgsColorScheme *>::iterator schemeIt = schemeInstanceList.begin();
123 for ( ; schemeIt != schemeInstanceList.end(); ++schemeIt )
124 {
125 T *scheme = dynamic_cast<T *>( *schemeIt );
126 if ( scheme )
127 {
128 schemeList.push_back( scheme );
129 }
130 }
131 }
132#endif
133
150 void setRandomStyleColorScheme( QgsColorScheme *scheme );
151
162 QgsColorScheme *randomStyleColorScheme();
163
185 QColor fetchRandomStyleColor() const;
186
194 void setProject( QgsProject *project );
195
196
197 private:
198 QList< QgsColorScheme * > mColorSchemeList;
199
200 QgsColorScheme *mRandomStyleColorScheme = nullptr;
201 QgsNamedColorList mRandomStyleColors;
202
203 QPointer< QgsProject > mProject;
204
205 mutable int mNextRandomStyleColorIndex = 0;
206
207 int mNextRandomStyleColorDirection = 1;
208};
209
210
211#endif
void addDefaultSchemes()
Adds all default color schemes to this color scheme.
void addColorScheme(QgsColorScheme *scheme)
Adds a color scheme to the registry.
QList< QgsColorScheme * > schemes() const
Returns all color schemes in the registry.
void populateFromInstance()
Adds all color schemes from the global instance to this color scheme.
bool removeColorScheme(QgsColorScheme *scheme)
Removes all matching color schemes from the registry.
void initStyleScheme()
Initializes the default random style color scheme for the user.
void addUserSchemes()
Creates schemes for all gpl palettes in the user's palettes folder.
QgsColorSchemeRegistry()=default
Constructor for an empty color scheme registry.
void schemes(QList< T * > &schemeList) const
Returns color schemes of a specific type.
Abstract base class for color schemes.
SchemeFlag
Flags for controlling behavior of color scheme.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:114
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
#define SIP_TRANSFER
Definition qgis_sip.h:35