Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a 'select all' action to model designer
  • Loading branch information
nyalldawson committed Mar 23, 2020
1 parent 4e1ebf0 commit 7bba9de
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
Expand Up @@ -94,6 +94,11 @@ Returns list of selected component items.
QgsModelComponentGraphicItem *componentItemAt( QPointF position ) const;
%Docstring
Returns the topmost component item at a specified ``position``.
%End

void selectAll();
%Docstring
Selects all the components in the scene.
%End

void deselectAll();
Expand Down
5 changes: 5 additions & 0 deletions src/gui/processing/models/qgsmodeldesignerdialog.cpp
Expand Up @@ -142,6 +142,11 @@ QgsModelDesignerDialog::QgsModelDesignerDialog( QWidget *parent, Qt::WindowFlags
} );
mView->snapper()->setSnapToGrid( mActionSnappingEnabled->isChecked() );

connect( mActionSelectAll, &QAction::triggered, this, [ = ]
{
mScene->selectAll();
} );

mUndoAction = mUndoStack->createUndoAction( this );
mUndoAction->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionUndo.svg" ) ) );
mUndoAction->setShortcuts( QKeySequence::Undo );
Expand Down
17 changes: 17 additions & 0 deletions src/gui/processing/models/qgsmodelgraphicsscene.cpp
Expand Up @@ -222,6 +222,23 @@ QgsModelComponentGraphicItem *QgsModelGraphicsScene::componentItemAt( QPointF po
return nullptr;
}

void QgsModelGraphicsScene::selectAll()
{
//select all items in scene
QgsModelComponentGraphicItem *focusedItem = nullptr;
const QList<QGraphicsItem *> itemList = items();
for ( QGraphicsItem *graphicsItem : itemList )
{
if ( QgsModelComponentGraphicItem *componentItem = dynamic_cast<QgsModelComponentGraphicItem *>( graphicsItem ) )
{
componentItem->setSelected( true );
if ( !focusedItem )
focusedItem = componentItem;
}
}
emit selectedItemChanged( focusedItem );
}

void QgsModelGraphicsScene::deselectAll()
{
//we can't use QGraphicsScene::clearSelection, as that emits no signals
Expand Down
5 changes: 5 additions & 0 deletions src/gui/processing/models/qgsmodelgraphicsscene.h
Expand Up @@ -106,6 +106,11 @@ class GUI_EXPORT QgsModelGraphicsScene : public QGraphicsScene
*/
QgsModelComponentGraphicItem *componentItemAt( QPointF position ) const;

/**
* Selects all the components in the scene.
*/
void selectAll();

/**
* Clears any selected items in the scene.
*
Expand Down
16 changes: 15 additions & 1 deletion src/ui/processing/qgsmodeldesignerdialogbase.ui
Expand Up @@ -87,9 +87,11 @@
<property name="title">
<string>&amp;Edit</string>
</property>
<addaction name="mActionSelectAll"/>
<addaction name="mActionSnapSelected"/>
<addaction name="separator"/>
<addaction name="mActionDeleteComponents"/>
<addaction name="separator"/>
<addaction name="mActionSnapSelected"/>
</widget>
<addaction name="menu_Model"/>
<addaction name="mMenuEdit"/>
Expand Down Expand Up @@ -627,6 +629,18 @@
<string>Snap Selected Components to Grid</string>
</property>
</action>
<action name="mActionSelectAll">
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionSelectAll.svg</normaloff>:/images/themes/default/mActionSelectAll.svg</iconset>
</property>
<property name="text">
<string>Select All</string>
</property>
<property name="shortcut">
<string>Ctrl+A</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down

0 comments on commit 7bba9de

Please sign in to comment.