Skip to content

Commit

Permalink
Move some more line label related settings to QgsLabelLineSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 17, 2020
1 parent d93d881 commit 5dfbfaa
Show file tree
Hide file tree
Showing 10 changed files with 281 additions and 90 deletions.
92 changes: 92 additions & 0 deletions python/core/auto_generated/labeling/qgslabellinesettings.sip.in
Expand Up @@ -61,6 +61,98 @@ prior to generating label positions.
%Docstring
Updates the thinning settings to respect any data defined properties
set within the specified ``properties`` collection.
%End

bool addDirectionSymbol() const;
%Docstring
Returns ``True`` if '<' or '>' (or custom strings set via leftDirectionSymbol and rightDirectionSymbol)
will be automatically added to the label text, pointing in the
direction of the line or polygon ring.

.. seealso:: :py:func:`setAddDirectionSymbol`

.. seealso:: :py:func:`leftDirectionSymbol`

.. seealso:: :py:func:`rightDirectionSymbol`

.. seealso:: :py:func:`placeDirectionSymbol`

.. seealso:: :py:func:`reverseDirectionSymbol`
%End

void setAddDirectionSymbol( bool enabled );
%Docstring
Sets whether '<' or '>' (or custom strings set via leftDirectionSymbol and rightDirectionSymbol)
will be automatically added to the label text, pointing in the
direction of the line or polygon ring.

.. seealso:: :py:func:`addDirectionSymbol`

.. seealso:: :py:func:`setLeftDirectionSymbol`

.. seealso:: :py:func:`setRightDirectionSymbol`

.. seealso:: :py:func:`setPlaceDirectionSymbol`

.. seealso:: :py:func:`setReverseDirectionSymbol`
%End

QString leftDirectionSymbol() const;
%Docstring
Returns the string to use for left direction arrows.

.. seealso:: :py:func:`setLeftDirectionSymbol`

.. seealso:: :py:func:`addDirectionSymbol`

.. seealso:: :py:func:`rightDirectionSymbol`
%End

void setLeftDirectionSymbol( const QString &symbol );
%Docstring
Sets the string to use for left direction arrows.

.. seealso:: :py:func:`leftDirectionSymbol`

.. seealso:: :py:func:`addDirectionSymbol`

.. seealso:: :py:func:`rightDirectionSymbol`
%End

QString rightDirectionSymbol() const;
%Docstring
Returns the string to use for right direction arrows.

.. seealso:: :py:func:`setRightDirectionSymbol`

.. seealso:: :py:func:`addDirectionSymbol`

.. seealso:: :py:func:`leftDirectionSymbol`
%End

void setRightDirectionSymbol( const QString &symbol );
%Docstring
Sets the string to use for right direction arrows.

.. seealso:: :py:func:`setLeftDirectionSymbol`

.. seealso:: :py:func:`addDirectionSymbol`

.. seealso:: :py:func:`rightDirectionSymbol`
%End

bool reverseDirectionSymbol() const;
%Docstring
Returns ``True`` if direction symbols should be reversed.

.. seealso:: :py:func:`setReverseDirectionSymbol`
%End

void setReverseDirectionSymbol( bool reversed );
%Docstring
Sets whether the direction symbols should be ``reversed``.

.. seealso:: :py:func:`reverseDirectionSymbol`
%End

};
Expand Down
21 changes: 13 additions & 8 deletions python/core/auto_generated/labeling/qgspallabeling.sip.in
Expand Up @@ -384,16 +384,8 @@ Returns the QgsExpression for this label settings. May be ``None`` if isExpressi

MultiLineAlign multilineAlign;

bool addDirectionSymbol;

QString leftDirectionSymbol;

QString rightDirectionSymbol;

DirectionSymbols placeDirectionSymbol;

bool reverseDirectionSymbol;

bool formatNumbers;

int decimals;
Expand Down Expand Up @@ -497,6 +489,11 @@ Sets the polygon placement ``flags``, which dictate how polygon labels can be pl
%Property( name = placementFlags, get = _getLinePlacementFlags, set = _setLinePlacementFlags )
%Property( name = mergeLines, get = _getMergeLines, set = _setMergeLines )

%Property( name = addDirectionSymbol, get = _getAddDirectionSymbol, set = _setAddDirectionSymbol )
%Property( name = leftDirectionSymbol, get = _getLeftDirectionSymbol, set = _setLeftDirectionSymbol )
%Property( name = rightDirectionSymbol, get = _getRightDirectionSymbol, set = _setRightDirectionSymbol )
%Property( name = reverseDirectionSymbol, get = _getReverseDirectionSymbol, set = _setReverseDirectionSymbol )

bool _limitNumLabels() const;
void _setLimitNumLabels( bool limit );
int _maxNumLabels() const;
Expand All @@ -513,6 +510,14 @@ Sets the polygon placement ``flags``, which dictate how polygon labels can be pl
void _setLinePlacementFlags( unsigned int flags );
bool _getMergeLines() const;
void _setMergeLines( bool merge );
bool _getAddDirectionSymbol() const;
void _setAddDirectionSymbol( bool add );
QString _getLeftDirectionSymbol() const;
void _setLeftDirectionSymbol( const QString &symbol );
QString _getRightDirectionSymbol() const;
void _setRightDirectionSymbol( const QString &symbol );
bool _getReverseDirectionSymbol() const;
void _setReverseDirectionSymbol( bool reverse );

double zIndex;

Expand Down
14 changes: 7 additions & 7 deletions src/core/dxf/qgsdxfexport.cpp
Expand Up @@ -2271,28 +2271,28 @@ void QgsDxfExport::drawLabel( const QString &layerId, QgsRenderContext &context,
QString wrapchr = tmpLyr.wrapChar.isEmpty() ? QStringLiteral( "\n" ) : tmpLyr.wrapChar;

//add the direction symbol if needed
if ( !txt.isEmpty() && tmpLyr.placement == QgsPalLayerSettings::Line && tmpLyr.addDirectionSymbol )
if ( !txt.isEmpty() && tmpLyr.placement == QgsPalLayerSettings::Line && tmpLyr.lineSettings().addDirectionSymbol() )
{
bool prependSymb = false;
QString symb = tmpLyr.rightDirectionSymbol;
QString symb = tmpLyr.lineSettings().rightDirectionSymbol();

if ( label->getReversed() )
{
prependSymb = true;
symb = tmpLyr.leftDirectionSymbol;
symb = tmpLyr.lineSettings().leftDirectionSymbol();
}

if ( tmpLyr.reverseDirectionSymbol )
if ( tmpLyr.lineSettings().reverseDirectionSymbol() )
{
if ( symb == tmpLyr.rightDirectionSymbol )
if ( symb == tmpLyr.lineSettings().rightDirectionSymbol() )
{
prependSymb = true;
symb = tmpLyr.leftDirectionSymbol;
symb = tmpLyr.lineSettings().leftDirectionSymbol();
}
else
{
prependSymb = false;
symb = tmpLyr.rightDirectionSymbol;
symb = tmpLyr.lineSettings().rightDirectionSymbol();
}
}

Expand Down
1 change: 0 additions & 1 deletion src/core/labeling/qgslabellinesettings.cpp
Expand Up @@ -32,4 +32,3 @@ void QgsLabelLineSettings::updateDataDefinedProperties( const QgsPropertyCollect
}
}
}

81 changes: 81 additions & 0 deletions src/core/labeling/qgslabellinesettings.h
Expand Up @@ -19,6 +19,7 @@
#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgslabeling.h"
#include <QString>

class QgsPropertyCollection;
class QgsExpressionContext;
Expand Down Expand Up @@ -75,9 +76,89 @@ class CORE_EXPORT QgsLabelLineSettings
*/
void updateDataDefinedProperties( const QgsPropertyCollection &properties, QgsExpressionContext &context );

/**
* Returns TRUE if '<' or '>' (or custom strings set via leftDirectionSymbol and rightDirectionSymbol)
* will be automatically added to the label text, pointing in the
* direction of the line or polygon ring.
*
* \see setAddDirectionSymbol()
* \see leftDirectionSymbol()
* \see rightDirectionSymbol()
* \see placeDirectionSymbol()
* \see reverseDirectionSymbol()
*/
bool addDirectionSymbol() const { return mAddDirectionSymbol; }

/**
* Sets whether '<' or '>' (or custom strings set via leftDirectionSymbol and rightDirectionSymbol)
* will be automatically added to the label text, pointing in the
* direction of the line or polygon ring.
*
* \see addDirectionSymbol()
* \see setLeftDirectionSymbol()
* \see setRightDirectionSymbol()
* \see setPlaceDirectionSymbol()
* \see setReverseDirectionSymbol()
*/
void setAddDirectionSymbol( bool enabled ) { mAddDirectionSymbol = enabled; }

/**
* Returns the string to use for left direction arrows.
*
* \see setLeftDirectionSymbol()
* \see addDirectionSymbol()
* \see rightDirectionSymbol()
*/
QString leftDirectionSymbol() const { return mLeftDirectionSymbol; }

/**
* Sets the string to use for left direction arrows.
*
* \see leftDirectionSymbol()
* \see addDirectionSymbol()
* \see rightDirectionSymbol()
*/
void setLeftDirectionSymbol( const QString &symbol ) { mLeftDirectionSymbol = symbol; }

/**
* Returns the string to use for right direction arrows.
*
* \see setRightDirectionSymbol()
* \see addDirectionSymbol()
* \see leftDirectionSymbol()
*/
QString rightDirectionSymbol() const { return mRightDirectionSymbol; }

/**
* Sets the string to use for right direction arrows.
*
* \see setLeftDirectionSymbol()
* \see addDirectionSymbol()
* \see rightDirectionSymbol()
*/
void setRightDirectionSymbol( const QString &symbol ) { mRightDirectionSymbol = symbol; }

/**
* Returns TRUE if direction symbols should be reversed.
*
* \see setReverseDirectionSymbol()
*/
bool reverseDirectionSymbol() const { return mReverseDirectionSymbol; }

/**
* Sets whether the direction symbols should be \a reversed.
*
* \see reverseDirectionSymbol()
*/
void setReverseDirectionSymbol( bool reversed ) { mReverseDirectionSymbol = reversed; }

private:
QgsLabeling::LinePlacementFlags mPlacementFlags = QgsLabeling::LinePlacementFlag::AboveLine | QgsLabeling::LinePlacementFlag::MapOrientation;
bool mMergeLines = false;
bool mAddDirectionSymbol = false;
QString mLeftDirectionSymbol = QString( '<' );
QString mRightDirectionSymbol = QString( '>' );
bool mReverseDirectionSymbol = false;
};

#endif // QGSLABELLINESETTINGS_H

0 comments on commit 5dfbfaa

Please sign in to comment.