Skip to content

Commit 850331f

Browse files
author
jef
committedMar 25, 2008

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed
 

‎src/core/renderer/qgsuniquevaluerenderer.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
QgsUniqueValueRenderer::QgsUniqueValueRenderer(QGis::VectorType type): mClassificationField(0)
3232
{
3333
mVectorType = type;
34+
mSymbolAttributesDirty = false;
3435
}
3536

3637
QgsUniqueValueRenderer::QgsUniqueValueRenderer(const QgsUniqueValueRenderer& other)
@@ -84,7 +85,7 @@ const QList<QgsSymbol*> QgsUniqueValueRenderer::symbols() const
8485
void QgsUniqueValueRenderer::insertValue(QString name, QgsSymbol* symbol)
8586
{
8687
mSymbols.insert(name, symbol);
87-
updateSymbolAttributes();
88+
mSymbolAttributesDirty=true;
8889
}
8990

9091
void QgsUniqueValueRenderer::setClassificationField(int field)
@@ -105,6 +106,11 @@ bool QgsUniqueValueRenderer::willRenderFeature(QgsFeature *f)
105106
void QgsUniqueValueRenderer::renderFeature(QPainter* p, QgsFeature& f,QImage* img,
106107
double* scalefactor, bool selected, double widthScale)
107108
{
109+
if(mSymbolAttributesDirty) {
110+
QgsDebugMsg("Missed updateSymbolAttributes() call - doing it now");
111+
updateSymbolAttributes();
112+
}
113+
108114
QgsSymbol* symbol = symbolForFeature(&f);
109115
if(!symbol) //no matching symbol
110116
{
@@ -131,13 +137,13 @@ void QgsUniqueValueRenderer::renderFeature(QPainter* p, QgsFeature& f,QImage* im
131137
//first find out the value for the scale classification attribute
132138
const QgsAttributeMap& attrs = f.attributeMap();
133139
fieldScale = sqrt(fabs(attrs[symbol->scaleClassificationField()].toDouble()));
134-
QgsDebugMsg(QString("Feature has field scale factor %1").arg(fieldScale));
140+
QgsDebugMsgLevel(QString("Feature has field scale factor %1").arg(fieldScale), 3);
135141
}
136142
if ( symbol->rotationClassificationField() >= 0 )
137143
{
138144
const QgsAttributeMap& attrs = f.attributeMap();
139145
rotation = attrs[symbol->rotationClassificationField()].toDouble();
140-
QgsDebugMsg(QString("Feature has rotation factor %1").arg(rotation));
146+
QgsDebugMsgLevel(QString("Feature has rotation factor %1").arg(rotation), 3);
141147
}
142148
*img = symbol->getPointSymbolAsImage( widthScale, selected, mSelectionColor,
143149
*scalefactor * fieldScale, rotation);
@@ -194,10 +200,11 @@ void QgsUniqueValueRenderer::readXML(const QDomNode& rnode, QgsVectorLayer& vl)
194200
{
195201
QgsSymbol* msy = new QgsSymbol(mVectorType);
196202
msy->readXML ( symbolnode );
197-
this->insertValue(msy->lowerValue(),msy);
203+
insertValue(msy->lowerValue(),msy);
198204
symbolnode = symbolnode.nextSibling();
199-
vl.setRenderer(this);
200205
}
206+
updateSymbolAttributes();
207+
vl.setRenderer(this);
201208
}
202209

203210
void QgsUniqueValueRenderer::clearValues()
@@ -212,8 +219,7 @@ void QgsUniqueValueRenderer::clearValues()
212219

213220
void QgsUniqueValueRenderer::updateSymbolAttributes()
214221
{
215-
// This function is only called after changing field specifier in the GUI.
216-
// Timing is not so important.
222+
mSymbolAttributesDirty = false;
217223

218224
mSymbolAttributes.clear();
219225

‎src/core/renderer/qgsuniquevaluerenderer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class CORE_EXPORT QgsUniqueValueRenderer: public QgsRenderer
4646
void updateSymbolAttributes();
4747
/**Returns the renderers name*/
4848
QString name() const;
49-
/**Inserts an entry into mEntries. The render items have to be created with the new operator and are automatically destroyed if not needed anymore*/
49+
/**Inserts an entry into mEntries. The render items have to be created with the new operator and
50+
are automatically destroyed if not needed anymore */
5051
void insertValue(QString name, QgsSymbol* symbol);
5152
/**Removes all entries from mEntries*/
5253
void clearValues();
@@ -66,6 +67,7 @@ class CORE_EXPORT QgsUniqueValueRenderer: public QgsRenderer
6667
QgsSymbol* symbolForFeature(const QgsFeature* f);
6768
/**Cached copy of all underlying symbols required attribute fields*/
6869
QgsAttributeList mSymbolAttributes;
70+
bool mSymbolAttributesDirty; // insertValue was called
6971
};
7072

7173
inline bool QgsUniqueValueRenderer::needsAttributes() const

0 commit comments

Comments
 (0)
Please sign in to comment.