mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-04 00:04:03 -04:00
Move query of layerTreeInsertionMethod setting out of core
This commit is contained in:
parent
cbec502ebf
commit
077a161ef1
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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() )
|
||||
{
|
||||
|
@ -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 )
|
||||
|
@ -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.
|
||||
|
@ -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 );
|
||||
|
Loading…
x
Reference in New Issue
Block a user