[QGIS Commit] r11066 - in branches/symbology-ng-branch: python/core src/core/symbology-ng src/gui/symbology-ng src/ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Jul 14 08:31:28 EDT 2009


Author: wonder
Date: 2009-07-14 08:31:27 -0400 (Tue, 14 Jul 2009)
New Revision: 11066

Modified:
   branches/symbology-ng-branch/python/core/symbology-ng-core.sip
   branches/symbology-ng-branch/src/core/symbology-ng/qgsrendererv2.cpp
   branches/symbology-ng-branch/src/core/symbology-ng/qgsrendererv2.h
   branches/symbology-ng-branch/src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp
   branches/symbology-ng-branch/src/gui/symbology-ng/qgsrendererv2propertiesdialog.h
   branches/symbology-ng-branch/src/ui/qgsrendererv2propsdialogbase.ui
Log:
Corrected renderer assignment in the renderer properties dialog.


Modified: branches/symbology-ng-branch/python/core/symbology-ng-core.sip
===================================================================
--- branches/symbology-ng-branch/python/core/symbology-ng-core.sip	2009-07-14 11:19:36 UTC (rev 11065)
+++ branches/symbology-ng-branch/python/core/symbology-ng-core.sip	2009-07-14 12:31:27 UTC (rev 11066)
@@ -53,7 +53,8 @@
 	
 	virtual QString dump();
 
-	
+  virtual QgsFeatureRendererV2* clone()=0 /Factory/;
+
   void renderFeature(QgsFeature& feature, QgsRenderContext& context, int layer = -1);
 
   QgsSymbolV2LevelOrder& symbolLevels();
@@ -88,6 +89,10 @@
 
   QgsSymbolV2* symbol() const;
   void setSymbol(QgsSymbolV2* s /Transfer/);
+
+  virtual QString dump();
+
+  virtual QgsFeatureRendererV2* clone() /Factory/;
 };
 
 //////////
@@ -114,6 +119,7 @@
   void setSymbol(QgsSymbolV2* s /Transfer/);
   void setLabel(QString label);
   
+  QString dump();
 };
 
 typedef QList<QgsRendererCategoryV2> QgsCategoryList;
@@ -138,6 +144,10 @@
 	
 	virtual QList<int> usedAttributes();
   
+  virtual QString dump();
+
+  virtual QgsFeatureRendererV2* clone() /Factory/;
+
   const QgsCategoryList& categories();
   
   //! return index of category with specified value (-1 if not found)
@@ -179,6 +189,8 @@
 
   void setSymbol(QgsSymbolV2* s /Transfer/);
   void setLabel(QString label);
+
+  QString dump();
 };
 
 typedef QList<QgsRendererRangeV2> QgsRangeList;
@@ -202,6 +214,10 @@
 
   virtual QList<int> usedAttributes();
 
+  virtual QString dump();
+
+  virtual QgsFeatureRendererV2* clone() /Factory/;
+
   int attributeIndex() const;
   void setAttributeIndex(int attr);
 

Modified: branches/symbology-ng-branch/src/core/symbology-ng/qgsrendererv2.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/symbology-ng/qgsrendererv2.cpp	2009-07-14 11:19:36 UTC (rev 11065)
+++ branches/symbology-ng-branch/src/core/symbology-ng/qgsrendererv2.cpp	2009-07-14 12:31:27 UTC (rev 11066)
@@ -241,7 +241,6 @@
   return "UNKNOWN RENDERER\n";
 }
 
-
 ///////////////////
 
 QgsSingleSymbolRendererV2::QgsSingleSymbolRendererV2(QgsSymbolV2* symbol)
@@ -291,6 +290,12 @@
   return QString("SINGLE: %1").arg(mSymbol->dump());
 }
 
+QgsFeatureRendererV2* QgsSingleSymbolRendererV2::clone()
+{
+  QgsSingleSymbolRendererV2* r = new QgsSingleSymbolRendererV2( mSymbol->clone() );
+  r->setSymbolLevels( symbolLevels() );
+  return r;
+}
 
 ///////////////////
 
@@ -480,7 +485,14 @@
   return s;
 }
 
+QgsFeatureRendererV2* QgsCategorizedSymbolRendererV2::clone()
+{
+  QgsCategorizedSymbolRendererV2* r = new QgsCategorizedSymbolRendererV2( mAttrNum, mCategories );
+  r->setSymbolLevels( symbolLevels() );
+  return r;
+}
 
+
 /////////////////////////
 // graduated
 
@@ -534,6 +546,10 @@
   mLabel = label;
 }
 
+QString QgsRendererRangeV2::dump()
+{
+  return QString("%1 - %2::%3::%4\n").arg(mLowerValue).arg(mUpperValue).arg(mLabel).arg(mSymbol->dump());
+}
 
 ///////////
 
@@ -612,7 +628,22 @@
   return true;
 }
 
+QString QgsGraduatedSymbolRendererV2::dump()
+{
+  QString s = QString("GRADUATED: idx %1\n").arg(mAttrNum);
+  for (int i=0; i<mRanges.count();i++)
+    s += mRanges[i].dump();
+  return s;
+}
 
+QgsFeatureRendererV2* QgsGraduatedSymbolRendererV2::clone()
+{
+  QgsGraduatedSymbolRendererV2* r = new QgsGraduatedSymbolRendererV2( mAttrNum, mRanges );
+  r->setSymbolLevels( symbolLevels() );
+  return r;
+}
+
+
 static QList<double> _calcEqualIntervalBreaks(double minimum, double maximum, int classes)
 {
   double step = (maximum - minimum) / classes;

Modified: branches/symbology-ng-branch/src/core/symbology-ng/qgsrendererv2.h
===================================================================
--- branches/symbology-ng-branch/src/core/symbology-ng/qgsrendererv2.h	2009-07-14 11:19:36 UTC (rev 11065)
+++ branches/symbology-ng-branch/src/core/symbology-ng/qgsrendererv2.h	2009-07-14 12:31:27 UTC (rev 11066)
@@ -61,6 +61,8 @@
 	virtual QList<int> usedAttributes()=0;
 	
 	virtual ~QgsFeatureRendererV2() {}
+
+  virtual QgsFeatureRendererV2* clone()=0;
 	
   void renderFeature(QgsFeature& feature, QgsRenderContext& context, int layer = -1);
 
@@ -101,6 +103,8 @@
 
   virtual QString dump();
 
+  virtual QgsFeatureRendererV2* clone();
+
 protected:
 	QgsSymbolV2* mSymbol;
 };
@@ -154,6 +158,8 @@
   
   virtual QString dump();
 
+  virtual QgsFeatureRendererV2* clone();
+
   const QgsCategoryList& categories() { return mCategories; }
   
   //! return index of category with specified value (-1 if not found)
@@ -200,6 +206,9 @@
   void setSymbol(QgsSymbolV2* s);
   void setLabel(QString label);
 
+  // debugging
+  QString dump();
+
 protected:
   double mLowerValue, mUpperValue;
   QgsSymbolV2* mSymbol;
@@ -225,7 +234,11 @@
   virtual void stopRender(QgsRenderContext& context);
 	
   virtual QList<int> usedAttributes();
-  
+
+  virtual QString dump();
+
+  virtual QgsFeatureRendererV2* clone();
+
   int attributeIndex() const { return mAttrNum; }
   void setAttributeIndex(int attr) { mAttrNum = attr; }
   

Modified: branches/symbology-ng-branch/src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp
===================================================================
--- branches/symbology-ng-branch/src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp	2009-07-14 11:19:36 UTC (rev 11065)
+++ branches/symbology-ng-branch/src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp	2009-07-14 12:31:27 UTC (rev 11066)
@@ -28,9 +28,13 @@
     mLayer->setRendererV2(new QgsSingleSymbolRendererV2( createDefaultSymbol() ));
     mLayer->setUsingRendererV2(true);
   }
+
+  mRenderer = mLayer->rendererV2()->clone();
   
   setupUi(this);
 
+  connect(buttonBox, SIGNAL(accepted()), this, SLOT(onOK()));
+
   connect(btnSymbolLevels, SIGNAL(clicked()), this, SLOT(symbolLevels()));
 
   connect(radSingleSymbol, SIGNAL(clicked()), this, SLOT(updateRenderer()));
@@ -83,28 +87,34 @@
 
 QgsRendererV2PropertiesDialog::~QgsRendererV2PropertiesDialog()
 {
-  //delete mGraduatedSymbol;
+  // delete the temporary renderer (if exists)
+  delete mRenderer;
 }
 
+void QgsRendererV2PropertiesDialog::onOK()
+{
+  mLayer->setRendererV2(mRenderer);
+  mRenderer = NULL;
+
+  accept();
+}
+
 QgsSingleSymbolRendererV2* QgsRendererV2PropertiesDialog::rendererSingle()
 {
-  QgsFeatureRendererV2* r = mLayer->rendererV2();
-  Q_ASSERT(r != NULL && r->type() == QgsFeatureRendererV2::RendererSingleSymbol);
-  return static_cast<QgsSingleSymbolRendererV2*>(r);
+  Q_ASSERT(mRenderer != NULL && mRenderer->type() == QgsFeatureRendererV2::RendererSingleSymbol);
+  return static_cast<QgsSingleSymbolRendererV2*>(mRenderer);
 }
 
 QgsCategorizedSymbolRendererV2* QgsRendererV2PropertiesDialog::rendererCategorized()
 {
-  QgsFeatureRendererV2* r = mLayer->rendererV2();
-  Q_ASSERT(r != NULL && r->type() == QgsFeatureRendererV2::RendererCategorizedSymbol);
-  return static_cast<QgsCategorizedSymbolRendererV2*>(r);
+  Q_ASSERT(mRenderer != NULL && mRenderer->type() == QgsFeatureRendererV2::RendererCategorizedSymbol);
+  return static_cast<QgsCategorizedSymbolRendererV2*>(mRenderer);
 }
 
 QgsGraduatedSymbolRendererV2* QgsRendererV2PropertiesDialog::rendererGraduated()
 {
-  QgsFeatureRendererV2* r = mLayer->rendererV2();
-  Q_ASSERT(r != NULL && r->type() == QgsFeatureRendererV2::RendererGraduatedSymbol);
-  return static_cast<QgsGraduatedSymbolRendererV2*>(r);
+  Q_ASSERT(mRenderer != NULL && mRenderer->type() == QgsFeatureRendererV2::RendererGraduatedSymbol);
+  return static_cast<QgsGraduatedSymbolRendererV2*>(mRenderer);
 }
 
 void QgsRendererV2PropertiesDialog::changeSingleSymbol()
@@ -125,12 +135,14 @@
 
 void QgsRendererV2PropertiesDialog::updateRenderer()
 {
+  delete mRenderer;
+
   if (radSingleSymbol->isChecked())
-    mLayer->setRendererV2( new QgsSingleSymbolRendererV2( createDefaultSymbol() ) );
+    mRenderer = new QgsSingleSymbolRendererV2( createDefaultSymbol() );
   else if (radCategorized->isChecked())
-    mLayer->setRendererV2( new QgsCategorizedSymbolRendererV2(-1, QgsCategoryList()) );
+    mRenderer = new QgsCategorizedSymbolRendererV2(-1, QgsCategoryList());
   else if (radGraduated->isChecked())
-    mLayer->setRendererV2( new QgsGraduatedSymbolRendererV2(-1, QgsRangeList()) );
+    mRenderer = new QgsGraduatedSymbolRendererV2(-1, QgsRangeList());
   else
     Q_ASSERT(false);
     
@@ -139,7 +151,7 @@
 
 void QgsRendererV2PropertiesDialog::updateUiFromRenderer()
 {
-  switch (mLayer->rendererV2()->type())
+  switch (mRenderer->type())
   {
     case QgsFeatureRendererV2::RendererSingleSymbol:
       radSingleSymbol->setChecked(true);
@@ -354,7 +366,8 @@
   */
       
   // recreate renderer
-  mLayer->setRendererV2(new QgsCategorizedSymbolRendererV2(idx, cats));
+  delete mRenderer;
+  mRenderer = new QgsCategorizedSymbolRendererV2(idx, cats);
   
   populateCategories();
 }
@@ -443,7 +456,8 @@
       mLayer, idx, classes, mode, mGraduatedSymbol, ramp);
   r->setMode(mode);
   
-  mLayer->setRendererV2(r);
+  delete mRenderer;
+  mRenderer = r;
   
   populateRanges();
 }
@@ -536,7 +550,7 @@
 {
   QgsSymbolV2List symbols;
 
-  switch (mLayer->rendererV2()->type())
+  switch (mRenderer->type())
   {
     case QgsFeatureRendererV2::RendererSingleSymbol:
     {
@@ -575,10 +589,9 @@
       break;
   }
 
-  // TODO: get symbol level order from layer!
-  QgsSymbolLevelsV2Dialog dlg(symbols, mLayer->rendererV2()->symbolLevels(), this);
+  QgsSymbolLevelsV2Dialog dlg(symbols, mRenderer->symbolLevels(), this);
   if (dlg.exec())
   {
-    mLayer->rendererV2()->setSymbolLevels( dlg.levels() );
+    mRenderer->setSymbolLevels( dlg.levels() );
   }
 }

Modified: branches/symbology-ng-branch/src/gui/symbology-ng/qgsrendererv2propertiesdialog.h
===================================================================
--- branches/symbology-ng-branch/src/gui/symbology-ng/qgsrendererv2propertiesdialog.h	2009-07-14 11:19:36 UTC (rev 11065)
+++ branches/symbology-ng-branch/src/gui/symbology-ng/qgsrendererv2propertiesdialog.h	2009-07-14 12:31:27 UTC (rev 11066)
@@ -7,6 +7,8 @@
 class QgsVectorLayer;
 class QgsStyleV2;
 class QgsSymbolV2;
+
+class QgsFeatureRendererV2;
 class QgsSingleSymbolRendererV2;
 class QgsCategorizedSymbolRendererV2;
 class QgsGraduatedSymbolRendererV2;
@@ -36,6 +38,8 @@
 
   void symbolLevels();
 
+  void onOK();
+
 protected:
   
   //! update UI to reflect changes in renderer
@@ -73,6 +77,9 @@
   QgsCategorizedSymbolRendererV2* rendererCategorized();
   QgsGraduatedSymbolRendererV2* rendererGraduated();
   
+  //! temporary renderer in current dialog
+  QgsFeatureRendererV2* mRenderer;
+
   QgsVectorLayer* mLayer;
   
   QgsStyleV2* mStyle;

Modified: branches/symbology-ng-branch/src/ui/qgsrendererv2propsdialogbase.ui
===================================================================
--- branches/symbology-ng-branch/src/ui/qgsrendererv2propsdialogbase.ui	2009-07-14 11:19:36 UTC (rev 11065)
+++ branches/symbology-ng-branch/src/ui/qgsrendererv2propsdialogbase.ui	2009-07-14 12:31:27 UTC (rev 11066)
@@ -465,29 +465,13 @@
  <connections>
   <connection>
    <sender>buttonBox</sender>
-   <signal>accepted()</signal>
-   <receiver>QgsRendererV2PropsDialogBase</receiver>
-   <slot>accept()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>248</x>
-     <y>254</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>157</x>
-     <y>274</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
-   <sender>buttonBox</sender>
    <signal>rejected()</signal>
    <receiver>QgsRendererV2PropsDialogBase</receiver>
    <slot>reject()</slot>
    <hints>
     <hint type="sourcelabel">
-     <x>316</x>
-     <y>260</y>
+     <x>325</x>
+     <y>388</y>
     </hint>
     <hint type="destinationlabel">
      <x>286</x>



More information about the QGIS-commit mailing list