Skip to content

Commit

Permalink
[FEATURE][labels] allow to delete custom label rotation
Browse files Browse the repository at this point in the history
by pressing DEL key when moving the label
  • Loading branch information
3nids committed Nov 20, 2019
1 parent 99bf968 commit 0e110cf
Showing 1 changed file with 49 additions and 7 deletions.
56 changes: 49 additions & 7 deletions src/app/qgsmaptoolrotatelabel.cpp
Expand Up @@ -235,14 +235,56 @@ void QgsMapToolRotateLabel::canvasPressEvent( QgsMapMouseEvent *e )

void QgsMapToolRotateLabel::keyReleaseEvent( QKeyEvent *e )
{
if ( mLabelRubberBand && e->key() == Qt::Key_Escape )
if ( mLabelRubberBand )
{
// escape is cancel
deleteRubberBands();
delete mRotationItem;
mRotationItem = nullptr;
delete mRotationPreviewBox;
mRotationPreviewBox = nullptr;
switch ( e->key() )
{
case Qt::Key_Delete:
{
// delete the label rotation
QgsVectorLayer *vlayer = mCurrentLabel.layer;
if ( vlayer )
{
int rotationCol;
if ( labelIsRotatable( vlayer, mCurrentLabel.settings, rotationCol ) )
{
vlayer->beginEditCommand( tr( "Delete Label Rotation" ) + QStringLiteral( " '%1'" ).arg( currentLabelText( 24 ) ) );
if ( !vlayer->changeAttributeValue( mCurrentLabel.pos.featureId, rotationCol, QVariant() ) )
{
// if the edit command fails, it's likely because the label x/y is being stored in a physical field (not a auxiliary one!)
// and the layer isn't in edit mode
if ( !vlayer->isEditable() )
{
QgisApp::instance()->messageBar()->pushWarning( tr( "Delete Label Rotation" ), tr( "Layer “%1” must be editable in order to move labels from it" ).arg( vlayer->name() ) );
}
else
{
QgisApp::instance()->messageBar()->pushWarning( tr( "Delete Label Rotation" ), tr( "Error encountered while storing new label position" ) );
}

}
vlayer->endEditCommand();
deleteRubberBands();
delete mRotationItem;
mRotationItem = nullptr;
delete mRotationPreviewBox;
mRotationPreviewBox = nullptr;
vlayer->triggerRepaint();
}
}
break;
}

case Qt::Key_Escape:
{
// escape is cancel
deleteRubberBands();
delete mRotationItem;
mRotationItem = nullptr;
delete mRotationPreviewBox;
mRotationPreviewBox = nullptr;
}
}
}
}

Expand Down

0 comments on commit 0e110cf

Please sign in to comment.