Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] Add select all, select none and invert selection to compose…
…r edit menu
  • Loading branch information
nyalldawson authored and mhugent committed Sep 12, 2013
1 parent 0f2932b commit bd62f30
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 3 deletions.
28 changes: 28 additions & 0 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -234,6 +234,10 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
editMenu->addAction( mActionPaste );
//TODO : "Ctrl+Shift+V" is one way to paste in place, but on some platforms you can use Shift+Ins and F18
editMenu->addAction( mActionPasteInPlace );
editMenu->addSeparator();
editMenu->addAction( mActionSelectAll );
editMenu->addAction( mActionDeselectAll );
editMenu->addAction( mActionInvertSelection );

QMenu *viewMenu = menuBar()->addMenu( tr( "View" ) );
viewMenu->addAction( mActionZoomIn );
Expand Down Expand Up @@ -1751,6 +1755,30 @@ void QgsComposer::on_mActionDeleteSelection_triggered()
}
}

void QgsComposer::on_mActionSelectAll_triggered()
{
if ( mView )
{
mView->selectAll();
}
}

void QgsComposer::on_mActionDeselectAll_triggered()
{
if ( mView )
{
mView->selectNone();
}
}

void QgsComposer::on_mActionInvertSelection_triggered()
{
if ( mView )
{
mView->selectInvert();
}
}

void QgsComposer::on_mActionRaiseItems_triggered()
{
if ( mComposition )
Expand Down
9 changes: 9 additions & 0 deletions src/app/composer/qgscomposer.h
Expand Up @@ -222,6 +222,15 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Delete selected item(s)
void on_mActionDeleteSelection_triggered();

//! Select all items
void on_mActionSelectAll_triggered();

//! Deselect all items
void on_mActionDeselectAll_triggered();

//! Invert selection
void on_mActionInvertSelection_triggered();

//! Ungroup selected item group
void on_mActionUngroupItems_triggered();

Expand Down
72 changes: 72 additions & 0 deletions src/gui/qgscomposerview.cpp
Expand Up @@ -38,6 +38,7 @@
#include "qgscomposerattributetable.h"
#include "qgslogger.h"
#include "qgsaddremovemultiframecommand.h"
#include "qgspaperitem.h"

QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WFlags f )
: QGraphicsView( parent )
Expand Down Expand Up @@ -595,6 +596,77 @@ void QgsComposerView::deleteSelectedItems()
}
}

void QgsComposerView::selectAll()
{
if ( !composition() )
{
return;
}

//select all items in composer
QList<QGraphicsItem *> itemList = composition()->items();
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
for ( ; itemIt != itemList.end(); ++itemIt )
{
QgsComposerItem* mypItem = dynamic_cast<QgsComposerItem *>( *itemIt );
QgsPaperItem* paperItem = dynamic_cast<QgsPaperItem*>( *itemIt );
if ( mypItem && !paperItem )
{
if ( !mypItem->positionLock() )
{
mypItem->setSelected( true );
}
else
{
//deselect all locked items
mypItem->setSelected( false );
}
emit selectedItemChanged( mypItem );
}
}
}

void QgsComposerView::selectNone()
{
if ( !composition() )
{
return;
}

composition()->clearSelection();
}

void QgsComposerView::selectInvert()
{
if ( !composition() )
{
return;
}

//check all items in composer
QList<QGraphicsItem *> itemList = composition()->items();
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
for ( ; itemIt != itemList.end(); ++itemIt )
{
QgsComposerItem* mypItem = dynamic_cast<QgsComposerItem *>( *itemIt );
QgsPaperItem* paperItem = dynamic_cast<QgsPaperItem*>( *itemIt );
if ( mypItem && !paperItem )
{
//flip selected state for items (and deselect any locked items)
if ( mypItem->selected() || mypItem->positionLock() )
{

mypItem->setSelected( false );
}
else
{
mypItem->setSelected( true );
emit selectedItemChanged( mypItem );
}
}
}
}

void QgsComposerView::keyPressEvent( QKeyEvent * e )
{
if ( !composition() )
Expand Down
9 changes: 9 additions & 0 deletions src/gui/qgscomposerview.h
Expand Up @@ -104,6 +104,15 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
/**Deletes selected items*/
void deleteSelectedItems();

/**Selects all items*/
void selectAll();

/**Deselects all items*/
void selectNone();

/**Inverts current selection*/
void selectInvert();

QgsComposerView::Tool currentTool() const {return mCurrentTool;}
void setCurrentTool( QgsComposerView::Tool t ) {mCurrentTool = t;}

Expand Down
36 changes: 33 additions & 3 deletions src/ui/qgscomposerbase.ui
Expand Up @@ -458,7 +458,7 @@
</iconset>
</property>
<property name="text">
<string>Undo</string>
<string>&amp;Undo</string>
</property>
<property name="toolTip">
<string>Revert last change</string>
Expand All @@ -473,7 +473,7 @@
<normaloff>:/images/themes/default/mActionRedo.png</normaloff>:/images/themes/default/mActionRedo.png</iconset>
</property>
<property name="text">
<string>Redo</string>
<string>&amp;Redo</string>
</property>
<property name="toolTip">
<string>Restore last change</string>
Expand Down Expand Up @@ -614,7 +614,37 @@
<property name="shortcut">
<string>Del</string>
</property>
</action>
</action>
<action name="mActionDeselectAll">
<property name="text">
<string>De&amp;select All</string>
</property>
<property name="toolTip">
<string>Deselect all</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+A</string>
</property>
</action>
<action name="mActionSelectAll">
<property name="text">
<string>Select &amp;All</string>
</property>
<property name="toolTip">
<string>Select all items</string>
</property>
<property name="shortcut">
<string>Ctrl+A</string>
</property>
</action>
<action name="mActionInvertSelection">
<property name="text">
<string>&amp;Invert Selection</string>
</property>
<property name="toolTip">
<string>Invert selection</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>
Expand Down

0 comments on commit bd62f30

Please sign in to comment.