QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
21 class QgsBrowserModel;
22 
29 class GUI_EXPORT QgsBrowserTreeView : public QTreeView
30 {
31  Q_OBJECT
32  public:
33  QgsBrowserTreeView( QWidget *parent = nullptr );
35 
36  virtual void setModel( QAbstractItemModel* model ) override;
38  void setBrowserModel( QgsBrowserModel *model );
40  QgsBrowserModel *browserModel( ) { return mBrowserModel; }
41  virtual void showEvent( QShowEvent * e ) override;
42  virtual void hideEvent( QHideEvent * e ) override;
43 
44  // returns true if at least one descendat is expanded, used in refresh
45  bool hasExpandedDescendant( const QModelIndex& index ) const;
46 
47  // Set section where to store settings (because we have 2 browser dock widgets)
48  void setSettingsSection( const QString & section ) { mSettingsSection = section; }
49 
50  protected slots:
51  virtual void rowsInserted( const QModelIndex & parentIndex, int start, int end ) override;
52 
53  private:
54  QString mSettingsSection;
55  // initial expanded paths
56  QStringList mExpandPaths;
57  void saveState();
58  void restoreState();
59 
60  QString expandedPathsKey() const;
61 
62  // Get list of expanded items paths recursively
63  QStringList expandedPathsList( const QModelIndex & index );
64 
65  // Expand path recursively to root
66  void expandTree( const QModelIndex & index );
67 
68  // returns true if expanded from root to item
69  bool treeExpanded( const QModelIndex & index );
70 
71  // Stores the browser model
72  QgsBrowserModel *mBrowserModel;
73 };
74 
75 #endif // QGSBROWSERTREEVIEW_H
static unsigned index
The QgsBrowserTreeView class extends QTreeView with save/restore tree state functionality.
void setSettingsSection(const QString &section)
virtual void showEvent(QShowEvent *event)
virtual void hideEvent(QHideEvent *event)
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
virtual void setModel(QAbstractItemModel *model)
QgsBrowserModel * browserModel()
Return the browser model.