QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 struct CORE_EXPORT Uri
44 {
46 Uri() = default;
48 explicit Uri( const QString &encData );
49
55 explicit Uri( QgsMapLayer *layer );
56
60 bool isValid() const { return !layerType.isEmpty(); }
61
63 QString data() const;
64
70 QgsVectorLayer *vectorLayer( bool &owner, QString &error ) const;
71
77 QgsRasterLayer *rasterLayer( bool &owner, QString &error ) const;
78
84 QgsMeshLayer *meshLayer( bool &owner, QString &error ) const;
85
95 QgsMapLayer *mapLayer() const;
96
121 QString layerType;
122
129 QString providerKey;
130
132 QString name;
134 QString uri;
135 QStringList supportedCrs;
136 QStringList supportedFormats;
137
142 QString layerId;
143
149 QString pId;
150
158
163 QString filePath;
164
165#ifdef SIP_RUN
166 // clang-format off
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// clang-format on
173#endif
174 };
175 typedef QList<QgsMimeDataUtils::Uri> UriList;
176
180 static QMimeData *encodeUriList( const UriList &layers ) SIP_FACTORY;
181
182 static bool isUriList( const QMimeData *data );
183
184 static UriList decodeUriList( const QMimeData *data );
185
189 static QByteArray layerTreeNodesToUriList( const QList<QgsLayerTreeNode *> &nodes );
190
198
199 private:
200 static QString encode( const QStringList &items );
201 static QStringList decode( const QString &encoded );
202 static QByteArray uriListToByteArray( const UriList &layers );
203
204
206};
207
209
210#endif // QGSMIMEDATAUTILS_H
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:294
@ Unknown
Unknown.
Definition qgis.h:295
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:83
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.