QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
qgsbrowsermodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsbrowsermodel.h
3  ---------------------
4  begin : July 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 QGSBROWSERMODEL_H
16 #define QGSBROWSERMODEL_H
17 
18 #include <QAbstractItemModel>
19 #include <QIcon>
20 #include <QMimeData>
21 #include <QMovie>
22 #include <QFuture>
23 #include <QFutureWatcher>
24 
25 #include "qgsdataitem.h"
26 
27 class CORE_EXPORT QgsBrowserWatcher : public QObject
28 {
29  Q_OBJECT
30 
31  public:
34 
35  void setFuture( QFuture<QVector <QgsDataItem*> > future );
36  bool isFinished() { return mFinished; }
37  QgsDataItem* item() const { return mItem; }
38 
39  signals:
40  void finished( QgsDataItem* item, QVector <QgsDataItem*> items );
41 
42  public slots:
43  void finished();
44 
45  private:
46  bool mFinished;
47  QgsDataItem *mItem;
48  QFutureWatcher<QVector <QgsDataItem*> > mFutureWatcher;
49 };
50 
51 class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
52 {
53  Q_OBJECT
54 
55  public:
56  explicit QgsBrowserModel( QObject *parent = 0 );
57  ~QgsBrowserModel();
58 
59  // implemented methods from QAbstractItemModel for read-only access
60 
63  virtual Qt::ItemFlags flags( const QModelIndex &index ) const;
64 
69  virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
70 
73  virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
74 
76  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
77 
80  virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;
81 
83  virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
84 
85  QModelIndex findItem( QgsDataItem *item, QgsDataItem *parent = 0 ) const;
86 
90  virtual QModelIndex parent( const QModelIndex &index ) const;
91 
93  virtual QStringList mimeTypes() const;
94 
96  virtual QMimeData * mimeData( const QModelIndexList &indexes ) const;
97 
99  virtual bool dropMimeData( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent );
100 
101  QgsDataItem *dataItem( const QModelIndex &idx ) const;
102 
103  bool hasChildren( const QModelIndex &parent = QModelIndex() ) const;
104 
105  // Refresh item specified by path
106  void refresh( QString path );
107 
108  // Refresh item childs
109  void refresh( const QModelIndex &index = QModelIndex() );
110 
117  QModelIndex findPath( QString path, Qt::MatchFlag matchFlag = Qt::MatchExactly );
118 
119  void connectItem( QgsDataItem *item );
120 
121  bool canFetchMore( const QModelIndex & parent ) const;
122  void fetchMore( const QModelIndex & parent );
123  static QVector<QgsDataItem*> createChildren( QgsDataItem *item );
124  bool fetching( QgsDataItem *item ) const;
125 
126  signals:
128  void fetchFinished( const QModelIndex & index );
129 
130  public slots:
131  // Reload the whole model
132  void reload();
133  void beginInsertItems( QgsDataItem *parent, int first, int last );
134  void endInsertItems();
135  void beginRemoveItems( QgsDataItem *parent, int first, int last );
136  void endRemoveItems();
137 
138  void addFavouriteDirectory( QString favDir );
139  void removeFavourite( const QModelIndex &index );
140 
141  void updateProjectHome();
142  void childrenCreated( QgsDataItem* item, QVector <QgsDataItem*> items );
143  void refreshChildrenCreated( QgsDataItem* item, QVector <QgsDataItem*> items );
144  void loadingFrameChanged();
145 
146  protected:
147  // populates the model
148  void addRootItems();
149  void removeRootItems();
150 
151  QVector<QgsDataItem*> mRootItems;
154 
155  private:
156  QList<QgsBrowserWatcher *> mWatchers;
157  QMovie mLoadingMovie;
158  QIcon mLoadingIcon;
159 };
160 
161 #endif // QGSBROWSERMODEL_H
Contains various Favourites directories.
Definition: qgsdataitem.h:319
static unsigned index
QgsFavouritesItem * mFavourites
QgsDataItem * item() const
QgsDirectoryItem * mProjectHome
A directory: contains subdirectories and layers.
Definition: qgsdataitem.h:247
base class for all items in the model
Definition: qgsdataitem.h:39
QVector< QgsDataItem * > mRootItems