QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsdataitem.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdataitem.h - Items representing data
3  -------------------
4  begin : 2011-04-01
5  copyright : (C) 2011 Radim Blazek
6  email : radim dot blazek at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #ifndef QGSDATAITEM_H
18 #define QGSDATAITEM_H
19 
20 #include <QIcon>
21 #include <QLibrary>
22 #include <QObject>
23 #include <QPixmap>
24 #include <QString>
25 #include <QVector>
26 #include <QTreeWidget>
27 
28 #include "qgsapplication.h"
29 #include "qgsmaplayer.h"
31 
32 class QgsDataProvider;
33 class QgsDataItem;
34 
35 // TODO: bad place, where to put this? qgsproviderregistry.h?
36 typedef int dataCapabilities_t();
37 typedef QgsDataItem * dataItem_t( QString, QgsDataItem* );
38 
39 
41 class CORE_EXPORT QgsDataItem : public QObject
42 {
43  Q_OBJECT
44  public:
45  enum Type
46  {
51  Favourites
52  };
53 
54  QgsDataItem( QgsDataItem::Type type, QgsDataItem* parent, QString name, QString path );
55  virtual ~QgsDataItem();
56 
57  bool hasChildren();
58 
59  int rowCount();
60 
61  //
62 
63  virtual void refresh();
64 
65  // Create vector of children
66  virtual QVector<QgsDataItem*> createChildren();
67 
68  // Populate children using children vector created by createChildren()
69  virtual void populate();
70  bool isPopulated() { return mPopulated; }
71 
72  // Insert new child using alphabetical order based on mName, emits necessary signal to model before and after, sets parent and connects signals
73  // refresh - refresh populated item, emit signals to model
74  virtual void addChildItem( QgsDataItem *child, bool refresh = false );
75 
76  // remove and delete child item, signals to browser are emitted
77  virtual void deleteChildItem( QgsDataItem * child );
78 
79  // remove child item but don't delete it, signals to browser are emitted
80  // returns pointer to the removed item or null if no such item was found
81  virtual QgsDataItem *removeChildItem( QgsDataItem * child );
82 
83  virtual bool equal( const QgsDataItem *other );
84 
85  virtual QWidget * paramWidget() { return 0; }
86 
87  // list of actions provided by this item - usually used for popup menu on right-click
88  virtual QList<QAction*> actions() { return QList<QAction*>(); }
89 
90  // whether accepts drag&drop'd layers - e.g. for import
91  virtual bool acceptDrop() { return false; }
92 
93  // try to process the data dropped on this item
94  virtual bool handleDrop( const QMimeData * /*data*/, Qt::DropAction /*action*/ ) { return false; }
95 
96  //
97 
99  {
100  NoCapabilities = 0,
101  SetCrs = 1 //Can set CRS on layer or group of layers
102  };
103 
104  // This will _write_ selected crs in data source
106  { Q_UNUSED( crs ); return false; }
107 
108  virtual Capability capabilities() { return NoCapabilities; }
109 
110  // static methods
111 
112  // Find child index in vector of items using '==' operator
113  static int findItem( QVector<QgsDataItem*> items, QgsDataItem * item );
114 
115  // members
116 
117  Type type() const { return mType; }
118  QgsDataItem* parent() const { return mParent; }
119  void setParent( QgsDataItem* parent ) { mParent = parent; }
120  QVector<QgsDataItem*> children() const { return mChildren; }
121  QIcon icon() const { return mIcon; }
122  QString name() const { return mName; }
123  QString path() const { return mPath; }
124 
125  void setIcon( QIcon icon ) { mIcon = icon; }
126 
127  void setToolTip( QString msg ) { mToolTip = msg; }
128  QString toolTip() const { return mToolTip; }
129 
130  protected:
131 
134  QVector<QgsDataItem*> mChildren; // easier to have it always
136  QString mName;
137  QString mPath; // it is also used to identify item in tree
138  QString mToolTip;
139  QIcon mIcon;
140 
141  public slots:
142  void emitBeginInsertItems( QgsDataItem* parent, int first, int last );
143  void emitEndInsertItems();
144  void emitBeginRemoveItems( QgsDataItem* parent, int first, int last );
145  void emitEndRemoveItems();
146 
147  signals:
148  void beginInsertItems( QgsDataItem* parent, int first, int last );
149  void endInsertItems();
150  void beginRemoveItems( QgsDataItem* parent, int first, int last );
151  void endRemoveItems();
152 };
153 
155 class CORE_EXPORT QgsLayerItem : public QgsDataItem
156 {
157  Q_OBJECT
158  public:
160  {
169  Table
170  };
171 
172  QgsLayerItem( QgsDataItem* parent, QString name, QString path, QString uri, LayerType layerType, QString providerKey );
173 
174  // --- reimplemented from QgsDataItem ---
175 
176  virtual bool equal( const QgsDataItem *other );
177 
178  // --- New virtual methods for layer item derived classes ---
179 
180  // Returns QgsMapLayer::LayerType
181  QgsMapLayer::LayerType mapLayerType();
182 
183  // Returns layer uri or empty string if layer cannot be created
184  QString uri() { return mUri; }
185 
186  // Returns provider key
187  QString providerKey() { return mProviderKey; }
188 
189  protected:
190 
191  QString mProviderKey;
192  QString mUri;
194 
195  public:
196  static const QIcon &iconPoint();
197  static const QIcon &iconLine();
198  static const QIcon &iconPolygon();
199  static const QIcon &iconTable();
200  static const QIcon &iconRaster();
201  static const QIcon &iconDefault();
202 
203  virtual QString layerName() const { return name(); }
204 };
205 
206 
208 class CORE_EXPORT QgsDataCollectionItem : public QgsDataItem
209 {
210  Q_OBJECT
211  public:
212  QgsDataCollectionItem( QgsDataItem* parent, QString name, QString path = QString::null );
214 
215  void setPopulated() { mPopulated = true; }
216  void addChild( QgsDataItem *item ) { mChildren.append( item ); }
217 
218  static const QIcon &iconDir(); // shared icon: open/closed directory
219  static const QIcon &iconDataCollection(); // default icon for data collection
220 };
221 
223 class CORE_EXPORT QgsDirectoryItem : public QgsDataCollectionItem
224 {
225  Q_OBJECT
226  public:
227  enum Column
228  {
236  };
237  QgsDirectoryItem( QgsDataItem* parent, QString name, QString path );
238  ~QgsDirectoryItem();
239 
240  QVector<QgsDataItem*> createChildren();
241 
242  virtual bool equal( const QgsDataItem *other );
243 
244  virtual QWidget *paramWidget();
245 
246  /* static QVector<QgsDataProvider*> mProviders; */
248  static QVector<QLibrary*> mLibraries;
249 };
250 
254 class CORE_EXPORT QgsErrorItem : public QgsDataItem
255 {
256  Q_OBJECT
257  public:
258 
259  QgsErrorItem( QgsDataItem* parent, QString error, QString path );
260  ~QgsErrorItem();
261 
262 };
263 
264 
265 // ---------
266 
267 class CORE_EXPORT QgsDirectoryParamWidget : public QTreeWidget
268 {
269  Q_OBJECT
270 
271  public:
272  QgsDirectoryParamWidget( QString path, QWidget* parent = NULL );
273 
274  protected:
275  void mousePressEvent( QMouseEvent* event );
276 
277  public slots:
278  void showHideColumn();
279 };
280 
282 class CORE_EXPORT QgsFavouritesItem : public QgsDataCollectionItem
283 {
284  Q_OBJECT
285  public:
286  QgsFavouritesItem( QgsDataItem* parent, QString name, QString path = QString() );
288 
289  QVector<QgsDataItem*> createChildren();
290 
291  void addDirectory( QString favIcon );
292  void removeDirectory( QgsDirectoryItem *item );
293 
294  static const QIcon &iconFavourites();
295 };
296 
298 class CORE_EXPORT QgsZipItem : public QgsDataCollectionItem
299 {
300  Q_OBJECT
301 
302  protected:
303  QString mVsiPrefix;
304  QStringList mZipFileList;
305 
306  public:
307  QgsZipItem( QgsDataItem* parent, QString name, QString path );
308  ~QgsZipItem();
309 
310  QVector<QgsDataItem*> createChildren();
311  const QStringList & getZipFileList();
312 
314  static QVector<dataItem_t *> mDataItemPtr;
315  static QStringList mProviderNames;
316 
317  static QString vsiPrefix( QString uri ) { return qgsVsiPrefix( uri ); }
318 
319  static QgsDataItem* itemFromPath( QgsDataItem* parent, QString path, QString name );
320 
321  static const QIcon &iconZip();
322 
323 };
324 
325 #endif // QGSDATAITEM_H
326 
A Collection: logical collection of layers or subcollections, e.g.
Definition: qgsdataitem.h:208
Contains various Favourites directories.
Definition: qgsdataitem.h:282
QVector< QgsDataItem * > children() const
Definition: qgsdataitem.h:120
QString name() const
Definition: qgsdataitem.h:122
QgsDataItem * parent() const
Definition: qgsdataitem.h:118
QString providerKey()
Definition: qgsdataitem.h:187
QString mProviderKey
Definition: qgsdataitem.h:191
virtual bool handleDrop(const QMimeData *, Qt::DropAction)
Definition: qgsdataitem.h:94
void addChild(QgsDataItem *item)
Definition: qgsdataitem.h:216
QString qgsVsiPrefix(QString path)
Definition: qgis.cpp:242
QIcon icon() const
Definition: qgsdataitem.h:121
Abstract base class for spatial data provider implementations.
void setIcon(QIcon icon)
Definition: qgsdataitem.h:125
static QIcon icon(QString icon)
QString uri()
Definition: qgsdataitem.h:184
virtual QWidget * paramWidget()
Definition: qgsdataitem.h:85
QString mToolTip
Definition: qgsdataitem.h:138
A zip file: contains layers, using GDAL/OGR VSIFILE mechanism.
Definition: qgsdataitem.h:298
virtual bool equal(const QgsDataItem *other)
int dataCapabilities_t()
Definition: qgsdataitem.h:36
bool isPopulated()
Definition: qgsdataitem.h:70
static QString vsiPrefix(QString uri)
Definition: qgsdataitem.h:317
QString mName
Definition: qgsdataitem.h:136
LayerType
Layers enum defining the types of layers that can be added to a map.
Definition: qgsmaplayer.h:54
QStringList mZipFileList
Definition: qgsdataitem.h:304
QString path() const
Definition: qgsdataitem.h:123
Data item that can be used to report problems (e.g.
Definition: qgsdataitem.h:254
Type type() const
Definition: qgsdataitem.h:117
virtual Capability capabilities()
Definition: qgsdataitem.h:108
static QStringList mProviderNames
Definition: qgsdataitem.h:315
A directory: contains subdirectories and layers.
Definition: qgsdataitem.h:223
virtual bool setCrs(QgsCoordinateReferenceSystem crs)
Definition: qgsdataitem.h:105
base class for all items in the model
Definition: qgsdataitem.h:41
static QVector< dataItem_t * > mDataItemPtr
Definition: qgsdataitem.h:314
QString mPath
Definition: qgsdataitem.h:137
QString mUri
Definition: qgsdataitem.h:192
QString mVsiPrefix
Definition: qgsdataitem.h:303
static QVector< QLibrary * > mLibraries
Definition: qgsdataitem.h:248
virtual QString layerName() const
Definition: qgsdataitem.h:203
void setParent(QgsDataItem *parent)
Definition: qgsdataitem.h:119
Class for storing a coordinate reference system (CRS)
QgsDataItem * mParent
Definition: qgsdataitem.h:133
void setToolTip(QString msg)
Definition: qgsdataitem.h:127
virtual QVector< QgsDataItem * > createChildren()
bool mPopulated
Definition: qgsdataitem.h:135
Item that represents a layer that can be opened with one of the providers.
Definition: qgsdataitem.h:155
QgsDataItem * dataItem_t(QString, QgsDataItem *)
Definition: qgsdataitem.h:37
QVector< QgsDataItem * > mChildren
Definition: qgsdataitem.h:134
QString toolTip() const
Definition: qgsdataitem.h:128
virtual QList< QAction * > actions()
Definition: qgsdataitem.h:88
virtual bool acceptDrop()
Definition: qgsdataitem.h:91
LayerType mLayerType
Definition: qgsdataitem.h:193