Skip to content

Commit

Permalink
Don't overwrite existing data defined property expressions when
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nyalldawson committed Sep 28, 2021
1 parent 9db24c2 commit b30c17f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
13 changes: 6 additions & 7 deletions src/app/labeling/qgsmaptoollabel.cpp
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 )
Expand Down
6 changes: 3 additions & 3 deletions src/app/labeling/qgsmaptoolmovelabel.cpp
Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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 ) )
Expand All @@ -211,7 +211,7 @@ void QgsMapToolMoveLabel::cadCanvasPressEvent( QgsMapMouseEvent *e )
{
QgsDiagramIndexes indexes;

if ( createAuxiliaryFields( indexes ) )
if ( createAuxiliaryFields( indexes, false ) )
return;

if ( !diagramMoveable( vlayer, xCol, yCol ) )
Expand Down
2 changes: 1 addition & 1 deletion src/app/labeling/qgsmaptoolrotatelabel.cpp
Expand Up @@ -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 ) )
Expand Down
4 changes: 2 additions & 2 deletions src/app/labeling/qgsmaptoolshowhidelabels.cpp
Expand Up @@ -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 ];
}
Expand All @@ -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 ];
}
Expand Down

0 comments on commit b30c17f

Please sign in to comment.