summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/divelistview.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-11-28 21:55:26 +0100
committerGravatar bstoeger <32835590+bstoeger@users.noreply.github.com>2019-12-04 13:00:23 +0100
commit28e97e75556e50c33fb064a60725ab7937ef5440 (patch)
treec3907cb5abce0117c6f7d208b520f9f1c2be1481 /desktop-widgets/divelistview.cpp
parentbe26b0bd9aa6817ea6aa5c374172fc9518379b55 (diff)
downloadsubsurface-28e97e75556e50c33fb064a60725ab7937ef5440.tar.gz
Cleanup: remove DiveListView::expandedRows member variable
The QList served as backing store for backupExpandedRows() and restoreExpandedRows(). However, these always came in pairs in the same scope. There is no reason to store the expanded rows over a longer time. Therefore, return the expanded rows from backupExpandedRows() and take them as argument in restoreExpandedRows(). Morover replace the QList<int> by the much lighter std::vector<int>. We certainly don't need copy-on-write, reference-counting and immutability of iterators in this case. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/divelistview.cpp')
-rw-r--r--desktop-widgets/divelistview.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp
index a4b5ad282..ee0c1c98f 100644
--- a/desktop-widgets/divelistview.cpp
+++ b/desktop-widgets/divelistview.cpp
@@ -135,7 +135,7 @@ void DiveListView::calculateInitialColumnWidth(int col)
void DiveListView::setColumnWidths()
{
QSettings settings;
- backupExpandedRows();
+ std::vector<int> expandedRows = 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 */
@@ -150,7 +150,7 @@ void DiveListView::setColumnWidths()
setColumnWidth(i, initialColumnWidths[i]);
}
settings.endGroup();
- restoreExpandedRows();
+ restoreExpandedRows(expandedRows);
setColumnWidth(lastVisibleColumn(), 10);
}
@@ -165,18 +165,19 @@ int DiveListView::lastVisibleColumn()
return lastColumn;
}
-void DiveListView::backupExpandedRows()
+std::vector<int> DiveListView::backupExpandedRows()
{
- expandedRows.clear();
+ std::vector<int> expandedRows;
for (int i = 0; i < model()->rowCount(); i++)
if (isExpanded(model()->index(i, 0)))
expandedRows.push_back(i);
+ return expandedRows;
}
-void DiveListView::restoreExpandedRows()
+void DiveListView::restoreExpandedRows(const std::vector<int> &expandedRows)
{
setAnimated(false);
- Q_FOREACH (const int &i, expandedRows)
+ for (int i: expandedRows)
setExpanded(model()->index(i, 0), true);
setAnimated(true);
}
@@ -437,13 +438,14 @@ void DiveListView::sortIndicatorChanged(int i, Qt::SortOrder order)
sortByColumn(i, order);
} else {
// clear the model, repopulate with new indexes.
- if (currentLayout == DiveTripModelBase::TREE)
- backupExpandedRows();
+ std::vector<int> expandedRows;
+ if(currentLayout == DiveTripModelBase::TREE)
+ expandedRows = backupExpandedRows();
currentLayout = newLayout;
resetModel();
sortByColumn(i, order);
if (newLayout == DiveTripModelBase::TREE)
- restoreExpandedRows();
+ restoreExpandedRows(expandedRows);
}
}