QGIS API Documentation 3.39.0-Master (67e056379ed)
Loading...
Searching...
No Matches
qgscolorscheme.h
Go to the documentation of this file.
1/***************************************************************************
2 qgscolorscheme.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 QGSCOLORSCHEME_H
19#define QGSCOLORSCHEME_H
20
21#include <QString>
22#include <QColor>
23#include <QPair>
24#include <QObject>
25
26#include "qgis_core.h"
27#include "qgis_sip.h"
28
33typedef QList< QPair< QColor, QString > > QgsNamedColorList;
34
44class CORE_EXPORT QgsColorScheme
45{
46
47#ifdef SIP_RUN
49 if ( dynamic_cast<QgsUserColorScheme *>( sipCpp ) != NULL )
50 sipType = sipType_QgsUserColorScheme;
51 else if ( dynamic_cast<QgsRecentColorScheme *>( sipCpp ) != NULL )
52 sipType = sipType_QgsRecentColorScheme;
53 else if ( dynamic_cast<QgsCustomColorScheme *>( sipCpp ) != NULL )
54 sipType = sipType_QgsCustomColorScheme;
55 else if ( dynamic_cast<QgsProjectColorScheme *>( sipCpp ) != NULL )
56 sipType = sipType_QgsProjectColorScheme;
57 else if ( dynamic_cast<QgsGplColorScheme *>( sipCpp ) != NULL )
58 sipType = sipType_QgsGplColorScheme;
59 else
60 sipType = sipType_QgsColorScheme;
62#endif
63
64 public:
65
70 {
71 ShowInColorDialog = 0x01,
72 ShowInColorButtonMenu = 0x02,
73 ShowInAllContexts = ShowInColorDialog | ShowInColorButtonMenu
74 };
75 Q_DECLARE_FLAGS( SchemeFlags, SchemeFlag )
76
77
80 QgsColorScheme() = default;
81
82 virtual ~QgsColorScheme() = default;
83
88 virtual QString schemeName() const = 0;
89
94 virtual SchemeFlags flags() const { return ShowInColorDialog; }
95
107 virtual QgsNamedColorList fetchColors( const QString &context = QString(),
108 const QColor &baseColor = QColor() ) = 0;
109
115 virtual bool isEditable() const { return false; }
116
125 virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() );
126
131 virtual QgsColorScheme *clone() const = 0 SIP_FACTORY;
132};
133
135
136
141class CORE_EXPORT QgsGplColorScheme : public QgsColorScheme
142{
143 public:
144
148 QgsGplColorScheme() = default;
149
150 QgsNamedColorList fetchColors( const QString &context = QString(),
151 const QColor &baseColor = QColor() ) override;
152
153 bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
154
155 protected:
156
161 virtual QString gplFilePath() = 0;
162
163};
164
171class CORE_EXPORT QgsUserColorScheme : public QgsGplColorScheme
172{
173 public:
174
179 QgsUserColorScheme( const QString &filename );
180
181 QString schemeName() const override;
182
183 QgsUserColorScheme *clone() const override SIP_FACTORY;
184
185 bool isEditable() const override { return mEditable; }
186
187 QgsColorScheme::SchemeFlags flags() const override;
188
193 void setName( const QString &name ) { mName = name; }
194
199 bool erase();
200
205 void setShowSchemeInMenu( bool show );
206
207 protected:
208
209 QString mName;
210
211 QString mFilename;
212
213 bool mEditable = false;
214
215 QString gplFilePath() override;
216
217};
218
224class CORE_EXPORT QgsRecentColorScheme : public QgsColorScheme
225{
226 public:
227
232
233 QString schemeName() const override { return QObject::tr( "Recent colors" ); }
234
235 SchemeFlags flags() const override { return ShowInAllContexts; }
236
237 QgsNamedColorList fetchColors( const QString &context = QString(),
238 const QColor &baseColor = QColor() ) override;
239
240 QgsRecentColorScheme *clone() const override SIP_FACTORY;
241
247 static void addRecentColor( const QColor &color );
248
253 static QColor lastUsedColor();
254};
255
261class CORE_EXPORT QgsCustomColorScheme : public QgsColorScheme
262{
263 public:
264
269
270 QString schemeName() const override { return QObject::tr( "Standard colors" ); }
271
272 SchemeFlags flags() const override { return ShowInAllContexts; }
273
274 QgsNamedColorList fetchColors( const QString &context = QString(),
275 const QColor &baseColor = QColor() ) override;
276
277 bool isEditable() const override { return true; }
278
279 bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
280
281 QgsCustomColorScheme *clone() const override SIP_FACTORY;
282};
283
289class CORE_EXPORT QgsProjectColorScheme : public QgsColorScheme
290{
291 public:
292
297
298 QString schemeName() const override { return QObject::tr( "Project colors" ); }
299
300 SchemeFlags flags() const override { return ShowInAllContexts; }
301
302 QgsNamedColorList fetchColors( const QString &context = QString(),
303 const QColor &baseColor = QColor() ) override;
304
305 bool isEditable() const override { return true; }
306
307 bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
308
309 QgsProjectColorScheme *clone() const override SIP_FACTORY;
310};
311
312#endif
Abstract base class for color schemes.
SchemeFlag
Flags for controlling behavior of color scheme.
virtual QgsColorScheme * clone() const =0
Clones a color scheme.
QFlags< SchemeFlag > SchemeFlags
virtual QgsNamedColorList fetchColors(const QString &context=QString(), const QColor &baseColor=QColor())=0
Gets a list of colors from the scheme.
virtual bool isEditable() const
Returns whether the color scheme is editable.
A color scheme which contains custom colors set through QGIS app options dialog.
SchemeFlags flags() const override
Returns the current flags for the color scheme.
bool isEditable() const override
Returns whether the color scheme is editable.
QString schemeName() const override
Gets the name for the color scheme.
QgsCustomColorScheme()=default
Constructor for QgsCustomColorScheme.
A color scheme which stores its colors in a gpl palette file.
virtual QString gplFilePath()=0
Returns the file path for the associated gpl palette file.
QgsGplColorScheme()=default
Constructor for QgsGplColorScheme.
A color scheme which contains project specific colors set through project properties dialog.
SchemeFlags flags() const override
Returns the current flags for the color scheme.
QgsProjectColorScheme()=default
Constructor for QgsProjectColorScheme.
bool isEditable() const override
Returns whether the color scheme is editable.
QString schemeName() const override
Gets the name for the color scheme.
A color scheme which contains the most recently used colors.
QgsRecentColorScheme()=default
Constructor for QgsRecentColorScheme.
QString schemeName() const override
Gets the name for the color scheme.
SchemeFlags flags() const override
Returns the current flags for the color scheme.
A color scheme which stores its colors in a gpl palette file within the "palettes" subfolder off the ...
void setName(const QString &name)
Sets the name for the scheme.
bool isEditable() const override
Returns whether the color scheme is editable.
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_END
Definition qgis_sip.h:208
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)