Skip to content
Permalink
Browse files

[feature] Add select next item above and below commands to composer e…

…dit menu
  • Loading branch information
nyalldawson authored and mhugent committed May 20, 2013
1 parent aaa2fcf commit 99e7ca824f7eb75ca2b75ab94f473104b7b337c2
@@ -238,6 +238,8 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
editMenu->addAction( mActionSelectAll );
editMenu->addAction( mActionDeselectAll );
editMenu->addAction( mActionInvertSelection );
editMenu->addAction( mActionSelectNextBelow );
editMenu->addAction( mActionSelectNextAbove );

QMenu *viewMenu = menuBar()->addMenu( tr( "View" ) );
viewMenu->addAction( mActionZoomIn );
@@ -1779,6 +1781,22 @@ void QgsComposer::on_mActionInvertSelection_triggered()
}
}

void QgsComposer::on_mActionSelectNextAbove_triggered()
{
if ( mComposition )
{
mComposition->selectNextByZOrder( QgsComposition::ZValueAbove );
}
}

void QgsComposer::on_mActionSelectNextBelow_triggered()
{
if ( mComposition )
{
mComposition->selectNextByZOrder( QgsComposition::ZValueBelow );
}
}

void QgsComposer::on_mActionRaiseItems_triggered()
{
if ( mComposition )
@@ -240,6 +240,12 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Unlock all items
void on_mActionUnlockAll_triggered();

//! Select next item below
void on_mActionSelectNextAbove_triggered();

//! Select next item above
void on_mActionSelectNextBelow_triggered();

//! Move selected items one position up
void on_mActionRaiseItems_triggered();

@@ -907,6 +907,75 @@ void QgsComposition::raiseItem( QgsComposerItem* item )
}
}

QgsComposerItem* QgsComposition::getComposerItemAbove( QgsComposerItem* item )
{
//search item z list for selected item
QLinkedListIterator<QgsComposerItem*> it( mItemZList );
if ( it.findNext( item ) )
{
//return next item (list is sorted from lowest->highest items)
if ( it.hasNext() )
{
return it.next();
}
}
return 0;
}

QgsComposerItem* QgsComposition::getComposerItemBelow( QgsComposerItem* item )
{
//search item z list for selected item
QLinkedListIterator<QgsComposerItem*> it( mItemZList );
if ( it.findNext( item ) )
{
//move position to before selected item
it.previous();
//now find previous item, since list is sorted from lowest->highest items
if ( it.hasPrevious() )
{
return it.previous();
}
}
return 0;
}

void QgsComposition::selectNextByZOrder( ZValueDirection direction )
{
QgsComposerItem* previousSelectedItem = 0;
QList<QgsComposerItem*> selectedItems = selectedComposerItems();
if ( selectedItems.size() > 0 )
{
previousSelectedItem = selectedItems.at( 0 );
}

if ( !previousSelectedItem )
{
return;
}

//select item with target z value
QgsComposerItem* selectedItem;
switch ( direction )
{
case QgsComposition::ZValueBelow:
selectedItem = getComposerItemBelow( previousSelectedItem );
break;
case QgsComposition::ZValueAbove:
selectedItem = getComposerItemAbove( previousSelectedItem );
break;
}

if ( !selectedItem )
{
return;
}

//ok, found a good target item
clearSelection();
selectedItem->setSelected( true );
emit selectedItemChanged( selectedItem );
}

void QgsComposition::lowerSelectedItems()
{
QList<QgsComposerItem*> selectedItems = selectedComposerItems();
@@ -82,6 +82,12 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
Crosses
};

enum ZValueDirection
{
ZValueBelow,
ZValueAbove
};

QgsComposition( QgsMapRenderer* mapRenderer );
~QgsComposition();

@@ -257,6 +263,11 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
void moveSelectedItemsToBottom();
void moveItemToBottom( QgsComposerItem* item );

//functions to find items by their position in the z list
void selectNextByZOrder( ZValueDirection direction );
QgsComposerItem* getComposerItemBelow( QgsComposerItem* item );
QgsComposerItem* getComposerItemAbove( QgsComposerItem* item );

//functions to align selected items
void alignSelectedItemsLeft();
void alignSelectedItemsHCenter();
@@ -651,6 +651,28 @@
<string>Invert selection</string>
</property>
</action>
<action name="mActionSelectNextBelow">
<property name="text">
<string>Select Next Item &amp;Below</string>
</property>
<property name="toolTip">
<string>Select next item below</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+[</string>
</property>
</action>
<action name="mActionSelectNextAbove">
<property name="text">
<string>Select Next Item &amp;Above</string>
</property>
<property name="toolTip">
<string>Select next item above</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+]</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>

0 comments on commit 99e7ca8

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