Skip to content

Commit bd62f30

Browse files
nyalldawsonmhugent
authored andcommitted
[FEATURE] Add select all, select none and invert selection to composer edit menu
1 parent 0f2932b commit bd62f30

File tree

5 files changed

+151
-3
lines changed

5 files changed

+151
-3
lines changed

src/app/composer/qgscomposer.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
234234
editMenu->addAction( mActionPaste );
235235
//TODO : "Ctrl+Shift+V" is one way to paste in place, but on some platforms you can use Shift+Ins and F18
236236
editMenu->addAction( mActionPasteInPlace );
237+
editMenu->addSeparator();
238+
editMenu->addAction( mActionSelectAll );
239+
editMenu->addAction( mActionDeselectAll );
240+
editMenu->addAction( mActionInvertSelection );
237241

238242
QMenu *viewMenu = menuBar()->addMenu( tr( "View" ) );
239243
viewMenu->addAction( mActionZoomIn );
@@ -1751,6 +1755,30 @@ void QgsComposer::on_mActionDeleteSelection_triggered()
17511755
}
17521756
}
17531757

1758+
void QgsComposer::on_mActionSelectAll_triggered()
1759+
{
1760+
if ( mView )
1761+
{
1762+
mView->selectAll();
1763+
}
1764+
}
1765+
1766+
void QgsComposer::on_mActionDeselectAll_triggered()
1767+
{
1768+
if ( mView )
1769+
{
1770+
mView->selectNone();
1771+
}
1772+
}
1773+
1774+
void QgsComposer::on_mActionInvertSelection_triggered()
1775+
{
1776+
if ( mView )
1777+
{
1778+
mView->selectInvert();
1779+
}
1780+
}
1781+
17541782
void QgsComposer::on_mActionRaiseItems_triggered()
17551783
{
17561784
if ( mComposition )

src/app/composer/qgscomposer.h

+9
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,15 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
222222
//! Delete selected item(s)
223223
void on_mActionDeleteSelection_triggered();
224224

225+
//! Select all items
226+
void on_mActionSelectAll_triggered();
227+
228+
//! Deselect all items
229+
void on_mActionDeselectAll_triggered();
230+
231+
//! Invert selection
232+
void on_mActionInvertSelection_triggered();
233+
225234
//! Ungroup selected item group
226235
void on_mActionUngroupItems_triggered();
227236

src/gui/qgscomposerview.cpp

+72
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "qgscomposerattributetable.h"
3939
#include "qgslogger.h"
4040
#include "qgsaddremovemultiframecommand.h"
41+
#include "qgspaperitem.h"
4142

4243
QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WFlags f )
4344
: QGraphicsView( parent )
@@ -595,6 +596,77 @@ void QgsComposerView::deleteSelectedItems()
595596
}
596597
}
597598

599+
void QgsComposerView::selectAll()
600+
{
601+
if ( !composition() )
602+
{
603+
return;
604+
}
605+
606+
//select all items in composer
607+
QList<QGraphicsItem *> itemList = composition()->items();
608+
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
609+
for ( ; itemIt != itemList.end(); ++itemIt )
610+
{
611+
QgsComposerItem* mypItem = dynamic_cast<QgsComposerItem *>( *itemIt );
612+
QgsPaperItem* paperItem = dynamic_cast<QgsPaperItem*>( *itemIt );
613+
if ( mypItem && !paperItem )
614+
{
615+
if ( !mypItem->positionLock() )
616+
{
617+
mypItem->setSelected( true );
618+
}
619+
else
620+
{
621+
//deselect all locked items
622+
mypItem->setSelected( false );
623+
}
624+
emit selectedItemChanged( mypItem );
625+
}
626+
}
627+
}
628+
629+
void QgsComposerView::selectNone()
630+
{
631+
if ( !composition() )
632+
{
633+
return;
634+
}
635+
636+
composition()->clearSelection();
637+
}
638+
639+
void QgsComposerView::selectInvert()
640+
{
641+
if ( !composition() )
642+
{
643+
return;
644+
}
645+
646+
//check all items in composer
647+
QList<QGraphicsItem *> itemList = composition()->items();
648+
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
649+
for ( ; itemIt != itemList.end(); ++itemIt )
650+
{
651+
QgsComposerItem* mypItem = dynamic_cast<QgsComposerItem *>( *itemIt );
652+
QgsPaperItem* paperItem = dynamic_cast<QgsPaperItem*>( *itemIt );
653+
if ( mypItem && !paperItem )
654+
{
655+
//flip selected state for items (and deselect any locked items)
656+
if ( mypItem->selected() || mypItem->positionLock() )
657+
{
658+
659+
mypItem->setSelected( false );
660+
}
661+
else
662+
{
663+
mypItem->setSelected( true );
664+
emit selectedItemChanged( mypItem );
665+
}
666+
}
667+
}
668+
}
669+
598670
void QgsComposerView::keyPressEvent( QKeyEvent * e )
599671
{
600672
if ( !composition() )

src/gui/qgscomposerview.h

+9
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
104104
/**Deletes selected items*/
105105
void deleteSelectedItems();
106106

107+
/**Selects all items*/
108+
void selectAll();
109+
110+
/**Deselects all items*/
111+
void selectNone();
112+
113+
/**Inverts current selection*/
114+
void selectInvert();
115+
107116
QgsComposerView::Tool currentTool() const {return mCurrentTool;}
108117
void setCurrentTool( QgsComposerView::Tool t ) {mCurrentTool = t;}
109118

src/ui/qgscomposerbase.ui

+33-3
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@
458458
</iconset>
459459
</property>
460460
<property name="text">
461-
<string>Undo</string>
461+
<string>&amp;Undo</string>
462462
</property>
463463
<property name="toolTip">
464464
<string>Revert last change</string>
@@ -473,7 +473,7 @@
473473
<normaloff>:/images/themes/default/mActionRedo.png</normaloff>:/images/themes/default/mActionRedo.png</iconset>
474474
</property>
475475
<property name="text">
476-
<string>Redo</string>
476+
<string>&amp;Redo</string>
477477
</property>
478478
<property name="toolTip">
479479
<string>Restore last change</string>
@@ -614,7 +614,37 @@
614614
<property name="shortcut">
615615
<string>Del</string>
616616
</property>
617-
</action>
617+
</action>
618+
<action name="mActionDeselectAll">
619+
<property name="text">
620+
<string>De&amp;select All</string>
621+
</property>
622+
<property name="toolTip">
623+
<string>Deselect all</string>
624+
</property>
625+
<property name="shortcut">
626+
<string>Ctrl+Shift+A</string>
627+
</property>
628+
</action>
629+
<action name="mActionSelectAll">
630+
<property name="text">
631+
<string>Select &amp;All</string>
632+
</property>
633+
<property name="toolTip">
634+
<string>Select all items</string>
635+
</property>
636+
<property name="shortcut">
637+
<string>Ctrl+A</string>
638+
</property>
639+
</action>
640+
<action name="mActionInvertSelection">
641+
<property name="text">
642+
<string>&amp;Invert Selection</string>
643+
</property>
644+
<property name="toolTip">
645+
<string>Invert selection</string>
646+
</property>
647+
</action>
618648
</widget>
619649
<resources>
620650
<include location="../../images/images.qrc"/>

0 commit comments

Comments
 (0)