QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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
89 void expandPath( const QString &path, bool selectPath = false );
90
91 protected:
92
93 void keyPressEvent( QKeyEvent *event ) override;
94
95 protected slots:
96 void rowsInserted( const QModelIndex &parentIndex, int start, int end ) override;
97
98 private:
99 QString mSettingsSection;
100 // initial expanded paths
101 QStringList mExpandPaths;
102 void saveState();
103 void restoreState();
104
105 QString expandedPathsKey() const;
106
107 // Get list of expanded items paths recursively
108 QStringList expandedPathsList( const QModelIndex &index );
109
110 // Expand path recursively to root
111 void expandTree( const QModelIndex &index );
112
113 // returns true if expanded from root to item
114 bool treeExpanded( const QModelIndex &index );
115 QgsBrowserGuiModel *mBrowserModel = nullptr;
116};
117
118#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