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