summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@nokia.com>2009-08-05 11:13:33 (GMT)
committerAlexis Menard <alexis.menard@nokia.com>2009-08-05 11:25:41 (GMT)
commitca2a9d87d81095f6ff7b821e3d8cbe120a6d9b23 (patch)
treefc5cfedda603c39cd954dfb8c5a06db619f6b53d
parentb4f1f4de1a0df7028440faaff146ac1560dc6169 (diff)
downloadQt-ca2a9d87d81095f6ff7b821e3d8cbe120a6d9b23.zip
Qt-ca2a9d87d81095f6ff7b821e3d8cbe120a6d9b23.tar.gz
Qt-ca2a9d87d81095f6ff7b821e3d8cbe120a6d9b23.tar.bz2
Fix regressions introduced by 31edb4d5a63b9b3c28cce1c4ca6eb99f62a09759
The commit 31edb4d5a63b9b3c28cce1c4ca6eb99f62a09759 introduced regressions in filters which breaks the mac native dialog, the non native dialog with HideNameFilterDetails activated. Task-number:259105 Reviewed-by:olivier Reviewed-by:prasanth
-rw-r--r--src/gui/dialogs/qfiledialog.cpp14
-rw-r--r--src/gui/dialogs/qfiledialog_win.cpp2
-rw-r--r--tests/auto/qfiledialog/tst_qfiledialog.cpp43
3 files changed, 54 insertions, 5 deletions
diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp
index 1ec94b6..f000033 100644
--- a/src/gui/dialogs/qfiledialog.cpp
+++ b/src/gui/dialogs/qfiledialog.cpp
@@ -394,6 +394,9 @@ QList<QUrl> QFileDialog::sidebarUrls() const
static const qint32 QFileDialogMagic = 0xbe;
+const char *qt_file_dialog_filter_reg_exp =
+"^(.*)\\(([a-zA-Z0-9_.*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$";
+
/*!
\since 4.3
Saves the state of the dialog's layout, history and current directory.
@@ -984,8 +987,13 @@ void QFileDialog::setNameFilters(const QStringList &filters)
if (testOption(HideNameFilterDetails)) {
QStringList strippedFilters;
+ QRegExp r(QString::fromLatin1(qt_file_dialog_filter_reg_exp));
for (int i = 0; i < cleanedFilters.count(); ++i) {
- strippedFilters.append(cleanedFilters[i].mid(0, cleanedFilters[i].indexOf(QLatin1String(" ("))));
+ QString filterName;
+ int index = r.indexIn(cleanedFilters[i]);
+ if (index >= 0)
+ filterName = r.cap(1);
+ strippedFilters.append(filterName.simplified());
}
d->qFileDialogUi->fileTypeCombo->addItems(strippedFilters);
} else {
@@ -2837,10 +2845,6 @@ void QFileDialogPrivate::_q_goToDirectory(const QString &path)
}
}
-const char *qt_file_dialog_filter_reg_exp =
-"(\\W|[a-zA-Z0-9 -]*)\\(([a-zA-Z0-9_.*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$";
-
-
// Makes a list of filters from a normal filter string "Image Files (*.png *.jpg)"
QStringList qt_clean_filter_list(const QString &filter)
{
diff --git a/src/gui/dialogs/qfiledialog_win.cpp b/src/gui/dialogs/qfiledialog_win.cpp
index c542ff0..02469b2 100644
--- a/src/gui/dialogs/qfiledialog_win.cpp
+++ b/src/gui/dialogs/qfiledialog_win.cpp
@@ -443,6 +443,8 @@ static bool qt_win_set_IFileDialogOptions(IFileDialog *pfd,
QString subfilter = *it;
if (!subfilter.isEmpty()) {
offsets<<currentOffset;
+ //Here the COMMON_ITEM_DIALOG API always add the details for the filter (e.g. *.txt)
+ //so we don't need to handle the flag HideNameFilterDetails.
winfilters += subfilter; // The name of the filter.
winfilters += QChar();
currentOffset += subfilter.size()+1;
diff --git a/tests/auto/qfiledialog/tst_qfiledialog.cpp b/tests/auto/qfiledialog/tst_qfiledialog.cpp
index c31ecf2..0f307dc 100644
--- a/tests/auto/qfiledialog/tst_qfiledialog.cpp
+++ b/tests/auto/qfiledialog/tst_qfiledialog.cpp
@@ -161,6 +161,7 @@ private slots:
void task251341_sideBarRemoveEntries();
void task254490_selectFileMultipleTimes();
void task257579_sideBarWithNonCleanUrls();
+ void task259105_filtersCornerCases();
private:
QByteArray userSettings;
@@ -2057,6 +2058,48 @@ void tst_QFiledialog::task257579_sideBarWithNonCleanUrls()
#endif
}
+void tst_QFiledialog::task259105_filtersCornerCases()
+{
+ QNonNativeFileDialog fd(0, "TestFileDialog");
+ fd.setNameFilter(QLatin1String("All Files! (*);;Text Files (*.txt)"));
+ fd.setOption(QFileDialog::HideNameFilterDetails, true);
+ fd.show();
+ QTest::qWait(250);
+
+ //Extensions are hidden
+ QComboBox *filters = qFindChild<QComboBox*>(&fd, "fileTypeCombo");
+ QVERIFY(filters);
+ QCOMPARE(filters->currentText(), QLatin1String("All Files!"));
+ filters->setCurrentIndex(1);
+ QCOMPARE(filters->currentText(), QLatin1String("Text Files"));
+
+ //We should have the full names
+ fd.setOption(QFileDialog::HideNameFilterDetails, false);
+ QTest::qWait(250);
+ filters->setCurrentIndex(0);
+ QCOMPARE(filters->currentText(), QLatin1String("All Files! (*)"));
+ filters->setCurrentIndex(1);
+ QCOMPARE(filters->currentText(), QLatin1String("Text Files (*.txt)"));
+
+ //Corner case undocumented of the task
+ fd.setNameFilter(QLatin1String("\352 (I like cheese) All Files! (*);;Text Files (*.txt)"));
+ QCOMPARE(filters->currentText(), QLatin1String("\352 (I like cheese) All Files! (*)"));
+ filters->setCurrentIndex(1);
+ QCOMPARE(filters->currentText(), QLatin1String("Text Files (*.txt)"));
+
+ fd.setOption(QFileDialog::HideNameFilterDetails, true);
+ filters->setCurrentIndex(0);
+ QTest::qWait(500);
+ QCOMPARE(filters->currentText(), QLatin1String("\352 (I like cheese) All Files!"));
+ filters->setCurrentIndex(1);
+ QCOMPARE(filters->currentText(), QLatin1String("Text Files"));
+ fd.setOption(QFileDialog::HideNameFilterDetails, true);
+ filters->setCurrentIndex(0);
+ QTest::qWait(500);
+ QCOMPARE(filters->currentText(), QLatin1String("\352 (I like cheese) All Files!"));
+ filters->setCurrentIndex(1);
+ QCOMPARE(filters->currentText(), QLatin1String("Text Files"));
+}
QTEST_MAIN(tst_QFiledialog)
#include "tst_qfiledialog.moc"