QFileDialog: save and restore all settings even if widgets not used

Some applications may use native file dialogs and some may use the
widget implementation, but QFileDialog always saves all settings to
the same place each time it destroyed.  So it is important to remember
all settings read in restoreState and put them back in saveState.
This bug was introduced by 37ca2224ec

Task-number: QTBUG-36888
Change-Id: Ied1db83817480312e963a042784d7bdd16f0a2b1
Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
This commit is contained in:
Shawn Rutledge 2014-09-01 10:32:25 +02:00
parent 032ab648c4
commit 2113bdee5d
2 changed files with 14 additions and 12 deletions

View File

@ -454,15 +454,15 @@ QByteArray QFileDialog::saveState() const
stream << d->qFileDialogUi->splitter->saveState();
stream << d->qFileDialogUi->sidebar->urls();
} else {
stream << QByteArray();
stream << QList<QUrl>();
stream << d->splitterState;
stream << d->sidebarUrls;
}
stream << history();
stream << *lastVisitedDir();
if (d->usingWidgets())
stream << d->qFileDialogUi->treeView->header()->saveState();
else
stream << QByteArray();
stream << d->headerData;
stream << qint32(viewMode());
return data;
}
@ -484,9 +484,6 @@ bool QFileDialog::restoreState(const QByteArray &state)
QDataStream stream(&sd, QIODevice::ReadOnly);
if (stream.atEnd())
return false;
QByteArray splitterState;
QByteArray headerData;
QList<QUrl> bookmarks;
QStringList history;
QString currentDirectory;
qint32 marker;
@ -497,11 +494,11 @@ bool QFileDialog::restoreState(const QByteArray &state)
if (marker != QFileDialogMagic || v != version)
return false;
stream >> splitterState
>> bookmarks
stream >> d->splitterState
>> d->sidebarUrls
>> history
>> currentDirectory
>> headerData
>> d->headerData
>> viewMode;
setDirectory(lastVisitedDir()->isEmpty() ? currentDirectory : *lastVisitedDir());
@ -510,7 +507,7 @@ bool QFileDialog::restoreState(const QByteArray &state)
if (!d->usingWidgets())
return true;
if (!d->qFileDialogUi->splitter->restoreState(splitterState))
if (!d->qFileDialogUi->splitter->restoreState(d->splitterState))
return false;
QList<int> list = d->qFileDialogUi->splitter->sizes();
if (list.count() >= 2 && list.at(0) == 0 && list.at(1) == 0) {
@ -519,12 +516,12 @@ bool QFileDialog::restoreState(const QByteArray &state)
d->qFileDialogUi->splitter->setSizes(list);
}
d->qFileDialogUi->sidebar->setUrls(bookmarks);
d->qFileDialogUi->sidebar->setUrls(d->sidebarUrls);
while (history.count() > 5)
history.pop_front();
setHistory(history);
QHeaderView *headerView = d->qFileDialogUi->treeView->header();
if (!headerView->restoreState(headerData))
if (!headerView->restoreState(d->headerData))
return false;
QList<QAction*> actions = headerView->actions();

View File

@ -273,6 +273,11 @@ public:
QSharedPointer<QFileDialogOptions> options;
// Memory of what was read from QSettings in restoreState() in case widgets are not used
QByteArray splitterState;
QByteArray headerData;
QList<QUrl> sidebarUrls;
~QFileDialogPrivate();
private: