diff --git a/src/app/qgsgraduatedsymboldialog.cpp b/src/app/qgsgraduatedsymboldialog.cpp index a212cc0e7722..3017ce228ea2 100644 --- a/src/app/qgsgraduatedsymboldialog.cpp +++ b/src/app/qgsgraduatedsymboldialog.cpp @@ -42,7 +42,6 @@ QgsGraduatedSymbolDialog::QgsGraduatedSymbolDialog(QgsVectorLayer * layer): QDia if (provider) { const QgsFieldMap & fields = provider->fields(); - int fieldnumber = 0; QString str; for (QgsFieldMap::const_iterator it = fields.begin(); @@ -52,11 +51,9 @@ QgsGraduatedSymbolDialog::QgsGraduatedSymbolDialog(QgsVectorLayer * layer): QDia QVariant::Type type = (*it).type(); if (type == QVariant::Int || type == QVariant::Double) { - str = (*it).name(); - classificationComboBox->insertItem(str); - mFieldMap.insert(std::make_pair(str, fieldnumber)); + classificationComboBox->insertItem(it->name()); + mFieldMap.insert(std::make_pair(it->name(), it.key())); } - fieldnumber++; } } else diff --git a/src/app/qgsuniquevaluedialog.cpp b/src/app/qgsuniquevaluedialog.cpp index 0d7753f14c4a..078809f37c0a 100644 --- a/src/app/qgsuniquevaluedialog.cpp +++ b/src/app/qgsuniquevaluedialog.cpp @@ -125,72 +125,79 @@ void QgsUniqueValueDialog::apply() void QgsUniqueValueDialog::changeClassificationAttribute() { - int nr = mClassificationComboBox->currentIndex(); - //delete old entries - for(std::map::iterator it=mValues.begin();it!=mValues.end();++it) + QString attributeName = mClassificationComboBox->currentText(); + + //delete old entries + for(std::map::iterator it=mValues.begin();it!=mValues.end();++it) { - delete it->second; + delete it->second; } - mValues.clear(); - - QgsVectorDataProvider *provider = dynamic_cast(mVectorLayer->getDataProvider()); - if (provider) + mValues.clear(); + + QgsVectorDataProvider *provider = dynamic_cast(mVectorLayer->getDataProvider()); + if (provider) { - QString value; - QgsAttributeList attlist; - attlist.append(nr); - QgsSymbol* symbol; - - provider->select(attlist, QgsRect(), false); - QgsFeature feat; - - //go through all the features and insert their value into the map and into mClassListWidget - mClassListWidget->clear(); - while(provider->getNextFeature(feat)) + QString value; + QgsAttributeList attlist; + + QgsSymbol* symbol; + int nr = provider->indexFromFieldName(attributeName); + if(nr == -1) + { + return; + } + attlist.append(nr); + + provider->select(attlist, QgsRect(), false); + QgsFeature feat; + + //go through all the features and insert their value into the map and into mClassListWidget + mClassListWidget->clear(); + while(provider->getNextFeature(feat)) { - const QgsAttributeMap& attrs = feat.attributeMap(); - value = attrs[nr].toString(); - - if(mValues.find(value)==mValues.end()) + const QgsAttributeMap& attrs = feat.attributeMap(); + value = attrs[nr].toString(); + + if(mValues.find(value)==mValues.end()) { - symbol=new QgsSymbol(mVectorLayer->vectorType(), value); - mValues.insert(std::make_pair(value,symbol)); + symbol=new QgsSymbol(mVectorLayer->vectorType(), value); + mValues.insert(std::make_pair(value,symbol)); } } - - //set symbology for all QgsSiSyDialogs - QColor thecolor; - - for(std::map::iterator it=mValues.begin();it!=mValues.end();++it) + + //set symbology for all QgsSiSyDialogs + QColor thecolor; + + for(std::map::iterator it=mValues.begin();it!=mValues.end();++it) { - //insert a random color - int red = 1 + (int) (255.0 * rand() / (RAND_MAX + 1.0)); - int green = 1 + (int) (255.0 * rand() / (RAND_MAX + 1.0)); - int blue = 1 + (int) (255.0 * rand() / (RAND_MAX + 1.0)); - thecolor.setRgb(red, green, blue); - mClassListWidget->addItem(it->first); - QgsSymbol* sym=it->second; - QPen pen; - QBrush brush; - if(mVectorLayer->vectorType() == QGis::Line) + //insert a random color + int red = 1 + (int) (255.0 * rand() / (RAND_MAX + 1.0)); + int green = 1 + (int) (255.0 * rand() / (RAND_MAX + 1.0)); + int blue = 1 + (int) (255.0 * rand() / (RAND_MAX + 1.0)); + thecolor.setRgb(red, green, blue); + mClassListWidget->addItem(it->first); + QgsSymbol* sym=it->second; + QPen pen; + QBrush brush; + if(mVectorLayer->vectorType() == QGis::Line) { - pen.setColor(thecolor); - pen.setStyle(Qt::SolidLine); - pen.setWidth(1); + pen.setColor(thecolor); + pen.setStyle(Qt::SolidLine); + pen.setWidth(1); } - else + else { - brush.setColor(thecolor); - brush.setStyle(Qt::SolidPattern); - pen.setColor(Qt::black); - pen.setStyle(Qt::SolidLine); - pen.setWidth(1); + brush.setColor(thecolor); + brush.setStyle(Qt::SolidPattern); + pen.setColor(Qt::black); + pen.setStyle(Qt::SolidLine); + pen.setWidth(1); } - sym->setPen(pen); - sym->setBrush(brush); + sym->setPen(pen); + sym->setBrush(brush); } } - mClassListWidget->setCurrentRow(0); + mClassListWidget->setCurrentRow(0); } void QgsUniqueValueDialog::changeCurrentValue()