Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 179c51c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
11 changes: 10 additions & 1 deletion python/core/layout/qgslayoutitemregistry.sip
Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions src/core/layout/qgslayoutitemregistry.cpp
Expand Up @@ -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*
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/core/layout/qgslayoutitemregistry.h
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsapplication.cpp
Expand Up @@ -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();
}
Expand Down
7 changes: 7 additions & 0 deletions tests/src/core/testqgslayoutitem.cpp
Expand Up @@ -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 )
Expand Down

0 comments on commit 179c51c

Please sign in to comment.