QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
62  explicit QgsBrowserModel( QObject *parent = nullptr , bool initialize = true );
63  ~QgsBrowserModel();
64 
66  {
67  PathRole = Qt::UserRole,
68  CommentRole = Qt::UserRole + 1,
69  };
70  // implemented methods from QAbstractItemModel for read-only access
71 
74  virtual Qt::ItemFlags flags( const QModelIndex &index ) const override;
75 
80  virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
81 
84  virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
85 
87  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
88 
91  virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
92 
94  virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const override;
95 
96  QModelIndex findItem( QgsDataItem *item, QgsDataItem *parent = nullptr ) const;
97 
101  virtual QModelIndex parent( const QModelIndex &index ) const override;
102 
104  virtual QStringList mimeTypes() const override;
105 
107  virtual QMimeData * mimeData( const QModelIndexList &indexes ) const override;
108 
110  virtual bool dropMimeData( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent ) override;
111 
112  QgsDataItem *dataItem( const QModelIndex &idx ) const;
113 
114  bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;
115 
117  void refresh( const QString& path );
118 
120  void refresh( const QModelIndex &index = QModelIndex() );
121 
128  QModelIndex findPath( const QString& path, Qt::MatchFlag matchFlag = Qt::MatchExactly );
129 
131  static QModelIndex findPath( QAbstractItemModel *model, const QString& path, Qt::MatchFlag matchFlag = Qt::MatchExactly );
132 
133  void connectItem( QgsDataItem *item );
134 
135  bool canFetchMore( const QModelIndex & parent ) const override;
136  void fetchMore( const QModelIndex & parent ) override;
137 
139  bool initialized( ) const { return mInitialized; }
140 
142  void init();
143 
144  signals:
146  void stateChanged( const QModelIndex & index, QgsDataItem::State oldState );
147 
148  public slots:
150  void reload();
151  void beginInsertItems( QgsDataItem *parent, int first, int last );
152  void endInsertItems();
153  void beginRemoveItems( QgsDataItem *parent, int first, int last );
154  void endRemoveItems();
155  void itemDataChanged( QgsDataItem * item );
156  void itemStateChanged( QgsDataItem * item, QgsDataItem::State oldState );
157 
158  void addFavouriteDirectory( const QString& favDir );
159  void removeFavourite( const QModelIndex &index );
160  void updateProjectHome();
161 
163  void hidePath( QgsDataItem *item );
164 
165  protected:
167  void addRootItems();
168  void removeRootItems();
169 
173 
174  private:
175  bool mInitialized;
176 };
177 
178 #endif // QGSBROWSERMODEL_H
Contains various Favourites directories.
Definition: qgsdataitem.h:512
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
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
virtual QStringList mimeTypes() const
bool initialized() const
Returns true if the model has been initialized.
QgsDirectoryItem * mProjectHome
QgsDataItem * item() const
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:403
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