QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
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 
176 
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 
209  static void addRecentColor( const QColor& color );
210 };
211 
217 class CORE_EXPORT QgsCustomColorScheme : public QgsColorScheme
218 {
219  public:
220 
222 
223  virtual ~QgsCustomColorScheme();
224 
225  virtual QString schemeName() const override { return QObject::tr( "Standard colors" ); }
226 
227  virtual SchemeFlags flags() const override { return ShowInAllContexts; }
228 
229  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
230  const QColor &baseColor = QColor() ) override;
231 
232  virtual bool isEditable() const override { return true; }
233 
234  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
235 
236  QgsCustomColorScheme* clone() const override;
237 };
238 
244 class CORE_EXPORT QgsProjectColorScheme : public QgsColorScheme
245 {
246  public:
247 
249 
250  virtual ~QgsProjectColorScheme();
251 
252  virtual QString schemeName() const override { return QObject::tr( "Project colors" ); }
253 
254  virtual SchemeFlags flags() const override { return ShowInAllContexts; }
255 
256  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
257  const QColor &baseColor = QColor() ) override;
258 
259  virtual bool isEditable() const override { return true; }
260 
261  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
262 
263  QgsProjectColorScheme* clone() const override;
264 };
265 
266 #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.
QString tr(const char *sourceText, const char *disambiguation, int n)
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.