QGIS API Documentation  master-3f58142
src/core/symbology-ng/qgscolorbrewerpalette.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgscolorbrewerpalette.h
00003     ---------------------
00004     begin                : November 2009
00005     copyright            : (C) 2009 by Martin Dobias
00006     email                : wonder dot sk at gmail dot com
00007  ***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015 #ifndef QGSCOLORBREWERPALETTE_H
00016 #define QGSCOLORBREWERPALETTE_H
00017 
00018 #include <QList>
00019 #include <QColor>
00020 
00021 #include "qgssymbollayerv2utils.h"
00022 
00023 class CORE_EXPORT QgsColorBrewerPalette
00024 {
00025   public:
00026     static QList<QColor> listSchemeColors( QString schemeName, int colors )
00027     {
00028       QList<QColor> pal;
00029       QString palette( brewerString );
00030       QStringList list = palette.split( QChar( '\n' ) );
00031       foreach ( QString entry, list )
00032       {
00033         QStringList items = entry.split( QChar( '-' ) );
00034         if ( items.count() != 3 || items[0] != schemeName || items[1].toInt() != colors )
00035           continue;
00036         QStringList colors = items[2].split( QChar( ' ' ) );
00037         foreach ( QString clr, colors )
00038         {
00039           pal << QgsSymbolLayerV2Utils::parseColor( clr );
00040         }
00041       }
00042       return pal;
00043     }
00044 
00045     static QStringList listSchemes()
00046     {
00047       QStringList schemes;
00048 
00049       QString palette( brewerString );
00050       QStringList list = palette.split( QChar( '\n' ) );
00051       foreach ( QString entry, list )
00052       {
00053         QStringList items = entry.split( QChar( '-' ) );
00054         if ( items.count() != 3 )
00055           continue;
00056         if ( !schemes.contains( items[0] ) )
00057           schemes << items[0];
00058       }
00059       return schemes;
00060     }
00061 
00062     static QList<int> listSchemeVariants( QString schemeName )
00063     {
00064       QList<int> variants;
00065 
00066       QString palette( brewerString );
00067       QStringList list = palette.split( QChar( '\n' ) );
00068       foreach ( QString entry, list )
00069       {
00070         QStringList items = entry.split( QChar( '-' ) );
00071         if ( items.count() != 3 || items[0] != schemeName )
00072           continue;
00073         variants << items[1].toInt();
00074       }
00075 
00076       return variants;
00077     }
00078 
00079     // extracted ColorBrewer data
00080     static const char *brewerString;
00081 };
00082 
00083 #endif // QGSCOLORBREWERPALETTE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines