mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
be26b0bd9a
commit
28e97e7555
2 changed files with 13 additions and 12 deletions
|
@ -135,7 +135,7 @@ void DiveListView::calculateInitialColumnWidth(int col)
|
||||||
void DiveListView::setColumnWidths()
|
void DiveListView::setColumnWidths()
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
backupExpandedRows();
|
std::vector<int> expandedRows = backupExpandedRows();
|
||||||
settings.beginGroup("ListWidget");
|
settings.beginGroup("ListWidget");
|
||||||
/* if no width are set, use the calculated width for each column;
|
/* if no width are set, use the calculated width for each column;
|
||||||
* for that to work we need to temporarily expand all rows */
|
* for that to work we need to temporarily expand all rows */
|
||||||
|
@ -150,7 +150,7 @@ void DiveListView::setColumnWidths()
|
||||||
setColumnWidth(i, initialColumnWidths[i]);
|
setColumnWidth(i, initialColumnWidths[i]);
|
||||||
}
|
}
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
restoreExpandedRows();
|
restoreExpandedRows(expandedRows);
|
||||||
setColumnWidth(lastVisibleColumn(), 10);
|
setColumnWidth(lastVisibleColumn(), 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,18 +165,19 @@ int DiveListView::lastVisibleColumn()
|
||||||
return lastColumn;
|
return lastColumn;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveListView::backupExpandedRows()
|
std::vector<int> DiveListView::backupExpandedRows()
|
||||||
{
|
{
|
||||||
expandedRows.clear();
|
std::vector<int> expandedRows;
|
||||||
for (int i = 0; i < model()->rowCount(); i++)
|
for (int i = 0; i < model()->rowCount(); i++)
|
||||||
if (isExpanded(model()->index(i, 0)))
|
if (isExpanded(model()->index(i, 0)))
|
||||||
expandedRows.push_back(i);
|
expandedRows.push_back(i);
|
||||||
|
return expandedRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveListView::restoreExpandedRows()
|
void DiveListView::restoreExpandedRows(const std::vector<int> &expandedRows)
|
||||||
{
|
{
|
||||||
setAnimated(false);
|
setAnimated(false);
|
||||||
Q_FOREACH (const int &i, expandedRows)
|
for (int i: expandedRows)
|
||||||
setExpanded(model()->index(i, 0), true);
|
setExpanded(model()->index(i, 0), true);
|
||||||
setAnimated(true);
|
setAnimated(true);
|
||||||
}
|
}
|
||||||
|
@ -437,13 +438,14 @@ void DiveListView::sortIndicatorChanged(int i, Qt::SortOrder order)
|
||||||
sortByColumn(i, order);
|
sortByColumn(i, order);
|
||||||
} else {
|
} else {
|
||||||
// clear the model, repopulate with new indexes.
|
// clear the model, repopulate with new indexes.
|
||||||
if (currentLayout == DiveTripModelBase::TREE)
|
std::vector<int> expandedRows;
|
||||||
backupExpandedRows();
|
if(currentLayout == DiveTripModelBase::TREE)
|
||||||
|
expandedRows = backupExpandedRows();
|
||||||
currentLayout = newLayout;
|
currentLayout = newLayout;
|
||||||
resetModel();
|
resetModel();
|
||||||
sortByColumn(i, order);
|
sortByColumn(i, order);
|
||||||
if (newLayout == DiveTripModelBase::TREE)
|
if (newLayout == DiveTripModelBase::TREE)
|
||||||
restoreExpandedRows();
|
restoreExpandedRows(expandedRows);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,6 @@ private:
|
||||||
void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags flags) override;
|
void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags flags) override;
|
||||||
void selectAll() override;
|
void selectAll() override;
|
||||||
void selectionChangeDone();
|
void selectionChangeDone();
|
||||||
QList<int> expandedRows;
|
|
||||||
DiveTripModelBase::Layout currentLayout;
|
DiveTripModelBase::Layout currentLayout;
|
||||||
QModelIndex contextMenuIndex;
|
QModelIndex contextMenuIndex;
|
||||||
bool dontEmitDiveChangedSignal;
|
bool dontEmitDiveChangedSignal;
|
||||||
|
@ -80,8 +79,8 @@ private:
|
||||||
void merge_trip(const QModelIndex &a, const int offset);
|
void merge_trip(const QModelIndex &a, const int offset);
|
||||||
void setColumnWidths();
|
void setColumnWidths();
|
||||||
void calculateInitialColumnWidth(int col);
|
void calculateInitialColumnWidth(int col);
|
||||||
void backupExpandedRows();
|
std::vector<int> backupExpandedRows();
|
||||||
void restoreExpandedRows();
|
void restoreExpandedRows(const std::vector<int> &);
|
||||||
int lastVisibleColumn();
|
int lastVisibleColumn();
|
||||||
void selectTrip(dive_trip *trip);
|
void selectTrip(dive_trip *trip);
|
||||||
void updateLastImageTimeOffset(int offset);
|
void updateLastImageTimeOffset(int offset);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue