[QGIS Commit] r11050 - in branches/symbology-ng-branch/src: core/pal plugins/labeling

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Jul 12 09:38:43 EDT 2009


Author: wonder
Date: 2009-07-12 09:38:42 -0400 (Sun, 12 Jul 2009)
New Revision: 11050

Modified:
   branches/symbology-ng-branch/src/core/pal/feature.cpp
   branches/symbology-ng-branch/src/core/pal/layer.cpp
   branches/symbology-ng-branch/src/core/pal/layer.h
   branches/symbology-ng-branch/src/core/pal/pal.h
   branches/symbology-ng-branch/src/plugins/labeling/labelinggui.cpp
   branches/symbology-ng-branch/src/plugins/labeling/labelingguibase.ui
   branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp
   branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h
Log:
Added support to put labels above, below or on the line (or any combination).
The orientation above/below is determined from the map orientation or line direction (left/right side).


Modified: branches/symbology-ng-branch/src/core/pal/feature.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/feature.cpp	2009-07-12 12:15:01 UTC (rev 11049)
+++ branches/symbology-ng-branch/src/core/pal/feature.cpp	2009-07-12 13:38:42 UTC (rev 11050)
@@ -372,6 +372,11 @@
     double alpha;
     double cost;
 
+    unsigned long flags = layer->getArrangementFlags();
+    if ( flags == 0 )
+      flags = FLAG_ON_LINE; // default flag
+    bool reversed = false;
+
     //LinkedList<PointSet*> *shapes_final;
 
     //shapes_final     = new LinkedList<PointSet*>(ptrPSetCompare);
@@ -476,10 +481,18 @@
 #ifdef _DEBUG_FULL_
       std::cout << "  Create new label" << std::endl;
 #endif
-      if ( layer->arrangement == P_LINE_AROUND )
+      if ( layer->arrangement == P_LINE )
       {
-        positions->push_back( new LabelPosition( i, bx + cos( beta ) *distlabel , by + sin( beta ) *distlabel, xrm, yrm, alpha, cost, this ) ); // Line
-        positions->push_back( new LabelPosition( i, bx - cos( beta ) * ( distlabel + yrm ) , by - sin( beta ) * ( distlabel + yrm ), xrm, yrm, alpha, cost, this ) ); // Line
+        std::cout << alpha*180/M_PI << std::endl;
+        if ( flags & FLAG_MAP_ORIENTATION )
+          reversed = ( alpha >= M_PI/2 || alpha < -M_PI/2 );
+
+        if ( (!reversed && (flags & FLAG_ABOVE_LINE)) || (reversed && (flags & FLAG_BELOW_LINE)) )
+          positions->push_back( new LabelPosition( i, bx + cos( beta ) *distlabel , by + sin( beta ) *distlabel, xrm, yrm, alpha, cost, this ) ); // Line
+        if ( (!reversed && (flags & FLAG_BELOW_LINE)) || (reversed && (flags & FLAG_ABOVE_LINE)) )
+          positions->push_back( new LabelPosition( i, bx - cos( beta ) * ( distlabel + yrm ) , by - sin( beta ) * ( distlabel + yrm ), xrm, yrm, alpha, cost, this ) ); // Line
+        if ( flags & FLAG_ON_LINE )
+          positions->push_back( new LabelPosition( i, bx - yrm*cos( beta ) / 2, by - yrm*sin( beta ) / 2, xrm, yrm, alpha, cost, this ) ); // Line
       }
       else if (layer->arrangement == P_HORIZ)
       {
@@ -488,7 +501,7 @@
       }
       else
       {
-        positions->push_back( new LabelPosition( i, bx - yrm*cos( beta ) / 2, by - yrm*sin( beta ) / 2, xrm, yrm, alpha, cost, this ) ); // Line
+        // an invalid arrangement?
       }
 
       l += dist;
@@ -846,7 +859,6 @@
               nbp = setPositionForPoint( cx, cy, scale, lPos, delta );
             break;
           case P_LINE:
-          case P_LINE_AROUND:
             nbp = setPositionForLine( scale, lPos, mapShape, delta );
             break;
           default:

Modified: branches/symbology-ng-branch/src/core/pal/layer.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/layer.cpp	2009-07-12 12:15:01 UTC (rev 11049)
+++ branches/symbology-ng-branch/src/core/pal/layer.cpp	2009-07-12 13:38:42 UTC (rev 11050)
@@ -57,7 +57,11 @@
 namespace pal
 {
 
-  Layer::Layer( const char *lyrName, double min_scale, double max_scale, Arrangement arrangement, Units label_unit, double defaultPriority, bool obstacle, bool active, bool toLabel, Pal *pal ) :  pal( pal ), obstacle( obstacle ), active( active ), toLabel( toLabel ), label_unit( label_unit ), min_scale( min_scale ), max_scale( max_scale ), arrangement( arrangement )
+  Layer::Layer( const char *lyrName, double min_scale, double max_scale, Arrangement arrangement, Units label_unit, double defaultPriority, bool obstacle, bool active, bool toLabel, Pal *pal )
+      :  pal( pal ), obstacle( obstacle ), active( active ),
+         toLabel( toLabel ), label_unit( label_unit ),
+         min_scale( min_scale ), max_scale( max_scale ),
+         arrangement( arrangement ), arrangementFlags( 0 )
   {
 
     this->name = new char[strlen( lyrName ) +1];

Modified: branches/symbology-ng-branch/src/core/pal/layer.h
===================================================================
--- branches/symbology-ng-branch/src/core/pal/layer.h	2009-07-12 12:15:01 UTC (rev 11049)
+++ branches/symbology-ng-branch/src/core/pal/layer.h	2009-07-12 13:38:42 UTC (rev 11050)
@@ -95,6 +95,9 @@
 
       Arrangement arrangement;
 
+      /** optional flags used for some placement methods */
+      unsigned long arrangementFlags;
+
       // indexes (spatial and id)
       RTree<Feature*, double, 2, double, 8, 4> *rtree;
       HashTable<Cell<Feature*>*> *hashtable;
@@ -166,6 +169,9 @@
        */
       void setArrangement( Arrangement arrangement );
 
+      unsigned long getArrangementFlags() const { return arrangementFlags; }
+      void setArrangementFlags( unsigned long flags ) { arrangementFlags = flags; }
+
       /**
        * \brief get units for label size
        */

Modified: branches/symbology-ng-branch/src/core/pal/pal.h
===================================================================
--- branches/symbology-ng-branch/src/core/pal/pal.h	2009-07-12 12:15:01 UTC (rev 11049)
+++ branches/symbology-ng-branch/src/core/pal/pal.h	2009-07-12 13:38:42 UTC (rev 11050)
@@ -101,13 +101,20 @@
     P_POINT_OVER, /** arranges candidates over a point (centroid for polygon)*/
     P_LINE, /**< Only for lines and polygons, arranges candidates over the line or the polygon perimeter */
     P_HORIZ, /**< Only for polygon, arranges candidates horizontaly */
-    P_FREE, /**< Only for polygon, arranges candidates with respect of polygon orientation */
-    P_LINE_AROUND /**< Only for lines and polygons, arranges candidates above and below the line or the polygon perimeter */
+    P_FREE /**< Only for polygon, arranges candidates with respect of polygon orientation */
   };
 
   /** typedef for _arrangement enumeration */
   typedef enum _arrangement Arrangement;
 
+  /** enumeration line arrangement flags. Flags can be combined. */
+  enum LineArrangementFlags
+  {
+    FLAG_ON_LINE     = 1,
+    FLAG_ABOVE_LINE  = 2,
+    FLAG_BELOW_LINE  = 4,
+    FLAG_MAP_ORIENTATION = 8
+  };
 
   /**
    *  \brief Pal main class.

Modified: branches/symbology-ng-branch/src/plugins/labeling/labelinggui.cpp
===================================================================
--- branches/symbology-ng-branch/src/plugins/labeling/labelinggui.cpp	2009-07-12 12:15:01 UTC (rev 11049)
+++ branches/symbology-ng-branch/src/plugins/labeling/labelinggui.cpp	2009-07-12 13:38:42 UTC (rev 11050)
@@ -80,17 +80,18 @@
         radOverPoint->setChecked(true);
         radOverCentroid->setChecked(true);
         break;
-      case LayerSettings::AroundLine:
-      case LayerSettings::OnLine:
+      case LayerSettings::Line:
         radLineParallel->setChecked(true);
         radPolygonPerimeter->setChecked(true);
-        if ( lyr.placement == LayerSettings::AroundLine )
-        {
-          radAroundLine->setChecked(true);
-          spinDistLine->setValue(lyr.dist);
-        }
+
+        spinDistLine->setValue(lyr.dist);
+        chkLineAbove->setChecked( lyr.placementFlags & LayerSettings::AboveLine );
+        chkLineBelow->setChecked( lyr.placementFlags & LayerSettings::BelowLine );
+        chkLineOn->setChecked( lyr.placementFlags & LayerSettings::OnLine );
+        if ( lyr.placementFlags & LayerSettings::MapOrientation )
+          radOrientationMap->setChecked(true);
         else
-          radOnLine->setChecked(true);
+          radOrientationLine->setChecked(true);
         break;
       case LayerSettings::Horizontal:
         radPolygonHorizontal->setChecked(true);
@@ -167,6 +168,7 @@
   lyr.fieldName = cboFieldName->currentText();
 
   lyr.dist = 0;
+  lyr.placementFlags = 0;
 
   if ( (stackedPlacement->currentWidget() == pagePoint && radAroundPoint->isChecked())
     || (stackedPlacement->currentWidget() == pagePolygon && radAroundCentroid->isChecked()) )
@@ -183,13 +185,17 @@
   else if ( (stackedPlacement->currentWidget() == pageLine && radLineParallel->isChecked())
     || (stackedPlacement->currentWidget() == pagePolygon && radPolygonPerimeter->isChecked()) )
   {
-    if (radAroundLine->isChecked())
-    {
-      lyr.placement = LayerSettings::AroundLine;
-      lyr.dist = spinDistLine->value();
-    }
-    else
-      lyr.placement = LayerSettings::OnLine;
+    lyr.placement = LayerSettings::Line;
+    lyr.dist = spinDistLine->value();
+    if (chkLineAbove->isChecked())
+      lyr.placementFlags |= LayerSettings::AboveLine;
+    if (chkLineBelow->isChecked())
+      lyr.placementFlags |= LayerSettings::BelowLine;
+    if (chkLineOn->isChecked())
+      lyr.placementFlags |= LayerSettings::OnLine;
+
+    if (radOrientationMap->isChecked())
+      lyr.placementFlags |= LayerSettings::MapOrientation;
   }
   else if ( (stackedPlacement->currentWidget() == pageLine && radLineHorizontal->isChecked())
     || (stackedPlacement->currentWidget() == pagePolygon && radPolygonHorizontal->isChecked()) )

Modified: branches/symbology-ng-branch/src/plugins/labeling/labelingguibase.ui
===================================================================
--- branches/symbology-ng-branch/src/plugins/labeling/labelingguibase.ui	2009-07-12 12:15:01 UTC (rev 11049)
+++ branches/symbology-ng-branch/src/plugins/labeling/labelingguibase.ui	2009-07-12 13:38:42 UTC (rev 11050)
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>454</width>
-    <height>514</height>
+    <height>526</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -175,7 +175,7 @@
       <item>
        <widget class="QStackedWidget" name="stackedOptions">
         <property name="currentIndex">
-         <number>0</number>
+         <number>1</number>
         </property>
         <widget class="QWidget" name="pageOptionsPoint">
          <layout class="QGridLayout" name="gridLayout_2">
@@ -232,9 +232,9 @@
         <widget class="QWidget" name="pageOptionsLine">
          <layout class="QVBoxLayout" name="verticalLayout_5">
           <item>
-           <widget class="QRadioButton" name="radOnLine">
+           <widget class="QCheckBox" name="chkLineAbove">
             <property name="text">
-             <string>on line</string>
+             <string>above line</string>
             </property>
             <property name="checked">
              <bool>true</bool>
@@ -242,13 +242,48 @@
            </widget>
           </item>
           <item>
-           <widget class="QRadioButton" name="radAroundLine">
+           <widget class="QCheckBox" name="chkLineOn">
             <property name="text">
-             <string>around line</string>
+             <string>on line</string>
             </property>
            </widget>
           </item>
           <item>
+           <widget class="QCheckBox" name="chkLineBelow">
+            <property name="text">
+             <string>below line</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <layout class="QHBoxLayout" name="horizontalLayout_7">
+            <item>
+             <widget class="QLabel" name="label">
+              <property name="text">
+               <string>Orientation</string>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QRadioButton" name="radOrientationMap">
+              <property name="text">
+               <string>map</string>
+              </property>
+              <property name="checked">
+               <bool>true</bool>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QRadioButton" name="radOrientationLine">
+              <property name="text">
+               <string>line</string>
+              </property>
+             </widget>
+            </item>
+           </layout>
+          </item>
+          <item>
            <layout class="QHBoxLayout" name="horizontalLayout_3">
             <item>
              <widget class="QLabel" name="label_16">
@@ -693,8 +728,6 @@
   <tabstop>radPolygonFree</tabstop>
   <tabstop>spinDistPoint</tabstop>
   <tabstop>spinAngle</tabstop>
-  <tabstop>radOnLine</tabstop>
-  <tabstop>radAroundLine</tabstop>
   <tabstop>spinDistLine</tabstop>
   <tabstop>btnChangeFont</tabstop>
   <tabstop>btnTextColor</tabstop>

Modified: branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp
===================================================================
--- branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp	2009-07-12 12:15:01 UTC (rev 11049)
+++ branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp	2009-07-12 13:38:42 UTC (rev 11050)
@@ -77,6 +77,7 @@
   layerId = s.layerId;
   fieldName = s.fieldName;
   placement = s.placement;
+  placementFlags = s.placementFlags;
   textFont = s.textFont;
   textColor = s.textColor;
   enabled = s.enabled;
@@ -239,9 +240,8 @@
   switch (lyr->placement)
   {
     case LayerSettings::AroundPoint: arrangement = P_POINT; break;
-    case LayerSettings::OverPoint: arrangement = P_POINT_OVER; break;
-    case LayerSettings::OnLine:      arrangement = P_LINE; break;
-    case LayerSettings::AroundLine:  arrangement = P_LINE_AROUND; break;
+    case LayerSettings::OverPoint:   arrangement = P_POINT_OVER; break;
+    case LayerSettings::Line:        arrangement = P_LINE; break;
     case LayerSettings::Horizontal:  arrangement = P_HORIZ; break;
     case LayerSettings::Free:        arrangement = P_FREE; break;
   }
@@ -257,6 +257,9 @@
 
   Layer* l = thisClass->mPal->addLayer(lyr->layerId.toLocal8Bit().data(), min_scale, max_scale, arrangement, METER, priority, lyr->obstacle, true, true);
 
+  if ( lyr->placementFlags )
+    l->setArrangementFlags( lyr->placementFlags );
+
   // save the pal layer to our layer context (with some additional info)
   lyr->palLayer = l;
   lyr->fieldIndex = fldIndex;

Modified: branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h
===================================================================
--- branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h	2009-07-12 12:15:01 UTC (rev 11049)
+++ branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h	2009-07-12 13:38:42 UTC (rev 11050)
@@ -35,15 +35,23 @@
   {
     AroundPoint, // Point / Polygon
     OverPoint, // Point / Polygon
-    OnLine, // Line / Polygon
-    AroundLine, // Line / Polygon
+    Line, // Line / Polygon
     Horizontal, // Polygon
     Free // Polygon
   };
 
+  enum LinePlacementFlags
+  {
+    OnLine    = 1,
+    AboveLine = 2,
+    BelowLine = 4,
+    MapOrientation = 8
+  };
+
   QString layerId;
   QString fieldName;
   Placement placement;
+  unsigned long placementFlags;
   QFont textFont;
   QColor textColor;
   bool enabled;



More information about the QGIS-commit mailing list