QGIS/src/core/processing/qgsprocessingutils.h
Nyall Dawson 377b181c4e Port more processing dataobjects methods to c++
Also
- simplify and add tests
- remove large memory leak (persistant store of all non-project layers)
- remove broken support for direct loading postgres/virtual layers
by string (Python version was very broken and would never match
a postgres/virtual layer)
2017-04-05 19:50:46 +10:00

119 lines
4.4 KiB
C++

/***************************************************************************
qgsprocessingutils.h
------------------------
begin : April 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSPROCESSINGUTILS_H
#define QGSPROCESSINGUTILS_H
#include "qgis_core.h"
#include "qgsrasterlayer.h"
#include "qgsvectorlayer.h"
class QgsProject;
#include <QString>
/**
* \class QgsProcessingUtils
* \ingroup core
* Utility functions for use with processing classes.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProcessingUtils
{
public:
/**
* Returns a list of raster layers 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 compatibleVectorLayers()
* \see compatibleLayers()
*/
static QList< QgsRasterLayer * > compatibleRasterLayers( QgsProject *project, bool sort = true );
/**
* Returns a list of vector layers from a \a project which are compatible with the processing
* framework.
*
* If the \a geometryTypes list is non-empty then the layers will be sorted so that only
* layers with geometry types included in the list will be returned. Leaving the \a geometryTypes
* list empty will cause all vector layers, regardless of their geometry type, to be returned.
*
* If the \a sort argument is true then the layers will be sorted by their QgsMapLayer::name()
* value.
* \see compatibleRasterLayers()
* \see compatibleLayers()
*/
static QList< QgsVectorLayer * > compatibleVectorLayers( QgsProject *project,
const QList< QgsWkbTypes::GeometryType > &geometryTypes = QList< QgsWkbTypes::GeometryType >(),
bool sort = true );
/**
* Returns a list of map layers 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()
*/
static QList< QgsMapLayer * > compatibleLayers( QgsProject *project, bool sort = true );
/**
* Interprets a \a string as a map layer from a project.
*
* This method attempts to match a string to a project map layer, using
* first the layer ID, then layer names, and finally layer source.
* If the string matches a normalized version of any layer source
* for layers in the specified \a project, then those matching layers will be
* returned.
* \see mapLayerFromString()
*/
static QgsMapLayer *mapLayerFromProject( const QString &string, QgsProject *project );
/**
* Interprets a string as a map layer. The method will attempt to
* load a layer matching the passed \a string. E.g. if the string is a file path,
* then the layer at this file path will be loaded.
* The caller takes responsibility for deleting the returned map layer.
* \see mapLayerFromProject()
*/
static QgsMapLayer *mapLayerFromString( const QString &string ) SIP_FACTORY;
/**
* Normalizes a layer \a source string for safe comparison across different
* operating system environments.
*/
static QString normalizeLayerSource( const QString &source );
private:
static bool canUseLayer( const QgsRasterLayer *layer );
static bool canUseLayer( const QgsVectorLayer *layer,
const QList< QgsWkbTypes::GeometryType > &geometryTypes );
};
#endif // QGSPROCESSINGUTILS_H