Skip to content
Permalink
Browse files

[FEATURE]: possibility to set label distance in map units

git-svn-id: http://svn.osgeo.org/qgis/trunk@15176 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Feb 16, 2011
1 parent 1a4ff7d commit 788d61b1b979569beba80ae6d7448cdfea0f889d
Showing with 56 additions and 20 deletions.
  1. +5 −2 src/app/qgslabelinggui.cpp
  2. +13 −1 src/core/qgspallabeling.cpp
  3. +1 −0 src/core/qgspallabeling.h
  4. +37 −17 src/ui/qgslabelingguibase.ui
@@ -74,12 +74,14 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
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 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
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 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
{
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 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
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 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
lyr.minFeatureSize = mMinSizeSpinBox->value();
lyr.fontSizeInMapUnits = ( mFontSizeUnitComboBox->currentIndex() == 1 );


//data defined labeling
setDataDefinedProperty( mSizeAttributeComboBox, QgsPalLayerSettings::Size, lyr );
setDataDefinedProperty( mColorAttributeComboBox, QgsPalLayerSettings::Color, lyr );
@@ -135,6 +135,7 @@ QgsPalLayerSettings::QgsPalLayerSettings()
rasterCompressFactor = 1.0;
addDirectionSymbol = false;
fontSizeInMapUnits = false;
distInMapUnits = false;
}

QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
@@ -161,6 +162,7 @@ QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
rasterCompressFactor = s.rasterCompressFactor;
addDirectionSymbol = s.addDirectionSymbol;
fontSizeInMapUnits = s.fontSizeInMapUnits;
distInMapUnits = s.distInMapUnits;

dataDefinedProperties = s.dataDefinedProperties;
fontMetrics = NULL;
@@ -286,6 +288,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
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 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )
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 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext

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
@@ -115,6 +115,7 @@ class CORE_EXPORT QgsPalLayerSettings
// 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 );
@@ -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">

0 comments on commit 788d61b

Please sign in to comment.
You can’t perform that action at this time.