QGIS API Documentation  3.2.0-Bonn (bc43194)
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 
23 class QgsLayerItem;
24 class QgsLayerTreeNode;
25 class QgsVectorLayer;
26 class QgsRasterLayer;
27 class QgsMeshLayer;
28 
33 class CORE_EXPORT QgsMimeDataUtils
34 {
35  public:
36 
37  struct CORE_EXPORT Uri
38  {
40  Uri() = default;
42  explicit Uri( QString &encData );
43 
48  bool isValid() const { return !layerType.isEmpty(); }
49 
51  QString data() const;
52 
58  QgsVectorLayer *vectorLayer( bool &owner, QString &error ) const;
59 
65  QgsRasterLayer *rasterLayer( bool &owner, QString &error ) const;
66 
72  QgsMeshLayer *meshLayer( bool &owner, QString &error ) const;
73 
75  QString layerType;
76 
83  QString providerKey;
85  QString name;
87  QString uri;
88  QStringList supportedCrs;
89  QStringList supportedFormats;
90  };
91  typedef QList<QgsMimeDataUtils::Uri> UriList;
92 
93  static QMimeData *encodeUriList( const UriList &layers );
94 
95  static bool isUriList( const QMimeData *data );
96 
97  static UriList decodeUriList( const QMimeData *data );
98 
103  static QByteArray layerTreeNodesToUriList( const QList<QgsLayerTreeNode *> &nodes );
104 
105  private:
106  static QString encode( const QStringList &items );
107  static QStringList decode( const QString &encoded );
108  static QByteArray uriListToByteArray( const UriList &layers );
109 
110 
111  friend class TestQgsMimeDataUtils;
112 
113 };
114 
116 
117 #endif // QGSMIMEDATAUTILS_H
118 
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
bool isValid() const
Returns whether the object contains valid data.
Q_DECLARE_METATYPE(QModelIndex)
This class is a base class for nodes in a layer tree.
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:409
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:90
Represents a vector layer which manages a vector based data sets.