From f34b7f42e5c9d2a50da51dbba5fa18467d0262c0 Mon Sep 17 00:00:00 2001 From: Dominik Haumann Date: Tue, 4 Feb 2014 19:00:09 +0100 Subject: QPA fix: allow setting the initially selected name filter (KDE) In KDE, without this patch, the Q_ASSERT in the following code fragment fails: QFileDialog dialog; QStringList list = QStringList() << "c (*.cpp)" << "h (*.h)"; dialog.setNameFilters(list); QString filter("h (*.h)"); dialog.selectNameFilter(filter); dialog.show(); Q_ASSERT(dialog.selectedNameFilter() == filter); The reason for the fail is that the selectNameFilter() does not properly propagate the filter to the QPA plugin. So the first part of this patch adds d->options->setInitiallySelectedNameFilter(filter); in the function QFileDialog::selectNameFilter(). The second part of this patch makes sure that the initially set name filter in the QFileDialogOptions "options" is not overwritten in the helperPrepareShow() function. This is achieved by adding an if(), following the if() for the initiallySelectedfiles() the line below. With this patch, the Q_ASSERT() holds true in KDE Framework 5's file dialog integration. Change-Id: I15d8c88a0fa3cdc03e3330f3458bbad139a71212 Reviewed-by: Kevin Ottens Reviewed-by: Friedemann Kleint Reviewed-by: Shawn Rutledge --- src/widgets/dialogs/qfiledialog.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index cd95b824a6..998866c039 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -627,7 +627,8 @@ void QFileDialogPrivate::helperPrepareShow(QPlatformDialogHelper *) options->setInitialDirectory(directory.exists() ? QUrl::fromLocalFile(directory.absolutePath()) : QUrl()); - options->setInitiallySelectedNameFilter(q->selectedNameFilter()); + if (options->initiallySelectedNameFilter().isEmpty()) + options->setInitiallySelectedNameFilter(q->selectedNameFilter()); if (options->initiallySelectedFiles().isEmpty()) options->setInitiallySelectedFiles(userSelectedFiles()); } @@ -1450,6 +1451,7 @@ QStringList QFileDialog::nameFilters() const void QFileDialog::selectNameFilter(const QString &filter) { Q_D(QFileDialog); + d->options->setInitiallySelectedNameFilter(filter); if (!d->usingWidgets()) { d->selectNameFilter_sys(filter); return; -- cgit v1.2.3