Added rasterLayer method

This commit is contained in:
Alessandro Pasotti 2017-08-22 11:18:11 +02:00
parent ef89a624a1
commit ab2589bc03
3 changed files with 27 additions and 0 deletions

View File

@ -48,6 +48,14 @@ Returns encoded representation of the object
:rtype: QgsVectorLayer
%End
QgsRasterLayer *rasterLayer( bool &owner, QString &error ) const;
%Docstring
Get raster layer from uri if possible, otherwise returns 0 and error is set
\param owner set to true if caller becomes owner
\param error set to error message if cannot get raster
:rtype: QgsRasterLayer
%End
QString layerType;
%Docstring
Type of URI. Recognized types: "vector" / "raster" / "plugin" / "custom"

View File

@ -100,6 +100,18 @@ QgsVectorLayer *QgsMimeDataUtils::Uri::vectorLayer( bool &owner, QString &error
return new QgsVectorLayer( uri, name, providerKey );
}
QgsRasterLayer *QgsMimeDataUtils::Uri::rasterLayer( bool &owner, QString &error ) const
{
owner = false;
if ( layerType != QLatin1String( "raster" ) )
{
error = QObject::tr( "%1: Not a raster layer." ).arg( name );
return nullptr;
}
owner = true;
return new QgsRasterLayer( uri, name, providerKey );
}
// -----
bool QgsMimeDataUtils::isUriList( const QMimeData *data )

View File

@ -23,6 +23,7 @@
class QgsLayerItem;
class QgsLayerTreeNode;
class QgsVectorLayer;
class QgsRasterLayer;
/** \ingroup core
* \class QgsMimeDataUtils
@ -51,6 +52,12 @@ class CORE_EXPORT QgsMimeDataUtils
*/
QgsVectorLayer *vectorLayer( bool &owner, QString &error ) const;
/** Get raster layer from uri if possible, otherwise returns 0 and error is set
* \param owner set to true if caller becomes owner
* \param error set to error message if cannot get raster
*/
QgsRasterLayer *rasterLayer( bool &owner, QString &error ) const;
//! Type of URI. Recognized types: "vector" / "raster" / "plugin" / "custom"
QString layerType;
//! For "vector" / "raster" type: provider id.