Skip to content

Commit

Permalink
speed up loading of projects using unique value renderers
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8272 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Mar 25, 2008
1 parent 256081e commit 850331f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 13 additions & 7 deletions src/core/renderer/qgsuniquevaluerenderer.cpp
Expand Up @@ -31,6 +31,7 @@
QgsUniqueValueRenderer::QgsUniqueValueRenderer(QGis::VectorType type): mClassificationField(0)
{
mVectorType = type;
mSymbolAttributesDirty = false;
}

QgsUniqueValueRenderer::QgsUniqueValueRenderer(const QgsUniqueValueRenderer& other)
Expand Down Expand Up @@ -84,7 +85,7 @@ const QList<QgsSymbol*> QgsUniqueValueRenderer::symbols() const
void QgsUniqueValueRenderer::insertValue(QString name, QgsSymbol* symbol)
{
mSymbols.insert(name, symbol);
updateSymbolAttributes();
mSymbolAttributesDirty=true;
}

void QgsUniqueValueRenderer::setClassificationField(int field)
Expand All @@ -105,6 +106,11 @@ bool QgsUniqueValueRenderer::willRenderFeature(QgsFeature *f)
void QgsUniqueValueRenderer::renderFeature(QPainter* p, QgsFeature& f,QImage* img,
double* scalefactor, bool selected, double widthScale)
{
if(mSymbolAttributesDirty) {
QgsDebugMsg("Missed updateSymbolAttributes() call - doing it now");
updateSymbolAttributes();
}

QgsSymbol* symbol = symbolForFeature(&f);
if(!symbol) //no matching symbol
{
Expand All @@ -131,13 +137,13 @@ void QgsUniqueValueRenderer::renderFeature(QPainter* p, QgsFeature& f,QImage* im
//first find out the value for the scale classification attribute
const QgsAttributeMap& attrs = f.attributeMap();
fieldScale = sqrt(fabs(attrs[symbol->scaleClassificationField()].toDouble()));
QgsDebugMsg(QString("Feature has field scale factor %1").arg(fieldScale));
QgsDebugMsgLevel(QString("Feature has field scale factor %1").arg(fieldScale), 3);
}
if ( symbol->rotationClassificationField() >= 0 )
{
const QgsAttributeMap& attrs = f.attributeMap();
rotation = attrs[symbol->rotationClassificationField()].toDouble();
QgsDebugMsg(QString("Feature has rotation factor %1").arg(rotation));
QgsDebugMsgLevel(QString("Feature has rotation factor %1").arg(rotation), 3);
}
*img = symbol->getPointSymbolAsImage( widthScale, selected, mSelectionColor,
*scalefactor * fieldScale, rotation);
Expand Down Expand Up @@ -194,10 +200,11 @@ void QgsUniqueValueRenderer::readXML(const QDomNode& rnode, QgsVectorLayer& vl)
{
QgsSymbol* msy = new QgsSymbol(mVectorType);
msy->readXML ( symbolnode );
this->insertValue(msy->lowerValue(),msy);
insertValue(msy->lowerValue(),msy);
symbolnode = symbolnode.nextSibling();
vl.setRenderer(this);
}
updateSymbolAttributes();
vl.setRenderer(this);
}

void QgsUniqueValueRenderer::clearValues()
Expand All @@ -212,8 +219,7 @@ void QgsUniqueValueRenderer::clearValues()

void QgsUniqueValueRenderer::updateSymbolAttributes()
{
// This function is only called after changing field specifier in the GUI.
// Timing is not so important.
mSymbolAttributesDirty = false;

mSymbolAttributes.clear();

Expand Down
4 changes: 3 additions & 1 deletion src/core/renderer/qgsuniquevaluerenderer.h
Expand Up @@ -46,7 +46,8 @@ class CORE_EXPORT QgsUniqueValueRenderer: public QgsRenderer
void updateSymbolAttributes();
/**Returns the renderers name*/
QString name() const;
/**Inserts an entry into mEntries. The render items have to be created with the new operator and are automatically destroyed if not needed anymore*/
/**Inserts an entry into mEntries. The render items have to be created with the new operator and
are automatically destroyed if not needed anymore */
void insertValue(QString name, QgsSymbol* symbol);
/**Removes all entries from mEntries*/
void clearValues();
Expand All @@ -66,6 +67,7 @@ class CORE_EXPORT QgsUniqueValueRenderer: public QgsRenderer
QgsSymbol* symbolForFeature(const QgsFeature* f);
/**Cached copy of all underlying symbols required attribute fields*/
QgsAttributeList mSymbolAttributes;
bool mSymbolAttributesDirty; // insertValue was called
};

inline bool QgsUniqueValueRenderer::needsAttributes() const
Expand Down

0 comments on commit 850331f

Please sign in to comment.