summaryrefslogtreecommitdiffstats
path: root/qt-ui/divelistview.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-11-08 21:08:14 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-09 15:33:55 +0900
commitd3fe3494fef7b43556bfd8bd3b2128a3e0dc623d (patch)
tree0259c843b3f121c407e5ec41608a1acbb9b6f0a2 /qt-ui/divelistview.cpp
parent38287a1c1ea32b00f64b0ef60d9a99aff855335a (diff)
downloadsubsurface-d3fe3494fef7b43556bfd8bd3b2128a3e0dc623d.tar.gz
Save / Restore the Tree after organizing by other columns.
This patch saves and restores the state of the TreeView after the user clicks on another columns that will make the tree disappear. All of the branche states are saved, this way the expanded nodes will be restored when the user gets back to tree mode. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divelistview.cpp')
-rw-r--r--qt-ui/divelistview.cpp40
1 files changed, 24 insertions, 16 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index 1217e0d25..b2f33ffa1 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -66,15 +66,8 @@ DiveListView::~DiveListView()
void DiveListView::setupUi(){
QSettings settings;
static bool firstRun = true;
- QList<int> expandedColumns;
- if(!firstRun){
- for(int i = 0; i < model()->rowCount(); i++){
- if(isExpanded( model()->index(i, 0) )){
- expandedColumns.push_back(i);
- }
- }
- }
-
+ if(firstRun)
+ backupExpandedRows();
settings.beginGroup("ListWidget");
/* if no width are set, use the calculated width for each column;
* for that to work we need to temporarily expand all rows */
@@ -89,18 +82,27 @@ void DiveListView::setupUi(){
setColumnWidth(i, 100);
}
settings.endGroup();
+ if(firstRun)
+ restoreExpandedRows();
+ else
+ collapseAll();
+ firstRun = false;
+}
- if(firstRun){
- Q_FOREACH(const int &i, expandedColumns){
- setExpanded( model()->index(i, 0), true );
+void DiveListView::backupExpandedRows(){
+ expandedRows.clear();
+ for(int i = 0; i < model()->rowCount(); i++){
+ if(isExpanded( model()->index(i, 0) )){
+ expandedRows.push_back(i);
}
- }else{
- collapseAll();
}
-
- firstRun = false;
}
+void DiveListView::restoreExpandedRows(){
+ Q_FOREACH(const int &i, expandedRows){
+ setExpanded( model()->index(i, 0), true );
+ }
+}
void DiveListView::fixMessyQtModelBehaviour()
{
QAbstractItemModel *m = model();
@@ -184,9 +186,15 @@ void DiveListView::headerClicked(int i)
sortByColumn(i, currentOrder);
} else {
// clear the model, repopulate with new indexes.
+ if(currentLayout == DiveTripModel::TREE){
+ backupExpandedRows();
+ }
reload(newLayout, false);
currentOrder = Qt::DescendingOrder;
sortByColumn(i, currentOrder);
+ if (newLayout == DiveTripModel::TREE){
+ restoreExpandedRows();
+ }
}
// repopulate the selections.