Skip to content
Permalink
Browse files

[feature][labeling] Expose Justify text alignment option for use

in multiline point/polygon labels

Allows multiline labels to be "justify" aligned
  • Loading branch information
nyalldawson committed Jul 9, 2020
1 parent 3e51559 commit cfd9afed712f6a5c42262358bb6919ddf73c173f
@@ -167,7 +167,8 @@ class QgsPalLayerSettings
MultiLeft,
MultiCenter,
MultiRight,
MultiFollowPlacement
MultiFollowPlacement,
MultiJustify,
};


@@ -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()
@@ -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 ) ) );
}
}
@@ -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
@@ -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;
@@ -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 );

0 comments on commit cfd9afe

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