Skip to content

Commit 31e49a2

Browse files
author
mhugent
committedJul 7, 2007
Fixed problems with classification fields in graduated symbol dialog and unique value dialog. this should address ticket #732 Layer Properties/Legendtype/Individual Symbol
git-svn-id: http://svn.osgeo.org/qgis/trunk@7066 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent c9da10c commit 31e49a2

File tree

2 files changed

+61
-57
lines changed

2 files changed

+61
-57
lines changed
 

‎src/app/qgsgraduatedsymboldialog.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ QgsGraduatedSymbolDialog::QgsGraduatedSymbolDialog(QgsVectorLayer * layer): QDia
4242
if (provider)
4343
{
4444
const QgsFieldMap & fields = provider->fields();
45-
int fieldnumber = 0;
4645
QString str;
4746

4847
for (QgsFieldMap::const_iterator it = fields.begin();
@@ -52,11 +51,9 @@ QgsGraduatedSymbolDialog::QgsGraduatedSymbolDialog(QgsVectorLayer * layer): QDia
5251
QVariant::Type type = (*it).type();
5352
if (type == QVariant::Int || type == QVariant::Double)
5453
{
55-
str = (*it).name();
56-
classificationComboBox->insertItem(str);
57-
mFieldMap.insert(std::make_pair(str, fieldnumber));
54+
classificationComboBox->insertItem(it->name());
55+
mFieldMap.insert(std::make_pair(it->name(), it.key()));
5856
}
59-
fieldnumber++;
6057
}
6158
}
6259
else

‎src/app/qgsuniquevaluedialog.cpp

Lines changed: 59 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -125,72 +125,79 @@ void QgsUniqueValueDialog::apply()
125125

126126
void 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

196203
void QgsUniqueValueDialog::changeCurrentValue()

0 commit comments

Comments
 (0)
Please sign in to comment.