Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added rasterLayer method
  • Loading branch information
elpaso committed Aug 22, 2017
1 parent ef89a62 commit ab2589b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions python/core/qgsmimedatautils.sip
Expand Up @@ -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"
Expand Down
12 changes: 12 additions & 0 deletions src/core/qgsmimedatautils.cpp
Expand Up @@ -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 )
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgsmimedatautils.h
Expand Up @@ -23,6 +23,7 @@
class QgsLayerItem;
class QgsLayerTreeNode;
class QgsVectorLayer;
class QgsRasterLayer;

/** \ingroup core
* \class QgsMimeDataUtils
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ab2589b

Please sign in to comment.