Navigation Menu

Skip to content

Commit

Permalink
switch to XY coordinate types when using label move tool
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 committed Jan 10, 2022
1 parent fd1b819 commit 9f7353b
Show file tree
Hide file tree
Showing 20 changed files with 433 additions and 156 deletions.
7 changes: 7 additions & 0 deletions python/core/auto_additions/qgslabeling.py
@@ -0,0 +1,7 @@
# The following has been generated automatically from src/core/labeling/qgslabeling.h
# monkey patching scoped based enum
QgsLabeling.CoordinateType.XY.__doc__ = "Coordinate defined by X and Y values"
QgsLabeling.CoordinateType.Point.__doc__ = "Coordinate defined by a point"
QgsLabeling.CoordinateType.__doc__ = 'Types of coordinate definitions\n\n.. versionadded:: 3.22\n\n' + '* ``XY``: ' + QgsLabeling.CoordinateType.XY.__doc__ + '\n' + '* ``Point``: ' + QgsLabeling.CoordinateType.Point.__doc__
# --
QgsLabeling.CoordinateType.baseClass = QgsLabeling
9 changes: 9 additions & 0 deletions python/core/auto_generated/labeling/qgslabeling.sip.in
Expand Up @@ -20,6 +20,9 @@ Contains constants and enums relating to labeling.
%TypeHeaderCode
#include "qgslabeling.h"
%End
public:
static const QMetaObject staticMetaObject;

public:

enum LinePlacementFlag
Expand All @@ -40,6 +43,12 @@ Contains constants and enums relating to labeling.
typedef QFlags<QgsLabeling::PolygonPlacementFlag> PolygonPlacementFlags;


enum class CoordinateType
{
XY,
Point
};

};

QFlags<QgsLabeling::LinePlacementFlag> operator|(QgsLabeling::LinePlacementFlag f1, QFlags<QgsLabeling::LinePlacementFlag> f2);
Expand Down
19 changes: 19 additions & 0 deletions python/core/auto_generated/labeling/qgspallabeling.sip.in
Expand Up @@ -218,6 +218,7 @@ Contains settings for how a map layer will be labeled.
// (data defined only)
PositionX,
PositionY,
PositionPoint,
Hali,
Vali,
Rotation,
Expand Down Expand Up @@ -419,6 +420,24 @@ Set unit for rotation of labels.

int priority;

QgsLabeling::CoordinateType placementCoordinateType() const;
%Docstring
Coordinates type for data defined placement.

.. seealso:: :py:func:`setPlacementCoordinateType`

.. versionadded:: 3.22
%End

void setPlacementCoordinateType( QgsLabeling::CoordinateType placementCoordinateType );
%Docstring
Set coordinates type for data defined placement.

.. seealso:: :py:func:`placementCoordinateType`

.. versionadded:: 3.22
%End


bool scaleVisibility;

Expand Down
Expand Up @@ -11,7 +11,7 @@



class QgsAbstractVectorLayerLabeling
class QgsAbstractVectorLayerLabeling : QObject
{
%Docstring(signature="appended")
Abstract base class - its implementations define different approaches to the labeling of a vector layer.
Expand Down Expand Up @@ -112,6 +112,10 @@ Returns the default layer settings to use for the specified vector ``layer``.
.. versionadded:: 3.20
%End

signals:

void labelingChanged();

protected:

virtual void writeTextSymbolizer( QDomNode &parent, QgsPalLayerSettings &settings, const QVariantMap &props ) const;
Expand Down
6 changes: 2 additions & 4 deletions python/gui/auto_generated/qgstextformatwidget.sip.in
Expand Up @@ -145,11 +145,9 @@ Sets the background color for the text preview widget.
:param color: background color
%End

void enableDataDefinedAlignment( bool enable );
void updateDataDefinedAlignment();
%Docstring
Controls whether data defined alignment buttons are enabled.

:param enable: set to ``True`` to enable alignment controls
Update the enabled state of the data defined alignment buttons.
%End

virtual QgsExpressionContext createExpressionContext() const;
Expand Down
8 changes: 8 additions & 0 deletions src/app/labeling/qgsmaptoolmovelabel.cpp
Expand Up @@ -354,6 +354,14 @@ void QgsMapToolMoveLabel::cadCanvasPressEvent( QgsMapMouseEvent *e )
}
}

if ( !isCalloutMove
&& vlayer->labeling()->settings().placementCoordinateType() != QgsLabeling::CoordinateType::XY )
{
QgsPalLayerSettings *settings = new QgsPalLayerSettings( mCurrentLabel.settings );
settings->setPlacementCoordinateType( QgsLabeling::CoordinateType::XY );
vlayer->labeling()->setSettings( settings );
}

bool success = vlayer->changeAttributeValue( featureId, xCol, xNewPos );
success = vlayer->changeAttributeValue( featureId, yCol, yNewPos ) && success;

Expand Down
15 changes: 15 additions & 0 deletions src/core/labeling/qgslabeling.h
Expand Up @@ -18,6 +18,7 @@

#include "qgis_core.h"
#include "qgis_sip.h"
#include <QObject>
#include <QFlags>

/**
Expand All @@ -30,6 +31,8 @@
*/
class CORE_EXPORT QgsLabeling
{
Q_GADGET

public:

/**
Expand All @@ -56,6 +59,18 @@ class CORE_EXPORT QgsLabeling
};
Q_DECLARE_FLAGS( PolygonPlacementFlags, PolygonPlacementFlag )

/**
* Types of coordinate definitions
*
* \since QGIS 3.22
*/
enum class CoordinateType : int
{
XY, //!< Coordinate defined by X and Y values
Point //!< Coordinate defined by a point
};
Q_ENUM( CoordinateType )

};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLabeling::LinePlacementFlags )
Expand Down

0 comments on commit 9f7353b

Please sign in to comment.