Skip to content

Commit 7c81a15

Browse files
committed
Grouped items are not selectable
1 parent 606ad21 commit 7c81a15

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/core/layout/qgslayoutitem.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ void QgsLayoutItem::setParentGroup( QgsLayoutItemGroup *group )
198198
mParentGroupUuid.clear();
199199
else
200200
mParentGroupUuid = group->uuid();
201+
setFlag( QGraphicsItem::ItemIsSelectable, !static_cast< bool>( group ) ); //item in groups cannot be selected
201202
}
202203

203204
void QgsLayoutItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget * )

tests/src/core/testqgslayoutitemgroup.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void TestQgsLayoutItemGroup::createGroupDirect()
100100
QVERIFY( !item->isGroupMember() );
101101
QVERIFY( !item2->parentGroup() );
102102
QVERIFY( !item2->isGroupMember() );
103+
QVERIFY( item->flags() & QGraphicsItem::ItemIsSelectable );
103104

104105
QgsLayoutItemGroup *group = new QgsLayoutItemGroup( &l );
105106
l.addLayoutItem( group );
@@ -112,6 +113,7 @@ void TestQgsLayoutItemGroup::createGroupDirect()
112113
group->addItem( item );
113114
QCOMPARE( item->parentGroup(), group );
114115
QVERIFY( item->isGroupMember() );
116+
QVERIFY( !( item->flags() & QGraphicsItem::ItemIsSelectable ) ); // group items are not selectable
115117
QVERIFY( !item2->parentGroup() );
116118
QVERIFY( !item2->isGroupMember() );
117119
QCOMPARE( group->items().count(), 1 );
@@ -124,6 +126,7 @@ void TestQgsLayoutItemGroup::createGroupDirect()
124126
QVERIFY( item->isGroupMember() );
125127
QCOMPARE( item2->parentGroup(), group );
126128
QVERIFY( item2->isGroupMember() );
129+
QVERIFY( !( item2->flags() & QGraphicsItem::ItemIsSelectable ) ); // group items are not selectable
127130
QCOMPARE( group->items().count(), 2 );
128131
QVERIFY( group->items().contains( item ) );
129132
QVERIFY( group->items().contains( item2 ) );
@@ -151,6 +154,7 @@ void TestQgsLayoutItemGroup::createGroupDirect()
151154
QVERIFY( !item2->parentGroup() );
152155
QCOMPARE( item2->layout(), &l );
153156
QVERIFY( l.items().contains( item2 ) );
157+
QVERIFY( item2->flags() & QGraphicsItem::ItemIsSelectable ); // should be selectable again
154158
}
155159

156160
void TestQgsLayoutItemGroup::createGroup()

0 commit comments

Comments
 (0)