QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgsbrowsertreeview.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsbrowsertreeview.h
3 --------------------------------------
4 Date : January 2015
5 Copyright : (C) 2015 by Radim Blazek
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
16#ifndef QGSBROWSERTREEVIEW_H
17#define QGSBROWSERTREEVIEW_H
18
19#include <QTreeView>
20#include "qgis_sip.h"
21#include "qgis_gui.h"
22
23#ifdef SIP_RUN
24// this is needed for the "convert to subclass" code below to compile
25% ModuleHeaderCode
26#include "qgsbrowsertreeview.h"
27% End
28#endif
29
31class QgsDataItem;
32
40class GUI_EXPORT QgsBrowserTreeView : public QTreeView
41{
42
43#ifdef SIP_RUN
45 if ( qobject_cast<QgsBrowserTreeView *>( sipCpp ) != nullptr )
46 sipType = sipType_QgsBrowserTreeView;
47 else
48 sipType = nullptr;
50#endif
51
52 Q_OBJECT
53 public:
54
56 QgsBrowserTreeView( QWidget *parent SIP_TRANSFERTHIS = nullptr );
57
58 void setModel( QAbstractItemModel *model ) override;
60 void setBrowserModel( QgsBrowserGuiModel *model );
62 QgsBrowserGuiModel *browserModel() { return mBrowserModel; }
63 void showEvent( QShowEvent *e ) override;
64 void hideEvent( QHideEvent *e ) override;
65
66 // returns true if at least one descendat is expanded, used in refresh
67 bool hasExpandedDescendant( const QModelIndex &index ) const;
68
69 // Set section where to store settings (because we have 2 browser dock widgets)
70 void setSettingsSection( const QString &section ) { mSettingsSection = section; }
71
79 bool setSelectedItem( QgsDataItem *item );
80
88 void expandPath( const QString &path );
89
90 protected:
91
92 void keyPressEvent( QKeyEvent *event ) override;
93
94 protected slots:
95 void rowsInserted( const QModelIndex &parentIndex, int start, int end ) override;
96
97 private:
98 QString mSettingsSection;
99 // initial expanded paths
100 QStringList mExpandPaths;
101 void saveState();
102 void restoreState();
103
104 QString expandedPathsKey() const;
105
106 // Get list of expanded items paths recursively
107 QStringList expandedPathsList( const QModelIndex &index );
108
109 // Expand path recursively to root
110 void expandTree( const QModelIndex &index );
111
112 // returns true if expanded from root to item
113 bool treeExpanded( const QModelIndex &index );
114 QgsBrowserGuiModel *mBrowserModel = nullptr;
115};
116
117#endif // QGSBROWSERTREEVIEW_H
A model for showing available data sources and other items in a structured tree.
The QgsBrowserTreeView class extends QTreeView with save/restore tree state functionality.
void setSettingsSection(const QString &section)
QgsBrowserGuiModel * browserModel()
Returns the browser model.
Base class for all items in the model.
Definition: qgsdataitem.h:46
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_END
Definition: qgis_sip.h:203