QGIS API Documentation  3.6.0-Noosa (5873452)
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 QgsBrowserModel;
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( QgsBrowserModel *model );
44  QgsBrowserModel *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  QgsBrowserModel *mBrowserModel = nullptr;
75 };
76 
77 #endif // QGSBROWSERTREEVIEW_H
The QgsBrowserTreeView class extends QTreeView with save/restore tree state functionality.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
void setSettingsSection(const QString &section)
A model for showing available data sources and other items in a structured tree.
QgsBrowserModel * browserModel()
Returns the browser model.