[QGIS Commit] r8272 - trunk/qgis/src/core/renderer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Mar 25 16:19:53 EDT 2008


Author: jef
Date: 2008-03-25 16:19:53 -0400 (Tue, 25 Mar 2008)
New Revision: 8272

Modified:
   trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.cpp
   trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.h
Log:
speed up loading of projects using unique value renderers

Modified: trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.cpp
===================================================================
--- trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.cpp	2008-03-25 20:16:03 UTC (rev 8271)
+++ trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.cpp	2008-03-25 20:19:53 UTC (rev 8272)
@@ -31,6 +31,7 @@
 QgsUniqueValueRenderer::QgsUniqueValueRenderer(QGis::VectorType type): mClassificationField(0)
 {
   mVectorType = type;
+  mSymbolAttributesDirty = false;
 }
 
 QgsUniqueValueRenderer::QgsUniqueValueRenderer(const QgsUniqueValueRenderer& other)
@@ -84,7 +85,7 @@
 void QgsUniqueValueRenderer::insertValue(QString name, QgsSymbol* symbol)
 {
   mSymbols.insert(name, symbol);
-  updateSymbolAttributes();
+  mSymbolAttributesDirty=true;
 }
 
 void QgsUniqueValueRenderer::setClassificationField(int field)
@@ -105,6 +106,11 @@
 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
   {
@@ -131,13 +137,13 @@
       //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);
@@ -194,10 +200,11 @@
   {
     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()
@@ -212,8 +219,7 @@
 
 void QgsUniqueValueRenderer::updateSymbolAttributes()
 {
-  // This function is only called after changing field specifier in the GUI.
-  // Timing is not so important.
+  mSymbolAttributesDirty = false;
 
   mSymbolAttributes.clear();
 

Modified: trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.h
===================================================================
--- trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.h	2008-03-25 20:16:03 UTC (rev 8271)
+++ trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.h	2008-03-25 20:19:53 UTC (rev 8272)
@@ -46,7 +46,8 @@
     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();
@@ -66,6 +67,7 @@
     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



More information about the QGIS-commit mailing list