QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
24 class QgsLayerItem;
25 class QgsLayerTreeNode;
26 class QgsVectorLayer;
27 class QgsRasterLayer;
28 class QgsMeshLayer;
29 
34 class CORE_EXPORT QgsMimeDataUtils
35 {
36  public:
37 
38  struct CORE_EXPORT Uri
39  {
41  Uri() = default;
43  explicit Uri( QString &encData );
44 
49  bool isValid() const { return !layerType.isEmpty(); }
50 
52  QString data() const;
53 
59  QgsVectorLayer *vectorLayer( bool &owner, QString &error ) const;
60 
66  QgsRasterLayer *rasterLayer( bool &owner, QString &error ) const;
67 
73  QgsMeshLayer *meshLayer( bool &owner, QString &error ) const;
74 
76  QString layerType;
77 
84  QString providerKey;
86  QString name;
88  QString uri;
89  QStringList supportedCrs;
90  QStringList supportedFormats;
91 
92 #ifdef SIP_RUN
93  SIP_PYOBJECT __repr__();
94  % MethodCode
95  QString str = QStringLiteral( "<QgsMimeDataUtils::Uri (%1): %2>" ).arg( sipCpp->providerKey, sipCpp->uri );
96  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
97  % End
98 #endif
99  };
100  typedef QList<QgsMimeDataUtils::Uri> UriList;
101 
105  static QMimeData *encodeUriList( const UriList &layers ) SIP_FACTORY;
106 
107  static bool isUriList( const QMimeData *data );
108 
109  static UriList decodeUriList( const QMimeData *data );
110 
115  static QByteArray layerTreeNodesToUriList( const QList<QgsLayerTreeNode *> &nodes );
116 
117  private:
118  static QString encode( const QStringList &items );
119  static QStringList decode( const QString &encoded );
120  static QByteArray uriListToByteArray( const UriList &layers );
121 
122 
123  friend class TestQgsMimeDataUtils;
124 
125 };
126 
128 
129 #endif // QGSMIMEDATAUTILS_H
130 
QString layerType
Type of URI. Recognized types: "vector" / "raster" / "mesh" / "plugin" / "custom" / "project"...
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QString name
Human readable name to be used e.g. in layer tree.
QStringList supportedFormats
Q_DECLARE_METATYPE(QModelIndex)
bool isValid() const
Returns whether the object contains valid data.
This class is a base class for nodes in a layer tree.
#define SIP_FACTORY
Definition: qgis_sip.h:69
QList< QgsMimeDataUtils::Uri > UriList
QString providerKey
For "vector" / "raster" type: provider id.
QString uri
Identifier of the data source recognized by its providerKey.
Item that represents a layer that can be opened with one of the providers.
Definition: qgsdataitem.h:435
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:89
Represents a vector layer which manages a vector based data sets.