QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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
33typedef QList< QPair< QColor, QString > > QgsNamedColorList;
34
44class CORE_EXPORT QgsColorScheme
45{
46#ifdef SIP_RUN
48 if ( dynamic_cast<QgsUserColorScheme *>( sipCpp ) != NULL )
49 sipType = sipType_QgsUserColorScheme;
50 else if ( dynamic_cast<QgsRecentColorScheme *>( sipCpp ) != NULL )
51 sipType = sipType_QgsRecentColorScheme;
52 else if ( dynamic_cast<QgsCustomColorScheme *>( sipCpp ) != NULL )
53 sipType = sipType_QgsCustomColorScheme;
54 else if ( dynamic_cast<QgsProjectColorScheme *>( sipCpp ) != NULL )
55 sipType = sipType_QgsProjectColorScheme;
56 else if ( dynamic_cast<QgsGplColorScheme *>( sipCpp ) != NULL )
57 sipType = sipType_QgsGplColorScheme;
58 else
59 sipType = sipType_QgsColorScheme;
61#endif
62
63 public:
64
74 Q_DECLARE_FLAGS( SchemeFlags, SchemeFlag )
75
76 QgsColorScheme() = default;
77
78 virtual ~QgsColorScheme() = default;
79
84 virtual QString schemeName() const = 0;
85
90 virtual SchemeFlags flags() const { return ShowInColorDialog; }
91
103 virtual QgsNamedColorList fetchColors( const QString &context = QString(), const QColor &baseColor = QColor() ) = 0;
104
110 virtual bool isEditable() const { return false; }
111
120 virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() );
121
126 virtual QgsColorScheme *clone() const = 0 SIP_FACTORY;
127};
128
130
131
136class CORE_EXPORT QgsGplColorScheme : public QgsColorScheme
137{
138 public:
139 QgsGplColorScheme() = default;
140
141 QgsNamedColorList fetchColors( const QString &context = QString(), const QColor &baseColor = QColor() ) override;
142
143 bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
144
145 protected:
150 virtual QString gplFilePath() = 0;
151};
152
159class CORE_EXPORT QgsUserColorScheme : public QgsGplColorScheme
160{
161 public:
166 QgsUserColorScheme( const QString &filename );
167
168 QString schemeName() const override;
169
170 QgsUserColorScheme *clone() const override SIP_FACTORY;
171
172 bool isEditable() const override { return mEditable; }
173
174 QgsColorScheme::SchemeFlags flags() const override;
175
180 void setName( const QString &name ) { mName = name; }
181
186 bool erase();
187
192 void setShowSchemeInMenu( bool show );
193
194 protected:
195 QString mName;
196
197 QString mFilename;
198
199 bool mEditable = false;
200
201 QString gplFilePath() override;
202};
203
209class CORE_EXPORT QgsRecentColorScheme : public QgsColorScheme
210{
211 public:
213
214 QString schemeName() const override { return QObject::tr( "Recent colors" ); }
215
216 SchemeFlags flags() const override { return ShowInAllContexts; }
217
218 QgsNamedColorList fetchColors( const QString &context = QString(), const QColor &baseColor = QColor() ) override;
219
220 QgsRecentColorScheme *clone() const override SIP_FACTORY;
221
227 static void addRecentColor( const QColor &color );
228
233 static QColor lastUsedColor();
234};
235
241class CORE_EXPORT QgsCustomColorScheme : public QgsColorScheme
242{
243 public:
245
246 QString schemeName() const override { return QObject::tr( "Standard colors" ); }
247
248 SchemeFlags flags() const override { return ShowInAllContexts; }
249
250 QgsNamedColorList fetchColors( const QString &context = QString(), const QColor &baseColor = QColor() ) override;
251
252 bool isEditable() const override { return true; }
253
254 bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
255
256 QgsCustomColorScheme *clone() const override SIP_FACTORY;
257};
258
264class CORE_EXPORT QgsProjectColorScheme : public QgsColorScheme
265{
266 public:
268
269 QString schemeName() const override { return QObject::tr( "Project colors" ); }
270
271 SchemeFlags flags() const override { return ShowInAllContexts; }
272
273 QgsNamedColorList fetchColors( const QString &context = QString(), const QColor &baseColor = QColor() ) override;
274
275 bool isEditable() const override { return true; }
276
277 bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
278
279 QgsProjectColorScheme *clone() const override SIP_FACTORY;
280};
281
282#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
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
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 ...
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.
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_FACTORY
Definition qgis_sip.h:83
#define SIP_END
Definition qgis_sip.h:215
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)