summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2017-06-01 19:59:58 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2017-09-17 17:00:56 +0000
commitc7a43a5d3d34ff0d7f1f8d88750643ffa8195efb (patch)
tree493b79b889ea5b23d9b9bf4129156db2e1747ad8
parent67906d61c6f786dbbced67becc25e1a396f3183c (diff)
downloadqtquickcontrols-c7a43a5d3d34ff0d7f1f8d88750643ffa8195efb.tar.gz
Add support for the defaultSuffix property in FileDialog
[ChangeLog][FileDialog] Added defaultSuffix property Task-number: QTBUG-39230 Change-Id: I7dc73c332ad62129d7158b6f6f5a614b8582ffbc Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r--src/dialogs/dialogs.pro2
-rw-r--r--src/dialogs/plugin.cpp5
-rw-r--r--src/dialogs/qquickabstractfiledialog.cpp8
-rw-r--r--src/dialogs/qquickabstractfiledialog_p.h4
-rw-r--r--src/dialogs/qquickplatformfiledialog.cpp14
-rw-r--r--tests/auto/dialogs/tst_dialogs.cpp23
6 files changed, 53 insertions, 3 deletions
diff --git a/src/dialogs/dialogs.pro b/src/dialogs/dialogs.pro
index ca5f408e..362f5584 100644
--- a/src/dialogs/dialogs.pro
+++ b/src/dialogs/dialogs.pro
@@ -3,7 +3,7 @@ requires(contains(QT_CONFIG, accessibility))
CXX_MODULE = qml
TARGET = dialogplugin
TARGETPATH = QtQuick/Dialogs
-IMPORT_VERSION = 1.2
+IMPORT_VERSION = 1.3
QMAKE_DOCS = $$PWD/doc/qtquickdialogs.qdocconf
diff --git a/src/dialogs/plugin.cpp b/src/dialogs/plugin.cpp
index a2fb1099..2e861fa5 100644
--- a/src/dialogs/plugin.cpp
+++ b/src/dialogs/plugin.cpp
@@ -72,7 +72,7 @@ static void initResources()
QT_BEGIN_NAMESPACE
/*!
- \qmlmodule QtQuick.Dialogs 1.2
+ \qmlmodule QtQuick.Dialogs 1.3
\title Qt Quick Dialogs QML Types
\ingroup qmlmodules
\brief Provides QML types for standard file, color picker and message dialogs
@@ -82,7 +82,7 @@ QT_BEGIN_NAMESPACE
To use the types in this module, import the module with the following line:
\code
- import QtQuick.Dialogs 1.2
+ import QtQuick.Dialogs 1.3
\endcode
*/
@@ -185,6 +185,7 @@ public:
#endif
qCDebug(lcRegistration) << " registering" << dialogQmlPath << "as Dialog";
qmlRegisterType(dialogQmlPath, uri, 1, 2, "Dialog");
+ qmlRegisterType(dialogQmlPath, uri, 1, 3, "Dialog");
}
}
diff --git a/src/dialogs/qquickabstractfiledialog.cpp b/src/dialogs/qquickabstractfiledialog.cpp
index 49d98a1a..b80bf86b 100644
--- a/src/dialogs/qquickabstractfiledialog.cpp
+++ b/src/dialogs/qquickabstractfiledialog.cpp
@@ -318,4 +318,12 @@ QJSValue QQuickAbstractFileDialog::__shortcuts()
return m_shortcutDetails;
}
+void QQuickAbstractFileDialog::setDefaultSuffix(const QString &suffix)
+{
+ if (suffix == m_options->defaultSuffix())
+ return;
+ m_options->setDefaultSuffix(suffix);
+ emit defaultSuffixChanged();
+}
+
QT_END_NAMESPACE
diff --git a/src/dialogs/qquickabstractfiledialog_p.h b/src/dialogs/qquickabstractfiledialog_p.h
index b4b7165d..cb7ac27e 100644
--- a/src/dialogs/qquickabstractfiledialog_p.h
+++ b/src/dialogs/qquickabstractfiledialog_p.h
@@ -74,6 +74,7 @@ class QQuickAbstractFileDialog : public QQuickAbstractDialog
Q_PROPERTY(QUrl fileUrl READ fileUrl NOTIFY selectionAccepted)
Q_PROPERTY(QList<QUrl> fileUrls READ fileUrls NOTIFY selectionAccepted)
Q_PROPERTY(bool sidebarVisible READ sidebarVisible WRITE setSidebarVisible NOTIFY sidebarVisibleChanged)
+ Q_PROPERTY(QString defaultSuffix READ defaultSuffix WRITE setDefaultSuffix NOTIFY defaultSuffixChanged)
Q_PROPERTY(QJSValue shortcuts READ shortcuts NOTIFY shortcutsChanged) // map of QStandardDirectory names to QUrls
Q_PROPERTY(QJSValue __shortcuts READ __shortcuts NOTIFY shortcutsChanged) // map of details for QML dialog implementations
@@ -95,6 +96,7 @@ public:
bool sidebarVisible() const { return m_sidebarVisible; }
QJSValue shortcuts();
QJSValue __shortcuts();
+ QString defaultSuffix() const { return m_options->defaultSuffix(); }
public Q_SLOTS:
void setVisible(bool v);
@@ -107,6 +109,7 @@ public Q_SLOTS:
void selectNameFilter(const QString &f);
void setSelectedNameFilterIndex(int idx);
void setSidebarVisible(bool s);
+ void setDefaultSuffix(const QString &suffix);
Q_SIGNALS:
void folderChanged();
@@ -116,6 +119,7 @@ Q_SIGNALS:
void selectionAccepted();
void sidebarVisibleChanged();
void shortcutsChanged();
+ void defaultSuffixChanged();
protected Q_SLOTS:
void updateFolder(const QUrl &f);
diff --git a/src/dialogs/qquickplatformfiledialog.cpp b/src/dialogs/qquickplatformfiledialog.cpp
index ab228d1f..b30f2b2b 100644
--- a/src/dialogs/qquickplatformfiledialog.cpp
+++ b/src/dialogs/qquickplatformfiledialog.cpp
@@ -422,4 +422,18 @@ void QQuickPlatformFileDialog::accept()
\l {Qt.labs.settings}{Settings}.
*/
+/*!
+ \qmlproperty string FileDialog::defaultSuffix
+ \since 5.10
+
+ This property holds the suffix added to the filename if no other suffix was
+ specified.
+
+ This property specifies a string that will be added to the filename if it
+ has no suffix already. The suffix is typically used to indicate the file
+ type (e.g. "txt" indicates a text file).
+
+ If the first character is a dot ('.'), it is removed.
+*/
+
QT_END_NAMESPACE
diff --git a/tests/auto/dialogs/tst_dialogs.cpp b/tests/auto/dialogs/tst_dialogs.cpp
index 20da6e43..1f802113 100644
--- a/tests/auto/dialogs/tst_dialogs.cpp
+++ b/tests/auto/dialogs/tst_dialogs.cpp
@@ -56,6 +56,7 @@ private slots:
void fileDialogDefaultModality();
void fileDialogNonModal();
void fileDialogNameFilters();
+ void fileDialogDefaultSuffix();
private:
};
@@ -207,6 +208,28 @@ void tst_dialogs::fileDialogNameFilters()
QCOMPARE(dlg->property("selectedNameFilter").toString(), filters.first());
}
+void tst_dialogs::fileDialogDefaultSuffix()
+{
+ QQuickView *window = new QQuickView;
+ QScopedPointer<QQuickWindow> cleanup(window);
+
+ const QUrl sourceUrl = testFileUrl("RectWithFileDialog.qml");
+ window->setSource(sourceUrl);
+ window->setGeometry(240, 240, 1024, 320);
+ window->show();
+ QTRY_VERIFY(QTest::qWaitForWindowExposed(window));
+ QVERIFY(window->rootObject());
+
+ QObject *dlg = qvariant_cast<QObject *>(window->rootObject()->property("fileDialog"));
+ QCOMPARE(dlg->property("defaultSuffix").toString(), QString());
+ dlg->setProperty("defaultSuffix", "txt");
+ QCOMPARE(dlg->property("defaultSuffix").toString(), QString("txt"));
+ dlg->setProperty("defaultSuffix", ".txt");
+ QCOMPARE(dlg->property("defaultSuffix").toString(), QString("txt"));
+ dlg->setProperty("defaultSuffix", QString());
+ QCOMPARE(dlg->property("defaultSuffix").toString(), QString());
+}
+
QTEST_MAIN(tst_dialogs)
#include "tst_dialogs.moc"