QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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
39class GUI_EXPORT QgsBrowserTreeView : public QTreeView
40{
41
42#ifdef SIP_RUN
44 if ( qobject_cast<QgsBrowserTreeView *>( sipCpp ) != nullptr )
45 sipType = sipType_QgsBrowserTreeView;
46 else
47 sipType = nullptr;
49#endif
50
51 Q_OBJECT
52 public:
53
55 QgsBrowserTreeView( QWidget *parent SIP_TRANSFERTHIS = nullptr );
56
57 void setModel( QAbstractItemModel *model ) override;
59 void setBrowserModel( QgsBrowserGuiModel *model );
61 QgsBrowserGuiModel *browserModel() { return mBrowserModel; }
62 void showEvent( QShowEvent *e ) override;
63 void hideEvent( QHideEvent *e ) override;
64
65 // returns true if at least one descendat is expanded, used in refresh
66 bool hasExpandedDescendant( const QModelIndex &index ) const;
67
68 // Set section where to store settings (because we have 2 browser dock widgets)
69 void setSettingsSection( const QString &section ) { mSettingsSection = section; }
70
78 bool setSelectedItem( QgsDataItem *item );
79
87 void expandPath( const QString &path );
88
89 protected:
90
91 void keyPressEvent( QKeyEvent *event ) override;
92
93 protected slots:
94 void rowsInserted( const QModelIndex &parentIndex, int start, int end ) override;
95
96 private:
97 QString mSettingsSection;
98 // initial expanded paths
99 QStringList mExpandPaths;
100 void saveState();
101 void restoreState();
102
103 QString expandedPathsKey() const;
104
105 // Get list of expanded items paths recursively
106 QStringList expandedPathsList( const QModelIndex &index );
107
108 // Expand path recursively to root
109 void expandTree( const QModelIndex &index );
110
111 // returns true if expanded from root to item
112 bool treeExpanded( const QModelIndex &index );
113 QgsBrowserGuiModel *mBrowserModel = nullptr;
114};
115
116#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:191
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_END
Definition: qgis_sip.h:208