Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE][layouts] Add group/ungroup action to layout context menu
Group/ungroup actions show only when an appropriate selection
is present. I.e. "group" appears when a selection of at least
two items is present, and "ungroup" appears only when at least
one of the selected items is a group.

Refs #1830
  • Loading branch information
nyalldawson committed Oct 9, 2017
1 parent fdc0f75 commit 53e24f1
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/app/layout/qgslayoutappmenuprovider.cpp
Expand Up @@ -15,6 +15,7 @@

#include "qgslayoutappmenuprovider.h"
#include "qgslayoutitempage.h"
#include "qgslayoutitemgroup.h"
#include "qgslayoutdesignerdialog.h"
#include "qgslayout.h"
#include <QMenu>
Expand All @@ -31,6 +32,46 @@ QMenu *QgsLayoutAppMenuProvider::createContextMenu( QWidget *parent, QgsLayout *
{
QMenu *menu = new QMenu( parent );

const QList< QgsLayoutItem * > selectedItems = layout->selectedLayoutItems();
if ( !selectedItems.empty() )
{
bool addedGroupAction = false;
if ( selectedItems.count() > 1 )
{
QAction *groupAction = new QAction( tr( "Group" ), menu );
connect( groupAction, &QAction::triggered, this, [this]()
{
mDesigner->view()->groupSelectedItems();
} );
menu->addAction( groupAction );
addedGroupAction = true;
}
bool foundSelectedGroup = false;
QList< QgsLayoutItemGroup * > groups;
layout->layoutItems( groups );
for ( QgsLayoutItemGroup *group : qgsAsConst( groups ) )
{
if ( group->isSelected() )
{
foundSelectedGroup = true;
break;
}
}
if ( foundSelectedGroup )
{
QAction *ungroupAction = new QAction( tr( "Ungroup" ), menu );
connect( ungroupAction, &QAction::triggered, this, [this]()
{
mDesigner->view()->ungroupSelectedItems();
} );
menu->addAction( ungroupAction );
addedGroupAction = true;
}

if ( addedGroupAction )
menu->addSeparator();
}

// is a page under the mouse?
QgsLayoutItemPage *page = layout->pageCollection()->pageAtPoint( layoutPoint );
if ( page )
Expand Down

0 comments on commit 53e24f1

Please sign in to comment.