Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rendering of line direction symbols in labels, cleanup label rendering code a bit #59114

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
14 changes: 12 additions & 2 deletions python/PyQt6/core/auto_generated/labeling/qgspallabeling.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,22 @@ legendString
:return: the string to show in the legend and in the preview icon
%End

void calculateLabelSize( const QFontMetricsF *fm, const QString &text, double &labelX, double &labelY, const QgsFeature *f = 0, QgsRenderContext *context = 0, double *rotatedLabelX /Out/ = 0, double *rotatedLabelY /Out/ = 0 );
void calculateLabelSize( const QFontMetricsF *fm, const QString &text, double &labelX, double &labelY, const QgsFeature *f = 0, QgsRenderContext *context = 0, double *rotatedLabelX /Out/ = 0, double *rotatedLabelY /Out/ = 0 ) /Deprecated/;
%Docstring
Calculates the space required to render the provided ``text`` in map units.
Results will be written to ``labelX`` and ``labelY``.

If the text orientation is set to rotation-based, the spaced taken to render
vertically oriented text will be written to ``rotatedLabelX`` and ``rotatedLabelY`` .
vertically oriented text will be written to ``rotatedLabelX`` and ``rotatedLabelY``.

.. warning::

This method only returns an approximate label size, and eg will not consider
HTML formatted text correctly.

.. deprecated:: 3.40

Will be removed from public API in QGIS 4.0.
%End

void registerFeature( const QgsFeature &f, QgsRenderContext &context );
Expand Down
20 changes: 20 additions & 0 deletions python/PyQt6/core/auto_generated/textrenderer/qgstextblock.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ Reserves the specified ``count`` of fragments for optimised fragment appending.
Appends a ``fragment`` to the block.
%End

void insert( int index, const QgsTextFragment &fragment );
%Docstring
Inserts a ``fragment`` into the block, at the specified index.

:raises IndexError: if no fragment exists at the specified index.

.. versionadded:: 3.40
%End
%MethodCode
if ( a0 < 0 || a0 > sipCpp->size() )
{
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
sipIsErr = 1;
}
else
{
sipCpp->insert( a0, *a1 );
}
%End


void clear();
%Docstring
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,28 @@ Appends a ``block`` to the document.
%End



void insert( int index, const QgsTextBlock &block );
%Docstring
Inserts a ``block`` into the document, at the specified index.

:raises IndexError: if no block exists at the specified index.

.. versionadded:: 3.40
%End
%MethodCode
if ( a0 < 0 || a0 > sipCpp->size() )
{
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
sipIsErr = 1;
}
else
{
sipCpp->insert( a0, *a1 );
}
%End


void reserve( int count );
%Docstring
Reserves the specified ``count`` of blocks for optimised block appending.
Expand Down
14 changes: 12 additions & 2 deletions python/core/auto_generated/labeling/qgspallabeling.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,22 @@ legendString
:return: the string to show in the legend and in the preview icon
%End

void calculateLabelSize( const QFontMetricsF *fm, const QString &text, double &labelX, double &labelY, const QgsFeature *f = 0, QgsRenderContext *context = 0, double *rotatedLabelX /Out/ = 0, double *rotatedLabelY /Out/ = 0 );
void calculateLabelSize( const QFontMetricsF *fm, const QString &text, double &labelX, double &labelY, const QgsFeature *f = 0, QgsRenderContext *context = 0, double *rotatedLabelX /Out/ = 0, double *rotatedLabelY /Out/ = 0 ) /Deprecated/;
%Docstring
Calculates the space required to render the provided ``text`` in map units.
Results will be written to ``labelX`` and ``labelY``.

If the text orientation is set to rotation-based, the spaced taken to render
vertically oriented text will be written to ``rotatedLabelX`` and ``rotatedLabelY`` .
vertically oriented text will be written to ``rotatedLabelX`` and ``rotatedLabelY``.

.. warning::

This method only returns an approximate label size, and eg will not consider
HTML formatted text correctly.

.. deprecated:: 3.40

Will be removed from public API in QGIS 4.0.
%End

void registerFeature( const QgsFeature &f, QgsRenderContext &context );
Expand Down
20 changes: 20 additions & 0 deletions python/core/auto_generated/textrenderer/qgstextblock.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ Reserves the specified ``count`` of fragments for optimised fragment appending.
Appends a ``fragment`` to the block.
%End

void insert( int index, const QgsTextFragment &fragment );
%Docstring
Inserts a ``fragment`` into the block, at the specified index.

:raises IndexError: if no fragment exists at the specified index.

.. versionadded:: 3.40
%End
%MethodCode
if ( a0 < 0 || a0 > sipCpp->size() )
{
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
sipIsErr = 1;
}
else
{
sipCpp->insert( a0, *a1 );
}
%End


void clear();
%Docstring
Expand Down
22 changes: 22 additions & 0 deletions python/core/auto_generated/textrenderer/qgstextdocument.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,28 @@ Appends a ``block`` to the document.
%End



void insert( int index, const QgsTextBlock &block );
%Docstring
Inserts a ``block`` into the document, at the specified index.

:raises IndexError: if no block exists at the specified index.

.. versionadded:: 3.40
%End
%MethodCode
if ( a0 < 0 || a0 > sipCpp->size() )
{
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
sipIsErr = 1;
}
else
{
sipCpp->insert( a0, *a1 );
}
%End


void reserve( int count );
%Docstring
Reserves the specified ``count`` of blocks for optimised block appending.
Expand Down
20 changes: 10 additions & 10 deletions src/analysis/processing/qgsalgorithmextractlabels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,23 +218,23 @@ class ExtractLabelSink : public QgsLabelSink
break;

case Qgis::LabelMultiLineAlignment::FollowPlacement:
switch ( label->getQuadrant() )
switch ( label->quadrant() )
{
case pal::LabelPosition::QuadrantAboveLeft:
case pal::LabelPosition::QuadrantLeft:
case pal::LabelPosition::QuadrantBelowLeft:
case Qgis::LabelQuadrantPosition::AboveLeft:
case Qgis::LabelQuadrantPosition::Left:
case Qgis::LabelQuadrantPosition::BelowLeft:
labelAlignment = QStringLiteral( "right" );
break;

case pal::LabelPosition::QuadrantAbove:
case pal::LabelPosition::QuadrantOver:
case pal::LabelPosition::QuadrantBelow:
case Qgis::LabelQuadrantPosition::Above:
case Qgis::LabelQuadrantPosition::Over:
case Qgis::LabelQuadrantPosition::Below:
labelAlignment = QStringLiteral( "center" );
break;

case pal::LabelPosition::QuadrantAboveRight:
case pal::LabelPosition::QuadrantRight:
case pal::LabelPosition::QuadrantBelowRight:
case Qgis::LabelQuadrantPosition::AboveRight:
case Qgis::LabelQuadrantPosition::Right:
case Qgis::LabelQuadrantPosition::BelowRight:
labelAlignment = QStringLiteral( "left" );
break;
}
Expand Down
22 changes: 11 additions & 11 deletions src/core/dxf/qgsdxfexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2439,21 +2439,21 @@ void QgsDxfExport::drawLabel( const QString &layerId, QgsRenderContext &context,
if ( tmpLyr.multilineAlign == Qgis::LabelMultiLineAlignment::FollowPlacement )
{
//calculate font alignment based on label quadrant
switch ( label->getQuadrant() )
switch ( label->quadrant() )
{
case pal::LabelPosition::QuadrantAboveLeft:
case pal::LabelPosition::QuadrantLeft:
case pal::LabelPosition::QuadrantBelowLeft:
case Qgis::LabelQuadrantPosition::AboveLeft:
case Qgis::LabelQuadrantPosition::Left:
case Qgis::LabelQuadrantPosition::BelowLeft:
tmpLyr.multilineAlign = Qgis::LabelMultiLineAlignment::Right;
break;
case pal::LabelPosition::QuadrantAbove:
case pal::LabelPosition::QuadrantOver:
case pal::LabelPosition::QuadrantBelow:
case Qgis::LabelQuadrantPosition::Above:
case Qgis::LabelQuadrantPosition::Over:
case Qgis::LabelQuadrantPosition::Below:
tmpLyr.multilineAlign = Qgis::LabelMultiLineAlignment::Center;
break;
case pal::LabelPosition::QuadrantAboveRight:
case pal::LabelPosition::QuadrantRight:
case pal::LabelPosition::QuadrantBelowRight:
case Qgis::LabelQuadrantPosition::AboveRight:
case Qgis::LabelQuadrantPosition::Right:
case Qgis::LabelQuadrantPosition::BelowRight:
tmpLyr.multilineAlign = Qgis::LabelMultiLineAlignment::Left;
break;
}
Expand Down Expand Up @@ -2482,7 +2482,7 @@ void QgsDxfExport::drawLabel( const QString &layerId, QgsRenderContext &context,
bool prependSymb = false;
QString symb = tmpLyr.lineSettings().rightDirectionSymbol();

if ( label->getReversed() )
if ( label->isReversedFromLineDirection() )
{
prependSymb = true;
symb = tmpLyr.lineSettings().leftDirectionSymbol();
Expand Down
Loading
Loading