Skip to content

Commit

Permalink
[FEATURE]: possibility to set label distance in map units
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15176 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Feb 16, 2011
1 parent a8fb1b4 commit bd6e6f0
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 20 deletions.
7 changes: 5 additions & 2 deletions src/app/qgslabelinggui.cpp
Expand Up @@ -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:
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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() ) )
Expand All @@ -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() )
Expand Down Expand Up @@ -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 );
Expand Down
14 changes: 13 additions & 1 deletion src/core/qgspallabeling.cpp
Expand Up @@ -135,6 +135,7 @@ QgsPalLayerSettings::QgsPalLayerSettings()
rasterCompressFactor = 1.0;
addDirectionSymbol = false;
fontSizeInMapUnits = false;
distInMapUnits = false;
}

QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
Expand All @@ -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;
Expand Down Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/core/qgspallabeling.h
Expand Up @@ -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 );
Expand Down
54 changes: 37 additions & 17 deletions src/ui/qgslabelingguibase.ui
Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand All @@ -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>
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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">
Expand Down

0 comments on commit bd6e6f0

Please sign in to comment.