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 <kevin.ottens@kdab.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
This commit is contained in:
parent
85498fdede
commit
f34b7f42e5
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user