QGIS API Documentation  3.0.2-Girona (307d082)
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 "qgis_core.h"
19 #include <QList>
20 #include <QColor>
21 
22 #include "qgssymbollayerutils.h"
23 
28 class CORE_EXPORT QgsColorBrewerPalette
29 {
30  public:
31  static QList<QColor> listSchemeColors( const QString &schemeName, int colors )
32  {
33  QList<QColor> pal;
34  QString palette( BREWER_STRING );
35  QStringList list = palette.split( QChar( '\n' ) );
36  Q_FOREACH ( const QString &entry, list )
37  {
38  QStringList items = entry.split( QChar( '-' ) );
39  if ( items.count() != 3 || items[0] != schemeName || items[1].toInt() != colors )
40  continue;
41  QStringList colors = items[2].split( QChar( ' ' ) );
42  Q_FOREACH ( const QString &clr, colors )
43  {
44  pal << QgsSymbolLayerUtils::parseColor( clr );
45  }
46  }
47  return pal;
48  }
49 
50  static QStringList listSchemes()
51  {
52  QStringList schemes;
53 
54  QString palette( BREWER_STRING );
55  QStringList list = palette.split( QChar( '\n' ) );
56  Q_FOREACH ( const QString &entry, list )
57  {
58  QStringList items = entry.split( QChar( '-' ) );
59  if ( items.count() != 3 )
60  continue;
61  if ( !schemes.contains( items[0] ) )
62  schemes << items[0];
63  }
64  return schemes;
65  }
66 
67  static QList<int> listSchemeVariants( const QString &schemeName )
68  {
69  QList<int> variants;
70 
71  QString palette( BREWER_STRING );
72  QStringList list = palette.split( QChar( '\n' ) );
73  Q_FOREACH ( const QString &entry, list )
74  {
75  QStringList items = entry.split( QChar( '-' ) );
76  if ( items.count() != 3 || items[0] != schemeName )
77  continue;
78  variants << items[1].toInt();
79  }
80 
81  return variants;
82  }
83 
84  // extracted ColorBrewer data
85  static const char *BREWER_STRING;
86 };
87 
88 // clazy:excludeall=qstring-allocations
89 
90 #endif // QGSCOLORBREWERPALETTE_H
static const char * BREWER_STRING
static QList< QColor > listSchemeColors(const QString &schemeName, int colors)
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...
static QList< int > listSchemeVariants(const QString &schemeName)
static QStringList listSchemes()