QGIS API Documentation 4.1.0-Master (60fea48833c)
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.h"
19#include "qgis_core.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:
64 explicit QgsBrowserModel( QObject *parent = nullptr );
65
66 ~QgsBrowserModel() override;
67
68 // *INDENT-OFF*
69
77 {
78 Path SIP_MONKEYPATCH_COMPAT_NAME( PathRole ) = Qt::UserRole,
79 Comment SIP_MONKEYPATCH_COMPAT_NAME( CommentRole ) = Qt::UserRole + 1,
80 Sort SIP_MONKEYPATCH_COMPAT_NAME( SortRole ),
81 ProviderKey SIP_MONKEYPATCH_COMPAT_NAME( ProviderKeyRole ),
82 LayerMetadata SIP_MONKEYPATCH_COMPAT_NAME( LayerMetadataRole ),
83 };
84 Q_ENUM( CustomRole )
85 // *INDENT-ON*
86
87 // implemented methods from QAbstractItemModel for read-only access
88
89 Qt::ItemFlags flags( const QModelIndex &index ) const override;
90 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
91 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
92 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
93 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
94 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
95 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
96 QModelIndex parent( const QModelIndex &index ) const override;
97 QStringList mimeTypes() const override;
98 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
99 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
100 bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;
101 bool canFetchMore( const QModelIndex &parent ) const override;
102 void fetchMore( const QModelIndex &parent ) override;
103
112 QModelIndex findItem( QgsDataItem *item, QgsDataItem *parent = nullptr ) const;
113
118 QgsDataItem *dataItem( const QModelIndex &idx ) const;
119
121 void refresh( const QString &path );
122
124 void refresh( const QModelIndex &index = QModelIndex() );
125
134 QModelIndex findPath( const QString &path, Qt::MatchFlag matchFlag = Qt::MatchExactly );
135
137 static QModelIndex findPath( QAbstractItemModel *model, const QString &path, Qt::MatchFlag matchFlag = Qt::MatchExactly ) SIP_SKIP;
138
148 QModelIndex findUri( const QString &uri, QModelIndex index = QModelIndex() );
149
153 Q_DECL_DEPRECATED void connectItem( QgsDataItem *item ) SIP_DEPRECATED;
154
160 bool initialized() const { return mInitialized; }
161
170 QMap<QString, QgsDirectoryItem *> driveItems() const;
171
177 QVector<QgsDataItem *> rootItems() const { return mRootItems; }
178
179 signals:
180
182 void stateChanged( const QModelIndex &index, Qgis::BrowserItemState oldState );
183
189 void connectionsChanged( const QString &providerKey );
190
191 public slots:
193 void reload();
194
201 void refreshDrives();
202
203 void beginInsertItems( QgsDataItem *parent, int first, int last );
204 void endInsertItems();
205 void beginRemoveItems( QgsDataItem *parent, int first, int last );
206 void endRemoveItems();
207 void itemDataChanged( QgsDataItem *item );
208
213
222 void addFavoriteDirectory( const QString &directory, const QString &name = QString() );
223
228 void removeFavorite( const QModelIndex &index );
229
236 void removeFavorite( QgsFavoriteItem *favorite ) SIP_SKIP;
237
238 void updateProjectHome();
239
241 void hidePath( QgsDataItem *item );
242
247 void initialize();
248
249 protected:
251 void addRootItems();
252 void removeRootItems();
253
254 QVector<QgsDataItem *> mRootItems;
257
258 private slots:
259 void dataItemProviderAdded( QgsDataItemProvider *provider );
260 void dataItemProviderWillBeRemoved( QgsDataItemProvider *provider );
261 void onConnectionsChanged( const QString &providerKey );
262
263 private:
264 bool mInitialized = false;
265 QMap< QString, QgsDirectoryItem * > mDriveItems;
266
267 void setupItemConnections( QgsDataItem *item );
268
269 void removeRootItem( QgsDataItem *item );
270
271 QgsDataItem *addProviderRootItem( QgsDataItemProvider *provider );
272
275};
276
277#endif // QGSBROWSERMODEL_H
BrowserItemState
Browser item states.
Definition qgis.h:964
void connectionsChanged(const QString &providerKey)
Emitted when connections for the specified providerKey have changed in the browser.
QgsFavoritesItem * mFavorites
void hidePath(QgsDataItem *item)
Hide the given path in the browser model.
void refreshDrives()
Refreshes the list of drive items, removing any corresponding to removed drives and adding newly adde...
void reload()
Reload the whole model.
void itemStateChanged(QgsDataItem *item, Qgis::BrowserItemState oldState)
Emitted when an item's state is changed.
void beginInsertItems(QgsDataItem *parent, int first, int last)
QVector< QgsDataItem * > mRootItems
void beginRemoveItems(QgsDataItem *parent, int first, int last)
QModelIndex parent(const QModelIndex &index) const override
void initialize()
Delayed initialization, needed because the provider registry must be already populated.
void addFavoriteDirectory(const QString &directory, const QString &name=QString())
Adds a directory to the favorites group.
friend class TestQgsBrowserModel
QgsBrowserModel(QObject *parent=nullptr)
Constructor for QgsBrowserModel, with the specified parent object.
QgsDirectoryItem * mProjectHome
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
void stateChanged(const QModelIndex &index, Qgis::BrowserItemState oldState)
Emitted when item children fetch was finished.
void itemDataChanged(QgsDataItem *item)
void addRootItems()
Populates the model.
bool initialized() const
Returns true if the model has been initialized.
QVector< QgsDataItem * > rootItems() const
Returns the root items for the model.
friend class TestQgsBrowserProxyModel
CustomRole
Custom model roles.
void removeFavorite(const QModelIndex &index)
Removes a favorite directory from its corresponding model index.
Interface for providers that add custom data items to the browser tree.
Base class for all items in the model.
Definition qgsdataitem.h:50
A browser item for directories: contains subdirectories and layers.
A directory item showing a single favorite directory.
A browser item which contains various Favorites directories.
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:267
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:269