Skip to content

Commit 179c51c

Browse files
committedJul 11, 2017
Don't auto populate QgsLayoutItemRegistry
Initially create an empty registry, allow it to be populated at a later stage.
1 parent 20ca51b commit 179c51c

File tree

5 files changed

+39
-7
lines changed

5 files changed

+39
-7
lines changed
 

‎python/core/layout/qgslayoutitemregistry.sip

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,23 @@ class QgsLayoutItemRegistry : QObject
110110

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

115115
QgsLayoutItemRegistry is not usually directly created, but rather accessed through
116116
QgsApplication.layoutItemRegistry().
117+
118+
.. seealso:: populate()
117119
%End
118120

119121
~QgsLayoutItemRegistry();
120122

123+
bool populate();
124+
%Docstring
125+
Populates the registry with standard item types. If called on a non-empty registry
126+
then this will have no effect and will return false.
127+
:rtype: bool
128+
%End
129+
121130

122131
QgsLayoutItemAbstractMetadata *itemMetadata( int type ) const;
123132
%Docstring

‎src/core/layout/qgslayoutitemregistry.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@
2020
QgsLayoutItemRegistry::QgsLayoutItemRegistry( QObject *parent )
2121
: QObject( parent )
2222
{
23+
}
24+
25+
QgsLayoutItemRegistry::~QgsLayoutItemRegistry()
26+
{
27+
qDeleteAll( mMetadata );
28+
}
29+
30+
bool QgsLayoutItemRegistry::populate()
31+
{
32+
if ( !mMetadata.isEmpty() )
33+
return false;
2334

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

3041
addLayoutItemType( new QgsLayoutItemMetadata( 101, QStringLiteral( "temp type" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddLabel.svg" ) ), createTemporaryItem ) );
31-
}
32-
33-
QgsLayoutItemRegistry::~QgsLayoutItemRegistry()
34-
{
35-
qDeleteAll( mMetadata );
42+
return true;
3643
}
3744

3845
QgsLayoutItemAbstractMetadata *QgsLayoutItemRegistry::itemMetadata( int type ) const

‎src/core/layout/qgslayoutitemregistry.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,23 @@ class CORE_EXPORT QgsLayoutItemRegistry : public QObject
232232
};
233233

234234
/**
235-
* Creates a registry and populates it with standard item types.
235+
* Creates a new empty item registry.
236236
*
237237
* QgsLayoutItemRegistry is not usually directly created, but rather accessed through
238238
* QgsApplication::layoutItemRegistry().
239+
*
240+
* \see populate()
239241
*/
240242
QgsLayoutItemRegistry( QObject *parent = nullptr );
241243

242244
~QgsLayoutItemRegistry();
243245

246+
/**
247+
* Populates the registry with standard item types. If called on a non-empty registry
248+
* then this will have no effect and will return false.
249+
*/
250+
bool populate();
251+
244252
//! QgsLayoutItemRegistry cannot be copied.
245253
QgsLayoutItemRegistry( const QgsLayoutItemRegistry &rh ) = delete;
246254
//! QgsLayoutItemRegistryQgsLayoutItemRegistry cannot be copied.

‎src/core/qgsapplication.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,7 @@ QgsApplication::ApplicationMembers::ApplicationMembers()
15961596
mProcessingRegistry = new QgsProcessingRegistry();
15971597
mPageSizeRegistry = new QgsPageSizeRegistry();
15981598
mLayoutItemRegistry = new QgsLayoutItemRegistry();
1599+
mLayoutItemRegistry->populate();
15991600
mProcessingRegistry->addProvider( new QgsNativeAlgorithms( mProcessingRegistry ) );
16001601
mAnnotationRegistry = new QgsAnnotationRegistry();
16011602
}

‎tests/src/core/testqgslayoutitem.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ void TestQgsLayoutItem::registry()
159159
QCOMPARE( props.size(), 1 );
160160
registry.resolvePaths( 2, props, QgsPathResolver(), true );
161161
QVERIFY( props.isEmpty() );
162+
163+
//test populate
164+
QgsLayoutItemRegistry reg2;
165+
QVERIFY( reg2.itemTypes().isEmpty() );
166+
QVERIFY( reg2.populate() );
167+
QVERIFY( !reg2.itemTypes().isEmpty() );
168+
QVERIFY( !reg2.populate() );
162169
}
163170

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

0 commit comments

Comments
 (0)
Please sign in to comment.