mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 21:53:23 +00:00
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>
This commit is contained in:
parent
38287a1c1e
commit
d3fe3494fe
2 changed files with 28 additions and 17 deletions
|
@ -66,15 +66,8 @@ DiveListView::~DiveListView()
|
||||||
void DiveListView::setupUi(){
|
void DiveListView::setupUi(){
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
static bool firstRun = true;
|
static bool firstRun = true;
|
||||||
QList<int> expandedColumns;
|
if(firstRun)
|
||||||
if(!firstRun){
|
backupExpandedRows();
|
||||||
for(int i = 0; i < model()->rowCount(); i++){
|
|
||||||
if(isExpanded( model()->index(i, 0) )){
|
|
||||||
expandedColumns.push_back(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 */
|
||||||
|
@ -89,18 +82,27 @@ void DiveListView::setupUi(){
|
||||||
setColumnWidth(i, 100);
|
setColumnWidth(i, 100);
|
||||||
}
|
}
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
if(firstRun)
|
||||||
if(firstRun){
|
restoreExpandedRows();
|
||||||
Q_FOREACH(const int &i, expandedColumns){
|
else
|
||||||
setExpanded( model()->index(i, 0), true );
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
collapseAll();
|
collapseAll();
|
||||||
}
|
|
||||||
|
|
||||||
firstRun = false;
|
firstRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DiveListView::backupExpandedRows(){
|
||||||
|
expandedRows.clear();
|
||||||
|
for(int i = 0; i < model()->rowCount(); i++){
|
||||||
|
if(isExpanded( model()->index(i, 0) )){
|
||||||
|
expandedRows.push_back(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiveListView::restoreExpandedRows(){
|
||||||
|
Q_FOREACH(const int &i, expandedRows){
|
||||||
|
setExpanded( model()->index(i, 0), true );
|
||||||
|
}
|
||||||
|
}
|
||||||
void DiveListView::fixMessyQtModelBehaviour()
|
void DiveListView::fixMessyQtModelBehaviour()
|
||||||
{
|
{
|
||||||
QAbstractItemModel *m = model();
|
QAbstractItemModel *m = model();
|
||||||
|
@ -184,9 +186,15 @@ void DiveListView::headerClicked(int i)
|
||||||
sortByColumn(i, currentOrder);
|
sortByColumn(i, currentOrder);
|
||||||
} else {
|
} else {
|
||||||
// clear the model, repopulate with new indexes.
|
// clear the model, repopulate with new indexes.
|
||||||
|
if(currentLayout == DiveTripModel::TREE){
|
||||||
|
backupExpandedRows();
|
||||||
|
}
|
||||||
reload(newLayout, false);
|
reload(newLayout, false);
|
||||||
currentOrder = Qt::DescendingOrder;
|
currentOrder = Qt::DescendingOrder;
|
||||||
sortByColumn(i, currentOrder);
|
sortByColumn(i, currentOrder);
|
||||||
|
if (newLayout == DiveTripModel::TREE){
|
||||||
|
restoreExpandedRows();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// repopulate the selections.
|
// repopulate the selections.
|
||||||
|
|
|
@ -49,6 +49,7 @@ signals:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool mouseClickSelection;
|
bool mouseClickSelection;
|
||||||
|
QList<int> expandedRows;
|
||||||
int sortColumn;
|
int sortColumn;
|
||||||
Qt::SortOrder currentOrder;
|
Qt::SortOrder currentOrder;
|
||||||
DiveTripModel::Layout currentLayout;
|
DiveTripModel::Layout currentLayout;
|
||||||
|
@ -56,6 +57,8 @@ private:
|
||||||
QModelIndex contextMenuIndex;
|
QModelIndex contextMenuIndex;
|
||||||
void merge_trip(const QModelIndex &a, const int offset);
|
void merge_trip(const QModelIndex &a, const int offset);
|
||||||
void setupUi();
|
void setupUi();
|
||||||
|
void backupExpandedRows();
|
||||||
|
void restoreExpandedRows();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DIVELISTVIEW_H
|
#endif // DIVELISTVIEW_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue