QGIS API Documentation  2.99.0-Master (25b0421)
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();
62 
64  {
65  PathRole = Qt::UserRole,
66  CommentRole = Qt::UserRole + 1,
67  };
68  // implemented methods from QAbstractItemModel for read-only access
69 
73  virtual Qt::ItemFlags flags( const QModelIndex &index ) const override;
74 
80  virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
81 
85  virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
86 
88  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
89 
93  virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
94 
96  virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
97 
98  QModelIndex findItem( QgsDataItem *item, QgsDataItem *parent = nullptr ) const;
99 
104  virtual QModelIndex parent( const QModelIndex &index ) const override;
105 
107  virtual QStringList mimeTypes() const override;
108 
110  virtual QMimeData *mimeData( const QModelIndexList &indexes ) const override;
111 
113  virtual bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
114 
115  QgsDataItem *dataItem( const QModelIndex &idx ) const;
116 
117  bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;
118 
120  void refresh( const QString &path );
121 
123  void refresh( const QModelIndex &index = QModelIndex() );
124 
132  QModelIndex findPath( const QString &path, Qt::MatchFlag matchFlag = Qt::MatchExactly );
133 
135  static QModelIndex findPath( QAbstractItemModel *model, const QString &path, Qt::MatchFlag matchFlag = Qt::MatchExactly ) SIP_SKIP;
136 
137  void connectItem( QgsDataItem *item );
138 
139  bool canFetchMore( const QModelIndex &parent ) const override;
140  void fetchMore( const QModelIndex &parent ) override;
141 
143  bool initialized( ) const { return mInitialized; }
144 
145  signals:
147  void stateChanged( const QModelIndex &index, QgsDataItem::State oldState );
148 
153  void connectionsChanged();
154 
155  public slots:
157  void reload();
158  void beginInsertItems( QgsDataItem *parent, int first, int last );
159  void endInsertItems();
160  void beginRemoveItems( QgsDataItem *parent, int first, int last );
161  void endRemoveItems();
162  void itemDataChanged( QgsDataItem *item );
163  void itemStateChanged( QgsDataItem *item, QgsDataItem::State oldState );
164 
170  void addFavoriteDirectory( const QString &directory );
171 
177  void removeFavorite( const QModelIndex &index );
178 
179  void updateProjectHome();
180 
182  void hidePath( QgsDataItem *item );
183 
185  void initialize();
186 
187  protected:
189  void addRootItems();
190  void removeRootItems();
191 
192  QVector<QgsDataItem *> mRootItems;
193  QgsFavoritesItem *mFavorites = nullptr;
194  QgsDirectoryItem *mProjectHome = nullptr;
195 
196  private:
197  bool mInitialized = false;
198 };
199 
200 #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:492
Base class for all items in the model.
Definition: qgsdataitem.h:49
Contains various Favorites directories.
Definition: qgsdataitem.h:606