Skip to content

Commit 782e267

Browse files
author
jef
committed
fix #1666
git-svn-id: http://svn.osgeo.org/qgis/trunk@10708 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 80b71a9 commit 782e267

File tree

2 files changed

+8
-49
lines changed

2 files changed

+8
-49
lines changed

src/app/qgscontinuouscolordialog.cpp

+8-46
Original file line numberDiff line numberDiff line change
@@ -39,53 +39,24 @@ QgsContinuousColorDialog::QgsContinuousColorDialog( QgsVectorLayer * layer )
3939
QObject::connect( btnMaxValue, SIGNAL( clicked() ), this, SLOT( selectMaximumColor() ) );
4040

4141
//find out the numerical fields of mVectorLayer
42-
QgsVectorDataProvider *provider = mVectorLayer->dataProvider();
43-
if ( provider )
44-
{
45-
const QgsFieldMap & fields = provider->fields();
46-
int fieldNumber( 0 ), comboNumber( 0 );
47-
QString str;
42+
const QgsFieldMap & fields = mVectorLayer->pendingFields();
4843

49-
for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it )
44+
for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it )
45+
{
46+
QVariant::Type type = it->type();
47+
if ( type == QVariant::Int || type == QVariant::Double )
5048
{
51-
QVariant::Type type = ( *it ).type();
52-
if ( type == QVariant::Int || type == QVariant::Double )
53-
{
54-
str = ( *it ).name();
55-
classificationComboBox->addItem( str );
56-
mFieldMap.insert( std::make_pair( comboNumber, fieldNumber ) );
57-
comboNumber++;
58-
}
59-
fieldNumber++;
49+
classificationComboBox->addItem( it->name(), it.key() );
6050
}
6151
}
62-
else
63-
{
64-
QgsDebugMsg( "data provider is null" );
65-
return;
66-
}
6752

6853
//restore the correct colors for minimum and maximum values
6954

7055
const QgsContinuousColorRenderer* renderer = dynamic_cast < const QgsContinuousColorRenderer * >( layer->renderer() );;
7156

7257
if ( renderer )
7358
{
74-
// Awkard - here we want to search through mFieldMap for a
75-
// particular value, while elsewhere in this code we need to search
76-
// for a particular key, so one or the other loses out, which is here.
77-
78-
std::map<int, int>::const_iterator iter = mFieldMap.begin();
79-
while ( iter != mFieldMap.end() )
80-
{
81-
if ( iter->second == renderer->classificationField() )
82-
break;
83-
iter++;
84-
}
85-
if ( iter != mFieldMap.end() )
86-
classificationComboBox->setCurrentIndex( iter->first );
87-
else
88-
classificationComboBox->setCurrentIndex( -1 );
59+
classificationComboBox->setCurrentIndex( classificationComboBox->findData( renderer->classificationField() ) );
8960

9061
const QgsSymbol* minsymbol = renderer->minimumSymbol();
9162
const QgsSymbol* maxsymbol = renderer->maximumSymbol();
@@ -147,16 +118,7 @@ QgsContinuousColorDialog::~QgsContinuousColorDialog()
147118

148119
void QgsContinuousColorDialog::apply()
149120
{
150-
int comboIndex = classificationComboBox->currentIndex();
151-
if ( comboIndex == -1 ) //don't do anything, if there is no classification field
152-
{
153-
return;
154-
}
155-
std::map < int, int >::iterator iter = mFieldMap.find( comboIndex );
156-
// Should never happen...
157-
assert( iter != mFieldMap.end() );
158-
159-
int classfield = iter->second;
121+
int classfield = classificationComboBox->itemData( classificationComboBox->currentIndex() ).toInt();
160122

161123
//find the minimum and maximum for the classification variable
162124
double minimum, maximum;

src/app/qgscontinuouscolordialog.h

-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ class QgsContinuousColorDialog: public QDialog, private Ui::QgsContinuousColorDi
4444

4545
protected:
4646
QgsVectorLayer* mVectorLayer;
47-
/**Stores the relationship between provider field indices and field selection
48-
combobox indices. First is the combobox index, second is the provider field index */
49-
std::map<int, int> mFieldMap;
5047

5148
private:
5249
/** Default constructor is private, do not use this */

0 commit comments

Comments
 (0)