QGIS API Documentation  2.17.0-Master (3a3b9ab7)
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 
31 class CORE_EXPORT QgsBrowserWatcher : public QFutureWatcher<QVector <QgsDataItem*> >
32 {
33  Q_OBJECT
34 
35  public:
38 
39  QgsDataItem* item() const { return mItem; }
40 
41  signals:
42  void finished( QgsDataItem* item, const QVector <QgsDataItem*>& items );
43 
44  private:
45  QgsDataItem *mItem;
46 };
47 
51 class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
52 {
53  Q_OBJECT
54 
55  public:
56  explicit QgsBrowserModel( QObject *parent = nullptr );
57  ~QgsBrowserModel();
58 
60  {
61  PathRole = Qt::UserRole,
62  CommentRole = Qt::UserRole + 1,
63  };
64  // implemented methods from QAbstractItemModel for read-only access
65 
68  virtual Qt::ItemFlags flags( const QModelIndex &index ) const override;
69 
74  virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
75 
78  virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
79 
81  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
82 
85  virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
86 
88  virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const override;
89 
90  QModelIndex findItem( QgsDataItem *item, QgsDataItem *parent = nullptr ) const;
91 
95  virtual QModelIndex parent( const QModelIndex &index ) const override;
96 
98  virtual QStringList mimeTypes() const override;
99 
101  virtual QMimeData * mimeData( const QModelIndexList &indexes ) const override;
102 
104  virtual bool dropMimeData( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent ) override;
105 
106  QgsDataItem *dataItem( const QModelIndex &idx ) const;
107 
108  bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;
109 
111  void refresh( const QString& path );
112 
114  void refresh( const QModelIndex &index = QModelIndex() );
115 
122  QModelIndex findPath( const QString& path, Qt::MatchFlag matchFlag = Qt::MatchExactly );
123 
125  static QModelIndex findPath( QAbstractItemModel *model, const QString& path, Qt::MatchFlag matchFlag = Qt::MatchExactly );
126 
127  void connectItem( QgsDataItem *item );
128 
129  bool canFetchMore( const QModelIndex & parent ) const override;
130  void fetchMore( const QModelIndex & parent ) override;
131 
132  signals:
134  void stateChanged( const QModelIndex & index, QgsDataItem::State oldState );
135 
136  public slots:
138  void reload();
139  void beginInsertItems( QgsDataItem *parent, int first, int last );
140  void endInsertItems();
141  void beginRemoveItems( QgsDataItem *parent, int first, int last );
142  void endRemoveItems();
143  void itemDataChanged( QgsDataItem * item );
144  void itemStateChanged( QgsDataItem * item, QgsDataItem::State oldState );
145 
146  void addFavouriteDirectory( const QString& favDir );
147  void removeFavourite( const QModelIndex &index );
148  void updateProjectHome();
149 
151  void hidePath( QgsDataItem *item );
152 
153  protected:
155  void addRootItems();
156  void removeRootItems();
157 
161 };
162 
163 #endif // QGSBROWSERMODEL_H
Contains various Favourites directories.
Definition: qgsdataitem.h:511
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:402
Base class for all items in the model.
Definition: qgsdataitem.h:79
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