QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgsmimedatautils.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmimedatautils.h
3 ---------------------
4 begin : November 2011
5 copyright : (C) 2011 by Martin Dobias
6 email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSMIMEDATAUTILS_H
16#define QGSMIMEDATAUTILS_H
17
18#include "qgis_core.h"
19#include "qgis_sip.h"
20#include "qgswkbtypes.h"
21
22#include <QMimeData>
23#include <QString>
24#include <QStringList>
25
26using namespace Qt::StringLiterals;
27
28class QgsLayerItem;
30class QgsVectorLayer;
31class QgsRasterLayer;
32class QgsMeshLayer;
33class QgsMapLayer;
34
40class CORE_EXPORT QgsMimeDataUtils
41{
42 public:
43
44 struct CORE_EXPORT Uri
45 {
47 Uri() = default;
49 explicit Uri( const QString &encData );
50
56 explicit Uri( QgsMapLayer *layer );
57
61 bool isValid() const { return !layerType.isEmpty(); }
62
64 QString data() const;
65
71 QgsVectorLayer *vectorLayer( bool &owner, QString &error ) const;
72
78 QgsRasterLayer *rasterLayer( bool &owner, QString &error ) const;
79
85 QgsMeshLayer *meshLayer( bool &owner, QString &error ) const;
86
96 QgsMapLayer *mapLayer() const;
97
122 QString layerType;
123
130 QString providerKey;
131
133 QString name;
135 QString uri;
136 QStringList supportedCrs;
137 QStringList supportedFormats;
138
143 QString layerId;
144
150 QString pId;
151
159
164 QString filePath;
165
166#ifdef SIP_RUN
167 SIP_PYOBJECT __repr__();
168 % MethodCode
169 QString str = u"<QgsMimeDataUtils::Uri (%1): %2>"_s.arg( sipCpp->providerKey, sipCpp->uri );
170 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
171 % End
172#endif
173 };
174 typedef QList<QgsMimeDataUtils::Uri> UriList;
175
179 static QMimeData *encodeUriList( const UriList &layers ) SIP_FACTORY;
180
181 static bool isUriList( const QMimeData *data );
182
183 static UriList decodeUriList( const QMimeData *data );
184
188 static QByteArray layerTreeNodesToUriList( const QList<QgsLayerTreeNode *> &nodes );
189
197
198 private:
199 static QString encode( const QStringList &items );
200 static QStringList decode( const QString &encoded );
201 static QByteArray uriListToByteArray( const UriList &layers );
202
203
205
206};
207
209
210#endif // QGSMIMEDATAUTILS_H
211
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:280
@ Unknown
Unknown.
Definition qgis.h:281
A browser item that represents a layer that can be opened with one of the providers.
Base class for nodes in a layer tree.
Base class for all map layer types.
Definition qgsmaplayer.h:83
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Contains utility functions for working with MIME data.
static QByteArray layerTreeNodesToUriList(const QList< QgsLayerTreeNode * > &nodes)
Returns encoded URI list from a list of layer tree nodes.
static bool isUriList(const QMimeData *data)
QList< QgsMimeDataUtils::Uri > UriList
friend class TestQgsMimeDataUtils
static QMimeData * encodeUriList(const UriList &layers)
Encodes a URI list to a new QMimeData object.
static UriList decodeUriList(const QMimeData *data)
static bool hasOriginatedFromCurrentAppInstance(const QgsMimeDataUtils::Uri &uri)
Returns true if uri originated from the current QGIS application instance.
Represents a raster layer.
Represents a vector layer which manages a vector based dataset.
#define SIP_FACTORY
Definition qgis_sip.h:84
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
Qgis::WkbType wkbType
WKB type, if associated with a vector layer, or QgsWkbTypes::Unknown if not yet known.
QString filePath
Path to file, if uri is associated with a file.
QString uri
Identifier of the data source recognized by its providerKey.
QString name
Human readable name to be used e.g. in layer tree.
QString pId
Unique ID associated with application instance.
QString providerKey
For "vector" / "raster" type: provider id.
QString layerId
Layer ID, if uri is associated with a layer from a QgsProject.
Uri()=default
Constructs invalid URI.
QString layerType
Type of URI.
bool isValid() const
Returns whether the object contains valid data.