mirror of
				https://github.com/qgis/QGIS.git
				synced 2025-11-04 00:04:25 -05:00 
			
		
		
		
	Don't auto populate QgsLayoutItemRegistry
Initially create an empty registry, allow it to be populated at a later stage.
This commit is contained in:
		
							parent
							
								
									20ca51b59c
								
							
						
					
					
						commit
						179c51c953
					
				@ -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 )
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user