QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
29 
39 class CORE_EXPORT QgsColorScheme
40 {
41  public:
42 
46  {
47  ShowInColorDialog = 0x01,
48  ShowInColorButtonMenu = 0x02,
49  ShowInAllContexts = ShowInColorDialog | ShowInColorButtonMenu
50  };
51  Q_DECLARE_FLAGS( SchemeFlags, SchemeFlag )
52 
54 
55  virtual ~QgsColorScheme();
56 
60  virtual QString schemeName() const = 0;
61 
65  virtual SchemeFlags flags() const { return ShowInColorDialog; }
66 
77  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
78  const QColor &baseColor = QColor() ) = 0;
79 
84  virtual bool isEditable() const { return false; }
85 
93  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() );
94 
98  virtual QgsColorScheme* clone() const = 0;
99 };
100 
101 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsColorScheme::SchemeFlags )
102 
103 
108 class CORE_EXPORT QgsGplColorScheme : public QgsColorScheme
109 {
110  public:
111 
113 
114  virtual ~QgsGplColorScheme();
115 
116  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
117  const QColor &baseColor = QColor() ) override;
118 
119  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
120 
121  protected:
122 
126  virtual QString gplFilePath() = 0;
127 
128 };
129 
136 class CORE_EXPORT QgsUserColorScheme : public QgsGplColorScheme
137 {
138  public:
139 
143  QgsUserColorScheme( const QString &filename );
144 
145  virtual ~QgsUserColorScheme();
146 
147  virtual QString schemeName() const override;
148 
149  virtual QgsColorScheme* clone() const override;
150 
151  virtual bool isEditable() const override { return true; }
152 
156  void setName( const QString &name ) { mName = name; }
157 
161  bool erase();
162 
163  protected:
164 
166 
168 
169  virtual QString gplFilePath() override;
170 
171 };
172 
178 class CORE_EXPORT QgsRecentColorScheme : public QgsColorScheme
179 {
180  public:
181 
183 
184  virtual ~QgsRecentColorScheme();
185 
186  virtual QString schemeName() const override { return QObject::tr( "Recent colors" ); }
187 
188  virtual SchemeFlags flags() const override { return ShowInAllContexts; }
189 
190  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
191  const QColor &baseColor = QColor() ) override;
192 
193  QgsColorScheme* clone() const override;
194 };
195 
201 class CORE_EXPORT QgsCustomColorScheme : public QgsColorScheme
202 {
203  public:
204 
206 
207  virtual ~QgsCustomColorScheme();
208 
209  virtual QString schemeName() const override { return QObject::tr( "Standard colors" ); }
210 
211  virtual SchemeFlags flags() const override { return ShowInAllContexts; }
212 
213  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
214  const QColor &baseColor = QColor() ) override;
215 
216  virtual bool isEditable() const override { return true; }
217 
218  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
219 
220  QgsColorScheme* clone() const override;
221 };
222 
228 class CORE_EXPORT QgsProjectColorScheme : public QgsColorScheme
229 {
230  public:
231 
233 
234  virtual ~QgsProjectColorScheme();
235 
236  virtual QString schemeName() const override { return QObject::tr( "Project colors" ); }
237 
238  virtual SchemeFlags flags() const override { return ShowInAllContexts; }
239 
240  virtual QgsNamedColorList fetchColors( const QString &context = QString(),
241  const QColor &baseColor = QColor() ) override;
242 
243  virtual bool isEditable() const override { return true; }
244 
245  virtual bool setColors( const QgsNamedColorList &colors, const QString &context = QString(), const QColor &baseColor = QColor() ) override;
246 
247  QgsColorScheme* clone() const override;
248 };
249 
250 #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 th...
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.