QGIS API Documentation  2.14.0-Essen
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 
40 class CORE_EXPORT QgsColorScheme
41 {
42  public:
43 
47  {
48  ShowInColorDialog = 0x01,
49  ShowInColorButtonMenu = 0x02,
50  ShowInAllContexts = ShowInColorDialog | ShowInColorButtonMenu
51  };
52  Q_DECLARE_FLAGS( SchemeFlags, SchemeFlag )
53 
55 
56  virtual ~QgsColorScheme();
57 
61  virtual QString schemeName() const = 0;
62 
66  virtual SchemeFlags flags() const { return ShowInColorDialog; }
67 
78  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
79  const QColor &baseColor = QColor() ) = 0;
80 
85  virtual bool isEditable() const { return false; }
86 
94  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() );
95 
99  virtual QgsColorScheme* clone() const = 0;
100 };
101 
102 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsColorScheme::SchemeFlags )
103 
104 
109 class CORE_EXPORT QgsGplColorScheme : public QgsColorScheme
110 {
111  public:
112 
114 
115  virtual ~QgsGplColorScheme();
116 
117  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
118  const QColor &baseColor = QColor() ) override;
119 
120  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
121 
122  protected:
123 
127  virtual QString gplFilePath() = 0;
128 
129 };
130 
137 class CORE_EXPORT QgsUserColorScheme : public QgsGplColorScheme
138 {
139  public:
140 
144  QgsUserColorScheme( const QString &filename );
145 
146  virtual ~QgsUserColorScheme();
147 
148  virtual QString schemeName() const override;
149 
150  virtual QgsUserColorScheme* clone() const override;
151 
152  virtual bool isEditable() const override { return true; }
153 
157  void setName( const QString &name ) { mName = name; }
158 
162  bool erase();
163 
164  protected:
165 
167 
169 
170  virtual QString gplFilePath() override;
171 
172 };
173 
179 class CORE_EXPORT QgsRecentColorScheme : public QgsColorScheme
180 {
181  public:
182 
184 
185  virtual ~QgsRecentColorScheme();
186 
187  virtual QString schemeName() const override { return QObject::tr( "Recent colors" ); }
188 
189  virtual SchemeFlags flags() const override { return ShowInAllContexts; }
190 
191  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
192  const QColor &baseColor = QColor() ) override;
193 
194  QgsRecentColorScheme* clone() const override;
195 
200  static void addRecentColor( const QColor& color );
201 };
202 
208 class CORE_EXPORT QgsCustomColorScheme : public QgsColorScheme
209 {
210  public:
211 
213 
214  virtual ~QgsCustomColorScheme();
215 
216  virtual QString schemeName() const override { return QObject::tr( "Standard colors" ); }
217 
218  virtual SchemeFlags flags() const override { return ShowInAllContexts; }
219 
220  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
221  const QColor &baseColor = QColor() ) override;
222 
223  virtual bool isEditable() const override { return true; }
224 
225  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
226 
227  QgsCustomColorScheme* clone() const override;
228 };
229 
235 class CORE_EXPORT QgsProjectColorScheme : public QgsColorScheme
236 {
237  public:
238 
240 
241  virtual ~QgsProjectColorScheme();
242 
243  virtual QString schemeName() const override { return QObject::tr( "Project colors" ); }
244 
245  virtual SchemeFlags flags() const override { return ShowInAllContexts; }
246 
247  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
248  const QColor &baseColor = QColor() ) override;
249 
250  virtual bool isEditable() const override { return true; }
251 
252  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
253 
254  QgsProjectColorScheme* clone() const override;
255 };
256 
257 #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.
Abstract base class for color schemes.
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
virtual bool isEditable() const override
Returns whether the color scheme is editable.
QString tr(const char *sourceText, const char *disambiguation, int n)
virtual bool isEditable() const
Returns whether the color scheme is editable.
virtual bool isEditable() const override
Returns whether the color scheme is editable.
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 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.