Skip to content
Permalink
Browse files

Added rasterLayer method

  • Loading branch information
elpaso committed Aug 22, 2017
1 parent ef89a62 commit ab2589bc0330942b5ba74287174a0d9ed1ae9efe
Showing with 27 additions and 0 deletions.
  1. +8 −0 python/core/qgsmimedatautils.sip
  2. +12 −0 src/core/qgsmimedatautils.cpp
  3. +7 −0 src/core/qgsmimedatautils.h
@@ -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"
@@ -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 )
@@ -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.

0 comments on commit ab2589b

Please sign in to comment.
You can’t perform that action at this time.