From cfd9afed712f6a5c42262358bb6919ddf73c173f Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 9 Jul 2020 10:50:45 +1000 Subject: [PATCH] [feature][labeling] Expose Justify text alignment option for use in multiline point/polygon labels Allows multiline labels to be "justify" aligned --- python/core/auto_generated/labeling/qgspallabeling.sip.in | 3 ++- src/app/labeling/qgslabelpropertydialog.cpp | 4 ++++ src/core/labeling/qgspallabeling.cpp | 4 ++++ src/core/labeling/qgspallabeling.h | 3 ++- src/core/labeling/qgsvectorlayerlabelprovider.cpp | 2 ++ src/gui/labeling/qgslabelinggui.cpp | 1 + 6 files changed, 15 insertions(+), 2 deletions(-) diff --git a/python/core/auto_generated/labeling/qgspallabeling.sip.in b/python/core/auto_generated/labeling/qgspallabeling.sip.in index c76bf2f4702..8e2495d1556 100644 --- a/python/core/auto_generated/labeling/qgspallabeling.sip.in +++ b/python/core/auto_generated/labeling/qgspallabeling.sip.in @@ -167,7 +167,8 @@ class QgsPalLayerSettings MultiLeft, MultiCenter, MultiRight, - MultiFollowPlacement + MultiFollowPlacement, + MultiJustify, }; diff --git a/src/app/labeling/qgslabelpropertydialog.cpp b/src/app/labeling/qgslabelpropertydialog.cpp index 36c892c26c5..94ec71b65e9 100644 --- a/src/app/labeling/qgslabelpropertydialog.cpp +++ b/src/app/labeling/qgslabelpropertydialog.cpp @@ -203,6 +203,9 @@ void QgsLabelPropertyDialog::init( const QString &layerId, const QString &provid case QgsPalLayerSettings::MultiRight: defaultMultilineAlign = QStringLiteral( "right" ); break; + case QgsPalLayerSettings::MultiJustify: + defaultMultilineAlign = QStringLiteral( "justify" ); + break; case QgsPalLayerSettings::MultiFollowPlacement: defaultMultilineAlign = QStringLiteral( "follow label placement" ); break; @@ -592,6 +595,7 @@ void QgsLabelPropertyDialog::fillMultiLineAlignComboBox() mMultiLineAlignComboBox->addItem( tr( "Left" ), "Left" ); mMultiLineAlignComboBox->addItem( tr( "Center" ), "Center" ); mMultiLineAlignComboBox->addItem( tr( "Right" ), "Right" ); + mMultiLineAlignComboBox->addItem( tr( "Justify" ), "Justify" ); } void QgsLabelPropertyDialog::fillHaliComboBox() diff --git a/src/core/labeling/qgspallabeling.cpp b/src/core/labeling/qgspallabeling.cpp index 13678db97f8..e808332fa55 100644 --- a/src/core/labeling/qgspallabeling.cpp +++ b/src/core/labeling/qgspallabeling.cpp @@ -3188,6 +3188,10 @@ void QgsPalLayerSettings::parseTextFormatting( QgsRenderContext &context ) { aligntype = QgsPalLayerSettings::MultiFollowPlacement; } + else if ( str.compare( QLatin1String( "Justify" ), Qt::CaseInsensitive ) == 0 ) + { + aligntype = QgsPalLayerSettings::MultiJustify; + } dataDefinedValues.insert( QgsPalLayerSettings::MultiLineAlignment, QVariant( static_cast< int >( aligntype ) ) ); } } diff --git a/src/core/labeling/qgspallabeling.h b/src/core/labeling/qgspallabeling.h index d2a00718fe5..ca5af649e57 100644 --- a/src/core/labeling/qgspallabeling.h +++ b/src/core/labeling/qgspallabeling.h @@ -311,8 +311,9 @@ class CORE_EXPORT QgsPalLayerSettings MultiLeft = 0, MultiCenter, MultiRight, - MultiFollowPlacement /*!< Alignment follows placement of label, e.g., labels to the left of a feature + MultiFollowPlacement, /*!< Alignment follows placement of label, e.g., labels to the left of a feature will be drawn with right alignment*/ + MultiJustify, //!< Justified }; //TODO QGIS 4.0 - Remove -- moved to QgsLabelEngineObstacleSettings diff --git a/src/core/labeling/qgsvectorlayerlabelprovider.cpp b/src/core/labeling/qgsvectorlayerlabelprovider.cpp index 1d342bcb241..5012957153d 100644 --- a/src/core/labeling/qgsvectorlayerlabelprovider.cpp +++ b/src/core/labeling/qgsvectorlayerlabelprovider.cpp @@ -618,6 +618,8 @@ void QgsVectorLayerLabelProvider::drawLabelPrivate( pal::LabelPosition *label, Q hAlign = QgsTextRenderer::AlignCenter; else if ( tmpLyr.multilineAlign == QgsPalLayerSettings::MultiRight ) hAlign = QgsTextRenderer::AlignRight; + else if ( tmpLyr.multilineAlign == QgsPalLayerSettings::MultiJustify ) + hAlign = QgsTextRenderer::AlignJustify; QgsTextRenderer::Component component; component.origin = outPt; diff --git a/src/gui/labeling/qgslabelinggui.cpp b/src/gui/labeling/qgslabelinggui.cpp index e7edc7ba56f..80ee470ba5b 100644 --- a/src/gui/labeling/qgslabelinggui.cpp +++ b/src/gui/labeling/qgslabelinggui.cpp @@ -192,6 +192,7 @@ QgsLabelingGui::QgsLabelingGui( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, mFontMultiLineAlignComboBox->addItem( tr( "Left" ), QgsPalLayerSettings::MultiLeft ); mFontMultiLineAlignComboBox->addItem( tr( "Center" ), QgsPalLayerSettings::MultiCenter ); mFontMultiLineAlignComboBox->addItem( tr( "Right" ), QgsPalLayerSettings::MultiRight ); + mFontMultiLineAlignComboBox->addItem( tr( "Justify" ), QgsPalLayerSettings::MultiJustify ); // connections for groupboxes with separate activation checkboxes (that need to honor data defined setting) connect( mBufferDrawChkBx, &QAbstractButton::toggled, this, &QgsLabelingGui::updateUi );