QGIS API Documentation 3.38.0-Grenoble (exported)
Loading...
Searching...
No Matches
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 "qgis.h"
20
21#include <QAbstractItemModel>
22#include <QIcon>
23#include <QMimeData>
24#include <QMovie>
25
26class QgsDataItem;
29class QgsFavoriteItem;
31
52class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
53{
54 Q_OBJECT
55
56 public:
57
65 explicit QgsBrowserModel( QObject *parent = nullptr );
66
67 ~QgsBrowserModel() override;
68
69 // *INDENT-OFF*
70
78 {
79 Path SIP_MONKEYPATCH_COMPAT_NAME( PathRole ) = Qt::UserRole,
80 Comment SIP_MONKEYPATCH_COMPAT_NAME( CommentRole ) = Qt::UserRole + 1,
81 Sort SIP_MONKEYPATCH_COMPAT_NAME( SortRole ),
82 ProviderKey SIP_MONKEYPATCH_COMPAT_NAME( ProviderKeyRole ),
83 LayerMetadata SIP_MONKEYPATCH_COMPAT_NAME( LayerMetadataRole ),
84 };
85 Q_ENUM( CustomRole )
86 // *INDENT-ON*
87
88 // implemented methods from QAbstractItemModel for read-only access
89
90 Qt::ItemFlags flags( const QModelIndex &index ) const override;
91 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
92 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
93 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
94 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
95 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
96 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
97 QModelIndex parent( const QModelIndex &index ) const override;
98 QStringList mimeTypes() const override;
99 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
100 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
101 bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;
102 bool canFetchMore( const QModelIndex &parent ) const override;
103 void fetchMore( const QModelIndex &parent ) override;
104
113 QModelIndex findItem( QgsDataItem *item, QgsDataItem *parent = nullptr ) const;
114
119 QgsDataItem *dataItem( const QModelIndex &idx ) const;
120
122 void refresh( const QString &path );
123
125 void refresh( const QModelIndex &index = QModelIndex() );
126
135 QModelIndex findPath( const QString &path, Qt::MatchFlag matchFlag = Qt::MatchExactly );
136
138 static QModelIndex findPath( QAbstractItemModel *model, const QString &path, Qt::MatchFlag matchFlag = Qt::MatchExactly ) SIP_SKIP;
139
149 QModelIndex findUri( const QString &uri, QModelIndex index = QModelIndex() );
150
154 Q_DECL_DEPRECATED void connectItem( QgsDataItem *item ) SIP_DEPRECATED;
155
161 bool initialized() const { return mInitialized; }
162
171 QMap<QString, QgsDirectoryItem *> driveItems() const;
172
178 QVector<QgsDataItem *> rootItems() const { return mRootItems; }
179
180 signals:
181
183 void stateChanged( const QModelIndex &index, Qgis::BrowserItemState oldState );
184
190 void connectionsChanged( const QString &providerKey );
191
192 public slots:
194 void reload();
195
202 void refreshDrives();
203
204 void beginInsertItems( QgsDataItem *parent, int first, int last );
205 void endInsertItems();
206 void beginRemoveItems( QgsDataItem *parent, int first, int last );
207 void endRemoveItems();
208 void itemDataChanged( QgsDataItem *item );
209
213 void itemStateChanged( QgsDataItem *item, Qgis::BrowserItemState oldState );
214
223 void addFavoriteDirectory( const QString &directory, const QString &name = QString() );
224
229 void removeFavorite( const QModelIndex &index );
230
237 void removeFavorite( QgsFavoriteItem *favorite ) SIP_SKIP;
238
239 void updateProjectHome();
240
242 void hidePath( QgsDataItem *item );
243
248 void initialize();
249
250 protected:
252 void addRootItems();
253 void removeRootItems();
254
255 QVector<QgsDataItem *> mRootItems;
256 QgsFavoritesItem *mFavorites = nullptr;
257 QgsDirectoryItem *mProjectHome = nullptr;
258
259 private slots:
260 void dataItemProviderAdded( QgsDataItemProvider *provider );
261 void dataItemProviderWillBeRemoved( QgsDataItemProvider *provider );
262 void onConnectionsChanged( const QString &providerKey );
263
264 private:
265 bool mInitialized = false;
266 QMap< QString, QgsDirectoryItem * > mDriveItems;
267
268 void setupItemConnections( QgsDataItem *item );
269
270 void removeRootItem( QgsDataItem *item );
271
272 QgsDataItem *addProviderRootItem( QgsDataItemProvider *provider );
273
274 friend class TestQgsBrowserModel;
275 friend class TestQgsBrowserProxyModel;
276};
277
278#endif // QGSBROWSERMODEL_H
BrowserItemState
Browser item states.
Definition qgis.h:693
A model for showing available data sources and other items in a structured tree.
void connectionsChanged(const QString &providerKey)
Emitted when connections for the specified providerKey have changed in the browser.
QVector< QgsDataItem * > mRootItems
void stateChanged(const QModelIndex &index, Qgis::BrowserItemState oldState)
Emitted when item children fetch was finished.
bool initialized() const
Returns true if the model has been initialized.
QVector< QgsDataItem * > rootItems() const
Returns the root items for the model.
CustomRole
Custom model roles.
This is the interface for those who want to add custom data items to the browser tree.
Base class for all items in the model.
Definition qgsdataitem.h:46
A directory: contains subdirectories and layers.
A directory item showing the a single favorite directory.
Contains various Favorites directories.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:271
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:273