QGIS API Documentation  2.99.0-Master (0cba29c)
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 #ifndef SIP_RUN
33 class CORE_EXPORT QgsBrowserWatcher : public QFutureWatcher<QVector <QgsDataItem *> >
34 {
35  Q_OBJECT
36 
37  public:
39 
40  QgsDataItem *item() const { return mItem; }
41 
42  signals:
43  void finished( QgsDataItem *item, const QVector <QgsDataItem *> &items );
44 
45  private:
46  QgsDataItem *mItem = nullptr;
47 };
48 #endif
49 
53 class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
54 {
55  Q_OBJECT
56 
57  public:
58  explicit QgsBrowserModel( QObject *parent = nullptr );
59  ~QgsBrowserModel();
60 
62  {
63  PathRole = Qt::UserRole,
64  CommentRole = Qt::UserRole + 1,
65  };
66  // implemented methods from QAbstractItemModel for read-only access
67 
70  virtual Qt::ItemFlags flags( const QModelIndex &index ) const override;
71 
76  virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
77 
80  virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
81 
83  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
84 
87  virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
88 
90  virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
91 
92  QModelIndex findItem( QgsDataItem *item, QgsDataItem *parent = nullptr ) const;
93 
97  virtual QModelIndex parent( const QModelIndex &index ) const override;
98 
100  virtual QStringList mimeTypes() const override;
101 
103  virtual QMimeData *mimeData( const QModelIndexList &indexes ) const override;
104 
106  virtual bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
107 
108  QgsDataItem *dataItem( const QModelIndex &idx ) const;
109 
110  bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;
111 
113  void refresh( const QString &path );
114 
116  void refresh( const QModelIndex &index = QModelIndex() );
117 
124  QModelIndex findPath( const QString &path, Qt::MatchFlag matchFlag = Qt::MatchExactly );
125 
127  static QModelIndex findPath( QAbstractItemModel *model, const QString &path, Qt::MatchFlag matchFlag = Qt::MatchExactly ) SIP_SKIP;
128 
129  void connectItem( QgsDataItem *item );
130 
131  bool canFetchMore( const QModelIndex &parent ) const override;
132  void fetchMore( const QModelIndex &parent ) override;
133 
134  signals:
136  void stateChanged( const QModelIndex &index, QgsDataItem::State oldState );
139  void connectionsChanged();
140 
141  public slots:
143  void reload();
144  void beginInsertItems( QgsDataItem *parent, int first, int last );
145  void endInsertItems();
146  void beginRemoveItems( QgsDataItem *parent, int first, int last );
147  void endRemoveItems();
148  void itemDataChanged( QgsDataItem *item );
149  void itemStateChanged( QgsDataItem *item, QgsDataItem::State oldState );
150 
156  void addFavoriteDirectory( const QString &directory );
157 
163  void removeFavorite( const QModelIndex &index );
164 
165  void updateProjectHome();
166 
168  void hidePath( QgsDataItem *item );
169 
170  protected:
172  void addRootItems();
173  void removeRootItems();
174 
175  QVector<QgsDataItem *> mRootItems;
176  QgsFavoritesItem *mFavorites = nullptr;
177  QgsDirectoryItem *mProjectHome = nullptr;
178 };
179 
180 #endif // QGSBROWSERMODEL_H
QgsDataItem * item() const
QVector< QgsDataItem * > mRootItems
#define SIP_SKIP
Definition: qgis_sip.h:119
A directory: contains subdirectories and layers.
Definition: qgsdataitem.h:427
Base class for all items in the model.
Definition: qgsdataitem.h:47
Contains various Favorites directories.
Definition: qgsdataitem.h:532