QGIS API Documentation  2.99.0-Master (d8402ac)
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 
55 class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
56 {
57  Q_OBJECT
58 
59  public:
60  explicit QgsBrowserModel( QObject *parent = nullptr );
61  ~QgsBrowserModel() override;
62 
64  {
65  PathRole = Qt::UserRole,
66  CommentRole = Qt::UserRole + 1,
68  };
69  // implemented methods from QAbstractItemModel for read-only access
70 
74  Qt::ItemFlags flags( const QModelIndex &index ) const override;
75 
81  QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
82 
86  QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
87 
89  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
90 
94  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
95 
97  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
98 
99  QModelIndex findItem( QgsDataItem *item, QgsDataItem *parent = nullptr ) const;
100 
105  QModelIndex parent( const QModelIndex &index ) const override;
106 
108  QStringList mimeTypes() const override;
109 
111  QMimeData *mimeData( const QModelIndexList &indexes ) const override;
112 
114  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
115 
116  QgsDataItem *dataItem( const QModelIndex &idx ) const;
117 
118  bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;
119 
121  void refresh( const QString &path );
122 
124  void refresh( const QModelIndex &index = QModelIndex() );
125 
133  QModelIndex findPath( const QString &path, Qt::MatchFlag matchFlag = Qt::MatchExactly );
134 
136  static QModelIndex findPath( QAbstractItemModel *model, const QString &path, Qt::MatchFlag matchFlag = Qt::MatchExactly ) SIP_SKIP;
137 
138  void connectItem( QgsDataItem *item );
139 
140  bool canFetchMore( const QModelIndex &parent ) const override;
141  void fetchMore( const QModelIndex &parent ) override;
142 
144  bool initialized( ) const { return mInitialized; }
145 
146  signals:
148  void stateChanged( const QModelIndex &index, QgsDataItem::State oldState );
149 
154  void connectionsChanged();
155 
156  public slots:
158  void reload();
159  void beginInsertItems( QgsDataItem *parent, int first, int last );
160  void endInsertItems();
161  void beginRemoveItems( QgsDataItem *parent, int first, int last );
162  void endRemoveItems();
163  void itemDataChanged( QgsDataItem *item );
164  void itemStateChanged( QgsDataItem *item, QgsDataItem::State oldState );
165 
175  void addFavoriteDirectory( const QString &directory, const QString &name = QString() );
176 
182  void removeFavorite( const QModelIndex &index );
183 
184  void updateProjectHome();
185 
187  void hidePath( QgsDataItem *item );
188 
190  void initialize();
191 
192  protected:
194  void addRootItems();
195  void removeRootItems();
196 
197  QVector<QgsDataItem *> mRootItems;
198  QgsFavoritesItem *mFavorites = nullptr;
199  QgsDirectoryItem *mProjectHome = nullptr;
200 
201  private:
202  bool mInitialized = false;
203 };
204 
205 #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:119
A directory: contains subdirectories and layers.
Definition: qgsdataitem.h:528
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:642