QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
26 class CORE_EXPORT QgsColorBrewerPalette
27 {
28  public:
29  static QList<QColor> listSchemeColors( const QString& schemeName, int colors )
30  {
32  QString palette( brewerString );
33  QStringList list = palette.split( QChar( '\n' ) );
34  Q_FOREACH ( const QString& entry, list )
35  {
36  QStringList items = entry.split( QChar( '-' ) );
37  if ( items.count() != 3 || items[0] != schemeName || items[1].toInt() != colors )
38  continue;
39  QStringList colors = items[2].split( QChar( ' ' ) );
40  Q_FOREACH ( const QString& clr, colors )
41  {
43  }
44  }
45  return pal;
46  }
47 
49  {
50  QStringList schemes;
51 
52  QString palette( brewerString );
53  QStringList list = palette.split( QChar( '\n' ) );
54  Q_FOREACH ( const QString& entry, list )
55  {
56  QStringList items = entry.split( QChar( '-' ) );
57  if ( items.count() != 3 )
58  continue;
59  if ( !schemes.contains( items[0] ) )
60  schemes << items[0];
61  }
62  return schemes;
63  }
64 
65  static QList<int> listSchemeVariants( const QString& schemeName )
66  {
67  QList<int> variants;
68 
69  QString palette( brewerString );
70  QStringList list = palette.split( QChar( '\n' ) );
71  Q_FOREACH ( const QString& entry, list )
72  {
73  QStringList items = entry.split( QChar( '-' ) );
74  if ( items.count() != 3 || items[0] != schemeName )
75  continue;
76  variants << items[1].toInt();
77  }
78 
79  return variants;
80  }
81 
82  // extracted ColorBrewer data
83  static const char *brewerString;
84 };
85 
86 #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...