QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
|
A model for showing available data sources and other items in a structured tree. More...
#include <qgsbrowsermodel.h>
Public Types | |
enum class | CustomRole : int { Path = Qt::UserRole , Comment = Qt::UserRole + 1 , Sort , ProviderKey , LayerMetadata } |
Custom model roles. More... | |
Public Slots | |
void | addFavoriteDirectory (const QString &directory, const QString &name=QString()) |
Adds a directory to the favorites group. | |
void | beginInsertItems (QgsDataItem *parent, int first, int last) |
void | beginRemoveItems (QgsDataItem *parent, int first, int last) |
void | endInsertItems () |
void | endRemoveItems () |
void | hidePath (QgsDataItem *item) |
Hide the given path in the browser model. | |
void | initialize () |
Delayed initialization, needed because the provider registry must be already populated. | |
void | itemDataChanged (QgsDataItem *item) |
void | itemStateChanged (QgsDataItem *item, Qgis::BrowserItemState oldState) |
Emitted when an item's state is changed. | |
void | refreshDrives () |
Refreshes the list of drive items, removing any corresponding to removed drives and adding newly added drives. | |
void | reload () |
Reload the whole model. | |
void | removeFavorite (const QModelIndex &index) |
Removes a favorite directory from its corresponding model index. | |
void | removeFavorite (QgsFavoriteItem *favorite) |
Removes a favorite item. | |
void | updateProjectHome () |
Signals | |
void | connectionsChanged (const QString &providerKey) |
Emitted when connections for the specified providerKey have changed in the browser. | |
void | stateChanged (const QModelIndex &index, Qgis::BrowserItemState oldState) |
Emitted when item children fetch was finished. | |
Public Member Functions | |
QgsBrowserModel (QObject *parent=nullptr) | |
Constructor for QgsBrowserModel, with the specified parent object. | |
~QgsBrowserModel () override | |
bool | canFetchMore (const QModelIndex &parent) const override |
int | columnCount (const QModelIndex &parent=QModelIndex()) const override |
Q_DECL_DEPRECATED void | connectItem (QgsDataItem *item) |
QVariant | data (const QModelIndex &index, int role=Qt::DisplayRole) const override |
QgsDataItem * | dataItem (const QModelIndex &idx) const |
Returns the data item at the specified index, or nullptr if no item exists at the index. | |
QMap< QString, QgsDirectoryItem * > | driveItems () const |
Returns a map of the root drive items shown in the browser. | |
bool | dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override |
void | fetchMore (const QModelIndex &parent) override |
QModelIndex | findItem (QgsDataItem *item, QgsDataItem *parent=nullptr) const |
Returns the model index corresponding to the specified data item. | |
QModelIndex | findPath (const QString &path, Qt::MatchFlag matchFlag=Qt::MatchExactly) |
Returns index of item with given path. | |
QModelIndex | findUri (const QString &uri, QModelIndex index=QModelIndex()) |
Returns index of layer item with given uri. | |
Qt::ItemFlags | flags (const QModelIndex &index) const override |
bool | hasChildren (const QModelIndex &parent=QModelIndex()) const override |
QVariant | headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override |
QModelIndex | index (int row, int column, const QModelIndex &parent=QModelIndex()) const override |
bool | initialized () const |
Returns true if the model has been initialized. | |
QMimeData * | mimeData (const QModelIndexList &indexes) const override |
QStringList | mimeTypes () const override |
QModelIndex | parent (const QModelIndex &index) const override |
void | refresh (const QModelIndex &index=QModelIndex()) |
Refresh item children. | |
void | refresh (const QString &path) |
Refresh item specified by path. | |
QVector< QgsDataItem * > | rootItems () const |
Returns the root items for the model. | |
int | rowCount (const QModelIndex &parent=QModelIndex()) const override |
bool | setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override |
Static Public Member Functions | |
static QModelIndex | findPath (QAbstractItemModel *model, const QString &path, Qt::MatchFlag matchFlag=Qt::MatchExactly) |
Protected Member Functions | |
void | addRootItems () |
Populates the model. | |
void | removeRootItems () |
Protected Attributes | |
QgsFavoritesItem * | mFavorites = nullptr |
QgsDirectoryItem * | mProjectHome = nullptr |
QVector< QgsDataItem * > | mRootItems |
Friends | |
class | TestQgsBrowserModel |
class | TestQgsBrowserProxyModel |
A model for showing available data sources and other items in a structured tree.
QgsBrowserModel is the foundation for the QGIS browser panel, and includes items for the different data providers and folders accessible to users.
QgsBrowserModel models are not initially populated and use a deferred initialization approach. After constructing a QgsBrowserModel, a call must be made to initialize() in order to populate the model.
Definition at line 52 of file qgsbrowsermodel.h.
|
strong |
Custom model roles.
Enumerator | |
---|---|
Path | Item path used to access path in the tree, see QgsDataItem::mPath. |
Comment | Item comment. |
Sort | Custom sort role, see QgsDataItem::sortKey() |
ProviderKey | Data item provider key that created the item, see QgsDataItem::providerKey()
|
LayerMetadata |
Definition at line 77 of file qgsbrowsermodel.h.
|
explicit |
Constructor for QgsBrowserModel, with the specified parent object.
Definition at line 69 of file qgsbrowsermodel.cpp.
|
override |
Definition at line 79 of file qgsbrowsermodel.cpp.
|
slot |
Adds a directory to the favorites group.
If name is specified, it will be used as the favorite's name. Otherwise the name will be set to match directory.
Definition at line 759 of file qgsbrowsermodel.cpp.
|
protected |
Populates the model.
Definition at line 111 of file qgsbrowsermodel.cpp.
|
slot |
Definition at line 588 of file qgsbrowsermodel.cpp.
|
slot |
Definition at line 603 of file qgsbrowsermodel.cpp.
|
override |
Definition at line 720 of file qgsbrowsermodel.cpp.
|
override |
Definition at line 412 of file qgsbrowsermodel.cpp.
|
signal |
Emitted when connections for the specified providerKey have changed in the browser.
Forwarded to the widget and used to notify the provider dialogs of a changed connection.
void QgsBrowserModel::connectItem | ( | QgsDataItem * | item | ) |
Definition at line 487 of file qgsbrowsermodel.cpp.
|
override |
Definition at line 287 of file qgsbrowsermodel.cpp.
QgsDataItem * QgsBrowserModel::dataItem | ( | const QModelIndex & | idx | ) | const |
Returns the data item at the specified index, or nullptr
if no item exists at the index.
Definition at line 712 of file qgsbrowsermodel.cpp.
QMap< QString, QgsDirectoryItem * > QgsBrowserModel::driveItems | ( | ) | const |
Returns a map of the root drive items shown in the browser.
These correspond to the top-level directory items shown, e.g. on Windows the C:\, D:\, etc, and on Linux the "/" root directory.
Definition at line 241 of file qgsbrowsermodel.cpp.
|
override |
Definition at line 698 of file qgsbrowsermodel.cpp.
|
slot |
Definition at line 598 of file qgsbrowsermodel.cpp.
|
slot |
Definition at line 611 of file qgsbrowsermodel.cpp.
|
override |
Definition at line 728 of file qgsbrowsermodel.cpp.
QModelIndex QgsBrowserModel::findItem | ( | QgsDataItem * | item, |
QgsDataItem * | parent = nullptr |
||
) | const |
Returns the model index corresponding to the specified data item.
If the item was not found, an invalid QModelIndex is returned.
If the parent item is argument is specified, then only items which are children of parent are searched. If no parent is specified, then all items within the model are searched.
Definition at line 572 of file qgsbrowsermodel.cpp.
QModelIndex QgsBrowserModel::findPath | ( | const QString & | path, |
Qt::MatchFlag | matchFlag = Qt::MatchExactly |
||
) |
Returns index of item with given path.
It only searches in currently fetched items, i.e. it does not fetch children.
path | item path |
matchFlag | supported is Qt::MatchExactly and Qt::MatchStartsWith which has reverse meaning, i.e. find item with the longest match from start with path (to get as close/deep as possible to deleted item). |
Definition at line 418 of file qgsbrowsermodel.cpp.
|
static |
Definition at line 423 of file qgsbrowsermodel.cpp.
QModelIndex QgsBrowserModel::findUri | ( | const QString & | uri, |
QModelIndex | index = QModelIndex() |
||
) |
Returns index of layer item with given uri.
It only searches in currently fetched items, i.e. it does not fetch children.
uri | item uri |
index | the current index of the parent (to search for children) |
Definition at line 463 of file qgsbrowsermodel.cpp.
|
override |
Definition at line 257 of file qgsbrowsermodel.cpp.
|
override |
Definition at line 403 of file qgsbrowsermodel.cpp.
|
override |
Definition at line 374 of file qgsbrowsermodel.cpp.
|
slot |
Hide the given path in the browser model.
Definition at line 782 of file qgsbrowsermodel.cpp.
|
override |
Definition at line 552 of file qgsbrowsermodel.cpp.
|
slot |
Delayed initialization, needed because the provider registry must be already populated.
Definition at line 247 of file qgsbrowsermodel.cpp.
|
inline |
Returns true
if the model has been initialized.
Definition at line 161 of file qgsbrowsermodel.h.
|
slot |
Definition at line 616 of file qgsbrowsermodel.cpp.
|
slot |
Emitted when an item's state is changed.
Definition at line 624 of file qgsbrowsermodel.cpp.
|
override |
Definition at line 665 of file qgsbrowsermodel.cpp.
|
override |
Definition at line 656 of file qgsbrowsermodel.cpp.
|
override |
Definition at line 563 of file qgsbrowsermodel.cpp.
void QgsBrowserModel::refresh | ( | const QModelIndex & | index = QModelIndex() | ) |
Refresh item children.
Definition at line 748 of file qgsbrowsermodel.cpp.
void QgsBrowserModel::refresh | ( | const QString & | path | ) |
Refresh item specified by path.
Definition at line 741 of file qgsbrowsermodel.cpp.
|
slot |
Refreshes the list of drive items, removing any corresponding to removed drives and adding newly added drives.
Definition at line 501 of file qgsbrowsermodel.cpp.
|
slot |
Reload the whole model.
Definition at line 492 of file qgsbrowsermodel.cpp.
|
slot |
Removes a favorite directory from its corresponding model index.
Definition at line 765 of file qgsbrowsermodel.cpp.
|
slot |
Removes a favorite item.
Definition at line 774 of file qgsbrowsermodel.cpp.
|
protected |
Definition at line 188 of file qgsbrowsermodel.cpp.
|
inline |
Returns the root items for the model.
Definition at line 178 of file qgsbrowsermodel.h.
|
override |
Definition at line 385 of file qgsbrowsermodel.cpp.
|
override |
Definition at line 346 of file qgsbrowsermodel.cpp.
|
signal |
Emitted when item children fetch was finished.
|
slot |
Definition at line 84 of file qgsbrowsermodel.cpp.
|
friend |
Definition at line 274 of file qgsbrowsermodel.h.
|
friend |
Definition at line 275 of file qgsbrowsermodel.h.
|
protected |
Definition at line 256 of file qgsbrowsermodel.h.
|
protected |
Definition at line 257 of file qgsbrowsermodel.h.
|
protected |
Definition at line 255 of file qgsbrowsermodel.h.