Don't auto populate QgsLayoutItemRegistry

Initially create an empty registry, allow it to be populated
at a later stage.
This commit is contained in:
Nyall Dawson 2017-07-07 09:43:36 +10:00
parent 20ca51b59c
commit 179c51c953
5 changed files with 39 additions and 7 deletions

View File

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

View File

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

View File

@ -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.

View File

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

View File

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