QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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
6  Email : [email protected]
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 class QgsBrowserGuiModel;
24 
32 class GUI_EXPORT QgsBrowserTreeView : public QTreeView
33 {
34  Q_OBJECT
35  public:
36 
38  QgsBrowserTreeView( QWidget *parent SIP_TRANSFERTHIS = nullptr );
39 
40  void setModel( QAbstractItemModel *model ) override;
42  void setBrowserModel( QgsBrowserGuiModel *model );
44  QgsBrowserGuiModel *browserModel() { return mBrowserModel; }
45  void showEvent( QShowEvent *e ) override;
46  void hideEvent( QHideEvent *e ) override;
47 
48  // returns true if at least one descendat is expanded, used in refresh
49  bool hasExpandedDescendant( const QModelIndex &index ) const;
50 
51  // Set section where to store settings (because we have 2 browser dock widgets)
52  void setSettingsSection( const QString &section ) { mSettingsSection = section; }
53 
54  protected:
55 
56  void keyPressEvent( QKeyEvent *event ) override;
57 
58  protected slots:
59  void rowsInserted( const QModelIndex &parentIndex, int start, int end ) override;
60 
61  private:
62  QString mSettingsSection;
63  // initial expanded paths
64  QStringList mExpandPaths;
65  void saveState();
66  void restoreState();
67 
68  QString expandedPathsKey() const;
69 
70  // Get list of expanded items paths recursively
71  QStringList expandedPathsList( const QModelIndex &index );
72 
73  // Expand path recursively to root
74  void expandTree( const QModelIndex &index );
75 
76  // returns true if expanded from root to item
77  bool treeExpanded( const QModelIndex &index );
78  QgsBrowserGuiModel *mBrowserModel = nullptr;
79 };
80 
81 #endif // QGSBROWSERTREEVIEW_H
QgsBrowserTreeView
The QgsBrowserTreeView class extends QTreeView with save/restore tree state functionality.
Definition: qgsbrowsertreeview.h:32
qgis_sip.h
QgsBrowserTreeView::setSettingsSection
void setSettingsSection(const QString &section)
Definition: qgsbrowsertreeview.h:52
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsBrowserGuiModel
A model for showing available data sources and other items in a structured tree.
Definition: qgsbrowserguimodel.h:36
QgsBrowserTreeView::browserModel
QgsBrowserGuiModel * browserModel()
Returns the browser model.
Definition: qgsbrowsertreeview.h:44