| QGIS API Documentation
    3.16.0-Hannover (43b64b13f3)
    | 
 
 
 
Go to the documentation of this file.
   15 #include <QStringList> 
   29 static const char *QGIS_URILIST_MIMETYPE = 
"application/x-vnd.qgis.qgis.uri";
 
   34   const QStringList decoded = decode( encData );
 
   35   if ( decoded.size() < 4 )
 
   43   if ( 
layerType == QLatin1String( 
"raster" ) && decoded.size() >= 6 )
 
   54   if ( decoded.size() > 6 )
 
   56   if ( decoded.size() > 7 )
 
   57     pId = decoded.at( 7 );
 
   58   if ( decoded.size() > 8 )
 
   61   QgsDebugMsgLevel( QStringLiteral( 
"type:%1 key:%2 name:%3 uri:%4 supportedCRS:%5 supportedFormats:%6" )
 
   68   : providerKey( layer->providerType() )
 
   69   , name( layer->name() )
 
   70   , uri( layer->dataProvider() ? layer->dataProvider()->dataSourceUri() : layer->source() )
 
   71   , layerId( layer->id() )
 
   72   , pId( QString::number( QCoreApplication::applicationPid() ) )
 
   74   switch ( layer->
type() )
 
   79       wkbType = qobject_cast< QgsVectorLayer *>( layer )->wkbType();
 
   96       layerType = QStringLiteral( 
"vector-tile" );
 
  111   return encode( QStringList() << layerType << providerKey << name << uri << encode( supportedCrs ) << encode( supportedFormats ) << layerId << pId << 
QgsWkbTypes::displayString( wkbType ) );
 
  118   if ( layerType != QLatin1String( 
"vector" ) )
 
  120     error = QObject::tr( 
"%1: Not a vector layer." ).arg( name );
 
  131   if ( providerKey == QLatin1String( 
"memory" ) )
 
  133     error = QObject::tr( 
"Cannot get memory layer." );
 
  146   if ( layerType != QLatin1String( 
"raster" ) )
 
  148     error = QObject::tr( 
"%1: Not a raster layer." ).arg( name );
 
  168   if ( layerType != QLatin1String( 
"mesh" ) )
 
  170     error = QObject::tr( 
"%1: Not a mesh layer." ).arg( name );
 
  199   return data->hasFormat( QGIS_URILIST_MIMETYPE );
 
  204   QMimeData *mimeData = 
new QMimeData();
 
  206   mimeData->setData( QGIS_URILIST_MIMETYPE, uriListToByteArray( layers ) );
 
  213   QByteArray encodedData = data->data( QGIS_URILIST_MIMETYPE );
 
  214   QDataStream stream( &encodedData, QIODevice::ReadOnly );
 
  217   while ( !stream.atEnd() )
 
  221     list.append( 
Uri( xUri ) );
 
  233       _addLayerTreeNodeToUriList( child, uris );
 
  252   const auto constNodes = nodes;
 
  254     _addLayerTreeNodeToUriList( node, uris );
 
  255   return uriListToByteArray( uris );
 
  260   if ( uri.
pId.isEmpty() )
 
  263   const qint64 pid = uri.
pId.toLongLong();
 
  264   return pid == QCoreApplication::applicationPid();
 
  267 QString QgsMimeDataUtils::encode( 
const QStringList &items )
 
  271   QRegularExpression re( QStringLiteral( 
"(?<!\\\\):" ) );
 
  272   const auto constItems = items;
 
  273   for ( 
const QString &item : constItems )
 
  276     str.replace( 
'\\', QLatin1String( 
"\\\\" ) );
 
  277     str.replace( re, QStringLiteral( 
"\\:" ) );
 
  278     encoded += str + 
':';
 
  280   return encoded.left( encoded.length() - 1 );
 
  283 QStringList QgsMimeDataUtils::decode( 
const QString &encoded )
 
  287   bool inEscape = 
false;
 
  288   const auto constEncoded = encoded;
 
  289   for ( QChar 
c : constEncoded )
 
  291     if ( 
c == 
'\\' && inEscape )
 
  295     else if ( 
c == 
'\\' )
 
  299     else if ( 
c == 
':' && !inEscape )
 
  301       items.append( item );
 
  310   items.append( item );
 
  317   QByteArray encodedData;
 
  319   QDataStream stream( &encodedData, QIODevice::WriteOnly );
 
  320   const auto constLayers = layers;
 
  321   for ( 
const Uri &u : constLayers )
 
  
QgsWkbTypes::Type wkbType
WKB type, if associated with a vector layer, or QgsWkbTypes::Unknown if not yet known.
QString name
Human readable name to be used e.g. in layer tree.
QString uri
Identifier of the data source recognized by its providerKey.
This class is a base class for nodes in a layer tree.
static QString displayString(Type type) SIP_HOLDGIL
Returns a display string type for a WKB type, e.g., the geometry name used in WKT geometry representa...
QStringList supportedFormats
#define QgsDebugMsgLevel(str, level)
static QByteArray layerTreeNodesToUriList(const QList< QgsLayerTreeNode * > &nodes)
Returns encoded URI list from a list of layer tree nodes.
QString layerType
Type of URI.
QgsCoordinateTransformContext transformContext
QgsMapLayer * mapLayer() const
Returns the layer from the active project corresponding to this uri (if possible),...
static QgsProject * instance()
Returns the QgsProject singleton instance.
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
QList< QgsMimeDataUtils::Uri > UriList
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
static Type parseType(const QString &wktStr)
Attempts to extract the WKB type from a WKT string.
QgsVectorLayer * vectorLayer(bool &owner, QString &error) const
Gets vector layer from uri if possible, otherwise returns nullptr and error is set.
QgsMeshLayer * meshLayer(bool &owner, QString &error) const
Gets mesh layer from uri if possible, otherwise returns nullptr and error is set.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Layer tree node points to a map layer.
static bool hasOriginatedFromCurrentAppInstance(const QgsMimeDataUtils::Uri &uri)
Returns true if uri originated from the current QGIS application instance.
QString pId
Unique ID associated with application instance.
QString data() const
Returns encoded representation of the object.
Represents a raster layer.
QgsMapLayer * layer() const
Returns the map layer associated with this node.
QgsRasterLayer * rasterLayer(bool &owner, QString &error) const
Gets raster layer from uri if possible, otherwise returns nullptr and error is set.
QString providerKey
For "vector" / "raster" type: provider id.
QString layerId
Layer ID, if uri is associated with a layer from a QgsProject.
Setting options for loading vector layers.
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
static QMimeData * encodeUriList(const UriList &layers)
Encodes a URI list to a new QMimeData object.
static UriList decodeUriList(const QMimeData *data)
Uri()=default
Constructs invalid URI.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Represents a vector layer which manages a vector based data sets.
Base class for all map layer types.
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
@ VectorTileLayer
Added in 3.14.
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
static bool isUriList(const QMimeData *data)