QGIS API Documentation  2.11.0-Master
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 QFutureWatcher<QVector <QgsDataItem*> >
28 {
29  Q_OBJECT
30 
31  public:
34 
35  QgsDataItem* item() const { return mItem; }
36 
37  signals:
38  void finished( QgsDataItem* item, QVector <QgsDataItem*> items );
39 
40  private:
41  QgsDataItem *mItem;
42 };
43 
44 class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
45 {
46  Q_OBJECT
47 
48  public:
49  explicit QgsBrowserModel( QObject *parent = 0 );
50  ~QgsBrowserModel();
51 
53  {
54  // item path used to access path in the tree, see QgsDataItem::mPath
55  PathRole = Qt::UserRole
56  };
57  // implemented methods from QAbstractItemModel for read-only access
58 
61  virtual Qt::ItemFlags flags( const QModelIndex &index ) const override;
62 
67  virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
68 
71  virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
72 
74  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
75 
78  virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
79 
81  virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const override;
82 
83  QModelIndex findItem( QgsDataItem *item, QgsDataItem *parent = 0 ) const;
84 
88  virtual QModelIndex parent( const QModelIndex &index ) const override;
89 
91  virtual QStringList mimeTypes() const override;
92 
94  virtual QMimeData * mimeData( const QModelIndexList &indexes ) const override;
95 
97  virtual bool dropMimeData( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent ) override;
98 
99  QgsDataItem *dataItem( const QModelIndex &idx ) const;
100 
101  bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;
102 
103  // Refresh item specified by path
104  void refresh( QString path );
105 
106  // Refresh item childs
107  void refresh( const QModelIndex &index = QModelIndex() );
108 
115  QModelIndex findPath( QString path, Qt::MatchFlag matchFlag = Qt::MatchExactly );
116  static QModelIndex findPath( QAbstractItemModel *model, QString path, Qt::MatchFlag matchFlag = Qt::MatchExactly );
117 
118  void connectItem( QgsDataItem *item );
119 
120  bool canFetchMore( const QModelIndex & parent ) const override;
121  void fetchMore( const QModelIndex & parent ) override;
122 
123  signals:
125  void stateChanged( const QModelIndex & index, QgsDataItem::State oldState );
126 
127  public slots:
128  // Reload the whole model
129  void reload();
130  void beginInsertItems( QgsDataItem *parent, int first, int last );
131  void endInsertItems();
132  void beginRemoveItems( QgsDataItem *parent, int first, int last );
133  void endRemoveItems();
134  void itemDataChanged( QgsDataItem * item );
135  void itemStateChanged( QgsDataItem * item, QgsDataItem::State oldState );
136 
137  void addFavouriteDirectory( QString favDir );
138  void removeFavourite( const QModelIndex &index );
139  void updateProjectHome();
140 
141  protected:
142  // populates the model
143  void addRootItems();
144  void removeRootItems();
145 
149 };
150 
151 #endif // QGSBROWSERMODEL_H
Contains various Favourites directories.
Definition: qgsdataitem.h:445
static unsigned index
virtual int rowCount(const QModelIndex &parent) const =0
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
virtual bool canFetchMore(const QModelIndex &parent) const
QgsFavouritesItem * mFavourites
QgsDataItem * item() const
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
virtual QStringList mimeTypes() const
QgsDirectoryItem * mProjectHome
virtual QVariant data(const QModelIndex &index, int role) const =0
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
A directory: contains subdirectories and layers.
Definition: qgsdataitem.h:362
Base class for all items in the model.
Definition: qgsdataitem.h:75
virtual bool hasChildren(const QModelIndex &parent) const
virtual int columnCount(const QModelIndex &parent) const =0
virtual void fetchMore(const QModelIndex &parent)
virtual Qt::ItemFlags flags(const QModelIndex &index) const
QObject * parent() const
typedef ItemFlags
QVector< QgsDataItem * > mRootItems