QGIS API Documentation  3.0.2-Girona (307d082)
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 
32 class CORE_EXPORT QgsMimeDataUtils
33 {
34  public:
35 
36  struct CORE_EXPORT Uri
37  {
39  Uri() = default;
41  explicit Uri( QString &encData );
42 
47  bool isValid() const { return !layerType.isEmpty(); }
48 
50  QString data() const;
51 
57  QgsVectorLayer *vectorLayer( bool &owner, QString &error ) const;
58 
64  QgsRasterLayer *rasterLayer( bool &owner, QString &error ) const;
65 
67  QString layerType;
68 
74  QString providerKey;
76  QString name;
78  QString uri;
79  QStringList supportedCrs;
80  QStringList supportedFormats;
81  };
82  typedef QList<QgsMimeDataUtils::Uri> UriList;
83 
84  static QMimeData *encodeUriList( const UriList &layers );
85 
86  static bool isUriList( const QMimeData *data );
87 
88  static UriList decodeUriList( const QMimeData *data );
89 
94  static QByteArray layerTreeNodesToUriList( const QList<QgsLayerTreeNode *> &nodes );
95 
96  private:
97  static QString encode( const QStringList &items );
98  static QStringList decode( const QString &encoded );
99  static QByteArray uriListToByteArray( const UriList &layers );
100 
101 };
102 
104 
105 #endif // QGSMIMEDATAUTILS_H
106 
QString layerType
Type of URI. Recognized types: "vector" / "raster" / "plugin" / "custom".
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 vector layer which manages a vector based data sets.