QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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 QgsColorScheme() = default;
78
79 virtual ~QgsColorScheme() = default;
80
85 virtual QString schemeName() const = 0;
86
91 virtual SchemeFlags flags() const { return ShowInColorDialog; }
92
104 virtual QgsNamedColorList fetchColors( const QString &context = QString(),
105 const QColor &baseColor = QColor() ) = 0;
106
112 virtual bool isEditable() const { return false; }
113
122 virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() );
123
128 virtual QgsColorScheme *clone() const = 0 SIP_FACTORY;
129};
130
132
133
138class CORE_EXPORT QgsGplColorScheme : public QgsColorScheme
139{
140 public:
141
142 QgsGplColorScheme() = default;
143
144 QgsNamedColorList fetchColors( const QString &context = QString(),
145 const QColor &baseColor = QColor() ) override;
146
147 bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
148
149 protected:
150
155 virtual QString gplFilePath() = 0;
156
157};
158
165class CORE_EXPORT QgsUserColorScheme : public QgsGplColorScheme
166{
167 public:
168
173 QgsUserColorScheme( const QString &filename );
174
175 QString schemeName() const override;
176
177 QgsUserColorScheme *clone() const override SIP_FACTORY;
178
179 bool isEditable() const override { return mEditable; }
180
181 QgsColorScheme::SchemeFlags flags() const override;
182
187 void setName( const QString &name ) { mName = name; }
188
193 bool erase();
194
199 void setShowSchemeInMenu( bool show );
200
201 protected:
202
203 QString mName;
204
205 QString mFilename;
206
207 bool mEditable = false;
208
209 QString gplFilePath() override;
210
211};
212
218class CORE_EXPORT QgsRecentColorScheme : public QgsColorScheme
219{
220 public:
221
223
224 QString schemeName() const override { return QObject::tr( "Recent colors" ); }
225
226 SchemeFlags flags() const override { return ShowInAllContexts; }
227
228 QgsNamedColorList fetchColors( const QString &context = QString(),
229 const QColor &baseColor = QColor() ) override;
230
231 QgsRecentColorScheme *clone() const override SIP_FACTORY;
232
238 static void addRecentColor( const QColor &color );
239
244 static QColor lastUsedColor();
245};
246
252class CORE_EXPORT QgsCustomColorScheme : public QgsColorScheme
253{
254 public:
255
257
258 QString schemeName() const override { return QObject::tr( "Standard colors" ); }
259
260 SchemeFlags flags() const override { return ShowInAllContexts; }
261
262 QgsNamedColorList fetchColors( const QString &context = QString(),
263 const QColor &baseColor = QColor() ) override;
264
265 bool isEditable() const override { return true; }
266
267 bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
268
269 QgsCustomColorScheme *clone() const override SIP_FACTORY;
270};
271
277class CORE_EXPORT QgsProjectColorScheme : public QgsColorScheme
278{
279 public:
280
282
283 QString schemeName() const override { return QObject::tr( "Project colors" ); }
284
285 SchemeFlags flags() const override { return ShowInAllContexts; }
286
287 QgsNamedColorList fetchColors( const QString &context = QString(),
288 const QColor &baseColor = QColor() ) override;
289
290 bool isEditable() const override { return true; }
291
292 bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
293
294 QgsProjectColorScheme *clone() const override SIP_FACTORY;
295};
296
297#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
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
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
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
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)