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 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 
52  // implemented methods from QAbstractItemModel for read-only access
53 
56  virtual Qt::ItemFlags flags( const QModelIndex &index ) const;
57 
62  virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
63 
66  virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
67 
69  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
70 
73  virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;
74 
76  virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
77 
78  QModelIndex findItem( QgsDataItem *item, QgsDataItem *parent = 0 ) const;
79 
83  virtual QModelIndex parent( const QModelIndex &index ) const;
84 
86  virtual QStringList mimeTypes() const;
87 
89  virtual QMimeData * mimeData( const QModelIndexList &indexes ) const;
90 
92  virtual bool dropMimeData( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent );
93 
94  QgsDataItem *dataItem( const QModelIndex &idx ) const;
95 
96  bool hasChildren( const QModelIndex &parent = QModelIndex() ) const;
97 
98  // Refresh item specified by path
99  void refresh( QString path );
100 
101  // Refresh item childs
102  void refresh( const QModelIndex &index = QModelIndex() );
103 
110  QModelIndex findPath( QString path, Qt::MatchFlag matchFlag = Qt::MatchExactly );
111 
112  void connectItem( QgsDataItem *item );
113 
114  bool canFetchMore( const QModelIndex & parent ) const;
115  void fetchMore( const QModelIndex & parent );
116 
117  signals:
119  void stateChanged( const QModelIndex & index, QgsDataItem::State oldState );
120 
121  public slots:
122  // Reload the whole model
123  void reload();
124  void beginInsertItems( QgsDataItem *parent, int first, int last );
125  void endInsertItems();
126  void beginRemoveItems( QgsDataItem *parent, int first, int last );
127  void endRemoveItems();
128  void itemDataChanged( QgsDataItem * item );
129  void itemStateChanged( QgsDataItem * item, QgsDataItem::State oldState );
130 
131  void addFavouriteDirectory( QString favDir );
132  void removeFavourite( const QModelIndex &index );
133  void updateProjectHome();
134 
135  protected:
136  // populates the model
137  void addRootItems();
138  void removeRootItems();
139 
140  QVector<QgsDataItem*> mRootItems;
143 };
144 
145 #endif // QGSBROWSERMODEL_H
Contains various Favourites directories.
Definition: qgsdataitem.h:395
static unsigned index
QgsFavouritesItem * mFavourites
QgsDataItem * item() const
QgsDirectoryItem * mProjectHome
A directory: contains subdirectories and layers.
Definition: qgsdataitem.h:313
Base class for all items in the model.
Definition: qgsdataitem.h:43
QVector< QgsDataItem * > mRootItems