QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 "qgis_gui.h"
20#include "qgis_sip.h"
21
22#include <QTreeView>
23
24#ifdef SIP_RUN
25// this is needed for the "convert to subclass" code below to compile
26//%ModuleHeaderCode
27#include "qgsbrowsertreeview.h"
28//%End
29#endif
30
32class QgsDataItem;
33
40class GUI_EXPORT QgsBrowserTreeView : public QTreeView
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:
54 QgsBrowserTreeView( QWidget *parent SIP_TRANSFERTHIS = nullptr );
55
56 void setModel( QAbstractItemModel *model ) override;
60 QgsBrowserGuiModel *browserModel() { return mBrowserModel; }
61 void showEvent( QShowEvent *e ) override;
62 void hideEvent( QHideEvent *e ) override;
63
64 // returns true if at least one descendat is expanded, used in refresh
65 bool hasExpandedDescendant( const QModelIndex &index ) const;
66
67 // Set section where to store settings (because we have 2 browser dock widgets)
68 void setSettingsSection( const QString &section ) { mSettingsSection = section; }
69
77 bool setSelectedItem( QgsDataItem *item );
78
88 void expandPath( const QString &path, bool selectPath = false );
89
90 protected:
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.
QgsBrowserTreeView(QWidget *parent=nullptr)
Constructor for QgsBrowserTreeView.
void setBrowserModel(QgsBrowserGuiModel *model)
Sets the browser model.
void setModel(QAbstractItemModel *model) override
void setSettingsSection(const QString &section)
QgsBrowserGuiModel * browserModel()
Returns the browser model.
Base class for all items in the model.
Definition qgsdataitem.h:47
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:199
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_END
Definition qgis_sip.h:216