Skip to content
Permalink
Browse files
[labeling] specify unit for data defined label rotation
  • Loading branch information
domi4484 committed Sep 1, 2021
1 parent 553bb27 commit 44fb7d67146669844b29fc1c4b32a228a7b0eec7
@@ -395,6 +395,8 @@ Sets the polygon placement ``flags``, which dictate how polygon labels can be pl

bool preserveRotation;

QgsUnitTypes::AngleUnit rotationUnit;

double maxCurvedCharAngleIn;

double maxCurvedCharAngleOut;
@@ -332,6 +332,7 @@ QgsPalLayerSettings &QgsPalLayerSettings::operator=( const QgsPalLayerSettings &
distMapUnitScale = s.distMapUnitScale;
angleOffset = s.angleOffset;
preserveRotation = s.preserveRotation;
rotationUnit = s.rotationUnit;
maxCurvedCharAngleIn = s.maxCurvedCharAngleIn;
maxCurvedCharAngleOut = s.maxCurvedCharAngleOut;
priority = s.priority;
@@ -797,6 +798,7 @@ void QgsPalLayerSettings::readFromLayerCustomProperties( QgsVectorLayer *layer )
}

preserveRotation = layer->customProperty( QStringLiteral( "labeling/preserveRotation" ), QVariant( true ) ).toBool();
rotationUnit = static_cast<QgsUnitTypes::AngleUnit>( layer->customProperty( QStringLiteral( "labeling/rotationUnit" ), QVariant( static_cast< unsigned int >( QgsUnitTypes::AngleDegrees ) ) ).toInt() );
maxCurvedCharAngleIn = layer->customProperty( QStringLiteral( "labeling/maxCurvedCharAngleIn" ), QVariant( 25.0 ) ).toDouble();
maxCurvedCharAngleOut = layer->customProperty( QStringLiteral( "labeling/maxCurvedCharAngleOut" ), QVariant( -25.0 ) ).toDouble();
priority = layer->customProperty( QStringLiteral( "labeling/priority" ) ).toInt();
@@ -1024,6 +1026,7 @@ void QgsPalLayerSettings::readXml( const QDomElement &elem, const QgsReadWriteCo
}

preserveRotation = placementElem.attribute( QStringLiteral( "preserveRotation" ), QStringLiteral( "1" ) ).toInt();
rotationUnit = static_cast<QgsUnitTypes::AngleUnit>( placementElem.attribute( QStringLiteral( "rotationUnit" ), 0 ).toInt() );
maxCurvedCharAngleIn = placementElem.attribute( QStringLiteral( "maxCurvedCharAngleIn" ), QStringLiteral( "25" ) ).toDouble();
maxCurvedCharAngleOut = placementElem.attribute( QStringLiteral( "maxCurvedCharAngleOut" ), QStringLiteral( "-25" ) ).toDouble();
priority = placementElem.attribute( QStringLiteral( "priority" ) ).toInt();
@@ -1213,6 +1216,7 @@ QDomElement QgsPalLayerSettings::writeXml( QDomDocument &doc, const QgsReadWrite
placementElem.setAttribute( QStringLiteral( "labelOffsetMapUnitScale" ), QgsSymbolLayerUtils::encodeMapUnitScale( labelOffsetMapUnitScale ) );
placementElem.setAttribute( QStringLiteral( "rotationAngle" ), angleOffset );
placementElem.setAttribute( QStringLiteral( "preserveRotation" ), preserveRotation );
placementElem.setAttribute( QStringLiteral( "rotationUnit" ), static_cast< unsigned int >( rotationUnit ) );
placementElem.setAttribute( QStringLiteral( "maxCurvedCharAngleIn" ), maxCurvedCharAngleIn );
placementElem.setAttribute( QStringLiteral( "maxCurvedCharAngleOut" ), maxCurvedCharAngleOut );
placementElem.setAttribute( QStringLiteral( "priority" ), priority );
@@ -2333,14 +2337,18 @@ std::unique_ptr<QgsLabelFeature> QgsPalLayerSettings::registerFeatureWithDetails
if ( !exprVal.isNull() )
{
bool ok;
double rotD = exprVal.toDouble( &ok );
const double rotation = exprVal.toDouble( &ok );
if ( ok )
{
dataDefinedRotation = true;

double rotationDegrees = rotation * QgsUnitTypes::fromUnitToUnitFactor( rotationUnit,
QgsUnitTypes::AngleDegrees );

// TODO: add setting to disable having data defined rotation follow
// map rotation ?
rotD += m2p.mapRotation();
angle = ( 360 - rotD ) * M_PI / 180.0;
rotationDegrees += m2p.mapRotation();
angle = ( 360 - rotationDegrees ) * M_PI / 180.0;
}
}
}
@@ -636,6 +636,9 @@ class CORE_EXPORT QgsPalLayerSettings
//! True if label rotation should be preserved during label pin/unpin operations.
bool preserveRotation = true;

//! Unit for rotation of labels.
QgsUnitTypes::AngleUnit rotationUnit = QgsUnitTypes::AngleDegrees;

/**
* Maximum angle between inside curved label characters (valid range 20.0 to 60.0).
* \see maxCurvedCharAngleOut
@@ -244,6 +244,15 @@ QgsLabelingGui::QgsLabelingGui( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas,
mFontMultiLineAlignComboBox->addItem( tr( "Right" ), QgsPalLayerSettings::MultiRight );
mFontMultiLineAlignComboBox->addItem( tr( "Justify" ), QgsPalLayerSettings::MultiJustify );

mCoordRotationUnitComboBox->addItem( QgsUnitTypes::toString( QgsUnitTypes::AngleDegrees ), QgsUnitTypes::AngleDegrees );
mCoordRotationUnitComboBox->addItem( QgsUnitTypes::toString( QgsUnitTypes::AngleRadians ), QgsUnitTypes::AngleRadians );
mCoordRotationUnitComboBox->addItem( QgsUnitTypes::toString( QgsUnitTypes::AngleGon ), QgsUnitTypes::AngleGon );
mCoordRotationUnitComboBox->addItem( QgsUnitTypes::toString( QgsUnitTypes::AngleMinutesOfArc ), QgsUnitTypes::AngleMinutesOfArc );
mCoordRotationUnitComboBox->addItem( QgsUnitTypes::toString( QgsUnitTypes::AngleSecondsOfArc ), QgsUnitTypes::AngleSecondsOfArc );
mCoordRotationUnitComboBox->addItem( QgsUnitTypes::toString( QgsUnitTypes::AngleTurn ), QgsUnitTypes::AngleTurn );
mCoordRotationUnitComboBox->addItem( QgsUnitTypes::toString( QgsUnitTypes::AngleMilliradiansSI ), QgsUnitTypes::AngleMilliradiansSI );
mCoordRotationUnitComboBox->addItem( QgsUnitTypes::toString( QgsUnitTypes::AngleMilNATO ), QgsUnitTypes::AngleMilNATO );

// connections for groupboxes with separate activation checkboxes (that need to honor data defined setting)
connect( mBufferDrawChkBx, &QAbstractButton::toggled, this, &QgsLabelingGui::updateUi );
connect( mBufferDrawDDBtn, &QgsPropertyOverrideButton::changed, this, &QgsLabelingGui::updateUi );
@@ -425,6 +434,10 @@ void QgsLabelingGui::setLayer( QgsMapLayer *mapLayer )

chkPreserveRotation->setChecked( mSettings.preserveRotation );

mCoordRotationUnitComboBox->setCurrentIndex( 0 );
if ( mCoordRotationUnitComboBox->findData( static_cast< unsigned int >( mSettings.rotationUnit ) ) >= 0 )
mCoordRotationUnitComboBox->setCurrentIndex( mCoordRotationUnitComboBox->findData( static_cast< unsigned int >( mSettings.rotationUnit ) ) );

mScaleBasedVisibilityChkBx->setChecked( mSettings.scaleVisibility );
mMinScaleWidget->setScale( mSettings.minimumScale );
mMaxScaleWidget->setScale( mSettings.maximumScale );
@@ -607,6 +620,7 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
lyr.useMaxLineLengthForAutoWrap = mAutoWrapTypeComboBox->currentIndex() == 0;
lyr.multilineAlign = static_cast< QgsPalLayerSettings::MultiLineAlign >( mFontMultiLineAlignComboBox->currentData().toInt() );
lyr.preserveRotation = chkPreserveRotation->isChecked();
lyr.rotationUnit = static_cast< QgsUnitTypes::AngleUnit >( mCoordRotationUnitComboBox->currentData().toInt() );
lyr.geometryGenerator = mGeometryGenerator->text();
lyr.geometryGeneratorType = mGeometryGeneratorType->currentData().value<QgsWkbTypes::GeometryType>();
lyr.geometryGeneratorEnabled = mGeometryGeneratorGroupBox->isChecked();
@@ -348,6 +348,7 @@ void QgsTextFormatWidget::initWidget()
<< mBufferOpacityWidget
<< mCentroidInsideCheckBox
<< mChkNoObstacle
<< mCoordRotationUnitComboBox
<< mDirectSymbChkBx
<< mDirectSymbLeftLineEdit
<< mDirectSymbRevChkBx
@@ -5540,6 +5540,9 @@ font-style: italic;</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="mCoordRotationUnitComboBox"/>
</item>
<item>
<widget class="QCheckBox" name="chkPreserveRotation">
<property name="toolTip">

0 comments on commit 44fb7d6

Please sign in to comment.