QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 )
36  , mRamp( ramp )
37 {
38 
39  setupUi( this );
40 
41  QSize iconSize( 50, 16 );
42  cboSchemeName->setIconSize( iconSize );
43 
45  Q_FOREACH ( const QString& schemeName, schemes )
46  {
47  // create a preview icon using five color variant
50  delete r;
51  cboSchemeName->addItem( icon, schemeName );
52  }
53 
54  cboSchemeName->setCurrentIndex( cboSchemeName->findText( ramp->schemeName() ) );
56  cboColors->setCurrentIndex( cboColors->findText( QString::number( ramp->colors() ) ) );
57 
58  connect( cboSchemeName, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setSchemeName() ) );
59  connect( cboColors, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setColors() ) );
60 
61  updatePreview();
62 }
63 
65 {
66  QString oldVariant = cboColors->currentText();
67 
68  cboColors->clear();
69  QString schemeName = cboSchemeName->currentText();
71  Q_FOREACH ( int variant, variants )
72  {
73  cboColors->addItem( QString::number( variant ) );
74  }
75 
76  // try to set the original variant again (if exists)
77  int idx = cboColors->findText( oldVariant );
78  if ( idx == -1 ) // not found?
79  {
80  // use the last item
81  idx = cboColors->count() - 1;
82  }
83  cboColors->setCurrentIndex( idx );
84 }
85 
87 {
88  QSize size( 300, 40 );
89  lblPreview->setPixmap( QgsSymbolLayerV2Utils::colorRampPreviewPixmap( mRamp, size ) );
90 }
91 
93 {
94  // populate list of variants
96 
97  mRamp->setSchemeName( cboSchemeName->currentText() );
98  updatePreview();
99 }
100 
102 {
103  int num = cboColors->currentText().toInt();
104  mRamp->setColors( num );
105  updatePreview();
106 }
void setupUi(QWidget *widget)
QgsVectorColorBrewerColorRampV2Dialog(QgsVectorColorBrewerColorRampV2 *ramp, QWidget *parent=nullptr)
static QIcon colorRampPreviewIcon(QgsVectorColorRampV2 *ramp, QSize size)
static QPixmap colorRampPreviewPixmap(QgsVectorColorRampV2 *ramp, QSize size)
const QPixmap * icon() const
void setIcon(const QIcon &icon)
void clear()
QSize size() const
QString number(int n, int base)
void setSchemeName(const QString &schemeName)
static QList< int > listSchemeVariants(const QString &schemeName)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)