Skip to content

Commit 53e24f1

Browse files
committedOct 9, 2017
[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
1 parent fdc0f75 commit 53e24f1

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
 

‎src/app/layout/qgslayoutappmenuprovider.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "qgslayoutappmenuprovider.h"
1717
#include "qgslayoutitempage.h"
18+
#include "qgslayoutitemgroup.h"
1819
#include "qgslayoutdesignerdialog.h"
1920
#include "qgslayout.h"
2021
#include <QMenu>
@@ -31,6 +32,46 @@ QMenu *QgsLayoutAppMenuProvider::createContextMenu( QWidget *parent, QgsLayout *
3132
{
3233
QMenu *menu = new QMenu( parent );
3334

35+
const QList< QgsLayoutItem * > selectedItems = layout->selectedLayoutItems();
36+
if ( !selectedItems.empty() )
37+
{
38+
bool addedGroupAction = false;
39+
if ( selectedItems.count() > 1 )
40+
{
41+
QAction *groupAction = new QAction( tr( "Group" ), menu );
42+
connect( groupAction, &QAction::triggered, this, [this]()
43+
{
44+
mDesigner->view()->groupSelectedItems();
45+
} );
46+
menu->addAction( groupAction );
47+
addedGroupAction = true;
48+
}
49+
bool foundSelectedGroup = false;
50+
QList< QgsLayoutItemGroup * > groups;
51+
layout->layoutItems( groups );
52+
for ( QgsLayoutItemGroup *group : qgsAsConst( groups ) )
53+
{
54+
if ( group->isSelected() )
55+
{
56+
foundSelectedGroup = true;
57+
break;
58+
}
59+
}
60+
if ( foundSelectedGroup )
61+
{
62+
QAction *ungroupAction = new QAction( tr( "Ungroup" ), menu );
63+
connect( ungroupAction, &QAction::triggered, this, [this]()
64+
{
65+
mDesigner->view()->ungroupSelectedItems();
66+
} );
67+
menu->addAction( ungroupAction );
68+
addedGroupAction = true;
69+
}
70+
71+
if ( addedGroupAction )
72+
menu->addSeparator();
73+
}
74+
3475
// is a page under the mouse?
3576
QgsLayoutItemPage *page = layout->pageCollection()->pageAtPoint( layoutPoint );
3677
if ( page )

0 commit comments

Comments
 (0)
Please sign in to comment.