Save the status of the tree before trying to reset the display.

This is a try: when the user changes the orientation on the columns
by clicking on the title of them and organizing by something that's
not the number, we lost track of the opened branches. this commit
doesn't fix that, but it fixes a possible similar issue.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
Tomaz Canabrava 2013-11-08 20:46:25 -02:00 committed by Dirk Hohndel
parent 7dbf76384f
commit 38287a1c1e
2 changed files with 22 additions and 4 deletions

View file

@ -65,6 +65,16 @@ 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);
}
}
}
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 */
@ -77,12 +87,18 @@ void DiveListView::setupUi(){
setColumnWidth(i, width.toInt());
else
setColumnWidth(i, 100);
}
settings.endGroup();
collapseAll();
expand(model()->index(0,0));
scrollTo(model()->index(0,0), QAbstractItemView::PositionAtCenter);
if(firstRun){
Q_FOREACH(const int &i, expandedColumns){
setExpanded( model()->index(i, 0), true );
}
}else{
collapseAll();
}
firstRun = false;
}
void DiveListView::fixMessyQtModelBehaviour()

View file

@ -60,6 +60,8 @@ MainWindow::MainWindow() : helpView(0)
ui.ListWidget->reloadHeaderActions();
ui.ListWidget->setFocus();
ui.globe->reload();
ui.ListWidget->expand(ui.ListWidget->model()->index(0,0));
ui.ListWidget->scrollTo(ui.ListWidget->model()->index(0,0), QAbstractItemView::PositionAtCenter);
}
// this gets called after we download dives from a divecomputer