Skip to content

Commit

Permalink
Port delete action - TODO: undo/redo
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 6, 2017
1 parent e3616f0 commit 95a76ee
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/gui/layout/qgslayoutview.sip
Expand Up @@ -278,6 +278,11 @@ class QgsLayoutView: QGraphicsView
.. seealso:: lockSelectedItems()
%End

void deleteSelectedItems();
%Docstring
Deletes all selected items.
%End

void viewChanged();
%Docstring
Updates associated rulers and other widgets after view extent or zoom has changed.
Expand Down
9 changes: 9 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -233,6 +233,10 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
//Ctrl+= should also trigger zoom in
QShortcut *ctrlEquals = new QShortcut( QKeySequence( QStringLiteral( "Ctrl+=" ) ), this );
connect( ctrlEquals, &QShortcut::activated, mActionZoomIn, &QAction::trigger );
//Backspace should also trigger delete selection
QShortcut *backSpace = new QShortcut( QKeySequence( QStringLiteral( "Backspace" ) ), this );
connect( backSpace, &QShortcut::activated, mActionDeleteSelection, &QAction::trigger );


connect( mActionZoomIn, &QAction::triggered, mView, &QgsLayoutView::zoomIn );
connect( mActionZoomOut, &QAction::triggered, mView, &QgsLayoutView::zoomOut );
Expand Down Expand Up @@ -322,6 +326,11 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla

connect( mActionHidePanels, &QAction::toggled, this, &QgsLayoutDesignerDialog::setPanelVisibility );

connect( mActionDeleteSelection, &QAction::triggered, this, [ = ]
{
mView->deleteSelectedItems();
} );

//create status bar labels
mStatusCursorXLabel = new QLabel( mStatusBar );
mStatusCursorXLabel->setMinimumWidth( 100 );
Expand Down
52 changes: 52 additions & 0 deletions src/gui/layout/qgslayoutview.cpp
Expand Up @@ -540,6 +540,58 @@ void QgsLayoutView::unlockAllItems()
emit itemFocused( focusItem );
}

void QgsLayoutView::deleteSelectedItems()
{
if ( !currentLayout() )
{
return;
}

#if 0 //TODO
if ( mCurrentTool == QgsComposerView::EditNodesItem )
{
if ( mNodesItemIndex != -1 )
{
composition()->beginCommand( mNodesItem, tr( "Remove item node" ) );
if ( mNodesItem->removeNode( mNodesItemIndex ) )
{
composition()->endCommand();
if ( mNodesItem->nodesSize() > 0 )
{
mNodesItemIndex = mNodesItem->selectedNode();
// setSelectedNode( mNodesItem, mNodesItemIndex );
}
else
{
mNodesItemIndex = -1;
mNodesItem = nullptr;
}
scene()->update();
}
else
{
composition()->cancelCommand();
}
}
}
else
{
#endif
const QList<QgsLayoutItem *> selectedItems = currentLayout()->selectedLayoutItems();

currentLayout()->undoStack()->beginMacro( tr( "Items deleted" ) );
//delete selected items
for ( QgsLayoutItem *item : selectedItems )
{
currentLayout()->removeLayoutItem( item );
}
currentLayout()->undoStack()->endMacro();

#if 0
}
#endif
}

void QgsLayoutView::mousePressEvent( QMouseEvent *event )
{
mSnapMarker->setVisible( false );
Expand Down
5 changes: 5 additions & 0 deletions src/gui/layout/qgslayoutview.h
Expand Up @@ -322,6 +322,11 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
*/
void unlockAllItems();

/**
* Deletes all selected items.
*/
void deleteSelectedItems();

/**
* Updates associated rulers and other widgets after view extent or zoom has changed.
* This should be called after calling any of the QGraphicsView
Expand Down
17 changes: 17 additions & 0 deletions src/ui/layout/qgslayoutdesignerbase.ui
Expand Up @@ -146,6 +146,8 @@
<addaction name="mActionUndo"/>
<addaction name="mActionRedo"/>
<addaction name="separator"/>
<addaction name="mActionDeleteSelection"/>
<addaction name="separator"/>
<addaction name="mActionSelectAll"/>
<addaction name="mActionDeselectAll"/>
<addaction name="mActionInvertSelection"/>
Expand Down Expand Up @@ -894,6 +896,21 @@
<string>Resizes item height to match the tallest selected item</string>
</property>
</action>
<action name="mActionDeleteSelection">
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionDeleteSelected.svg</normaloff>:/images/themes/default/mActionDeleteSelected.svg</iconset>
</property>
<property name="text">
<string>&amp;Delete</string>
</property>
<property name="toolTip">
<string>Delete selected items</string>
</property>
<property name="shortcut">
<string>Del</string>
</property>
</action>
</widget>
<resources>
<include location="../../../images/images.qrc"/>
Expand Down

0 comments on commit 95a76ee

Please sign in to comment.