QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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 <QMimeData>
19#include <QStringList>
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
23#include "qgswkbtypes.h"
24
25class QgsLayerItem;
27class QgsVectorLayer;
28class QgsRasterLayer;
29class QgsMeshLayer;
30class QgsMapLayer;
31
37class CORE_EXPORT QgsMimeDataUtils
38{
39 public:
40
41 struct CORE_EXPORT Uri
42 {
44 Uri() = default;
46 explicit Uri( const QString &encData );
47
53 explicit Uri( QgsMapLayer *layer );
54
58 bool isValid() const { return !layerType.isEmpty(); }
59
61 QString data() const;
62
68 QgsVectorLayer *vectorLayer( bool &owner, QString &error ) const;
69
75 QgsRasterLayer *rasterLayer( bool &owner, QString &error ) const;
76
82 QgsMeshLayer *meshLayer( bool &owner, QString &error ) const;
83
93 QgsMapLayer *mapLayer() const;
94
113 QString layerType;
114
121 QString providerKey;
122
124 QString name;
126 QString uri;
127 QStringList supportedCrs;
128 QStringList supportedFormats;
129
134 QString layerId;
135
141 QString pId;
142
150
155 QString filePath;
156
157#ifdef SIP_RUN
158 SIP_PYOBJECT __repr__();
159 % MethodCode
160 QString str = QStringLiteral( "<QgsMimeDataUtils::Uri (%1): %2>" ).arg( sipCpp->providerKey, sipCpp->uri );
161 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
162 % End
163#endif
164 };
165 typedef QList<QgsMimeDataUtils::Uri> UriList;
166
170 static QMimeData *encodeUriList( const UriList &layers ) SIP_FACTORY;
171
172 static bool isUriList( const QMimeData *data );
173
174 static UriList decodeUriList( const QMimeData *data );
175
179 static QByteArray layerTreeNodesToUriList( const QList<QgsLayerTreeNode *> &nodes );
180
187 static bool hasOriginatedFromCurrentAppInstance( const QgsMimeDataUtils::Uri &uri );
188
189 private:
190 static QString encode( const QStringList &items );
191 static QStringList decode( const QString &encoded );
192 static QByteArray uriListToByteArray( const UriList &layers );
193
194
195 friend class TestQgsMimeDataUtils;
196
197};
198
200
201#endif // QGSMIMEDATAUTILS_H
202
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
@ Unknown
Unknown.
Item that represents a layer that can be opened with one of the providers.
This class is a base class for nodes in a layer tree.
Base class for all map layer types.
Definition qgsmaplayer.h:76
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Contains utility functions for working with MIME data.
QList< QgsMimeDataUtils::Uri > UriList
Represents a raster layer.
Represents a vector layer which manages a vector based data sets.
#define str(x)
Definition qgis.cpp:39
#define SIP_FACTORY
Definition qgis_sip.h:76
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
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.