QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
25 class QgsLayerItem;
26 class QgsLayerTreeNode;
27 class QgsVectorLayer;
28 class QgsRasterLayer;
29 class QgsMeshLayer;
30 class QgsMapLayer;
31 
36 class CORE_EXPORT QgsMimeDataUtils
37 {
38  public:
39 
40  struct CORE_EXPORT Uri
41  {
43  Uri() = default;
45  explicit Uri( const QString &encData );
46 
52  explicit Uri( QgsMapLayer *layer );
53 
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 
112  QString layerType;
113 
120  QString providerKey;
121 
123  QString name;
125  QString uri;
126  QStringList supportedCrs;
127  QStringList supportedFormats;
128 
133  QString layerId;
134 
140  QString pId;
141 
149 
154  QString filePath;
155 
156 #ifdef SIP_RUN
157  SIP_PYOBJECT __repr__();
158  % MethodCode
159  QString str = QStringLiteral( "<QgsMimeDataUtils::Uri (%1): %2>" ).arg( sipCpp->providerKey, sipCpp->uri );
160  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
161  % End
162 #endif
163  };
164  typedef QList<QgsMimeDataUtils::Uri> UriList;
165 
169  static QMimeData *encodeUriList( const UriList &layers ) SIP_FACTORY;
170 
171  static bool isUriList( const QMimeData *data );
172 
173  static UriList decodeUriList( const QMimeData *data );
174 
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 
QgsMimeDataUtils::Uri::name
QString name
Human readable name to be used e.g. in layer tree.
Definition: qgsmimedatautils.h:123
QgsMimeDataUtils::Uri::uri
QString uri
Identifier of the data source recognized by its providerKey.
Definition: qgsmimedatautils.h:125
QgsMimeDataUtils::Uri::isValid
bool isValid() const
Returns whether the object contains valid data.
Definition: qgsmimedatautils.h:58
QgsLayerTreeNode
This class is a base class for nodes in a layer tree.
Definition: qgslayertreenode.h:75
QgsMimeDataUtils::Uri::supportedFormats
QStringList supportedFormats
Definition: qgsmimedatautils.h:127
QgsMimeDataUtils::Uri::layerType
QString layerType
Type of URI.
Definition: qgsmimedatautils.h:112
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
QgsMimeDataUtils::UriList
QList< QgsMimeDataUtils::Uri > UriList
Definition: qgsmimedatautils.h:164
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsWkbTypes::Unknown
@ Unknown
Definition: qgswkbtypes.h:71
QgsMeshLayer
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:98
qgis_sip.h
QgsMimeDataUtils::Uri::filePath
QString filePath
Path to file, if uri is associated with a file.
Definition: qgsmimedatautils.h:154
QgsMimeDataUtils::Uri::pId
QString pId
Unique ID associated with application instance.
Definition: qgsmimedatautils.h:140
QgsRasterLayer
Represents a raster layer.
Definition: qgsrasterlayer.h:76
QgsMimeDataUtils::Uri
Definition: qgsmimedatautils.h:40
QgsMimeDataUtils::Uri::supportedCrs
QStringList supportedCrs
Definition: qgsmimedatautils.h:126
QgsMimeDataUtils::Uri::providerKey
QString providerKey
For "vector" / "raster" type: provider id.
Definition: qgsmimedatautils.h:120
QgsMimeDataUtils::Uri::layerId
QString layerId
Layer ID, if uri is associated with a layer from a QgsProject.
Definition: qgsmimedatautils.h:133
QgsMimeDataUtils
Definition: qgsmimedatautils.h:36
str
#define str(x)
Definition: qgis.cpp:37
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QgsLayerItem
Item that represents a layer that can be opened with one of the providers.
Definition: qgslayeritem.h:29
qgswkbtypes.h