|
Quantum GIS API Documentation
master-ce49b66
|
00001 /*************************************************************************** 00002 qgsvectorcolorbrewercolorrampv2dialog.cpp 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 00016 #include "qgsvectorcolorbrewercolorrampv2dialog.h" 00017 00018 #include "qgsvectorcolorrampv2.h" 00019 00020 #include <QAbstractButton> 00021 00022 #if 0 // unused 00023 static void updateColorButton( QAbstractButton* button, QColor color ) 00024 { 00025 QPixmap p( 20, 20 ); 00026 p.fill( color ); 00027 button->setIcon( QIcon( p ) ); 00028 } 00029 #endif 00030 00032 00033 00034 QgsVectorColorBrewerColorRampV2Dialog::QgsVectorColorBrewerColorRampV2Dialog( QgsVectorColorBrewerColorRampV2* ramp, QWidget* parent ) 00035 : QDialog( parent ), mRamp( ramp ) 00036 { 00037 00038 setupUi( this ); 00039 00040 QSize iconSize( 50, 16 ); 00041 cboSchemeName->setIconSize( iconSize ); 00042 00043 QStringList schemes = QgsVectorColorBrewerColorRampV2::listSchemeNames(); 00044 foreach ( QString schemeName, schemes ) 00045 { 00046 // create a preview icon using five color variant 00047 QgsVectorColorBrewerColorRampV2* r = new QgsVectorColorBrewerColorRampV2( schemeName, 5 ); 00048 QIcon icon = QgsSymbolLayerV2Utils::colorRampPreviewIcon( r, iconSize ); 00049 delete r; 00050 cboSchemeName->addItem( icon, schemeName ); 00051 } 00052 00053 cboSchemeName->setCurrentIndex( cboSchemeName->findText( ramp->schemeName() ) ); 00054 populateVariants(); 00055 cboColors->setCurrentIndex( cboColors->findText( QString::number( ramp->colors() ) ) ); 00056 00057 connect( cboSchemeName, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setSchemeName() ) ); 00058 connect( cboColors, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setColors() ) ); 00059 00060 updatePreview(); 00061 } 00062 00063 void QgsVectorColorBrewerColorRampV2Dialog::populateVariants() 00064 { 00065 QString oldVariant = cboColors->currentText(); 00066 00067 cboColors->clear(); 00068 QString schemeName = cboSchemeName->currentText(); 00069 QList<int> variants = QgsVectorColorBrewerColorRampV2::listSchemeVariants( schemeName ); 00070 foreach ( int variant, variants ) 00071 { 00072 cboColors->addItem( QString::number( variant ) ); 00073 } 00074 00075 // try to set the original variant again (if exists) 00076 int idx = cboColors->findText( oldVariant ); 00077 if ( idx == -1 ) // not found? 00078 { 00079 // use the last item 00080 idx = cboColors->count() - 1; 00081 } 00082 cboColors->setCurrentIndex( idx ); 00083 } 00084 00085 void QgsVectorColorBrewerColorRampV2Dialog::updatePreview() 00086 { 00087 QSize size( 300, 40 ); 00088 lblPreview->setPixmap( QgsSymbolLayerV2Utils::colorRampPreviewPixmap( mRamp, size ) ); 00089 } 00090 00091 void QgsVectorColorBrewerColorRampV2Dialog::setSchemeName() 00092 { 00093 // populate list of variants 00094 populateVariants(); 00095 00096 mRamp->setSchemeName( cboSchemeName->currentText() ); 00097 updatePreview(); 00098 } 00099 00100 void QgsVectorColorBrewerColorRampV2Dialog::setColors() 00101 { 00102 int num = cboColors->currentText().toInt(); 00103 mRamp->setColors( num ); 00104 updatePreview(); 00105 }