QGIS API Documentation 4.3.0-Master (b46232e4f9a)
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;
34class QgsProject;
35
41class CORE_EXPORT QgsMimeDataUtils
42{
43 public:
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
66 // TODO QGIS 5.0 -- remove this version of function in favor of the one with explicit project parameter
76 Q_DECL_DEPRECATED QgsVectorLayer *vectorLayer( bool &owner SIP_OUT, QString &error SIP_OUT ) const SIP_DEPRECATED;
77
88 QgsVectorLayer *vectorLayer( bool &owner SIP_OUT, QString &error SIP_OUT, QgsProject *project ) const;
89
90 // TODO QGIS 5.0 -- remove this version of function in favor of the one with explicit project parameter
100 Q_DECL_DEPRECATED QgsRasterLayer *rasterLayer( bool &owner SIP_OUT, QString &error SIP_OUT ) const SIP_DEPRECATED;
101
112 QgsRasterLayer *rasterLayer( bool &owner SIP_OUT, QString &error SIP_OUT, QgsProject *project ) const;
113
114 // TODO QGIS 5.0 -- remove this version of function in favor of the one with explicit project parameter
124 Q_DECL_DEPRECATED QgsMeshLayer *meshLayer( bool &owner SIP_OUT, QString &error SIP_OUT ) const SIP_DEPRECATED;
125
136 QgsMeshLayer *meshLayer( bool &owner SIP_OUT, QString &error SIP_OUT, QgsProject *project ) const;
137
138 // TODO QGIS 5.0 -- remove this version of function in favor of the one with explicit project parameter
151 Q_DECL_DEPRECATED QgsMapLayer *mapLayer() const SIP_DEPRECATED;
152
166 QgsMapLayer *mapLayer( QgsProject *project ) const;
167
192 QString layerType;
193
200 QString providerKey;
201
203 QString name;
205 QString uri;
206 QStringList supportedCrs;
207 QStringList supportedFormats;
208
213 QString layerId;
214
220 QString pId;
221
228 Qgis::WkbType wkbType = Qgis::WkbType::Unknown;
229
234 QString filePath;
235
236#ifdef SIP_RUN
237 // clang-format off
238 SIP_PYOBJECT __repr__();
239 % MethodCode
240 QString str = u"<QgsMimeDataUtils::Uri (%1): %2>"_s.arg( sipCpp->providerKey, sipCpp->uri );
241 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
242 % End
243// clang-format on
244#endif
245 };
246 typedef QList<QgsMimeDataUtils::Uri> UriList;
247
251 static QMimeData *encodeUriList( const UriList &layers ) SIP_FACTORY;
252
253 static bool isUriList( const QMimeData *data );
254
255 static UriList decodeUriList( const QMimeData *data );
256
260 static QByteArray layerTreeNodesToUriList( const QList<QgsLayerTreeNode *> &nodes );
261
269
270 private:
271 static QString encode( const QStringList &items );
272 static QStringList decode( const QString &encoded );
273 static QByteArray uriListToByteArray( const UriList &layers );
274
275
277};
278
280
281#endif // QGSMIMEDATAUTILS_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
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.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:114
Represents a raster layer.
Represents a vector layer which manages a vector based dataset.
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_OUT
Definition qgis_sip.h:57
#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.