mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-07 00:05:28 -04:00
[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
This commit is contained in:
parent
fdc0f75066
commit
53e24f1951
@ -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 )
|
||||
|
Loading…
x
Reference in New Issue
Block a user