From b30c17f07d00850597d8bb1b2cfb1f454498b391 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 28 Sep 2021 10:15:57 +1000 Subject: [PATCH] Don't overwrite existing data defined property expressions when an interactive map tool is used to move/rotate/edit labels But instead automatically upgrade this property to use a coalesce("aux field", 'existing' || 'property' || 'expression') type expression, so that the tool will place the interactively edited position/rotation/etc in the auxiliary field but default to using the expression for all other features Fixes #44475 --- src/app/labeling/qgsmaptoollabel.cpp | 13 ++++++------- src/app/labeling/qgsmaptoolmovelabel.cpp | 6 +++--- src/app/labeling/qgsmaptoolrotatelabel.cpp | 2 +- src/app/labeling/qgsmaptoolshowhidelabels.cpp | 4 ++-- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/app/labeling/qgsmaptoollabel.cpp b/src/app/labeling/qgsmaptoollabel.cpp index 0a5b19b2a59..4a007dc6a8a 100644 --- a/src/app/labeling/qgsmaptoollabel.cpp +++ b/src/app/labeling/qgsmaptoollabel.cpp @@ -884,9 +884,9 @@ bool QgsMapToolLabel::createAuxiliaryFields( LabelDetails &details, QgsPalIndexe { index = vlayer->fields().lookupField( prop.field() ); } - else if ( prop.propertyType() != QgsProperty::ExpressionBasedProperty || overwriteExpression ) + else { - index = QgsAuxiliaryLayer::createProperty( p, vlayer ); + index = QgsAuxiliaryLayer::createProperty( p, vlayer, overwriteExpression ); changed = true; } @@ -935,9 +935,9 @@ bool QgsMapToolLabel::createAuxiliaryFields( LabelDetails &details, QgsDiagramIn { index = vlayer->fields().lookupField( prop.field() ); } - else if ( prop.propertyType() != QgsProperty::ExpressionBasedProperty || overwriteExpression ) + else { - index = QgsAuxiliaryLayer::createProperty( p, vlayer ); + index = QgsAuxiliaryLayer::createProperty( p, vlayer, overwriteExpression ); changed = true; } @@ -985,12 +985,11 @@ bool QgsMapToolLabel::createAuxiliaryFields( QgsCalloutPosition &details, QgsCal { index = vlayer->fields().lookupField( prop.field() ); } - else if ( prop.propertyType() != QgsProperty::ExpressionBasedProperty || overwriteExpression ) + else { - index = QgsAuxiliaryLayer::createProperty( p, vlayer ); + index = QgsAuxiliaryLayer::createProperty( p, vlayer, overwriteExpression ); changed = true; } - calloutIndexes[p] = index; } if ( changed ) diff --git a/src/app/labeling/qgsmaptoolmovelabel.cpp b/src/app/labeling/qgsmaptoolmovelabel.cpp index 9861f4b77c5..1e143c116aa 100644 --- a/src/app/labeling/qgsmaptoolmovelabel.cpp +++ b/src/app/labeling/qgsmaptoolmovelabel.cpp @@ -111,7 +111,7 @@ void QgsMapToolMoveLabel::cadCanvasPressEvent( QgsMapMouseEvent *e ) { QgsCalloutIndexes indexes; - if ( createAuxiliaryFields( calloutPosition, indexes ) ) + if ( createAuxiliaryFields( calloutPosition, indexes, false ) ) return; if ( !canModifyCallout( calloutPosition, mCurrentCalloutMoveOrigin, xCol, yCol ) ) @@ -188,7 +188,7 @@ void QgsMapToolMoveLabel::cadCanvasPressEvent( QgsMapMouseEvent *e ) { QgsPalIndexes indexes; - if ( createAuxiliaryFields( indexes ) ) + if ( createAuxiliaryFields( indexes, false ) ) return; if ( !labelMoveable( vlayer, mCurrentLabel.settings, xCol, yCol ) ) @@ -211,7 +211,7 @@ void QgsMapToolMoveLabel::cadCanvasPressEvent( QgsMapMouseEvent *e ) { QgsDiagramIndexes indexes; - if ( createAuxiliaryFields( indexes ) ) + if ( createAuxiliaryFields( indexes, false ) ) return; if ( !diagramMoveable( vlayer, xCol, yCol ) ) diff --git a/src/app/labeling/qgsmaptoolrotatelabel.cpp b/src/app/labeling/qgsmaptoolrotatelabel.cpp index 370e225d221..53c6d99062a 100644 --- a/src/app/labeling/qgsmaptoolrotatelabel.cpp +++ b/src/app/labeling/qgsmaptoolrotatelabel.cpp @@ -117,7 +117,7 @@ void QgsMapToolRotateLabel::canvasPressEvent( QgsMapMouseEvent *e ) if ( !labelIsRotatable( mCurrentLabel.layer, mCurrentLabel.settings, rotationCol ) ) { QgsPalIndexes indexes; - if ( createAuxiliaryFields( indexes ) ) + if ( createAuxiliaryFields( indexes, false ) ) return; if ( !labelIsRotatable( mCurrentLabel.layer, mCurrentLabel.settings, rotationCol ) ) diff --git a/src/app/labeling/qgsmaptoolshowhidelabels.cpp b/src/app/labeling/qgsmaptoolshowhidelabels.cpp index dba9a5e8cb1..b641b9e323d 100644 --- a/src/app/labeling/qgsmaptoolshowhidelabels.cpp +++ b/src/app/labeling/qgsmaptoolshowhidelabels.cpp @@ -331,7 +331,7 @@ bool QgsMapToolShowHideLabels::showHide( const QgsLabelPosition &pos, bool show if ( !diagramCanShowHide( vlayer, showCol ) ) { QgsDiagramIndexes indexes; - createAuxiliaryFields( details, indexes ); + createAuxiliaryFields( details, indexes, false ); showCol = indexes[ QgsDiagramLayerSettings::Show ]; } @@ -341,7 +341,7 @@ bool QgsMapToolShowHideLabels::showHide( const QgsLabelPosition &pos, bool show if ( !labelCanShowHide( vlayer, showCol ) ) { QgsPalIndexes indexes; - createAuxiliaryFields( details, indexes ); + createAuxiliaryFields( details, indexes, false ); showCol = indexes[ QgsPalLayerSettings::Show ]; }