mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-08 00:05:09 -04:00
condense compatibleRasterLayers/compatibleMeshLayers/compatiblePluginLayers into one unified function
This commit is contained in:
parent
a94ad63df7
commit
473ac474a3
@ -40,26 +40,7 @@
|
|||||||
|
|
||||||
QList<QgsRasterLayer *> QgsProcessingUtils::compatibleRasterLayers( QgsProject *project, bool sort )
|
QList<QgsRasterLayer *> QgsProcessingUtils::compatibleRasterLayers( QgsProject *project, bool sort )
|
||||||
{
|
{
|
||||||
if ( !project )
|
return compatibleMapLayers< QgsRasterLayer >( project, sort );
|
||||||
return QList<QgsRasterLayer *>();
|
|
||||||
|
|
||||||
QList<QgsRasterLayer *> layers;
|
|
||||||
|
|
||||||
const auto rasterLayers = project->layers<QgsRasterLayer *>();
|
|
||||||
for ( QgsRasterLayer *l : rasterLayers )
|
|
||||||
{
|
|
||||||
if ( canUseLayer( l ) )
|
|
||||||
layers << l;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( sort )
|
|
||||||
{
|
|
||||||
std::sort( layers.begin(), layers.end(), []( const QgsRasterLayer * a, const QgsRasterLayer * b ) -> bool
|
|
||||||
{
|
|
||||||
return QString::localeAwareCompare( a->name(), b->name() ) < 0;
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
return layers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QgsVectorLayer *> QgsProcessingUtils::compatibleVectorLayers( QgsProject *project, const QList<int> &geometryTypes, bool sort )
|
QList<QgsVectorLayer *> QgsProcessingUtils::compatibleVectorLayers( QgsProject *project, const QList<int> &geometryTypes, bool sort )
|
||||||
@ -87,35 +68,22 @@ QList<QgsVectorLayer *> QgsProcessingUtils::compatibleVectorLayers( QgsProject *
|
|||||||
|
|
||||||
QList<QgsMeshLayer *> QgsProcessingUtils::compatibleMeshLayers( QgsProject *project, bool sort )
|
QList<QgsMeshLayer *> QgsProcessingUtils::compatibleMeshLayers( QgsProject *project, bool sort )
|
||||||
{
|
{
|
||||||
if ( !project )
|
return compatibleMapLayers< QgsMeshLayer >( project, sort );
|
||||||
return QList<QgsMeshLayer *>();
|
|
||||||
|
|
||||||
QList<QgsMeshLayer *> layers;
|
|
||||||
const auto meshLayers = project->layers<QgsMeshLayer *>();
|
|
||||||
for ( QgsMeshLayer *l : meshLayers )
|
|
||||||
{
|
|
||||||
if ( canUseLayer( l ) )
|
|
||||||
layers << l;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( sort )
|
|
||||||
{
|
|
||||||
std::sort( layers.begin(), layers.end(), []( const QgsMeshLayer * a, const QgsMeshLayer * b ) -> bool
|
|
||||||
{
|
|
||||||
return QString::localeAwareCompare( a->name(), b->name() ) < 0;
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
return layers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QgsPluginLayer *> QgsProcessingUtils::compatiblePluginLayers( QgsProject *project, bool sort )
|
QList<QgsPluginLayer *> QgsProcessingUtils::compatiblePluginLayers( QgsProject *project, bool sort )
|
||||||
{
|
{
|
||||||
if ( !project )
|
return compatibleMapLayers< QgsPluginLayer >( project, sort );
|
||||||
return QList<QgsPluginLayer *>();
|
}
|
||||||
|
|
||||||
QList<QgsPluginLayer *> layers;
|
template<typename T> QList<T *> QgsProcessingUtils::compatibleMapLayers( QgsProject *project, bool sort )
|
||||||
const auto pluginLayers = project->layers<QgsPluginLayer *>();
|
{
|
||||||
for ( QgsPluginLayer *l : pluginLayers )
|
if ( !project )
|
||||||
|
return QList<T *>();
|
||||||
|
|
||||||
|
QList<T *> layers;
|
||||||
|
const auto projectLayers = project->layers<T *>();
|
||||||
|
for ( T *l : projectLayers )
|
||||||
{
|
{
|
||||||
if ( canUseLayer( l ) )
|
if ( canUseLayer( l ) )
|
||||||
layers << l;
|
layers << l;
|
||||||
@ -123,7 +91,7 @@ QList<QgsPluginLayer *> QgsProcessingUtils::compatiblePluginLayers( QgsProject *
|
|||||||
|
|
||||||
if ( sort )
|
if ( sort )
|
||||||
{
|
{
|
||||||
std::sort( layers.begin(), layers.end(), []( const QgsPluginLayer * a, const QgsPluginLayer * b ) -> bool
|
std::sort( layers.begin(), layers.end(), []( const T * a, const T * b ) -> bool
|
||||||
{
|
{
|
||||||
return QString::localeAwareCompare( a->name(), b->name() ) < 0;
|
return QString::localeAwareCompare( a->name(), b->name() ) < 0;
|
||||||
} );
|
} );
|
||||||
@ -138,7 +106,8 @@ QList<QgsMapLayer *> QgsProcessingUtils::compatibleLayers( QgsProject *project,
|
|||||||
|
|
||||||
QList<QgsMapLayer *> layers;
|
QList<QgsMapLayer *> layers;
|
||||||
|
|
||||||
const auto rasterLayers = compatibleRasterLayers( project, false );
|
//~ const auto rasterLayers = compatibleRasterLayers( project, false );
|
||||||
|
const auto rasterLayers = compatibleMapLayers< QgsRasterLayer >( project, false );
|
||||||
for ( QgsRasterLayer *rl : rasterLayers )
|
for ( QgsRasterLayer *rl : rasterLayers )
|
||||||
layers << rl;
|
layers << rl;
|
||||||
|
|
||||||
@ -146,11 +115,13 @@ QList<QgsMapLayer *> QgsProcessingUtils::compatibleLayers( QgsProject *project,
|
|||||||
for ( QgsVectorLayer *vl : vectorLayers )
|
for ( QgsVectorLayer *vl : vectorLayers )
|
||||||
layers << vl;
|
layers << vl;
|
||||||
|
|
||||||
const auto meshLayers = compatibleMeshLayers( project, false );
|
//~ const auto meshLayers = compatibleMeshLayers( project, false );
|
||||||
|
const auto meshLayers = compatibleMapLayers< QgsMeshLayer >( project, false );
|
||||||
for ( QgsMeshLayer *vl : meshLayers )
|
for ( QgsMeshLayer *vl : meshLayers )
|
||||||
layers << vl;
|
layers << vl;
|
||||||
|
|
||||||
const auto pluginLayers = compatiblePluginLayers( project, false );
|
//~ const auto pluginLayers = compatiblePluginLayers( project, false );
|
||||||
|
const auto pluginLayers = compatibleMapLayers< QgsPluginLayer >( project, false );
|
||||||
for ( QgsPluginLayer *pl : pluginLayers )
|
for ( QgsPluginLayer *pl : pluginLayers )
|
||||||
layers << pl;
|
layers << pl;
|
||||||
|
|
||||||
|
@ -440,6 +440,20 @@ class CORE_EXPORT QgsProcessingUtils
|
|||||||
static bool canUseLayer( const QgsVectorLayer *layer,
|
static bool canUseLayer( const QgsVectorLayer *layer,
|
||||||
const QList< int > &sourceTypes = QList< int >() );
|
const QList< int > &sourceTypes = QList< int >() );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of map layers with the given layer type from a \a project which are compatible
|
||||||
|
* with the processing framework.
|
||||||
|
*
|
||||||
|
* If the \a sort argument is TRUE then the layers will be sorted by their QgsMapLayer::name()
|
||||||
|
* value.
|
||||||
|
* \see compatibleRasterLayers()
|
||||||
|
* \see compatibleVectorLayers()
|
||||||
|
* \see compatibleMeshLayers()
|
||||||
|
* \see compatiblePluginLayers()
|
||||||
|
* \since QGIS 3.22
|
||||||
|
*/
|
||||||
|
template< typename T> static QList< T * > compatibleMapLayers( QgsProject *project, bool sort = true );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interprets a \a string as a map layer from a store.
|
* Interprets a \a string as a map layer from a store.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user