QGIS API Documentation  3.6.0-Noosa (5873452)
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 
89  QString layerType;
90 
97  QString providerKey;
98 
100  QString name;
102  QString uri;
103  QStringList supportedCrs;
104  QStringList supportedFormats;
105 
106 #ifdef SIP_RUN
107  SIP_PYOBJECT __repr__();
108  % MethodCode
109  QString str = QStringLiteral( "<QgsMimeDataUtils::Uri (%1): %2>" ).arg( sipCpp->providerKey, sipCpp->uri );
110  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
111  % End
112 #endif
113  };
114  typedef QList<QgsMimeDataUtils::Uri> UriList;
115 
119  static QMimeData *encodeUriList( const UriList &layers ) SIP_FACTORY;
120 
121  static bool isUriList( const QMimeData *data );
122 
123  static UriList decodeUriList( const QMimeData *data );
124 
129  static QByteArray layerTreeNodesToUriList( const QList<QgsLayerTreeNode *> &nodes );
130 
131  private:
132  static QString encode( const QStringList &items );
133  static QStringList decode( const QString &encoded );
134  static QByteArray uriListToByteArray( const UriList &layers );
135 
136 
137  friend class TestQgsMimeDataUtils;
138 
139 };
140 
142 
143 #endif // QGSMIMEDATAUTILS_H
144 
QString layerType
Type of URI.
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.
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.
#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:436
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.