QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsvectorcolorbrewercolorrampv2dialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorcolorbrewercolorrampv2dialog.cpp
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 
17 
18 #include "qgsvectorcolorrampv2.h"
19 
20 #include <QAbstractButton>
21 
22 #if 0 // unused
23 static void updateColorButton( QAbstractButton* button, QColor color )
24 {
25  QPixmap p( 20, 20 );
26  p.fill( color );
27  button->setIcon( QIcon( p ) );
28 }
29 #endif
30 
32 
33 
35  : QDialog( parent ), mRamp( ramp )
36 {
37 
38  setupUi( this );
39 
40  QSize iconSize( 50, 16 );
41  cboSchemeName->setIconSize( iconSize );
42 
44  foreach ( QString schemeName, schemes )
45  {
46  // create a preview icon using five color variant
49  delete r;
50  cboSchemeName->addItem( icon, schemeName );
51  }
52 
53  cboSchemeName->setCurrentIndex( cboSchemeName->findText( ramp->schemeName() ) );
55  cboColors->setCurrentIndex( cboColors->findText( QString::number( ramp->colors() ) ) );
56 
57  connect( cboSchemeName, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setSchemeName() ) );
58  connect( cboColors, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setColors() ) );
59 
60  updatePreview();
61 }
62 
64 {
65  QString oldVariant = cboColors->currentText();
66 
67  cboColors->clear();
68  QString schemeName = cboSchemeName->currentText();
69  QList<int> variants = QgsVectorColorBrewerColorRampV2::listSchemeVariants( schemeName );
70  foreach ( int variant, variants )
71  {
72  cboColors->addItem( QString::number( variant ) );
73  }
74 
75  // try to set the original variant again (if exists)
76  int idx = cboColors->findText( oldVariant );
77  if ( idx == -1 ) // not found?
78  {
79  // use the last item
80  idx = cboColors->count() - 1;
81  }
82  cboColors->setCurrentIndex( idx );
83 }
84 
86 {
87  QSize size( 300, 40 );
88  lblPreview->setPixmap( QgsSymbolLayerV2Utils::colorRampPreviewPixmap( mRamp, size ) );
89 }
90 
92 {
93  // populate list of variants
95 
96  mRamp->setSchemeName( cboSchemeName->currentText() );
97  updatePreview();
98 }
99 
101 {
102  int num = cboColors->currentText().toInt();
103  mRamp->setColors( num );
104  updatePreview();
105 }
static QIcon colorRampPreviewIcon(QgsVectorColorRampV2 *ramp, QSize size)
static QPixmap colorRampPreviewPixmap(QgsVectorColorRampV2 *ramp, QSize size)
static QList< int > listSchemeVariants(QString schemeName)
QgsVectorColorBrewerColorRampV2Dialog(QgsVectorColorBrewerColorRampV2 *ramp, QWidget *parent=NULL)
static QIcon icon(QString icon)
void setSchemeName(QString schemeName)
double size
Definition: qgssvgcache.cpp:77