QGIS API Documentation 4.3.0-Master (375ff838570)
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
31class QgsProject;
32
37typedef QList< QPair< QColor, QString > > QgsNamedColorList;
38
48class CORE_EXPORT QgsColorScheme
49{
50#ifdef SIP_RUN
52 if ( dynamic_cast<QgsUserColorScheme *>( sipCpp ) != NULL )
53 sipType = sipType_QgsUserColorScheme;
54 else if ( dynamic_cast<QgsRecentColorScheme *>( sipCpp ) != NULL )
55 sipType = sipType_QgsRecentColorScheme;
56 else if ( dynamic_cast<QgsCustomColorScheme *>( sipCpp ) != NULL )
57 sipType = sipType_QgsCustomColorScheme;
58 else if ( dynamic_cast<QgsProjectColorScheme *>( sipCpp ) != NULL )
59 sipType = sipType_QgsProjectColorScheme;
60 else if ( dynamic_cast<QgsGplColorScheme *>( sipCpp ) != NULL )
61 sipType = sipType_QgsGplColorScheme;
62 else
63 sipType = sipType_QgsColorScheme;
65#endif
66
67 public:
68
78 Q_DECLARE_FLAGS( SchemeFlags, SchemeFlag )
79
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(), const QColor &baseColor = QColor() ) = 0;
108
114 virtual bool isEditable() const { return false; }
115
124 virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() );
125
130 virtual QgsColorScheme *clone() const = 0 SIP_FACTORY;
131};
132
134
135
140class CORE_EXPORT QgsGplColorScheme : public QgsColorScheme
141{
142 public:
143 QgsGplColorScheme() = default;
144
145 QgsNamedColorList fetchColors( const QString &context = QString(), const QColor &baseColor = QColor() ) override;
146
147 bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
148
149 protected:
154 virtual QString gplFilePath() = 0;
155};
156
163class CORE_EXPORT QgsUserColorScheme : public QgsGplColorScheme
164{
165 public:
170 QgsUserColorScheme( const QString &filename );
171
172 QString schemeName() const override;
173
174 QgsUserColorScheme *clone() const override SIP_FACTORY;
175
176 bool isEditable() const override { return mEditable; }
177
178 QgsColorScheme::SchemeFlags flags() const override;
179
184 void setName( const QString &name ) { mName = name; }
185
190 bool erase();
191
196 void setShowSchemeInMenu( bool show );
197
198#ifndef SIP_RUN
200#endif
201
202 protected:
203 QString mName;
204
205 QString mFilename;
206
207 bool mEditable = false;
208
209 QString gplFilePath() override;
210};
211
217class CORE_EXPORT QgsRecentColorScheme : public QgsColorScheme
218{
219 public:
221
222 QString schemeName() const override { return QObject::tr( "Recent colors" ); }
223
224 SchemeFlags flags() const override { return ShowInAllContexts; }
225
226 QgsNamedColorList fetchColors( const QString &context = QString(), const QColor &baseColor = QColor() ) override;
227
228 QgsRecentColorScheme *clone() const override SIP_FACTORY;
229
235 static void addRecentColor( const QColor &color );
236
241 static QColor lastUsedColor();
242
243#ifndef SIP_RUN
245#endif
246};
247
253class CORE_EXPORT QgsCustomColorScheme : public QgsColorScheme
254{
255 public:
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(), const QColor &baseColor = QColor() ) override;
263
264 bool isEditable() const override { return true; }
265
266 bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
267
268 QgsCustomColorScheme *clone() const override SIP_FACTORY;
269
270#ifndef SIP_RUN
273#endif
274};
275
281class CORE_EXPORT QgsProjectColorScheme : public QgsColorScheme
282{
283 public:
289 Q_DECL_DEPRECATED QgsProjectColorScheme() SIP_DEPRECATED;
290
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(), const QColor &baseColor = QColor() ) override;
303
304 bool isEditable() const override { return true; }
305
306 bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
307
308 QgsProjectColorScheme *clone() const override SIP_FACTORY;
309
310 private:
311 QgsProject *mProject = nullptr;
312};
313
314#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.
bool isEditable() const override
Returns whether the color scheme is editable.
QString schemeName() const override
Gets the name for the color scheme.
Q_DECL_DEPRECATED QgsProjectColorScheme()
Constructor for a project color scheme bound to the current QgsProject instance().
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:114
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:203
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:277
#define SIP_SKIP
Definition qgis_sip.h:138
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_END
Definition qgis_sip.h:220
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTimeZoneComboBox::StandardItems)