Skip to content
Permalink
Browse files

Emit signal when new layout item types are added to registry

  • Loading branch information
nyalldawson committed Jul 3, 2017
1 parent d23abf9 commit 97e8d9cf9e0fdca825a74faeccc533eef82b1bd4
@@ -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 );
};
@@ -38,6 +38,7 @@ bool QgsLayoutItemRegistry::addLayoutItemType( QgsLayoutItemAbstractMetadata *me
return false;

mMetadata[metadata->type()] = metadata;
emit typeAdded( metadata->type(), metadata->visibleName() );
return true;
}

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

0 comments on commit 97e8d9c

Please sign in to comment.
You can’t perform that action at this time.