Move query of layerTreeInsertionMethod setting out of core

This commit is contained in:
Marco Hugentobler 2024-03-27 10:53:26 +01:00 committed by Nyall Dawson
parent cbec502ebf
commit 077a161ef1
7 changed files with 28 additions and 22 deletions

View File

@ -26,20 +26,21 @@ files also store the layer tree info for the exported layers, including group in
%End
public:
static bool loadLayerDefinition( const QString &path, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage /Out/, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint = 0 );
static bool loadLayerDefinition( const QString &path, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage /Out/, Qgis::LayerTreeInsertionMethod insertMethod = Qgis::LayerTreeInsertionMethod::OptimalInInsertionGroup, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint = 0 );
%Docstring
Loads the QLR at path into QGIS. New layers are added to given project into layer tree specified by rootGroup
:param path: file path to the qlr
:param project: the current project
:param rootGroup: the layer tree group to insert the qlr content
:param insertPoint: describes where in rootGroup the qlr layers/groups shall be inserted
:param insertMethod: method for layer tree (since QGIS 3.38)
:param insertPoint: describes where in rootGroup the qlr layers/groups shall be inserted (since QGIS 3.38)
:return: - true in case of success
- errorMessage: the returned error message
%End
static bool loadLayerDefinition( QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage /Out/, QgsReadWriteContext &context, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint = 0 );
static bool loadLayerDefinition( QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage /Out/, QgsReadWriteContext &context, Qgis::LayerTreeInsertionMethod insertMethod = Qgis::LayerTreeInsertionMethod::OptimalInInsertionGroup, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint = 0 );
%Docstring
Loads the QLR from the XML document. New layers are added to given project into layer tree specified by rootGroup
@ -47,7 +48,8 @@ Loads the QLR from the XML document. New layers are added to given project into
:param project: the current project
:param rootGroup: the layer tree group to insert the qlr content
:param context: the read write context
:param insertPoint: describes where in rootGroup the qlr layers/groups shall be inserted
:param insertMethod: method for layer tree (since QGIS 3.38)
:param insertPoint: describes where in rootGroup the qlr layers/groups shall be inserted (since QGIS 3.38)
:return: - true in case of success
- errorMessage: the returned error message

View File

@ -26,20 +26,21 @@ files also store the layer tree info for the exported layers, including group in
%End
public:
static bool loadLayerDefinition( const QString &path, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage /Out/, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint = 0 );
static bool loadLayerDefinition( const QString &path, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage /Out/, Qgis::LayerTreeInsertionMethod insertMethod = Qgis::LayerTreeInsertionMethod::OptimalInInsertionGroup, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint = 0 );
%Docstring
Loads the QLR at path into QGIS. New layers are added to given project into layer tree specified by rootGroup
:param path: file path to the qlr
:param project: the current project
:param rootGroup: the layer tree group to insert the qlr content
:param insertPoint: describes where in rootGroup the qlr layers/groups shall be inserted
:param insertMethod: method for layer tree (since QGIS 3.38)
:param insertPoint: describes where in rootGroup the qlr layers/groups shall be inserted (since QGIS 3.38)
:return: - true in case of success
- errorMessage: the returned error message
%End
static bool loadLayerDefinition( QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage /Out/, QgsReadWriteContext &context, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint = 0 );
static bool loadLayerDefinition( QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage /Out/, QgsReadWriteContext &context, Qgis::LayerTreeInsertionMethod insertMethod = Qgis::LayerTreeInsertionMethod::OptimalInInsertionGroup, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint = 0 );
%Docstring
Loads the QLR from the XML document. New layers are added to given project into layer tree specified by rootGroup
@ -47,7 +48,8 @@ Loads the QLR from the XML document. New layers are added to given project into
:param project: the current project
:param rootGroup: the layer tree group to insert the qlr content
:param context: the read write context
:param insertPoint: describes where in rootGroup the qlr layers/groups shall be inserted
:param insertMethod: method for layer tree (since QGIS 3.38)
:param insertPoint: describes where in rootGroup the qlr layers/groups shall be inserted (since QGIS 3.38)
:return: - true in case of success
- errorMessage: the returned error message

View File

@ -1236,7 +1236,9 @@ void QgsAppLayerHandling::openLayerDefinition( const QString &filename, const Qg
context.setPathResolver( QgsPathResolver( filename ) );
context.setProjectTranslator( QgsProject::instance() );
loaded = QgsLayerDefinition::loadLayerDefinition( doc, QgsProject::instance(), QgsProject::instance()->layerTreeRoot(), errorMessage, context, insertPoint );
QgsSettings settings;
Qgis::LayerTreeInsertionMethod insertionMethod = settings.enumValue( QStringLiteral( "/qgis/layerTreeInsertionMethod" ), Qgis::LayerTreeInsertionMethod::OptimalInInsertionGroup );
loaded = QgsLayerDefinition::loadLayerDefinition( doc, QgsProject::instance(), QgsProject::instance()->layerTreeRoot(), errorMessage, context, insertionMethod, insertPoint );
}
}

View File

@ -10791,8 +10791,11 @@ void QgisApp::pasteLayer()
root = QgsProject::instance()->layerTreeRoot();
}
QgsSettings settings;
Qgis::LayerTreeInsertionMethod insertionMethod = settings.enumValue( QStringLiteral( "/qgis/layerTreeInsertionMethod" ), Qgis::LayerTreeInsertionMethod::OptimalInInsertionGroup );
QgsLayerTreeRegistryBridge::InsertionPoint insertionPoint = layerTreeInsertionPoint();
bool loaded = QgsLayerDefinition::loadLayerDefinition( doc, QgsProject::instance(), root,
errorMessage, readWriteContext );
errorMessage, readWriteContext, insertionMethod, &insertionPoint );
if ( !loaded || !errorMessage.isEmpty() )
{

View File

@ -38,7 +38,7 @@
#include "qgslayertreegroup.h"
#include "qgslayertreelayer.h"
bool QgsLayerDefinition::loadLayerDefinition( const QString &path, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint )
bool QgsLayerDefinition::loadLayerDefinition( const QString &path, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage, Qgis::LayerTreeInsertionMethod insertMethod, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint )
{
QFile file( path );
if ( !file.open( QIODevice::ReadOnly ) )
@ -62,10 +62,10 @@ bool QgsLayerDefinition::loadLayerDefinition( const QString &path, QgsProject *p
context.setPathResolver( QgsPathResolver( path ) );
context.setProjectTranslator( project );
return loadLayerDefinition( doc, project, rootGroup, errorMessage, context, insertPoint );
return loadLayerDefinition( doc, project, rootGroup, errorMessage, context, insertMethod, insertPoint );
}
bool QgsLayerDefinition::loadLayerDefinition( QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage, QgsReadWriteContext &context, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint )
bool QgsLayerDefinition::loadLayerDefinition( QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage, QgsReadWriteContext &context, Qgis::LayerTreeInsertionMethod insertMethod, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint )
{
errorMessage.clear();
@ -195,10 +195,7 @@ bool QgsLayerDefinition::loadLayerDefinition( QDomDocument doc, QgsProject *proj
root->abandonChildren();
delete root;
QgsSettings settings;
Qgis::LayerTreeInsertionMethod insertionMethod = settings.enumValue( QStringLiteral( "/qgis/layerTreeInsertionMethod" ), Qgis::LayerTreeInsertionMethod::OptimalInInsertionGroup );
switch ( insertionMethod )
switch ( insertMethod )
{
case Qgis::LayerTreeInsertionMethod::AboveInsertionPoint:
if ( insertPoint )

View File

@ -52,10 +52,11 @@ class CORE_EXPORT QgsLayerDefinition
* \param project the current project
* \param rootGroup the layer tree group to insert the qlr content
* \param errorMessage the returned error message
* \param insertMethod method for layer tree (since QGIS 3.38)
* \param insertPoint describes where in rootGroup the qlr layers/groups shall be inserted (since QGIS 3.38)
* \return true in case of success
*/
static bool loadLayerDefinition( const QString &path, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage SIP_OUT, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint = nullptr );
static bool loadLayerDefinition( const QString &path, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage SIP_OUT, Qgis::LayerTreeInsertionMethod insertMethod = Qgis::LayerTreeInsertionMethod::OptimalInInsertionGroup, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint = nullptr );
/**
* Loads the QLR from the XML document. New layers are added to given project into layer tree specified by rootGroup
@ -64,10 +65,11 @@ class CORE_EXPORT QgsLayerDefinition
* \param rootGroup the layer tree group to insert the qlr content
* \param errorMessage the returned error message
* \param context the read write context
* \param insertMethod method for layer tree (since QGIS 3.38)
* \param insertPoint describes where in rootGroup the qlr layers/groups shall be inserted (since QGIS 3.38)
* \return true in case of success
*/
static bool loadLayerDefinition( QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage SIP_OUT, QgsReadWriteContext &context, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint = nullptr );
static bool loadLayerDefinition( QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage SIP_OUT, QgsReadWriteContext &context, Qgis::LayerTreeInsertionMethod insertMethod = Qgis::LayerTreeInsertionMethod::OptimalInInsertionGroup, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint = nullptr );
/**
* Exports the selected layer tree nodes to a QLR file.

View File

@ -97,10 +97,8 @@ void TestQgsLayerDefinition::testFindLayers()
void TestQgsLayerDefinition::testLoadTopOfTree()
{
QgsSettings settings;
settings.setEnumValue( QStringLiteral( "/qgis/layerTreeInsertionMethod" ), Qgis::LayerTreeInsertionMethod::TopOfTree );
QString errorMsg;
QgsLayerDefinition::loadLayerDefinition( TEST_DATA_DIR + QStringLiteral( "/vector_and_raster.qlr" ), QgsProject::instance(), QgsProject::instance()->layerTreeRoot(), errorMsg );
QgsLayerDefinition::loadLayerDefinition( TEST_DATA_DIR + QStringLiteral( "/vector_and_raster.qlr" ), QgsProject::instance(), QgsProject::instance()->layerTreeRoot(), errorMsg, Qgis::LayerTreeInsertionMethod::TopOfTree );
//todo: test if new layers are on top
QList<QgsMapLayer *> orderedLayers = QgsProject::instance()->layerTreeRoot()->layerOrder();
QCOMPARE( orderedLayers.length(), 3 );