QGIS API Documentation  2.99.0-Master (7d4f81d)
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 
30 class CORE_EXPORT QgsMimeDataUtils
31 {
32  public:
33 
34  struct CORE_EXPORT Uri
35  {
37  Uri();
39  explicit Uri( QString &encData );
40 
43  bool isValid() const { return !layerType.isEmpty(); }
44 
46  QString data() const;
47 
52  QgsVectorLayer *vectorLayer( bool &owner, QString &error ) const;
53 
55  QString layerType;
59  QString providerKey;
61  QString name;
63  QString uri;
64  QStringList supportedCrs;
65  QStringList supportedFormats;
66  };
67  typedef QList<QgsMimeDataUtils::Uri> UriList;
68 
69  static QMimeData *encodeUriList( const UriList &layers );
70 
71  static bool isUriList( const QMimeData *data );
72 
73  static UriList decodeUriList( const QMimeData *data );
74 
79  static QByteArray layerTreeNodesToUriList( const QList<QgsLayerTreeNode *> &nodes );
80 
81  private:
82  static QString encode( const QStringList &items );
83  static QStringList decode( const QString &encoded );
84  static QByteArray uriListToByteArray( const UriList &layers );
85 
86 };
87 
89 
90 #endif // QGSMIMEDATAUTILS_H
91 
QString layerType
Type of URI. Recognized types: "vector" / "raster" / "plugin" / "custom".
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:328
Represents a vector layer which manages a vector based data sets.