Skip to content
Permalink
Browse files

[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 53e24f1951471f2881d423e67de610cfa292102c
Showing with 41 additions and 0 deletions.
  1. +41 −0 src/app/layout/qgslayoutappmenuprovider.cpp
@@ -15,6 +15,7 @@

#include "qgslayoutappmenuprovider.h"
#include "qgslayoutitempage.h"
#include "qgslayoutitemgroup.h"
#include "qgslayoutdesignerdialog.h"
#include "qgslayout.h"
#include <QMenu>
@@ -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 )

0 comments on commit 53e24f1

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