QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
28 typedef QList< QPair< QColor, QString > > QgsNamedColorList;
29 
39 class CORE_EXPORT QgsColorScheme
40 {
41  public:
42 
46  {
47  ShowInColorDialog = 0x01, /*< show scheme in color picker dialog */
48  ShowInColorButtonMenu = 0x02, /*< show scheme in color button drop down menu */
49  ShowInAllContexts = ShowInColorDialog | ShowInColorButtonMenu /*< show scheme in all contexts */
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() );
118 
119  virtual bool setColors( const QgsNamedColorList colors, const QString context = QString(), const QColor baseColor = QColor() );
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;
148 
149  virtual QgsColorScheme* clone() const;
150 
151  virtual bool isEditable() const { return true; }
152 
156  void setName( const QString name ) { mName = name; }
157 
161  bool erase();
162 
163  protected:
164 
165  QString mName;
166 
167  QString mFilename;
168 
169  virtual QString gplFilePath();
170 
171 };
172 
178 class CORE_EXPORT QgsRecentColorScheme : public QgsColorScheme
179 {
180  public:
181 
183 
184  virtual ~QgsRecentColorScheme();
185 
186  virtual QString schemeName() const { return QT_TR_NOOP( "Recent colors" ); }
187 
188  virtual SchemeFlags flags() const { return ShowInAllContexts; }
189 
190  virtual QgsNamedColorList fetchColors( const QString context = QString(),
191  const QColor baseColor = QColor() );
192 
193  QgsColorScheme* clone() const;
194 };
195 
201 class CORE_EXPORT QgsCustomColorScheme : public QgsColorScheme
202 {
203  public:
204 
206 
207  virtual ~QgsCustomColorScheme();
208 
209  virtual QString schemeName() const { return QT_TR_NOOP( "Standard colors" ); }
210 
211  virtual SchemeFlags flags() const { return ShowInAllContexts; }
212 
213  virtual QgsNamedColorList fetchColors( const QString context = QString(),
214  const QColor baseColor = QColor() );
215 
216  virtual bool isEditable() const { return true; }
217 
218  virtual bool setColors( const QgsNamedColorList colors, const QString context = QString(), const QColor baseColor = QColor() );
219 
220  QgsColorScheme* clone() const;
221 };
222 
228 class CORE_EXPORT QgsProjectColorScheme : public QgsColorScheme
229 {
230  public:
231 
233 
234  virtual ~QgsProjectColorScheme();
235 
236  virtual QString schemeName() const { return QT_TR_NOOP( "Project colors" ); }
237 
238  virtual SchemeFlags flags() const { return ShowInAllContexts; }
239 
240  virtual QgsNamedColorList fetchColors( const QString context = QString(),
241  const QColor baseColor = QColor() );
242 
243  virtual bool isEditable() const { return true; }
244 
245  virtual bool setColors( const QgsNamedColorList colors, const QString context = QString(), const QColor baseColor = QColor() );
246 
247  QgsColorScheme* clone() const;
248 };
249 
250 #endif
A color scheme which contains custom colors set through QGIS app options dialog.
Definition: qgscolorscheme.h:201
A color scheme which stores its colors in a gpl palette file within the "palettes" subfolder off the ...
Definition: qgscolorscheme.h:136
virtual QString schemeName() const
Gets the name for the color scheme.
Definition: qgscolorscheme.h:186
virtual bool isEditable() const
Returns whether the color scheme is editable.
Definition: qgscolorscheme.h:216
A color scheme which contains project specific colors set through project properties dialog...
Definition: qgscolorscheme.h:228
virtual QgsColorScheme * clone() const =0
Clones a color scheme.
Abstract base class for color schemes.
Definition: qgscolorscheme.h:39
void setName(const QString name)
Sets the name for the scheme.
Definition: qgscolorscheme.h:156
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
Definition: qgscolorscheme.h:28
virtual SchemeFlags flags() const
Returns the current flags for the color scheme.
Definition: qgscolorscheme.h:238
Definition: qgscolorscheme.h:49
virtual bool isEditable() const
Returns whether the color scheme is editable.
Definition: qgscolorscheme.h:243
virtual bool setColors(const QgsNamedColorList colors, const QString context=QString(), const QColor baseColor=QColor())
Sets the colors for the scheme.
Definition: qgscolorscheme.cpp:37
virtual bool isEditable() const
Returns whether the color scheme is editable.
Definition: qgscolorscheme.h:84
virtual QString gplFilePath()=0
Returns the file path for the associated gpl palette file.
QString mFilename
Definition: qgscolorscheme.h:167
virtual QString schemeName() const
Gets the name for the color scheme.
Definition: qgscolorscheme.h:209
virtual bool isEditable() const
Returns whether the color scheme is editable.
Definition: qgscolorscheme.h:151
A color scheme which contains the most recently used colors.
Definition: qgscolorscheme.h:178
virtual QString schemeName() const
Gets the name for the color scheme.
Definition: qgscolorscheme.h:236
virtual SchemeFlags flags() const
Returns the current flags for the color scheme.
Definition: qgscolorscheme.h:211
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.
virtual SchemeFlags flags() const
Returns the current flags for the color scheme.
Definition: qgscolorscheme.h:188
SchemeFlag
Flags for controlling behaviour of color scheme.
Definition: qgscolorscheme.h:45
QString mName
Definition: qgscolorscheme.h:165
A color scheme which stores its colors in a gpl palette file.
Definition: qgscolorscheme.h:108