mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Emit signal when new layout item types are added to registry
This commit is contained in:
parent
d23abf955a
commit
97e8d9cf9e
@ -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( ®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 ) );
|
||||
|
Loading…
x
Reference in New Issue
Block a user