QGIS API Documentation  2.99.0-Master (6a61179)
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 
30 typedef QList< QPair< QColor, QString > > QgsNamedColorList;
31 
41 class CORE_EXPORT QgsColorScheme
42 {
43  public:
44 
48  {
49  ShowInColorDialog = 0x01,
50  ShowInColorButtonMenu = 0x02,
51  ShowInAllContexts = ShowInColorDialog | ShowInColorButtonMenu
52  };
53  Q_DECLARE_FLAGS( SchemeFlags, SchemeFlag )
54 
56 
57  virtual ~QgsColorScheme();
58 
62  virtual QString schemeName() const = 0;
63 
67  virtual SchemeFlags flags() const { return ShowInColorDialog; }
68 
79  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
80  const QColor &baseColor = QColor() ) = 0;
81 
86  virtual bool isEditable() const { return false; }
87 
95  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() );
96 
100  virtual QgsColorScheme* clone() const = 0;
101 };
102 
103 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsColorScheme::SchemeFlags )
104 
105 
110 class CORE_EXPORT QgsGplColorScheme : public QgsColorScheme
111 {
112  public:
113 
115 
116  virtual ~QgsGplColorScheme();
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 ~QgsUserColorScheme();
148 
149  virtual QString schemeName() const override;
150 
151  virtual QgsUserColorScheme* clone() const override;
152 
153  virtual bool isEditable() const override { return true; }
154 
155  virtual QgsColorScheme::SchemeFlags flags() const override;
156 
160  void setName( const QString &name ) { mName = name; }
161 
165  bool erase();
166 
171  void setShowSchemeInMenu( bool show );
172 
173  protected:
174 
175  QString mName;
176 
177  QString mFilename;
178 
179  virtual QString gplFilePath() override;
180 
181 };
182 
188 class CORE_EXPORT QgsRecentColorScheme : public QgsColorScheme
189 {
190  public:
191 
193 
194  virtual ~QgsRecentColorScheme();
195 
196  virtual QString schemeName() const override { return QObject::tr( "Recent colors" ); }
197 
198  virtual SchemeFlags flags() const override { return ShowInAllContexts; }
199 
200  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
201  const QColor &baseColor = QColor() ) override;
202 
203  QgsRecentColorScheme* clone() const override;
204 
210  static void addRecentColor( const QColor& color );
211 
216  static QColor lastUsedColor();
217 };
218 
224 class CORE_EXPORT QgsCustomColorScheme : public QgsColorScheme
225 {
226  public:
227 
229 
230  virtual ~QgsCustomColorScheme();
231 
232  virtual QString schemeName() const override { return QObject::tr( "Standard colors" ); }
233 
234  virtual SchemeFlags flags() const override { return ShowInAllContexts; }
235 
236  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
237  const QColor &baseColor = QColor() ) override;
238 
239  virtual bool isEditable() const override { return true; }
240 
241  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
242 
243  QgsCustomColorScheme* clone() const override;
244 };
245 
251 class CORE_EXPORT QgsProjectColorScheme : public QgsColorScheme
252 {
253  public:
254 
256 
257  virtual ~QgsProjectColorScheme();
258 
259  virtual QString schemeName() const override { return QObject::tr( "Project colors" ); }
260 
261  virtual SchemeFlags flags() const override { return ShowInAllContexts; }
262 
263  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
264  const QColor &baseColor = QColor() ) override;
265 
266  virtual bool isEditable() const override { return true; }
267 
268  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
269 
270  QgsProjectColorScheme* clone() const override;
271 };
272 
273 #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 behaviour 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.