QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
15 #include <QStringList>
28 #include <QRegularExpression>
30 static const char *QGIS_URILIST_MIMETYPE =
"application/x-vnd.qgis.qgis.uri";
35 const QStringList decoded = decode( encData );
36 if ( decoded.size() < 4 )
44 if (
layerType == QLatin1String(
"raster" ) && decoded.size() >= 6 )
55 if ( decoded.size() > 6 )
57 if ( decoded.size() > 7 )
58 pId = decoded.at( 7 );
59 if ( decoded.size() > 8 )
61 if ( decoded.size() > 9 )
64 QgsDebugMsgLevel( QStringLiteral(
"type:%1 key:%2 name:%3 uri:%4 supportedCRS:%5 supportedFormats:%6" )
71 : providerKey( layer->providerType() )
72 , name( layer->name() )
73 , uri( layer->dataProvider() ? layer->dataProvider()->dataSourceUri() : layer->source() )
74 , layerId( layer->id() )
75 , pId( QString::number( QCoreApplication::applicationPid() ) )
77 switch ( layer->
type() )
82 wkbType = qobject_cast< QgsVectorLayer *>( layer )->wkbType();
98 layerType = QStringLiteral(
"pointcloud" );
103 layerType = QStringLiteral(
"vector-tile" );
119 return encode( { layerType,
123 encode( supportedCrs ),
124 encode( supportedFormats ),
136 if ( layerType != QLatin1String(
"vector" ) )
138 error = QObject::tr(
"%1: Not a vector layer." ).arg( name );
149 if ( providerKey == QLatin1String(
"memory" ) )
151 error = QObject::tr(
"Cannot get memory layer." );
164 if ( layerType != QLatin1String(
"raster" ) )
166 error = QObject::tr(
"%1: Not a raster layer." ).arg( name );
186 if ( layerType != QLatin1String(
"mesh" ) )
188 error = QObject::tr(
"%1: Not a mesh layer." ).arg( name );
217 return data->hasFormat( QGIS_URILIST_MIMETYPE );
222 QMimeData *mimeData =
new QMimeData();
224 mimeData->setData( QGIS_URILIST_MIMETYPE, uriListToByteArray( layers ) );
231 QByteArray encodedData = data->data( QGIS_URILIST_MIMETYPE );
232 QDataStream stream( &encodedData, QIODevice::ReadOnly );
235 while ( !stream.atEnd() )
239 list.append(
Uri( xUri ) );
251 _addLayerTreeNodeToUriList( child, uris );
270 const auto constNodes = nodes;
272 _addLayerTreeNodeToUriList( node, uris );
273 return uriListToByteArray( uris );
278 if ( uri.
pId.isEmpty() )
281 const qint64 pid = uri.
pId.toLongLong();
282 return pid == QCoreApplication::applicationPid();
285 QString QgsMimeDataUtils::encode(
const QStringList &items )
289 const QRegularExpression re( QStringLiteral(
"(?<!\\\\):" ) );
290 const auto constItems = items;
291 for (
const QString &item : constItems )
294 str.replace(
'\\', QLatin1String(
"\\\\" ) );
295 str.replace( re, QStringLiteral(
"\\:" ) );
296 encoded +=
str +
':';
298 return encoded.left( encoded.length() - 1 );
301 QStringList QgsMimeDataUtils::decode(
const QString &encoded )
305 bool inEscape =
false;
306 const auto constEncoded = encoded;
307 for (
const QChar
c : constEncoded )
309 if (
c ==
'\\' && inEscape )
313 else if (
c ==
'\\' )
317 else if (
c ==
':' && !inEscape )
319 items.append( item );
328 items.append( item );
335 QByteArray encodedData;
337 QDataStream stream( &encodedData, QIODevice::WriteOnly );
338 const auto constLayers = layers;
339 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 non-translated display string type for a WKB type, e.g., the geometry name used in WKT geom...
QStringList supportedFormats
@ MeshLayer
Mesh layer. Added in QGIS 3.2.
@ VectorLayer
Vector layer.
#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.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
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.
@ GroupLayer
Composite group layer. Added in QGIS 3.24.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Layer tree node points to a map layer.
@ RasterLayer
Raster layer.
QString filePath
Path to file, if uri is associated with a file.
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. This is the base class for all map layer types (vector,...
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
@ VectorTileLayer
Vector tile layer. Added in QGIS 3.14.
@ PointCloudLayer
Point cloud layer. Added in QGIS 3.18.
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
@ PluginLayer
Plugin based layer.
static bool isUriList(const QMimeData *data)