QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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
70 {
71 PathRole = Qt::UserRole,
72 CommentRole = Qt::UserRole + 1,
76 };
77 // implemented methods from QAbstractItemModel for read-only access
78
79 Qt::ItemFlags flags( const QModelIndex &index ) const override;
80 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
81 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
82 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
83 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
84 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
85 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
86 QModelIndex parent( const QModelIndex &index ) const override;
87 QStringList mimeTypes() const override;
88 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
89 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
90 bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;
91 bool canFetchMore( const QModelIndex &parent ) const override;
92 void fetchMore( const QModelIndex &parent ) override;
93
102 QModelIndex findItem( QgsDataItem *item, QgsDataItem *parent = nullptr ) const;
103
108 QgsDataItem *dataItem( const QModelIndex &idx ) const;
109
111 void refresh( const QString &path );
112
114 void refresh( const QModelIndex &index = QModelIndex() );
115
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
138 QModelIndex findUri( const QString &uri, QModelIndex index = QModelIndex() );
139
143 Q_DECL_DEPRECATED void connectItem( QgsDataItem *item ) SIP_DEPRECATED;
144
150 bool initialized() const { return mInitialized; }
151
160 QMap<QString, QgsDirectoryItem *> driveItems() const;
161
167 QVector<QgsDataItem *> rootItems() const { return mRootItems; }
168
169 signals:
170
172 void stateChanged( const QModelIndex &index, Qgis::BrowserItemState oldState );
173
179 void connectionsChanged( const QString &providerKey );
180
181 public slots:
183 void reload();
184
191 void refreshDrives();
192
193 void beginInsertItems( QgsDataItem *parent, int first, int last );
194 void endInsertItems();
195 void beginRemoveItems( QgsDataItem *parent, int first, int last );
196 void endRemoveItems();
197 void itemDataChanged( QgsDataItem *item );
198
202 void itemStateChanged( QgsDataItem *item, Qgis::BrowserItemState oldState );
203
213 void addFavoriteDirectory( const QString &directory, const QString &name = QString() );
214
220 void removeFavorite( const QModelIndex &index );
221
228 void removeFavorite( QgsFavoriteItem *favorite ) SIP_SKIP;
229
230 void updateProjectHome();
231
233 void hidePath( QgsDataItem *item );
234
239 void initialize();
240
241 protected:
243 void addRootItems();
244 void removeRootItems();
245
246 QVector<QgsDataItem *> mRootItems;
247 QgsFavoritesItem *mFavorites = nullptr;
248 QgsDirectoryItem *mProjectHome = nullptr;
249
250 private slots:
251 void dataItemProviderAdded( QgsDataItemProvider *provider );
252 void dataItemProviderWillBeRemoved( QgsDataItemProvider *provider );
253 void onConnectionsChanged( const QString &providerKey );
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 QgsDataItem *addProviderRootItem( QgsDataItemProvider *provider );
264
265 friend class TestQgsBrowserModel;
266 friend class TestQgsBrowserProxyModel;
267};
268
269#endif // QGSBROWSERMODEL_H
BrowserItemState
Browser item states.
Definition: qgis.h:368
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.
@ ProviderKeyRole
Data item provider key that created the item, see QgsDataItem::providerKey()
@ SortRole
Custom sort role, see QgsDataItem::sortKey()
QVector< QgsDataItem * > rootItems() const
Returns the root items for the model.
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