[QGIS Commit] r9692 - in branches/vector_overlay_branch/src: app core ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon Nov 24 05:49:09 EST 2008


Author: mhugent
Date: 2008-11-24 05:49:09 -0500 (Mon, 24 Nov 2008)
New Revision: 9692

Modified:
   branches/vector_overlay_branch/src/app/qgsoptions.cpp
   branches/vector_overlay_branch/src/app/qgsprojectproperties.cpp
   branches/vector_overlay_branch/src/core/qgsmaprenderer.cpp
   branches/vector_overlay_branch/src/core/qgsmaprenderer.h
   branches/vector_overlay_branch/src/core/qgspalobjectpositionmanager.cpp
   branches/vector_overlay_branch/src/core/qgspalobjectpositionmanager.h
   branches/vector_overlay_branch/src/ui/qgsoptionsbase.ui
   branches/vector_overlay_branch/src/ui/qgsprojectpropertiesbase.ui
Log:
Let the user select overlay object placement method

Modified: branches/vector_overlay_branch/src/app/qgsoptions.cpp
===================================================================
--- branches/vector_overlay_branch/src/app/qgsoptions.cpp	2008-11-24 10:15:34 UTC (rev 9691)
+++ branches/vector_overlay_branch/src/app/qgsoptions.cpp	2008-11-24 10:49:09 UTC (rev 9692)
@@ -190,6 +190,20 @@
 #ifdef Q_WS_MAC //MH: disable incremental update on Mac for now to avoid problems with resizing 
   groupBox_5->setEnabled( false );
 #endif //Q_WS_MAC
+
+   //overlay placement algorithm
+  mOverlayAlgorithmComboBox->insertItem(0, "Central point");
+  mOverlayAlgorithmComboBox->insertItem(1, "Chain");
+  mOverlayAlgorithmComboBox->insertItem(2, "Popmusic tabu chain");
+  mOverlayAlgorithmComboBox->insertItem(3, "Popmusic tabu");
+  mOverlayAlgorithmComboBox->insertItem(4, "Popmusic chain");
+
+  QString overlayAlgorithmString = settings.value( "qgis/overlayPlacementAlgorithm", "Central point").toString();
+  if(overlayAlgorithmString == "Chain"){mOverlayAlgorithmComboBox->setCurrentIndex(1);}
+  else if(overlayAlgorithmString == "Popmusic tabu chain"){mOverlayAlgorithmComboBox->setCurrentIndex(2);}
+  else if(overlayAlgorithmString == "Popmusic tabu"){mOverlayAlgorithmComboBox->setCurrentIndex(3);}
+  else if(overlayAlgorithmString == "Popmusic chain"){mOverlayAlgorithmComboBox->setCurrentIndex(4);}
+  else{mOverlayAlgorithmComboBox->setCurrentIndex(0);} //default is central point
 }
 
 //! Destructor
@@ -263,6 +277,7 @@
   settings.setValue( "qgis/capitaliseLayerName", capitaliseCheckBox->isChecked() );
   settings.setValue( "qgis/askToSaveProjectChanges", chbAskToSaveProjectChanges->isChecked() );
   settings.setValue( "qgis/warnOldProjectVersion", chbWarnOldProjectVersion->isChecked() );
+  settings.setValue( "qgis/overlayPlacementAlgorithm", mOverlayAlgorithmComboBox->currentText() );
 
   if ( cmbTheme->currentText().length() == 0 )
   {

Modified: branches/vector_overlay_branch/src/app/qgsprojectproperties.cpp
===================================================================
--- branches/vector_overlay_branch/src/app/qgsprojectproperties.cpp	2008-11-24 10:15:34 UTC (rev 9691)
+++ branches/vector_overlay_branch/src/app/qgsprojectproperties.cpp	2008-11-24 10:49:09 UTC (rev 9692)
@@ -163,7 +163,6 @@
       mSnappingLayerSettings.insert( *idIter, newEntry );
     }
   }
-
 }
 
 QgsProjectProperties::~QgsProjectProperties()

Modified: branches/vector_overlay_branch/src/core/qgsmaprenderer.cpp
===================================================================
--- branches/vector_overlay_branch/src/core/qgsmaprenderer.cpp	2008-11-24 10:15:34 UTC (rev 9691)
+++ branches/vector_overlay_branch/src/core/qgsmaprenderer.cpp	2008-11-24 10:49:09 UTC (rev 9692)
@@ -25,7 +25,7 @@
 #include "qgsmaplayer.h"
 #include "qgsmaplayerregistry.h"
 #include "qgsdistancearea.h"
-//#include "qgscentralpointpositionmanager.h"
+#include "qgscentralpointpositionmanager.h"
 #include "qgsoverlayobjectpositionmanager.h"
 #include "qgspalobjectpositionmanager.h"
 #include "qgsvectorlayer.h"
@@ -36,6 +36,7 @@
 #include <QDomNode>
 #include <QPainter>
 #include <QListIterator>
+#include <QSettings>
 #include <QTime>
 #include "qgslogger.h"
 
@@ -57,9 +58,6 @@
   mDestCRS = new QgsCoordinateReferenceSystem( GEO_EPSG_CRS_ID, QgsCoordinateReferenceSystem::EpsgCrsId ); //WGS 84
 
   mOutputUnits = QgsMapRenderer::Millimeters;
-
-  mOverlayPos = new QgsPALObjectPositionManager();
-  //mOverlayPos = new QgsCentralPointPositionManager();
 }
 
 QgsMapRenderer::~QgsMapRenderer()
@@ -67,7 +65,6 @@
   delete mScaleCalculator;
   delete mDistArea;
   delete mDestCRS;
-  delete mOverlayPos;
 }
 
 
@@ -137,12 +134,6 @@
   return mSize;
 }
 
- void QgsMapRenderer::setOverlayManager(QgsOverlayObjectPositionManager* m)
- {
-   delete mOverlayPos;
-   mOverlayPos = m;
- }
-
 void QgsMapRenderer::adjustExtentToSize()
 {
   int myHeight = mSize.height();
@@ -265,8 +256,9 @@
   mRenderContext.setRasterScaleFactor( rasterScaleFactor );
 
   bool placeOverlays = false;
+  QgsOverlayObjectPositionManager* overlayManager = overlayManagerFromSettings();
   QList<QgsVectorOverlay*> allOverlayList; //list of all overlays, used to draw them after layers have been rendered
-  if(mOverlayPos)
+  if(overlayManager)
   {
     placeOverlays = true;
   }
@@ -364,7 +356,7 @@
       }
 
       //create overlay objects for features within the view extent
-      if(ml->type() == QgsMapLayer::VectorLayer && mOverlayPos)
+      if(ml->type() == QgsMapLayer::VectorLayer && overlayManager)
       {
         QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>(ml);
         if(vl)
@@ -379,7 +371,7 @@
               allOverlayList.push_back(*overlayIt);
             }
 
-	    mOverlayPos->addLayer(vl, thisLayerOverlayList);
+        overlayManager->addLayer(vl, thisLayerOverlayList);
           }
       }
 
@@ -466,16 +458,17 @@
   } // if (!mOverview)
 
   //find overlay positions and draw the vector overlays
-  if(mOverlayPos)
+  if(overlayManager && allOverlayList.size() > 0)
   {
-    mOverlayPos->findObjectPositions(mRenderContext);
+    overlayManager->findObjectPositions(mRenderContext);
     //draw all the overlays
     QList<QgsVectorOverlay*>::iterator allOverlayIt = allOverlayList.begin();
     for(; allOverlayIt != allOverlayList.end(); ++allOverlayIt)
     {
       (*allOverlayIt)->drawOverlayObjects(mRenderContext);
     }
-    mOverlayPos->removeLayers();
+    overlayManager->removeLayers();
+    delete overlayManager;
   }
 
   // make sure progress bar arrives at 100%!
@@ -772,6 +765,42 @@
   return mLayerSet;
 }
 
+QgsOverlayObjectPositionManager* QgsMapRenderer::overlayManagerFromSettings()
+{
+  QSettings settings;
+  QString overlayAlgorithmQString = settings.value( "qgis/overlayPlacementAlgorithm", "Central point").toString();
+
+QgsOverlayObjectPositionManager* result = 0;
+
+  if(overlayAlgorithmQString != "Central point")
+  {
+    QgsPALObjectPositionManager* palManager = new QgsPALObjectPositionManager();
+    if(overlayAlgorithmQString == "Chain")
+    {
+      palManager->setPlacementAlgorithm("Chain");
+    }
+    else if(overlayAlgorithmQString == "Popmusic tabu chain")
+    {
+      palManager->setPlacementAlgorithm("Popmusic tabu chain");
+    }
+    else if(overlayAlgorithmQString == "Popmusic tabu")
+    {
+      palManager->setPlacementAlgorithm("Popmusic tabu");
+    }
+    else if(overlayAlgorithmQString == "Popmusic chain")
+    {
+      palManager->setPlacementAlgorithm("Popmusic chain");
+    }
+    result = palManager;
+  }
+  else
+  {
+    result = new QgsCentralPointPositionManager();
+  }
+
+  return result;
+}
+
 bool QgsMapRenderer::readXML( QDomNode & theNode )
 {
   QDomNode myNode = theNode.namedItem( "units" );

Modified: branches/vector_overlay_branch/src/core/qgsmaprenderer.h
===================================================================
--- branches/vector_overlay_branch/src/core/qgsmaprenderer.h	2008-11-24 10:15:34 UTC (rev 9691)
+++ branches/vector_overlay_branch/src/core/qgsmaprenderer.h	2008-11-24 10:49:09 UTC (rev 9692)
@@ -134,9 +134,6 @@
     //! change current layer set
     void setLayerSet( const QStringList& layers );
 
-    //! Set object containing overlay placement. Takes ownership of the passed object.
-    void setOverlayManager(QgsOverlayObjectPositionManager* m);
-
     //! updates extent of the layer set
     void updateFullExtent();
 
@@ -182,6 +179,9 @@
      */
     bool splitLayersExtent( QgsMapLayer* layer, QgsRect& extent, QgsRect& r2 );
 
+    /**Creates an overlay object position manager subclass according to the current settings*/
+    QgsOverlayObjectPositionManager* overlayManagerFromSettings();
+
   protected:
 
     //! indicates drawing in progress
@@ -224,9 +224,6 @@
 
     //!Output units
     OutputUnits mOutputUnits;
-
-    //!Arrangement of labels and diagrams
-    QgsOverlayObjectPositionManager* mOverlayPos;
 };
 
 #endif

Modified: branches/vector_overlay_branch/src/core/qgspalobjectpositionmanager.cpp
===================================================================
--- branches/vector_overlay_branch/src/core/qgspalobjectpositionmanager.cpp	2008-11-24 10:15:34 UTC (rev 9691)
+++ branches/vector_overlay_branch/src/core/qgspalobjectpositionmanager.cpp	2008-11-24 10:49:09 UTC (rev 9692)
@@ -153,3 +153,23 @@
       mPositionEngine.removeLayer(*removeIt);
   }
 }
+//Chain, Popmusic tabu chain, Popmusic tabu, Popmusic chain
+void QgsPALObjectPositionManager::setPlacementAlgorithm(const QString& algorithmName)
+{
+  if(algorithmName == "Popmusic tabu chain")
+  {
+    mPositionEngine.setSearch(pal::POPMUSIC_TABU_CHAIN);
+  }
+  else if(algorithmName == "Popmusic tabu")
+  {
+    mPositionEngine.setSearch(pal::POPMUSIC_TABU);
+  }
+  else if(algorithmName == "Popmusic chain")
+  {
+    mPositionEngine.setSearch(pal::POPMUSIC_CHAIN);
+  }
+  else //default is "Chain"
+  {
+    mPositionEngine.setSearch(pal::CHAIN);
+  }
+}

Modified: branches/vector_overlay_branch/src/core/qgspalobjectpositionmanager.h
===================================================================
--- branches/vector_overlay_branch/src/core/qgspalobjectpositionmanager.h	2008-11-24 10:15:34 UTC (rev 9691)
+++ branches/vector_overlay_branch/src/core/qgspalobjectpositionmanager.h	2008-11-24 10:49:09 UTC (rev 9692)
@@ -30,6 +30,10 @@
     void findObjectPositions(const QgsRenderContext& renderContext);
     void removeLayers();
 
+    /**Sets algorithm used for object placements. Possibilities are:
+      Chain, Popmusic tabu chain, Popmusic tabu, Popmusic chain*/
+    void setPlacementAlgorithm(const QString& algorithmName);
+
   private:
     pal::Pal mPositionEngine;
     int mNumberOfLayers;

Modified: branches/vector_overlay_branch/src/ui/qgsoptionsbase.ui
===================================================================
--- branches/vector_overlay_branch/src/ui/qgsoptionsbase.ui	2008-11-24 10:15:34 UTC (rev 9691)
+++ branches/vector_overlay_branch/src/ui/qgsoptionsbase.ui	2008-11-24 10:49:09 UTC (rev 9692)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>617</width>
-    <height>559</height>
+    <width>851</width>
+    <height>733</height>
    </rect>
   </property>
   <property name="windowTitle" >
@@ -22,6 +22,16 @@
    <bool>true</bool>
   </property>
   <layout class="QGridLayout" >
+   <item row="1" column="0" >
+    <widget class="QDialogButtonBox" name="buttonBox" >
+     <property name="orientation" >
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons" >
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
    <item row="0" column="0" >
     <widget class="QTabWidget" name="tabWidget" >
      <property name="currentIndex" >
@@ -580,6 +590,59 @@
        </item>
       </layout>
      </widget>
+     <widget class="QWidget" name="mOverlayTab" >
+      <attribute name="title" >
+       <string>Overlay</string>
+      </attribute>
+      <widget class="QGroupBox" name="mPositionGroupBox" >
+       <property name="geometry" >
+        <rect>
+         <x>10</x>
+         <y>10</y>
+         <width>801</width>
+         <height>111</height>
+        </rect>
+       </property>
+       <property name="title" >
+        <string>Position</string>
+       </property>
+       <widget class="QWidget" name="layoutWidget" >
+        <property name="geometry" >
+         <rect>
+          <x>20</x>
+          <y>40</y>
+          <width>761</width>
+          <height>42</height>
+         </rect>
+        </property>
+        <layout class="QHBoxLayout" >
+         <item>
+          <widget class="QLabel" name="mAlgorithmLabel" >
+           <property name="text" >
+            <string>Placement algorithm:</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="QComboBox" name="mOverlayAlgorithmComboBox" />
+         </item>
+         <item>
+          <spacer>
+           <property name="orientation" >
+            <enum>Qt::Horizontal</enum>
+           </property>
+           <property name="sizeHint" >
+            <size>
+             <width>221</width>
+             <height>20</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
+        </layout>
+       </widget>
+      </widget>
+     </widget>
      <widget class="QWidget" name="tabDigitizing" >
       <attribute name="title" >
        <string>Digitizing</string>
@@ -1045,16 +1108,6 @@
      </widget>
     </widget>
    </item>
-   <item row="1" column="0" >
-    <widget class="QDialogButtonBox" name="buttonBox" >
-     <property name="orientation" >
-      <enum>Qt::Horizontal</enum>
-     </property>
-     <property name="standardButtons" >
-      <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
-     </property>
-    </widget>
-   </item>
   </layout>
  </widget>
  <layoutdefault spacing="6" margin="11" />

Modified: branches/vector_overlay_branch/src/ui/qgsprojectpropertiesbase.ui
===================================================================
--- branches/vector_overlay_branch/src/ui/qgsprojectpropertiesbase.ui	2008-11-24 10:15:34 UTC (rev 9691)
+++ branches/vector_overlay_branch/src/ui/qgsprojectpropertiesbase.ui	2008-11-24 10:49:09 UTC (rev 9692)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>452</width>
-    <height>495</height>
+    <width>536</width>
+    <height>713</height>
    </rect>
   </property>
   <property name="windowTitle" >
@@ -323,16 +323,16 @@
  <layoutdefault spacing="6" margin="11" />
  <customwidgets>
   <customwidget>
+   <class>QgsColorButton</class>
+   <extends>QToolButton</extends>
+   <header>qgscolorbutton.h</header>
+  </customwidget>
+  <customwidget>
    <class>QgsProjectionSelector</class>
    <extends>QWidget</extends>
    <header>qgsprojectionselector.h</header>
    <container>1</container>
   </customwidget>
-  <customwidget>
-   <class>QgsColorButton</class>
-   <extends>QToolButton</extends>
-   <header>qgscolorbutton.h</header>
-  </customwidget>
  </customwidgets>
  <tabstops>
   <tabstop>titleEdit</tabstop>



More information about the QGIS-commit mailing list