Skip to content

Commit

Permalink
Emit signal when new layout item types are added to registry
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 3, 2017
1 parent d23abf9 commit 97e8d9c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions python/core/layout/qgslayoutitemregistry.sip
Expand Up @@ -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 );
};
Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgslayoutitemregistry.cpp
Expand Up @@ -38,6 +38,7 @@ bool QgsLayoutItemRegistry::addLayoutItemType( QgsLayoutItemAbstractMetadata *me
return false;

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

Expand Down
8 changes: 8 additions & 0 deletions src/core/layout/qgslayoutitemregistry.h
Expand Up @@ -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 );
Expand Down
8 changes: 8 additions & 0 deletions tests/src/core/testqgslayoutitem.cpp
Expand Up @@ -23,6 +23,7 @@
#include <QObject>
#include <QPainter>
#include <QImage>
#include <QtTest/QSignalSpy>

class TestQgsLayoutItem: public QObject
{
Expand Down Expand Up @@ -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 ) );
Expand Down

0 comments on commit 97e8d9c

Please sign in to comment.