[QGIS Commit] r15176 - in trunk/qgis/src: app core ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed Feb 16 04:11:48 EST 2011


Author: mhugent
Date: 2011-02-16 01:11:48 -0800 (Wed, 16 Feb 2011)
New Revision: 15176

Modified:
   trunk/qgis/src/app/qgslabelinggui.cpp
   trunk/qgis/src/core/qgspallabeling.cpp
   trunk/qgis/src/core/qgspallabeling.h
   trunk/qgis/src/ui/qgslabelingguibase.ui
Log:
[FEATURE]: possibility to set label distance in map units

Modified: trunk/qgis/src/app/qgslabelinggui.cpp
===================================================================
--- trunk/qgis/src/app/qgslabelinggui.cpp	2011-02-15 09:20:27 UTC (rev 15175)
+++ trunk/qgis/src/app/qgslabelinggui.cpp	2011-02-16 09:11:48 UTC (rev 15176)
@@ -74,12 +74,14 @@
   populateDataDefinedCombos( lyr );
 
   // placement
+  int distUnitIndex = lyr.distInMapUnits ? 1 : 0;
   switch ( lyr.placement )
   {
     case QgsPalLayerSettings::AroundPoint:
       radAroundPoint->setChecked( true );
       radAroundCentroid->setChecked( true );
       spinDistPoint->setValue( lyr.dist );
+      mPointDistanceUnitComboBox->setCurrentIndex( distUnitIndex );
       //spinAngle->setValue(lyr.angle);
       break;
     case QgsPalLayerSettings::OverPoint:
@@ -107,6 +109,7 @@
   if ( lyr.placement == QgsPalLayerSettings::Line || lyr.placement == QgsPalLayerSettings::Curved )
   {
     spinDistLine->setValue( lyr.dist );
+    mLineDistanceUnitComboBox->setCurrentIndex( distUnitIndex );
     chkLineAbove->setChecked( lyr.placementFlags & QgsPalLayerSettings::AboveLine );
     chkLineBelow->setChecked( lyr.placementFlags & QgsPalLayerSettings::BelowLine );
     chkLineOn->setChecked( lyr.placementFlags & QgsPalLayerSettings::OnLine );
@@ -202,7 +205,7 @@
   {
     lyr.placement = QgsPalLayerSettings::AroundPoint;
     lyr.dist = spinDistPoint->value();
-    //lyr.angle = spinAngle->value();
+    lyr.distInMapUnits = ( mPointDistanceUnitComboBox->currentIndex() == 1 );
   }
   else if (( stackedPlacement->currentWidget() == pagePoint && radOverPoint->isChecked() )
            || ( stackedPlacement->currentWidget() == pagePolygon && radOverCentroid->isChecked() ) )
@@ -216,6 +219,7 @@
     bool curved = ( stackedPlacement->currentWidget() == pageLine && radLineCurved->isChecked() );
     lyr.placement = ( curved ? QgsPalLayerSettings::Curved : QgsPalLayerSettings::Line );
     lyr.dist = spinDistLine->value();
+    lyr.distInMapUnits = ( mLineDistanceUnitComboBox->currentIndex() == 1 );
     if ( chkLineAbove->isChecked() )
       lyr.placementFlags |= QgsPalLayerSettings::AboveLine;
     if ( chkLineBelow->isChecked() )
@@ -276,7 +280,6 @@
   lyr.minFeatureSize = mMinSizeSpinBox->value();
   lyr.fontSizeInMapUnits = ( mFontSizeUnitComboBox->currentIndex() == 1 );
 
-
   //data defined labeling
   setDataDefinedProperty( mSizeAttributeComboBox, QgsPalLayerSettings::Size, lyr );
   setDataDefinedProperty( mColorAttributeComboBox, QgsPalLayerSettings::Color, lyr );

Modified: trunk/qgis/src/core/qgspallabeling.cpp
===================================================================
--- trunk/qgis/src/core/qgspallabeling.cpp	2011-02-15 09:20:27 UTC (rev 15175)
+++ trunk/qgis/src/core/qgspallabeling.cpp	2011-02-16 09:11:48 UTC (rev 15176)
@@ -135,6 +135,7 @@
   rasterCompressFactor = 1.0;
   addDirectionSymbol = false;
   fontSizeInMapUnits = false;
+  distInMapUnits = false;
 }
 
 QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
@@ -161,6 +162,7 @@
   rasterCompressFactor = s.rasterCompressFactor;
   addDirectionSymbol = s.addDirectionSymbol;
   fontSizeInMapUnits = s.fontSizeInMapUnits;
+  distInMapUnits = s.distInMapUnits;
 
   dataDefinedProperties = s.dataDefinedProperties;
   fontMetrics = NULL;
@@ -286,6 +288,7 @@
   addDirectionSymbol = layer->customProperty( "labeling/addDirectionSymbol" ).toBool();
   minFeatureSize = layer->customProperty( "labeling/minFeatureSize" ).toDouble();
   fontSizeInMapUnits = layer->customProperty( "labeling/fontSizeInMapUnits" ).toBool();
+  distInMapUnits = layer->customProperty( "labeling/distInMapUnits" ).toBool();
   _readDataDefinedPropertyMap( layer, dataDefinedProperties );
 }
 
@@ -320,6 +323,7 @@
   layer->setCustomProperty( "labeling/addDirectionSymbol", addDirectionSymbol );
   layer->setCustomProperty( "labeling/minFeatureSize", minFeatureSize );
   layer->setCustomProperty( "labeling/fontSizeInMapUnits", fontSizeInMapUnits );
+  layer->setCustomProperty( "labeling/distInMapUnits", distInMapUnits );
   _writeDataDefinedPropertyMap( layer, dataDefinedProperties );
 }
 
@@ -574,7 +578,15 @@
 
   if ( distance != 0 )
   {
-    feat->setDistLabel( qAbs( ptOne.x() - ptZero.x() )* distance * vectorScaleFactor );
+    if( distInMapUnits ) //convert distance from mm/map units to pixels
+    {
+      distance /= context.mapToPixel().mapUnitsPerPixel();
+    }
+    else //mm
+    {
+      distance *= vectorScaleFactor;
+    }
+    feat->setDistLabel( qAbs( ptOne.x() - ptZero.x() )* distance );
   }
 
   //add parameters for data defined labeling to QgsPalGeometry

Modified: trunk/qgis/src/core/qgspallabeling.h
===================================================================
--- trunk/qgis/src/core/qgspallabeling.h	2011-02-15 09:20:27 UTC (rev 15175)
+++ trunk/qgis/src/core/qgspallabeling.h	2011-02-16 09:11:48 UTC (rev 15176)
@@ -115,6 +115,7 @@
     // Works only if Placement == Line
     bool addDirectionSymbol;
     bool fontSizeInMapUnits; //true if font size is in map units (otherwise in points)
+    bool distInMapUnits; //true if distance is in map units (otherwise in mm)
 
     // called from register feature hook
     void calculateLabelSize( const QFontMetricsF* fm, QString text, double& labelX, double& labelY );

Modified: trunk/qgis/src/ui/qgslabelingguibase.ui
===================================================================
--- trunk/qgis/src/ui/qgslabelingguibase.ui	2011-02-15 09:20:27 UTC (rev 15175)
+++ trunk/qgis/src/ui/qgslabelingguibase.ui	2011-02-16 09:11:48 UTC (rev 15176)
@@ -393,8 +393,8 @@
            <rect>
             <x>0</x>
             <y>0</y>
-            <width>640</width>
-            <height>483</height>
+            <width>643</width>
+            <height>435</height>
            </rect>
           </property>
           <layout class="QGridLayout" name="gridLayout_13">
@@ -658,7 +658,7 @@
               <item>
                <widget class="QStackedWidget" name="stackedOptions">
                 <property name="currentIndex">
-                 <number>1</number>
+                 <number>0</number>
                 </property>
                 <widget class="QWidget" name="pageOptionsPoint">
                  <layout class="QGridLayout" name="gridLayout_7">
@@ -675,14 +675,10 @@
                   <item row="0" column="1">
                    <widget class="QDoubleSpinBox" name="spinDistPoint">
                     <property name="decimals">
-                     <number>2</number>
+                     <number>4</number>
                     </property>
-                   </widget>
-                  </item>
-                  <item row="0" column="2">
-                   <widget class="QLabel" name="label_22">
-                    <property name="text">
-                     <string>mm</string>
+                    <property name="maximum">
+                     <double>999999999.000000000000000</double>
                     </property>
                    </widget>
                   </item>
@@ -710,6 +706,20 @@
                     </property>
                    </widget>
                   </item>
+                  <item row="0" column="2">
+                   <widget class="QComboBox" name="mPointDistanceUnitComboBox">
+                    <item>
+                     <property name="text">
+                      <string>In mm</string>
+                     </property>
+                    </item>
+                    <item>
+                     <property name="text">
+                      <string>In map units</string>
+                     </property>
+                    </item>
+                   </widget>
+                  </item>
                  </layout>
                 </widget>
                 <widget class="QWidget" name="pageOptionsLine">
@@ -781,15 +791,25 @@
                     <item>
                      <widget class="QDoubleSpinBox" name="spinDistLine">
                       <property name="decimals">
-                       <number>2</number>
+                       <number>4</number>
                       </property>
+                      <property name="maximum">
+                       <double>999999999.000000000000000</double>
+                      </property>
                      </widget>
                     </item>
                     <item>
-                     <widget class="QLabel" name="label_27">
-                      <property name="text">
-                       <string>mm</string>
-                      </property>
+                     <widget class="QComboBox" name="mLineDistanceUnitComboBox">
+                      <item>
+                       <property name="text">
+                        <string>In mm</string>
+                       </property>
+                      </item>
+                      <item>
+                       <property name="text">
+                        <string>In map units</string>
+                       </property>
+                      </item>
                      </widget>
                     </item>
                    </layout>
@@ -827,8 +847,8 @@
            <rect>
             <x>0</x>
             <y>0</y>
-            <width>640</width>
-            <height>615</height>
+            <width>643</width>
+            <height>532</height>
            </rect>
           </property>
           <layout class="QGridLayout" name="gridLayout_11">



More information about the QGIS-commit mailing list