From 97e8d9cf9e0fdca825a74faeccc533eef82b1bd4 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 3 Jul 2017 13:29:23 +1000 Subject: [PATCH] Emit signal when new layout item types are added to registry --- python/core/layout/qgslayoutitemregistry.sip | 8 ++++++++ src/core/layout/qgslayoutitemregistry.cpp | 1 + src/core/layout/qgslayoutitemregistry.h | 8 ++++++++ tests/src/core/testqgslayoutitem.cpp | 8 ++++++++ 4 files changed, 25 insertions(+) diff --git a/python/core/layout/qgslayoutitemregistry.sip b/python/core/layout/qgslayoutitemregistry.sip index 9ac96ebcf5e..fa69829fa5a 100644 --- a/python/core/layout/qgslayoutitemregistry.sip +++ b/python/core/layout/qgslayoutitemregistry.sip @@ -148,6 +148,14 @@ class QgsLayoutItemRegistry : QObject :rtype: QMap< int, str> %End + signals: + + void typeAdded( int type, const QString &name ); +%Docstring + Emitted whenever a new item type is added to the registry, with the specified + ``type`` and visible ``name``. +%End + private: QgsLayoutItemRegistry( const QgsLayoutItemRegistry &rh ); }; diff --git a/src/core/layout/qgslayoutitemregistry.cpp b/src/core/layout/qgslayoutitemregistry.cpp index 38933feaedd..53cd3305901 100644 --- a/src/core/layout/qgslayoutitemregistry.cpp +++ b/src/core/layout/qgslayoutitemregistry.cpp @@ -38,6 +38,7 @@ bool QgsLayoutItemRegistry::addLayoutItemType( QgsLayoutItemAbstractMetadata *me return false; mMetadata[metadata->type()] = metadata; + emit typeAdded( metadata->type(), metadata->visibleName() ); return true; } diff --git a/src/core/layout/qgslayoutitemregistry.h b/src/core/layout/qgslayoutitemregistry.h index 650efec16b8..bc4515111c0 100644 --- a/src/core/layout/qgslayoutitemregistry.h +++ b/src/core/layout/qgslayoutitemregistry.h @@ -239,6 +239,14 @@ class CORE_EXPORT QgsLayoutItemRegistry : public QObject */ QMap< int, QString> itemTypes() const; + signals: + + /** + * Emitted whenever a new item type is added to the registry, with the specified + * \a type and visible \a name. + */ + void typeAdded( int type, const QString &name ); + private: #ifdef SIP_RUN QgsLayoutItemRegistry( const QgsLayoutItemRegistry &rh ); diff --git a/tests/src/core/testqgslayoutitem.cpp b/tests/src/core/testqgslayoutitem.cpp index 4062f07ba8e..4c321a49099 100644 --- a/tests/src/core/testqgslayoutitem.cpp +++ b/tests/src/core/testqgslayoutitem.cpp @@ -23,6 +23,7 @@ #include #include #include +#include class TestQgsLayoutItem: public QObject { @@ -128,10 +129,17 @@ void TestQgsLayoutItem::registry() { props.clear(); }; + + QSignalSpy spyTypeAdded( ®istry, &QgsLayoutItemRegistry::typeAdded ); + QgsLayoutItemMetadata *metadata = new QgsLayoutItemMetadata( 2, QStringLiteral( "my type" ), create, resolve, createWidget ); QVERIFY( registry.addLayoutItemType( metadata ) ); + QCOMPARE( spyTypeAdded.count(), 1 ); + QCOMPARE( spyTypeAdded.value( 0 ).at( 0 ).toInt(), 2 ); + QCOMPARE( spyTypeAdded.value( 0 ).at( 1 ).toString(), QStringLiteral( "my type" ) ); // duplicate type id QVERIFY( !registry.addLayoutItemType( metadata ) ); + QCOMPARE( spyTypeAdded.count(), 1 ); //retrieve metadata QVERIFY( !registry.itemMetadata( -1 ) );