Skip to content

Commit 253e575

Browse files
author
g_j_m
committedNov 13, 2006
Fix a bug where the continuous colour renderer would display and use the wrong layer attribute on the second and subsequent invocations of the vector layer properties dialog box (caused by a mismatch between the combo box index and provider attribute index, due to excluding attributes that couldn't be used to colour the features)
Fix a bug where the 'draw polygon outline' toggle would appear sometimes for a linestring layer Fix a typo in a comment git-svn-id: http://svn.osgeo.org/qgis/trunk@6084 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 8bbd806 commit 253e575

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed
 

‎src/gui/qgscontinuouscolordialog.cpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ QgsContinuousColorDialog::QgsContinuousColorDialog(QgsVectorLayer * layer)
4343
if (provider = dynamic_cast<QgsVectorDataProvider*>(mVectorLayer->getDataProvider()))
4444
{
4545
std::vector < QgsField > const & fields = provider->fields();
46-
int fieldnumber = 0;
46+
int fieldnumber(0), combonumber(0);
4747
QString str;
4848

4949
for (std::vector < QgsField >::const_iterator it = fields.begin(); it != fields.end(); ++it)
@@ -54,7 +54,8 @@ QgsContinuousColorDialog::QgsContinuousColorDialog(QgsVectorLayer * layer)
5454
str = (*it).name();
5555
str = str.left(1).upper() + str.right(str.length() - 1); //make the first letter uppercase
5656
classificationComboBox->insertItem(str);
57-
mFieldMap.insert(std::make_pair(str, fieldnumber));
57+
mFieldMap.insert(std::make_pair(combonumber, fieldnumber));
58+
combonumber++;
5859
}
5960
fieldnumber++;
6061
}
@@ -78,7 +79,22 @@ QgsContinuousColorDialog::QgsContinuousColorDialog(QgsVectorLayer * layer)
7879

7980
if (renderer)
8081
{
81-
classificationComboBox->setCurrentItem(renderer->classificationField());
82+
// Awkard - here we want to search through mFieldMap for a
83+
// particular value, while elsewhere in this code we need to search
84+
// for a particular key, so one or the other loses out, which is here.
85+
86+
std::map<int,int>::const_iterator iter = mFieldMap.begin();
87+
while (iter != mFieldMap.end())
88+
{
89+
if (iter->second == renderer->classificationField())
90+
break;
91+
iter++;
92+
}
93+
if (iter != mFieldMap.end())
94+
classificationComboBox->setCurrentItem(iter->first);
95+
else
96+
classificationComboBox->setCurrentItem(-1);
97+
8298
const QgsSymbol* minsymbol = renderer->minimumSymbol();
8399
const QgsSymbol* maxsymbol = renderer->maximumSymbol();
84100

@@ -108,6 +124,8 @@ QgsContinuousColorDialog::QgsContinuousColorDialog(QgsVectorLayer * layer)
108124
cb_polygonOutline->setCheckState(Qt::Checked);
109125
else
110126
cb_polygonOutline->setCheckState(Qt::Unchecked);
127+
if (mVectorLayer->vectorType() != QGis::Polygon)
128+
cb_polygonOutline->setVisible(false);
111129
}
112130
else
113131
{
@@ -142,14 +160,17 @@ QgsContinuousColorDialog::~QgsContinuousColorDialog()
142160

143161
void QgsContinuousColorDialog::apply()
144162
{
145-
QString fieldstring = classificationComboBox->currentText();
146-
if (fieldstring.isEmpty()) //don't do anything, it there is no classification field
163+
int comboIndex = classificationComboBox->currentIndex();
164+
if (comboIndex == -1) //don't do anything, if there is no classification field
147165
{
148166
return;
149167
}
150-
std::map < QString, int >::iterator iter = mFieldMap.find(fieldstring);
168+
std::map < int, int >::iterator iter = mFieldMap.find(comboIndex);
169+
// Should never happen...
170+
assert(iter != mFieldMap.end());
171+
151172
int classfield = iter->second;
152-
173+
153174
//find the minimum and maximum for the classification variable
154175
double minimum, maximum;
155176
QgsVectorDataProvider *provider = dynamic_cast<QgsVectorDataProvider*>(mVectorLayer->getDataProvider());

‎src/gui/qgscontinuouscolordialog.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ class QgsContinuousColorDialog: public QDialog, private Ui::QgsContinuousColorDi
4848

4949
protected:
5050
QgsVectorLayer* mVectorLayer;
51-
/**Stores the names and numbers of the fields with numeric values*/
52-
std::map<QString,int> mFieldMap;
51+
/**Stores the relationship between provider field indices and field selection
52+
combobox indices. First is the combobox index, second is the provider field index */
53+
std::map<int,int> mFieldMap;
5354

5455
private:
5556
/** Default constructor is private, do not use this */

0 commit comments

Comments
 (0)
Please sign in to comment.