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