QGIS API Documentation  2.14.0-Essen
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 
30 class CORE_EXPORT QgsBrowserWatcher : public QFutureWatcher<QVector <QgsDataItem*> >
31 {
32  Q_OBJECT
33 
34  public:
37 
38  QgsDataItem* item() const { return mItem; }
39 
40  signals:
41  void finished( QgsDataItem* item, const QVector <QgsDataItem*>& items );
42 
43  private:
44  QgsDataItem *mItem;
45 };
46 
47 class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
48 {
49  Q_OBJECT
50 
51  public:
52  explicit QgsBrowserModel( QObject *parent = nullptr );
53  ~QgsBrowserModel();
54 
56  {
57  PathRole = Qt::UserRole,
58  CommentRole = Qt::UserRole + 1,
59  };
60  // implemented methods from QAbstractItemModel for read-only access
61 
64  virtual Qt::ItemFlags flags( const QModelIndex &index ) const override;
65 
70  virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
71 
74  virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
75 
77  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
78 
81  virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
82 
84  virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const override;
85 
86  QModelIndex findItem( QgsDataItem *item, QgsDataItem *parent = nullptr ) const;
87 
91  virtual QModelIndex parent( const QModelIndex &index ) const override;
92 
94  virtual QStringList mimeTypes() const override;
95 
97  virtual QMimeData * mimeData( const QModelIndexList &indexes ) const override;
98 
100  virtual bool dropMimeData( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent ) override;
101 
102  QgsDataItem *dataItem( const QModelIndex &idx ) const;
103 
104  bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;
105 
107  void refresh( const QString& path );
108 
110  void refresh( const QModelIndex &index = QModelIndex() );
111 
118  QModelIndex findPath( const QString& path, Qt::MatchFlag matchFlag = Qt::MatchExactly );
119 
121  static QModelIndex findPath( QAbstractItemModel *model, const QString& path, Qt::MatchFlag matchFlag = Qt::MatchExactly );
122 
123  void connectItem( QgsDataItem *item );
124 
125  bool canFetchMore( const QModelIndex & parent ) const override;
126  void fetchMore( const QModelIndex & parent ) override;
127 
128  signals:
130  void stateChanged( const QModelIndex & index, QgsDataItem::State oldState );
131 
132  public slots:
134  void reload();
135  void beginInsertItems( QgsDataItem *parent, int first, int last );
136  void endInsertItems();
137  void beginRemoveItems( QgsDataItem *parent, int first, int last );
138  void endRemoveItems();
139  void itemDataChanged( QgsDataItem * item );
140  void itemStateChanged( QgsDataItem * item, QgsDataItem::State oldState );
141 
142  void addFavouriteDirectory( const QString& favDir );
143  void removeFavourite( const QModelIndex &index );
144  void updateProjectHome();
145 
147  void hidePath( QgsDataItem *item );
148 
149  protected:
151  void addRootItems();
152  void removeRootItems();
153 
157 };
158 
159 #endif // QGSBROWSERMODEL_H
Contains various Favourites directories.
Definition: qgsdataitem.h:497
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:392
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