Skip to content
Permalink
Browse files

Don't auto populate QgsLayoutItemRegistry

Initially create an empty registry, allow it to be populated
at a later stage.
  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent 20ca51b commit 179c51c9532bf9c489c01a80bae05202755e57ff
@@ -110,14 +110,23 @@ class QgsLayoutItemRegistry : QObject

QgsLayoutItemRegistry( QObject *parent = 0 );
%Docstring
Creates a registry and populates it with standard item types.
Creates a new empty item registry.

QgsLayoutItemRegistry is not usually directly created, but rather accessed through
QgsApplication.layoutItemRegistry().

.. seealso:: populate()
%End

~QgsLayoutItemRegistry();

bool populate();
%Docstring
Populates the registry with standard item types. If called on a non-empty registry
then this will have no effect and will return false.
:rtype: bool
%End


QgsLayoutItemAbstractMetadata *itemMetadata( int type ) const;
%Docstring
@@ -20,6 +20,17 @@
QgsLayoutItemRegistry::QgsLayoutItemRegistry( QObject *parent )
: QObject( parent )
{
}

QgsLayoutItemRegistry::~QgsLayoutItemRegistry()
{
qDeleteAll( mMetadata );
}

bool QgsLayoutItemRegistry::populate()
{
if ( !mMetadata.isEmpty() )
return false;

// add temporary item to register
auto createTemporaryItem = []( QgsLayout * layout, const QVariantMap & )->QgsLayoutItem*
@@ -28,11 +39,7 @@ QgsLayoutItemRegistry::QgsLayoutItemRegistry( QObject *parent )
};

addLayoutItemType( new QgsLayoutItemMetadata( 101, QStringLiteral( "temp type" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddLabel.svg" ) ), createTemporaryItem ) );
}

QgsLayoutItemRegistry::~QgsLayoutItemRegistry()
{
qDeleteAll( mMetadata );
return true;
}

QgsLayoutItemAbstractMetadata *QgsLayoutItemRegistry::itemMetadata( int type ) const
@@ -232,15 +232,23 @@ class CORE_EXPORT QgsLayoutItemRegistry : public QObject
};

/**
* Creates a registry and populates it with standard item types.
* Creates a new empty item registry.
*
* QgsLayoutItemRegistry is not usually directly created, but rather accessed through
* QgsApplication::layoutItemRegistry().
*
* \see populate()
*/
QgsLayoutItemRegistry( QObject *parent = nullptr );

~QgsLayoutItemRegistry();

/**
* Populates the registry with standard item types. If called on a non-empty registry
* then this will have no effect and will return false.
*/
bool populate();

//! QgsLayoutItemRegistry cannot be copied.
QgsLayoutItemRegistry( const QgsLayoutItemRegistry &rh ) = delete;
//! QgsLayoutItemRegistryQgsLayoutItemRegistry cannot be copied.
@@ -1596,6 +1596,7 @@ QgsApplication::ApplicationMembers::ApplicationMembers()
mProcessingRegistry = new QgsProcessingRegistry();
mPageSizeRegistry = new QgsPageSizeRegistry();
mLayoutItemRegistry = new QgsLayoutItemRegistry();
mLayoutItemRegistry->populate();
mProcessingRegistry->addProvider( new QgsNativeAlgorithms( mProcessingRegistry ) );
mAnnotationRegistry = new QgsAnnotationRegistry();
}
@@ -159,6 +159,13 @@ void TestQgsLayoutItem::registry()
QCOMPARE( props.size(), 1 );
registry.resolvePaths( 2, props, QgsPathResolver(), true );
QVERIFY( props.isEmpty() );

//test populate
QgsLayoutItemRegistry reg2;
QVERIFY( reg2.itemTypes().isEmpty() );
QVERIFY( reg2.populate() );
QVERIFY( !reg2.itemTypes().isEmpty() );
QVERIFY( !reg2.populate() );
}

bool TestQgsLayoutItem::renderCheck( QString testName, QImage &image, int mismatchCount )

0 comments on commit 179c51c

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