Skip to content
Permalink
Browse files
Add a signal when an item is added to a layout
  • Loading branch information
nyalldawson committed Jun 9, 2021
1 parent 6bd24e5 commit 309a2a6bad481e1da314001b9ed57ca8d78f9393
@@ -663,6 +663,13 @@ and updated.
Emitted whenever the ``total`` number of background tasks running in items from the layout changes.

.. versionadded:: 3.10
%End

void itemAdded( QgsLayoutItem *item );
%Docstring
Emitted when an ``item`` was added to the layout.

.. versionadded:: 3.20
%End

};
@@ -872,6 +872,7 @@ void QgsLayout::addLayoutItemPrivate( QgsLayoutItem *item )
updateBounds();
mItemsModel->rebuildZList();
connect( item, &QgsLayoutItem::backgroundTaskCountChanged, this, &QgsLayout::itemBackgroundTaskCountChanged );
emit itemAdded( item );
}

void QgsLayout::removeLayoutItemPrivate( QgsLayoutItem *item )
@@ -713,6 +713,13 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
*/
void backgroundTaskCountChanged( int total );

/**
* Emitted when an \a item was added to the layout.
*
* \since QGIS 3.20
*/
void itemAdded( QgsLayoutItem *item );

private slots:
void itemBackgroundTaskCountChanged( int count );

@@ -383,7 +383,10 @@ void TestQgsLayout::addItem()
shape1->attemptResize( QgsLayoutSize( 140, 70 ) );
shape1->attemptMove( QgsLayoutPoint( 90, 50 ) );

QSignalSpy itemAddedSpy( &l, &QgsLayout::itemAdded );
l.addLayoutItem( shape1 );
QCOMPARE( itemAddedSpy.count(), 1 );
QCOMPARE( itemAddedSpy.at( 0 ).at( 0 ).value< QgsLayoutItem * >(), shape1 );
QVERIFY( l.items().contains( shape1 ) );
// bounds should be updated to include item
QGSCOMPARENEAR( l.sceneRect().left(), 89.850, 0.001 );

0 comments on commit 309a2a6

Please sign in to comment.