QGIS API Documentation  2.99.0-Master (a18066b)
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 
32 typedef QList< QPair< QColor, QString > > QgsNamedColorList;
33 
43 class CORE_EXPORT QgsColorScheme
44 {
45  public:
46 
50  {
51  ShowInColorDialog = 0x01,
52  ShowInColorButtonMenu = 0x02,
53  ShowInAllContexts = ShowInColorDialog | ShowInColorButtonMenu
54  };
55  Q_DECLARE_FLAGS( SchemeFlags, SchemeFlag )
56 
57 
60  QgsColorScheme() = default;
61 
62  virtual ~QgsColorScheme() = default;
63 
67  virtual QString schemeName() const = 0;
68 
72  virtual SchemeFlags flags() const { return ShowInColorDialog; }
73 
84  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
85  const QColor &baseColor = QColor() ) = 0;
86 
91  virtual bool isEditable() const { return false; }
92 
100  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() );
101 
105  virtual QgsColorScheme* clone() const = 0;
106 };
107 
108 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsColorScheme::SchemeFlags )
109 
110 
115 class CORE_EXPORT QgsGplColorScheme : public QgsColorScheme
116 {
117  public:
118 
120 
121  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
122  const QColor &baseColor = QColor() ) override;
123 
124  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
125 
126  protected:
127 
131  virtual QString gplFilePath() = 0;
132 
133 };
134 
141 class CORE_EXPORT QgsUserColorScheme : public QgsGplColorScheme
142 {
143  public:
144 
148  QgsUserColorScheme( const QString &filename );
149 
150  virtual QString schemeName() const override;
151 
152  virtual QgsUserColorScheme* clone() const override;
153 
154  virtual bool isEditable() const override { return true; }
155 
156  virtual QgsColorScheme::SchemeFlags flags() const override;
157 
161  void setName( const QString &name ) { mName = name; }
162 
166  bool erase();
167 
172  void setShowSchemeInMenu( bool show );
173 
174  protected:
175 
176  QString mName;
177 
178  QString mFilename;
179 
180  virtual QString gplFilePath() override;
181 
182 };
183 
189 class CORE_EXPORT QgsRecentColorScheme : public QgsColorScheme
190 {
191  public:
192 
194 
195  virtual QString schemeName() const override { return QObject::tr( "Recent colors" ); }
196 
197  virtual SchemeFlags flags() const override { return ShowInAllContexts; }
198 
199  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
200  const QColor &baseColor = QColor() ) override;
201 
202  QgsRecentColorScheme* clone() const override;
203 
209  static void addRecentColor( const QColor& color );
210 
215  static QColor lastUsedColor();
216 };
217 
223 class CORE_EXPORT QgsCustomColorScheme : public QgsColorScheme
224 {
225  public:
226 
228 
229  virtual QString schemeName() const override { return QObject::tr( "Standard colors" ); }
230 
231  virtual SchemeFlags flags() const override { return ShowInAllContexts; }
232 
233  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
234  const QColor &baseColor = QColor() ) override;
235 
236  virtual bool isEditable() const override { return true; }
237 
238  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
239 
240  QgsCustomColorScheme* clone() const override;
241 };
242 
248 class CORE_EXPORT QgsProjectColorScheme : public QgsColorScheme
249 {
250  public:
251 
253 
254  virtual QString schemeName() const override { return QObject::tr( "Project colors" ); }
255 
256  virtual SchemeFlags flags() const override { return ShowInAllContexts; }
257 
258  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
259  const QColor &baseColor = QColor() ) override;
260 
261  virtual bool isEditable() const override { return true; }
262 
263  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
264 
265  QgsProjectColorScheme* clone() const override;
266 };
267 
268 #endif
A color scheme which contains custom colors set through QGIS app options dialog.
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.
virtual SchemeFlags flags() const override
Returns the current flags for the color scheme.
A color scheme which contains project specific colors set through project properties dialog...
virtual QgsColorScheme * clone() const =0
Clones a color scheme.
virtual SchemeFlags flags() const override
Returns the current flags for the color scheme.
virtual SchemeFlags flags() const
Returns the current flags for the color scheme.
Abstract base class for color schemes.
virtual bool isEditable() const override
Returns whether the color scheme is editable.
Show scheme in all contexts.
virtual 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.
virtual QString gplFilePath()=0
Returns the file path for the associated gpl palette file.
virtual QString schemeName() const override
Gets the name for the color scheme.
A color scheme which contains the most recently used colors.
virtual SchemeFlags flags() const override
Returns the current flags for the color scheme.
virtual bool isEditable() const
Returns whether the color scheme is editable.
virtual QString schemeName() const =0
Gets the name for the color scheme.
virtual QgsNamedColorList fetchColors(const QString &context=QString(), const QColor &baseColor=QColor())=0
Gets a list of colors from the scheme.
SchemeFlag
Flags for controlling behavior of color scheme.
virtual QString schemeName() const override
Gets the name for the color scheme.
virtual QString schemeName() const override
Gets the name for the color scheme.
virtual bool setColors(const QgsNamedColorList &colors, const QString &context=QString(), const QColor &baseColor=QColor())
Sets the colors for the scheme.
A color scheme which stores its colors in a gpl palette file.
virtual bool isEditable() const override
Returns whether the color scheme is editable.