QGIS API Documentation 4.1.0-Master (376402f9aeb)
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 "qgis_core.h"
22#include "qgis_sip.h"
23
24#include <QColor>
25#include <QObject>
26#include <QPair>
27#include <QString>
28
31
36typedef QList< QPair< QColor, QString > > QgsNamedColorList;
37
47class CORE_EXPORT QgsColorScheme
48{
49#ifdef SIP_RUN
51 if ( dynamic_cast<QgsUserColorScheme *>( sipCpp ) != NULL )
52 sipType = sipType_QgsUserColorScheme;
53 else if ( dynamic_cast<QgsRecentColorScheme *>( sipCpp ) != NULL )
54 sipType = sipType_QgsRecentColorScheme;
55 else if ( dynamic_cast<QgsCustomColorScheme *>( sipCpp ) != NULL )
56 sipType = sipType_QgsCustomColorScheme;
57 else if ( dynamic_cast<QgsProjectColorScheme *>( sipCpp ) != NULL )
58 sipType = sipType_QgsProjectColorScheme;
59 else if ( dynamic_cast<QgsGplColorScheme *>( sipCpp ) != NULL )
60 sipType = sipType_QgsGplColorScheme;
61 else
62 sipType = sipType_QgsColorScheme;
64#endif
65
66 public:
67
77 Q_DECLARE_FLAGS( SchemeFlags, SchemeFlag )
78
79 QgsColorScheme() = default;
80
81 virtual ~QgsColorScheme() = default;
82
87 virtual QString schemeName() const = 0;
88
93 virtual SchemeFlags flags() const { return ShowInColorDialog; }
94
106 virtual QgsNamedColorList fetchColors( const QString &context = QString(), const QColor &baseColor = QColor() ) = 0;
107
113 virtual bool isEditable() const { return false; }
114
123 virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() );
124
129 virtual QgsColorScheme *clone() const = 0 SIP_FACTORY;
130};
131
133
134
139class CORE_EXPORT QgsGplColorScheme : public QgsColorScheme
140{
141 public:
142 QgsGplColorScheme() = default;
143
144 QgsNamedColorList fetchColors( const QString &context = QString(), const QColor &baseColor = QColor() ) override;
145
146 bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
147
148 protected:
153 virtual QString gplFilePath() = 0;
154};
155
162class CORE_EXPORT QgsUserColorScheme : public QgsGplColorScheme
163{
164 public:
169 QgsUserColorScheme( const QString &filename );
170
171 QString schemeName() const override;
172
173 QgsUserColorScheme *clone() const override SIP_FACTORY;
174
175 bool isEditable() const override { return mEditable; }
176
177 QgsColorScheme::SchemeFlags flags() const override;
178
183 void setName( const QString &name ) { mName = name; }
184
189 bool erase();
190
195 void setShowSchemeInMenu( bool show );
196
197#ifndef SIP_RUN
199#endif
200
201 protected:
202 QString mName;
203
204 QString mFilename;
205
206 bool mEditable = false;
207
208 QString gplFilePath() override;
209};
210
216class CORE_EXPORT QgsRecentColorScheme : public QgsColorScheme
217{
218 public:
220
221 QString schemeName() const override { return QObject::tr( "Recent colors" ); }
222
223 SchemeFlags flags() const override { return ShowInAllContexts; }
224
225 QgsNamedColorList fetchColors( const QString &context = QString(), const QColor &baseColor = QColor() ) override;
226
227 QgsRecentColorScheme *clone() const override SIP_FACTORY;
228
234 static void addRecentColor( const QColor &color );
235
240 static QColor lastUsedColor();
241
242#ifndef SIP_RUN
244#endif
245};
246
252class CORE_EXPORT QgsCustomColorScheme : public QgsColorScheme
253{
254 public:
256
257 QString schemeName() const override { return QObject::tr( "Standard colors" ); }
258
259 SchemeFlags flags() const override { return ShowInAllContexts; }
260
261 QgsNamedColorList fetchColors( const QString &context = QString(), const QColor &baseColor = QColor() ) override;
262
263 bool isEditable() const override { return true; }
264
265 bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
266
267 QgsCustomColorScheme *clone() const override SIP_FACTORY;
268
269#ifndef SIP_RUN
272#endif
273};
274
280class CORE_EXPORT QgsProjectColorScheme : public QgsColorScheme
281{
282 public:
284
285 QString schemeName() const override { return QObject::tr( "Project colors" ); }
286
287 SchemeFlags flags() const override { return ShowInAllContexts; }
288
289 QgsNamedColorList fetchColors( const QString &context = QString(), const QColor &baseColor = QColor() ) override;
290
291 bool isEditable() const override { return true; }
292
293 bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
294
295 QgsProjectColorScheme *clone() const override SIP_FACTORY;
296};
297
298#endif
SchemeFlag
Flags for controlling behavior of color scheme.
@ ShowInAllContexts
Show scheme in all contexts.
@ ShowInColorButtonMenu
Show scheme in color button drop-down menu.
@ ShowInColorDialog
Show scheme in color picker dialog.
virtual QgsColorScheme * clone() const =0
Clones a color scheme.
virtual QString schemeName() const =0
Gets the name for the color scheme.
virtual SchemeFlags flags() const
Returns the current flags for the 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.
QgsColorScheme()=default
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
static const QgsSettingsEntryVariant * settingsPaletteLabels
static const QgsSettingsEntryVariant * settingsPaletteColors
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.
QgsNamedColorList fetchColors(const QString &context=QString(), const QColor &baseColor=QColor()) override
Gets a list of colors from the scheme.
bool setColors(const QgsNamedColorList &colors, const QString &context=QString(), const QColor &baseColor=QColor()) override
Sets the colors for the scheme.
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
static const QgsSettingsEntryVariant * settingsRecentColors
QString schemeName() const override
Gets the name for the color scheme.
SchemeFlags flags() const override
Returns the current flags for the color scheme.
A string list settings entry.
A variant settings entry.
A color scheme which stores its colors in a gpl palette file within the "palettes" subfolder off the ...
QString schemeName() const override
Gets the name for the color scheme.
void setName(const QString &name)
Sets the name for the scheme.
QgsUserColorScheme(const QString &filename)
Constructs a new user color scheme, using a specified gpl palette file.
QString gplFilePath() override
Returns the file path for the associated gpl palette file.
static const QgsSettingsEntryStringList * settingsShowInMenuList
bool isEditable() const override
Returns whether the color scheme is editable.
QgsUserColorScheme * clone() const override
Clones a color scheme.
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:198
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:274
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_END
Definition qgis_sip.h:215
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)