[QGIS Commit] r10185 - branches/vector_overlay_branch/src/plugins/diagram_overlay

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Feb 17 07:22:25 EST 2009


Author: mhugent
Date: 2009-02-17 07:22:25 -0500 (Tue, 17 Feb 2009)
New Revision: 10185

Modified:
   branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramdialog.cpp
   branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramfactory.cpp
   branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramfactory.h
   branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramoverlay.cpp
   branches/vector_overlay_branch/src/plugins/diagram_overlay/qgssvgdiagramfactory.cpp
   branches/vector_overlay_branch/src/plugins/diagram_overlay/qgswkndiagramfactory.cpp
Log:
more diagram improvements

Modified: branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramdialog.cpp
===================================================================
--- branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramdialog.cpp	2009-02-17 09:05:11 UTC (rev 10184)
+++ branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramdialog.cpp	2009-02-17 12:22:25 UTC (rev 10185)
@@ -173,7 +173,7 @@
     }
 
     //attList comes from the diagram factory widget
-    QgsAttributeList attList = diagramFactory->categoryAttributes();
+    QgsAttributeList attList;
 
     QgsDiagramRenderer* diagramRenderer = 0;
     QgsDiagramFactory::SizeUnit diagramSizeUnit = QgsDiagramFactory::MM; //mm on output medium is default
@@ -195,7 +195,9 @@
     }
 
     diagramRenderer->setFactory(diagramFactory);
-    diagramFactory->setScalingAttributes(attList);
+    QgsAttributeList scalingAttributeList;
+    scalingAttributeList.push_back(classAttr);
+    diagramFactory->setScalingAttributes(scalingAttributeList);
     //also set units to the diagram factory
     diagramFactory->setSizeUnit(diagramSizeUnit);
 

Modified: branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramfactory.cpp
===================================================================
--- branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramfactory.cpp	2009-02-17 09:05:11 UTC (rev 10184)
+++ branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramfactory.cpp	2009-02-17 12:22:25 UTC (rev 10185)
@@ -46,3 +46,43 @@
 
      return 1.0;
  }
+
+ bool QgsDiagramFactory::writeScalingAttributesToXML(QDomElement& factoryElem, QDomDocument& doc) const
+ {
+    if(factoryElem.isNull())
+     {
+        return false;
+    }
+
+     QgsAttributeList::const_iterator it = mScalingAttributes.constBegin();
+     for(; it != mScalingAttributes.constEnd(); ++it)
+     {
+        QDomElement scalingAttributeElem = doc.createElement("scalingAttribute");
+        QDomText scalingAttributeText = doc.createTextNode(QString::number(*it));
+        scalingAttributeElem.appendChild(scalingAttributeText);
+        factoryElem.appendChild(scalingAttributeElem);
+     }
+     return false;
+ }
+
+ bool QgsDiagramFactory::readScalingAttributesFromXML(const QDomElement& factoryElem)
+ {
+     if(factoryElem.isNull())
+     {
+        return false;
+     }
+
+     mScalingAttributes.clear();
+     QDomNodeList scalingAttributeList = factoryElem.elementsByTagName("scalingAttribute");
+     for(int i = 0; i < scalingAttributeList.size(); ++i)
+     {
+        QDomElement currentScalingElem = scalingAttributeList.at(i).toElement();
+        bool conversionSuccess = false;
+        int currentIndex = currentScalingElem.text().toInt(&conversionSuccess);
+        if(conversionSuccess)
+        {
+            mScalingAttributes.push_back(currentIndex);
+        }
+     }
+     return true;
+ }

Modified: branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramfactory.h
===================================================================
--- branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramfactory.h	2009-02-17 09:05:11 UTC (rev 10184)
+++ branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramfactory.h	2009-02-17 12:22:25 UTC (rev 10185)
@@ -25,6 +25,7 @@
 class QgsFeature;
 class QgsRenderContext;
 class QDomDocument;
+class QDomElement;
 class QDomNode;
 class QImage;
 
@@ -83,13 +84,10 @@
   void setSizeUnit(SizeUnit u){mSizeUnit = u;}
   SizeUnit sizeUnit() const {return mSizeUnit;}
 
-   //setters and getters for scaling attribute
+   //setters and getters for scaling attributes
   QgsAttributeList scalingAttributes() const {return mScalingAttributes;}
   void setScalingAttributes(const QgsAttributeList& att){mScalingAttributes = att;}
 
-  /**Returns the attributes represented in the pies / bars*/
-  virtual QgsAttributeList categoryAttributes() const {return QgsAttributeList();}
-
   /**Read settings from project file*/
   virtual bool readXML(const QDomNode& factoryNode) = 0;
 
@@ -98,8 +96,14 @@
   SizeUnit mSizeUnit;
 
   /**List of scaling attribute indexes (the values are summed up to
-     receive the scaling value)*/
+     receive the value that is used for diagram size calculation)*/
   QgsAttributeList mScalingAttributes;
+
+  /**Writes the scaling attributes indices to project file. Usually called from subclasses*/
+  bool writeScalingAttributesToXML(QDomElement& factoryElem, QDomDocument& doc) const;
+
+  /**Reads the scaling attributes from project file. Usually called from subclasses*/
+  bool readScalingAttributesFromXML(const QDomElement& factoryElem);
 };
 
 #endif

Modified: branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramoverlay.cpp
===================================================================
--- branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramoverlay.cpp	2009-02-17 09:05:11 UTC (rev 10184)
+++ branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramoverlay.cpp	2009-02-17 12:22:25 UTC (rev 10185)
@@ -238,7 +238,7 @@
         return false;
     }
 
-    if(!newFactory->readXML(overlayNode))
+    if(!newFactory->readXML(factoryElem))
     {
         delete newFactory;
         return false;

Modified: branches/vector_overlay_branch/src/plugins/diagram_overlay/qgssvgdiagramfactory.cpp
===================================================================
--- branches/vector_overlay_branch/src/plugins/diagram_overlay/qgssvgdiagramfactory.cpp	2009-02-17 09:05:11 UTC (rev 10184)
+++ branches/vector_overlay_branch/src/plugins/diagram_overlay/qgssvgdiagramfactory.cpp	2009-02-17 12:22:25 UTC (rev 10185)
@@ -97,12 +97,39 @@
     svgPathElem.appendChild(svgPathText);
     factoryElem.appendChild(svgPathElem);
     overlay_node.appendChild(factoryElem);
+
+    //and superclass specific information
+    writeScalingAttributesToXML(factoryElem, doc);
+
     return true;
 }
 
 bool QgsSVGDiagramFactory::readXML(const QDomNode& factoryNode)
 {
-    //soon...
+    QDomElement factoryElem = factoryNode.toElement();
+    if(factoryElem.isNull())
+    {
+        return false;
+    }
+
+    //get <svgPath> element
+    QDomElement svgPathElem = factoryElem.namedItem("svgPath").toElement();
+    if(svgPathElem.isNull())
+    {
+        return false;
+    }
+
+    QString svgFilePath = svgPathElem.text();
+    if(!mRenderer.load(svgFilePath))
+    {
+        return false;
+    }
+    mSvgFilePath = svgFilePath;
+
+    //read scaling attributes by superclass
+    readScalingAttributesFromXML(factoryElem);
+
+    return true;
 }
 
 

Modified: branches/vector_overlay_branch/src/plugins/diagram_overlay/qgswkndiagramfactory.cpp
===================================================================
--- branches/vector_overlay_branch/src/plugins/diagram_overlay/qgswkndiagramfactory.cpp	2009-02-17 09:05:11 UTC (rev 10184)
+++ branches/vector_overlay_branch/src/plugins/diagram_overlay/qgswkndiagramfactory.cpp	2009-02-17 12:22:25 UTC (rev 10185)
@@ -56,7 +56,7 @@
   QDomText wknText = doc.createTextNode(mDiagramType);
   wellKnownNameElem.appendChild(wknText);
   factoryElement.appendChild(wellKnownNameElem);
-	    
+
   //classification fields
   QList<int>::const_iterator scaling_it = mScalingAttributes.constBegin();
   for(; scaling_it != mScalingAttributes.constEnd(); ++scaling_it)
@@ -99,6 +99,9 @@
   //write subclass specific information
   _writeXML(factoryElement, doc);
 
+  //and superclass specific information
+  writeScalingAttributesToXML(factoryElement, doc);
+
   return true;
 }
 
@@ -191,5 +194,9 @@
         }
       mCategories.push_back(newCategory);
     }
+
+  //read scaling attributes by superclass
+  readScalingAttributesFromXML(factoryElem);
+
   return true;
 }



More information about the QGIS-commit mailing list