@@ -125,72 +125,79 @@ void QgsUniqueValueDialog::apply()
125125
126126void QgsUniqueValueDialog::changeClassificationAttribute ()
127127{
128- int nr = mClassificationComboBox ->currentIndex ();
129- // delete old entries
130- for (std::map<QString,QgsSymbol*>::iterator it=mValues .begin ();it!=mValues .end ();++it)
128+ QString attributeName = mClassificationComboBox ->currentText ();
129+
130+ // delete old entries
131+ for (std::map<QString,QgsSymbol*>::iterator it=mValues .begin ();it!=mValues .end ();++it)
131132 {
132- delete it->second ;
133+ delete it->second ;
133134 }
134- mValues .clear ();
135-
136- QgsVectorDataProvider *provider = dynamic_cast <QgsVectorDataProvider *>(mVectorLayer ->getDataProvider ());
137- if (provider)
135+ mValues .clear ();
136+
137+ QgsVectorDataProvider *provider = dynamic_cast <QgsVectorDataProvider *>(mVectorLayer ->getDataProvider ());
138+ if (provider)
138139 {
139- QString value;
140- QgsAttributeList attlist;
141- attlist.append (nr);
142- QgsSymbol* symbol;
143-
144- provider->select (attlist, QgsRect (), false );
145- QgsFeature feat;
146-
147- // go through all the features and insert their value into the map and into mClassListWidget
148- mClassListWidget ->clear ();
149- while (provider->getNextFeature (feat))
140+ QString value;
141+ QgsAttributeList attlist;
142+
143+ QgsSymbol* symbol;
144+ int nr = provider->indexFromFieldName (attributeName);
145+ if (nr == -1 )
146+ {
147+ return ;
148+ }
149+ attlist.append (nr);
150+
151+ provider->select (attlist, QgsRect (), false );
152+ QgsFeature feat;
153+
154+ // go through all the features and insert their value into the map and into mClassListWidget
155+ mClassListWidget ->clear ();
156+ while (provider->getNextFeature (feat))
150157 {
151- const QgsAttributeMap& attrs = feat.attributeMap ();
152- value = attrs[nr].toString ();
153-
154- if (mValues .find (value)==mValues .end ())
158+ const QgsAttributeMap& attrs = feat.attributeMap ();
159+ value = attrs[nr].toString ();
160+
161+ if (mValues .find (value)==mValues .end ())
155162 {
156- symbol=new QgsSymbol (mVectorLayer ->vectorType (), value);
157- mValues .insert (std::make_pair (value,symbol));
163+ symbol=new QgsSymbol (mVectorLayer ->vectorType (), value);
164+ mValues .insert (std::make_pair (value,symbol));
158165 }
159166 }
160-
161- // set symbology for all QgsSiSyDialogs
162- QColor thecolor;
163-
164- for (std::map<QString,QgsSymbol*>::iterator it=mValues .begin ();it!=mValues .end ();++it)
167+
168+ // set symbology for all QgsSiSyDialogs
169+ QColor thecolor;
170+
171+ for (std::map<QString,QgsSymbol*>::iterator it=mValues .begin ();it!=mValues .end ();++it)
165172 {
166- // insert a random color
167- int red = 1 + (int ) (255.0 * rand () / (RAND_MAX + 1.0 ));
168- int green = 1 + (int ) (255.0 * rand () / (RAND_MAX + 1.0 ));
169- int blue = 1 + (int ) (255.0 * rand () / (RAND_MAX + 1.0 ));
170- thecolor.setRgb (red, green, blue);
171- mClassListWidget ->addItem (it->first );
172- QgsSymbol* sym=it->second ;
173- QPen pen;
174- QBrush brush;
175- if (mVectorLayer ->vectorType () == QGis::Line)
173+ // insert a random color
174+ int red = 1 + (int ) (255.0 * rand () / (RAND_MAX + 1.0 ));
175+ int green = 1 + (int ) (255.0 * rand () / (RAND_MAX + 1.0 ));
176+ int blue = 1 + (int ) (255.0 * rand () / (RAND_MAX + 1.0 ));
177+ thecolor.setRgb (red, green, blue);
178+ mClassListWidget ->addItem (it->first );
179+ QgsSymbol* sym=it->second ;
180+ QPen pen;
181+ QBrush brush;
182+ if (mVectorLayer ->vectorType () == QGis::Line)
176183 {
177- pen.setColor (thecolor);
178- pen.setStyle (Qt::SolidLine);
179- pen.setWidth (1 );
184+ pen.setColor (thecolor);
185+ pen.setStyle (Qt::SolidLine);
186+ pen.setWidth (1 );
180187 }
181- else
188+ else
182189 {
183- brush.setColor (thecolor);
184- brush.setStyle (Qt::SolidPattern);
185- pen.setColor (Qt::black);
186- pen.setStyle (Qt::SolidLine);
187- pen.setWidth (1 );
190+ brush.setColor (thecolor);
191+ brush.setStyle (Qt::SolidPattern);
192+ pen.setColor (Qt::black);
193+ pen.setStyle (Qt::SolidLine);
194+ pen.setWidth (1 );
188195 }
189- sym->setPen (pen);
190- sym->setBrush (brush);
196+ sym->setPen (pen);
197+ sym->setBrush (brush);
191198 }
192199 }
193- mClassListWidget ->setCurrentRow (0 );
200+ mClassListWidget ->setCurrentRow (0 );
194201}
195202
196203void QgsUniqueValueDialog::changeCurrentValue ()
0 commit comments