Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[feature] Add select next item above and below commands to composer e…
…dit menu
  • Loading branch information
nyalldawson authored and mhugent committed Sep 21, 2013
1 parent aaa2fcf commit 99e7ca8
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 )
Expand Down
6 changes: 6 additions & 0 deletions src/app/composer/qgscomposer.h
Expand Up @@ -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();

Expand Down
69 changes: 69 additions & 0 deletions src/core/composer/qgscomposition.cpp
Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions src/core/composer/qgscomposition.h
Expand Up @@ -82,6 +82,12 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
Crosses
};

enum ZValueDirection
{
ZValueBelow,
ZValueAbove
};

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

Expand Down Expand Up @@ -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();
Expand Down
22 changes: 22 additions & 0 deletions src/ui/qgscomposerbase.ui
Expand Up @@ -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"/>
Expand Down

0 comments on commit 99e7ca8

Please sign in to comment.