Navigation Menu

Skip to content

Commit

Permalink
Make rotate label tool work with label not pinned or dd moved fix #43967
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 committed Sep 16, 2021
1 parent 78e4691 commit 881e655
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 39 deletions.
12 changes: 2 additions & 10 deletions src/app/labeling/qgsmaptoollabel.cpp
Expand Up @@ -203,7 +203,7 @@ void QgsMapToolLabel::createRubberBands()

//fixpoint rubber band
QgsPointXY fixPoint;
if ( currentLabelRotationPoint( fixPoint, false, false ) )
if ( currentLabelRotationPoint( fixPoint, false ) )
{
if ( mCanvas )
{
Expand Down Expand Up @@ -389,7 +389,7 @@ bool QgsMapToolLabel::currentLabelPreserveRotation()
return true; // default, so there is no accidental data loss
}

bool QgsMapToolLabel::currentLabelRotationPoint( QgsPointXY &pos, bool ignoreUpsideDown, bool rotatingUnpinned )
bool QgsMapToolLabel::currentLabelRotationPoint( QgsPointXY &pos, bool ignoreUpsideDown )
{
QVector<QgsPointXY> cornerPoints = mCurrentLabel.pos.cornerPoints;
if ( cornerPoints.size() < 4 )
Expand Down Expand Up @@ -418,14 +418,6 @@ bool QgsMapToolLabel::currentLabelRotationPoint( QgsPointXY &pos, bool ignoreUps
QString haliString, valiString;
currentAlignment( haliString, valiString );

// rotate unpinned labels (i.e. no hali/vali settings) as if hali/vali was Center/Half
if ( rotatingUnpinned )
{
haliString = QStringLiteral( "Center" );
valiString = QStringLiteral( "Half" );
}

// QFont labelFont = labelFontCurrentFeature();
QFontMetricsF labelFontMetrics( mCurrentLabel.pos.labelFont );

// NOTE: this assumes the label corner points comprise a rectangle and that the
Expand Down
2 changes: 1 addition & 1 deletion src/app/labeling/qgsmaptoollabel.h
Expand Up @@ -138,7 +138,7 @@ class APP_EXPORT QgsMapToolLabel: public QgsMapToolAdvancedDigitizing
* \param ignoreUpsideDown treat label as right-side-up
* \returns TRUE in case of success
*/
bool currentLabelRotationPoint( QgsPointXY &pos, bool ignoreUpsideDown = false, bool rotatingUnpinned = false );
bool currentLabelRotationPoint( QgsPointXY &pos, bool ignoreUpsideDown = false );

//! Creates label / feature / fixpoint rubber bands for the current label position
void createRubberBands();
Expand Down
3 changes: 1 addition & 2 deletions src/app/labeling/qgsmaptoolmovelabel.cpp
Expand Up @@ -169,7 +169,6 @@ void QgsMapToolMoveLabel::cadCanvasPressEvent( QgsMapMouseEvent *e )
if ( !labelAtPosition( e, labelPos ) )
{
mCurrentLabel = LabelDetails();

return;
}

Expand Down Expand Up @@ -241,7 +240,7 @@ void QgsMapToolMoveLabel::cadCanvasPressEvent( QgsMapMouseEvent *e )

mStartPointMapCoords = e->mapPoint();
QgsPointXY referencePoint;
if ( !currentLabelRotationPoint( referencePoint, !currentLabelPreserveRotation(), false ) )
if ( !currentLabelRotationPoint( referencePoint, !currentLabelPreserveRotation() ) )
{
referencePoint.setX( mCurrentLabel.pos.labelRect.xMinimum() );
referencePoint.setY( mCurrentLabel.pos.labelRect.yMinimum() );
Expand Down
2 changes: 1 addition & 1 deletion src/app/labeling/qgsmaptoolpinlabels.cpp
Expand Up @@ -380,7 +380,7 @@ bool QgsMapToolPinLabels::pinUnpinCurrentLabel( bool pin )
// QgsPointXY labelpoint = labelpos.cornerPoints.at( 0 );

QgsPointXY referencePoint;
if ( !currentLabelRotationPoint( referencePoint, !preserveRot, false ) )
if ( !currentLabelRotationPoint( referencePoint, !preserveRot ) )
{
referencePoint.setX( labelpos.labelRect.xMinimum() );
referencePoint.setY( labelpos.labelRect.yMinimum() );
Expand Down
25 changes: 2 additions & 23 deletions src/app/labeling/qgsmaptoolrotatelabel.cpp
Expand Up @@ -104,19 +104,9 @@ void QgsMapToolRotateLabel::canvasPressEvent( QgsMapMouseEvent *e )
if ( !mCurrentLabel.valid )
return;

// only rotate non-pinned OverPoint placements until other placements are supported in pal::Feature

if ( !mCurrentLabel.pos.isPinned
&& mCurrentLabel.settings.placement != QgsPalLayerSettings::OverPoint )
{
return;
}

// rotate unpinned labels (i.e. no hali/vali settings) as if hali/vali was Center/Half
if ( !currentLabelRotationPoint( mRotationPoint, false, !mCurrentLabel.pos.isPinned ) )
{
// Get label rotation point
if ( !currentLabelRotationPoint( mRotationPoint, false ) )
return;
}

{
mCurrentMouseAzimuth = convertAzimuth( mRotationPoint.azimuth( toMapCoordinates( e->pos() ) ) );
Expand Down Expand Up @@ -295,17 +285,6 @@ void QgsMapToolRotateLabel::keyReleaseEvent( QKeyEvent *e )
}
}

bool QgsMapToolRotateLabel::canModifyLabel( const QgsMapToolLabel::LabelDetails &label )
{
// only rotate non-pinned OverPoint placements until other placements are supported in pal::Feature

if ( !label.pos.isPinned
&& label.settings.placement != QgsPalLayerSettings::OverPoint )
return false;

return true;
}

int QgsMapToolRotateLabel::roundTo15Degrees( double n )
{
const int m = static_cast< int >( n / 15.0 + 0.5 );
Expand Down
2 changes: 0 additions & 2 deletions src/app/labeling/qgsmaptoolrotatelabel.h
Expand Up @@ -37,8 +37,6 @@ class APP_EXPORT QgsMapToolRotateLabel: public QgsMapToolLabel

protected:

bool canModifyLabel( const LabelDetails &label ) override;

static int roundTo15Degrees( double n );
//! Converts azimuth value so that 0 is corresponds to East
static double convertAzimuth( double a );
Expand Down

0 comments on commit 881e655

Please sign in to comment.