QGIS API Documentation  2.15.0-Master (02a0ebe)
qgscolorbrewerpalette.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscolorbrewerpalette.h
3  ---------------------
4  begin : November 2009
5  copyright : (C) 2009 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSCOLORBREWERPALETTE_H
16 #define QGSCOLORBREWERPALETTE_H
17 
18 #include <QList>
19 #include <QColor>
20 
21 #include "qgssymbollayerv2utils.h"
22 
23 class CORE_EXPORT QgsColorBrewerPalette
24 {
25  public:
26  static QList<QColor> listSchemeColors( const QString& schemeName, int colors )
27  {
29  QString palette( brewerString );
30  QStringList list = palette.split( QChar( '\n' ) );
31  Q_FOREACH ( const QString& entry, list )
32  {
33  QStringList items = entry.split( QChar( '-' ) );
34  if ( items.count() != 3 || items[0] != schemeName || items[1].toInt() != colors )
35  continue;
36  QStringList colors = items[2].split( QChar( ' ' ) );
37  Q_FOREACH ( const QString& clr, colors )
38  {
40  }
41  }
42  return pal;
43  }
44 
46  {
47  QStringList schemes;
48 
49  QString palette( brewerString );
50  QStringList list = palette.split( QChar( '\n' ) );
51  Q_FOREACH ( const QString& entry, list )
52  {
53  QStringList items = entry.split( QChar( '-' ) );
54  if ( items.count() != 3 )
55  continue;
56  if ( !schemes.contains( items[0] ) )
57  schemes << items[0];
58  }
59  return schemes;
60  }
61 
62  static QList<int> listSchemeVariants( const QString& schemeName )
63  {
64  QList<int> variants;
65 
66  QString palette( brewerString );
67  QStringList list = palette.split( QChar( '\n' ) );
68  Q_FOREACH ( const QString& entry, list )
69  {
70  QStringList items = entry.split( QChar( '-' ) );
71  if ( items.count() != 3 || items[0] != schemeName )
72  continue;
73  variants << items[1].toInt();
74  }
75 
76  return variants;
77  }
78 
79  // extracted ColorBrewer data
80  static const char *brewerString;
81 };
82 
83 #endif // QGSCOLORBREWERPALETTE_H
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
bool contains(const QString &str, Qt::CaseSensitivity cs) const
static QList< QColor > listSchemeColors(const QString &schemeName, int colors)
static QList< int > listSchemeVariants(const QString &schemeName)
int count(const T &value) const
static QStringList listSchemes()
static const char * brewerString
QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries)
static QColor parseColor(const QString &colorStr, bool strictEval=false)
Attempts to parse a string as a color using a variety of common formats, including hex codes...