Skip to content
Permalink
Browse files

[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 bd62f307f2ec4ec8c88858f72b86f0ac23fd57a8
@@ -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 );
@@ -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 )
@@ -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();

@@ -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 )
@@ -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() )
@@ -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;}

@@ -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>
@@ -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>
@@ -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"/>

0 comments on commit bd62f30

Please sign in to comment.
You can’t perform that action at this time.