@@ -39,53 +39,24 @@ QgsContinuousColorDialog::QgsContinuousColorDialog( QgsVectorLayer * layer )
39
39
QObject::connect ( btnMaxValue, SIGNAL ( clicked () ), this , SLOT ( selectMaximumColor () ) );
40
40
41
41
// 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 ();
48
43
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 )
50
48
{
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 () );
60
50
}
61
51
}
62
- else
63
- {
64
- QgsDebugMsg ( " data provider is null" );
65
- return ;
66
- }
67
52
68
53
// restore the correct colors for minimum and maximum values
69
54
70
55
const QgsContinuousColorRenderer* renderer = dynamic_cast < const QgsContinuousColorRenderer * >( layer->renderer () );;
71
56
72
57
if ( renderer )
73
58
{
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 () ) );
89
60
90
61
const QgsSymbol* minsymbol = renderer->minimumSymbol ();
91
62
const QgsSymbol* maxsymbol = renderer->maximumSymbol ();
@@ -147,16 +118,7 @@ QgsContinuousColorDialog::~QgsContinuousColorDialog()
147
118
148
119
void QgsContinuousColorDialog::apply ()
149
120
{
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 ();
160
122
161
123
// find the minimum and maximum for the classification variable
162
124
double minimum, maximum;
0 commit comments