QGIS API Documentation  2.99.0-Master (0a63d1f)
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 
58 
59  virtual ~QgsColorScheme() = default;
60 
64  virtual QString schemeName() const = 0;
65 
69  virtual SchemeFlags flags() const { return ShowInColorDialog; }
70 
81  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
82  const QColor &baseColor = QColor() ) = 0;
83 
88  virtual bool isEditable() const { return false; }
89 
97  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() );
98 
102  virtual QgsColorScheme* clone() const = 0;
103 };
104 
105 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsColorScheme::SchemeFlags )
106 
107 
112 class CORE_EXPORT QgsGplColorScheme : public QgsColorScheme
113 {
114  public:
115 
117 
118  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
119  const QColor &baseColor = QColor() ) override;
120 
121  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
122 
123  protected:
124 
128  virtual QString gplFilePath() = 0;
129 
130 };
131 
138 class CORE_EXPORT QgsUserColorScheme : public QgsGplColorScheme
139 {
140  public:
141 
145  QgsUserColorScheme( const QString &filename );
146 
147  virtual QString schemeName() const override;
148 
149  virtual QgsUserColorScheme* clone() const override;
150 
151  virtual bool isEditable() const override { return true; }
152 
153  virtual QgsColorScheme::SchemeFlags flags() const override;
154 
158  void setName( const QString &name ) { mName = name; }
159 
163  bool erase();
164 
169  void setShowSchemeInMenu( bool show );
170 
171  protected:
172 
173  QString mName;
174 
175  QString mFilename;
176 
177  virtual QString gplFilePath() override;
178 
179 };
180 
186 class CORE_EXPORT QgsRecentColorScheme : public QgsColorScheme
187 {
188  public:
189 
191 
192  virtual QString schemeName() const override { return QObject::tr( "Recent colors" ); }
193 
194  virtual SchemeFlags flags() const override { return ShowInAllContexts; }
195 
196  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
197  const QColor &baseColor = QColor() ) override;
198 
199  QgsRecentColorScheme* clone() const override;
200 
206  static void addRecentColor( const QColor& color );
207 
212  static QColor lastUsedColor();
213 };
214 
220 class CORE_EXPORT QgsCustomColorScheme : public QgsColorScheme
221 {
222  public:
223 
225 
226  virtual QString schemeName() const override { return QObject::tr( "Standard colors" ); }
227 
228  virtual SchemeFlags flags() const override { return ShowInAllContexts; }
229 
230  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
231  const QColor &baseColor = QColor() ) override;
232 
233  virtual bool isEditable() const override { return true; }
234 
235  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
236 
237  QgsCustomColorScheme* clone() const override;
238 };
239 
245 class CORE_EXPORT QgsProjectColorScheme : public QgsColorScheme
246 {
247  public:
248 
250 
251  virtual QString schemeName() const override { return QObject::tr( "Project colors" ); }
252 
253  virtual SchemeFlags flags() const override { return ShowInAllContexts; }
254 
255  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
256  const QColor &baseColor = QColor() ) override;
257 
258  virtual bool isEditable() const override { return true; }
259 
260  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
261 
262  QgsProjectColorScheme* clone() const override;
263 };
264 
265 #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.