QGIS API Documentation  2.99.0-Master (b8fd1fd)
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 "qgis_core.h"
19 #include <QAbstractItemModel>
20 #include <QIcon>
21 #include <QMimeData>
22 #include <QMovie>
23 #include <QFuture>
24 #include <QFutureWatcher>
25 
26 #include "qgsdataitem.h"
27 
32 class CORE_EXPORT QgsBrowserWatcher : public QFutureWatcher<QVector <QgsDataItem *> >
33 {
34  Q_OBJECT
35 
36  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 = nullptr;
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 
151  void addFavoriteDirectory( const QString &directory );
152 
158  void removeFavorite( const QModelIndex &index );
159 
160  void updateProjectHome();
161 
163  void hidePath( QgsDataItem *item );
164 
165  protected:
167  void addRootItems();
168  void removeRootItems();
169 
170  QVector<QgsDataItem *> mRootItems;
171  QgsFavoritesItem *mFavorites = nullptr;
172  QgsDirectoryItem *mProjectHome = nullptr;
173 };
174 
175 #endif // QGSBROWSERMODEL_H
static unsigned index
QgsDataItem * item() const
QVector< QgsDataItem * > mRootItems
A directory: contains subdirectories and layers.
Definition: qgsdataitem.h:395
Base class for all items in the model.
Definition: qgsdataitem.h:46
Contains various Favorites directories.
Definition: qgsdataitem.h:500