Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mhugent committed Jul 7, 2007
1 parent c9da10c commit 31e49a2
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 57 deletions.
7 changes: 2 additions & 5 deletions src/app/qgsgraduatedsymboldialog.cpp
Expand Up @@ -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();
Expand All @@ -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
Expand Down
111 changes: 59 additions & 52 deletions src/app/qgsuniquevaluedialog.cpp
Expand Up @@ -125,72 +125,79 @@ void QgsUniqueValueDialog::apply()

void QgsUniqueValueDialog::changeClassificationAttribute()
{
int nr = mClassificationComboBox->currentIndex();
//delete old entries
for(std::map<QString,QgsSymbol*>::iterator it=mValues.begin();it!=mValues.end();++it)
QString attributeName = mClassificationComboBox->currentText();

//delete old entries
for(std::map<QString,QgsSymbol*>::iterator it=mValues.begin();it!=mValues.end();++it)
{
delete it->second;
delete it->second;
}
mValues.clear();
QgsVectorDataProvider *provider = dynamic_cast<QgsVectorDataProvider *>(mVectorLayer->getDataProvider());
if (provider)
mValues.clear();

QgsVectorDataProvider *provider = dynamic_cast<QgsVectorDataProvider *>(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<QString,QgsSymbol*>::iterator it=mValues.begin();it!=mValues.end();++it)
//set symbology for all QgsSiSyDialogs
QColor thecolor;
for(std::map<QString,QgsSymbol*>::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()
Expand Down

0 comments on commit 31e49a2

Please sign in to comment.