QGIS API Documentation  2.6.0-Brighton
 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 
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