Emit signal when new layout item types are added to registry

This commit is contained in:
Nyall Dawson 2017-07-03 13:29:23 +10:00
parent d23abf955a
commit 97e8d9cf9e
4 changed files with 25 additions and 0 deletions

View File

@ -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 );
};

View File

@ -38,6 +38,7 @@ bool QgsLayoutItemRegistry::addLayoutItemType( QgsLayoutItemAbstractMetadata *me
return false;
mMetadata[metadata->type()] = metadata;
emit typeAdded( metadata->type(), metadata->visibleName() );
return true;
}

View File

@ -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 );

View File

@ -23,6 +23,7 @@
#include <QObject>
#include <QPainter>
#include <QImage>
#include <QtTest/QSignalSpy>
class TestQgsLayoutItem: public QObject
{
@ -128,10 +129,17 @@ void TestQgsLayoutItem::registry()
{
props.clear();
};
QSignalSpy spyTypeAdded( &registry, &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 ) );