QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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 
33 #ifndef SIP_RUN
34 class CORE_EXPORT QgsBrowserWatcher : public QFutureWatcher<QVector <QgsDataItem *> >
35 {
36  Q_OBJECT
37 
38  public:
40 
41  QgsDataItem *item() const { return mItem; }
42 
43  signals:
44  void finished( QgsDataItem *item, const QVector <QgsDataItem *> &items );
45 
46  private:
47  QgsDataItem *mItem = nullptr;
48 };
49 #endif
50 
71 class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
72 {
73  Q_OBJECT
74 
75  public:
76 
84  explicit QgsBrowserModel( QObject *parent = nullptr );
85 
86  ~QgsBrowserModel() override;
87 
89  {
90  PathRole = Qt::UserRole,
91  CommentRole = Qt::UserRole + 1,
94  };
95  // implemented methods from QAbstractItemModel for read-only access
96 
97  Qt::ItemFlags flags( const QModelIndex &index ) const override;
98  QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
99  bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
100  QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
101  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
102  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
103  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
104  QModelIndex parent( const QModelIndex &index ) const override;
105  QStringList mimeTypes() const override;
106  QMimeData *mimeData( const QModelIndexList &indexes ) const override;
107  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
108  bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;
109  bool canFetchMore( const QModelIndex &parent ) const override;
110  void fetchMore( const QModelIndex &parent ) override;
111 
120  QModelIndex findItem( QgsDataItem *item, QgsDataItem *parent = nullptr ) const;
121 
126  QgsDataItem *dataItem( const QModelIndex &idx ) const;
127 
129  void refresh( const QString &path );
130 
132  void refresh( const QModelIndex &index = QModelIndex() );
133 
142  QModelIndex findPath( const QString &path, Qt::MatchFlag matchFlag = Qt::MatchExactly );
143 
145  static QModelIndex findPath( QAbstractItemModel *model, const QString &path, Qt::MatchFlag matchFlag = Qt::MatchExactly ) SIP_SKIP;
146 
156  QModelIndex findUri( const QString &uri, QModelIndex index = QModelIndex() );
157 
161  Q_DECL_DEPRECATED void connectItem( QgsDataItem *item ) SIP_DEPRECATED;
162 
168  bool initialized() const { return mInitialized; }
169 
178  QMap<QString, QgsDirectoryItem *> driveItems() const;
179  signals:
180 
182  void stateChanged( const QModelIndex &index, QgsDataItem::State oldState );
183 
188  void connectionsChanged();
189 
190  public slots:
192  void reload();
193 
200  void refreshDrives();
201 
202  void beginInsertItems( QgsDataItem *parent, int first, int last );
203  void endInsertItems();
204  void beginRemoveItems( QgsDataItem *parent, int first, int last );
205  void endRemoveItems();
206  void itemDataChanged( QgsDataItem *item );
207  void itemStateChanged( QgsDataItem *item, QgsDataItem::State oldState );
208 
218  void addFavoriteDirectory( const QString &directory, const QString &name = QString() );
219 
225  void removeFavorite( const QModelIndex &index );
226 
233  void removeFavorite( QgsFavoriteItem *favorite ) SIP_SKIP;
234 
235  void updateProjectHome();
236 
238  void hidePath( QgsDataItem *item );
239 
244  void initialize();
245 
246  protected:
248  void addRootItems();
249  void removeRootItems();
250 
251  QVector<QgsDataItem *> mRootItems;
252  QgsFavoritesItem *mFavorites = nullptr;
253  QgsDirectoryItem *mProjectHome = nullptr;
254 
255  private:
256  bool mInitialized = false;
257  QMap< QString, QgsDirectoryItem * > mDriveItems;
258 
259  void setupItemConnections( QgsDataItem *item );
260 
261  void removeRootItem( QgsDataItem *item );
262 
263  friend class TestQgsBrowserModel;
264  friend class TestQgsBrowserProxyModel;
265 };
266 
267 #endif // QGSBROWSERMODEL_H
bool initialized() const
Returns true if the model has been initialized.
QgsDataItem * item() const
QVector< QgsDataItem * > mRootItems
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
A directory: contains subdirectories and layers.
Definition: qgsdataitem.h:654
Base class for all items in the model.
Definition: qgsdataitem.h:49
Custom sort role, see QgsDataItem::sortKey()
Contains various Favorites directories.
Definition: qgsdataitem.h:789
Data item provider key that created the item,.
A model for showing available data sources and other items in a structured tree.