QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 slots:
55  void rowsInserted( const QModelIndex &parentIndex, int start, int end ) override;
56 
57  private:
58  QString mSettingsSection;
59  // initial expanded paths
60  QStringList mExpandPaths;
61  void saveState();
62  void restoreState();
63 
64  QString expandedPathsKey() const;
65 
66  // Get list of expanded items paths recursively
67  QStringList expandedPathsList( const QModelIndex &index );
68 
69  // Expand path recursively to root
70  void expandTree( const QModelIndex &index );
71 
72  // returns true if expanded from root to item
73  bool treeExpanded( const QModelIndex &index );
74  QgsBrowserGuiModel *mBrowserModel = nullptr;
75 };
76 
77 #endif // QGSBROWSERTREEVIEW_H
QgsBrowserTreeView
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
Definition: qgsbrowserguimodel.h:37
QgsBrowserTreeView::browserModel
QgsBrowserGuiModel * browserModel()
Returns the browser model.
Definition: qgsbrowsertreeview.h:44