diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-08-21 12:15:06 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-09-14 10:09:03 +0000 |
commit | 4730221dbce520e6884cd07346ba89c80ec2c466 (patch) | |
tree | 0fab1d1ab5afd70c95496538b7aba1152b71058a /src/imports/platform/qquickplatformfiledialog_p.h | |
parent | 658b0f610a71fab8c103b913d2cfd11c3c7c6bef (diff) |
Fix FileDialog::selectedNameFilter review findings
FileDialog::nameFilters contains an array of name filter strings that
combine the name and extensions. For example:
- "Text files (*.txt)"
- "HTML files (*.html *.htm)"
When dealing with multiple name filters, it is quite clumsy to use
a string type of 'selectedNameFilter' which is one of the above full
file name filter string values. Make it possible to read/write the
index of the selected name filter, and provide the filter's name and
extensions separately.
Change-Id: Ie416cc4ab3dcde93c10769b6f7ac44915307f194
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/imports/platform/qquickplatformfiledialog_p.h')
-rw-r--r-- | src/imports/platform/qquickplatformfiledialog_p.h | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/src/imports/platform/qquickplatformfiledialog_p.h b/src/imports/platform/qquickplatformfiledialog_p.h index a4c61c54..51f88d46 100644 --- a/src/imports/platform/qquickplatformfiledialog_p.h +++ b/src/imports/platform/qquickplatformfiledialog_p.h @@ -54,6 +54,8 @@ QT_BEGIN_NAMESPACE +class QQuickPlatformFileNameFilter; + class QQuickPlatformFileDialog : public QQuickPlatformDialog { Q_OBJECT @@ -65,7 +67,7 @@ class QQuickPlatformFileDialog : public QQuickPlatformDialog Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged FINAL) Q_PROPERTY(QFileDialogOptions::FileDialogOptions options READ options WRITE setOptions RESET resetOptions NOTIFY optionsChanged FINAL) Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters RESET resetNameFilters NOTIFY nameFiltersChanged FINAL) - Q_PROPERTY(QString selectedNameFilter READ selectedNameFilter WRITE setSelectedNameFilter NOTIFY selectedNameFilterChanged FINAL) + Q_PROPERTY(QQuickPlatformFileNameFilter *selectedNameFilter READ selectedNameFilter CONSTANT) Q_PROPERTY(QString defaultSuffix READ defaultSuffix WRITE setDefaultSuffix RESET resetDefaultSuffix NOTIFY defaultSuffixChanged FINAL) Q_PROPERTY(QString acceptLabel READ acceptLabel WRITE setAcceptLabel RESET resetAcceptLabel NOTIFY acceptLabelChanged FINAL) Q_PROPERTY(QString rejectLabel READ rejectLabel WRITE setRejectLabel RESET resetRejectLabel NOTIFY rejectLabelChanged FINAL) @@ -107,8 +109,7 @@ public: void setNameFilters(const QStringList &filters); void resetNameFilters(); - QString selectedNameFilter() const; - void setSelectedNameFilter(const QString &filter); + QQuickPlatformFileNameFilter *selectedNameFilter() const; QString defaultSuffix() const; void setDefaultSuffix(const QString &suffix); @@ -131,7 +132,6 @@ Q_SIGNALS: void folderChanged(); void optionsChanged(); void nameFiltersChanged(); - void selectedNameFilterChanged(); void defaultSuffixChanged(); void acceptLabelChanged(); void rejectLabelChanged(); @@ -140,6 +140,7 @@ protected: bool useNativeDialog() const override; void onCreate(QPlatformDialogHelper *dialog) override; void onShow(QPlatformDialogHelper *dialog) override; + void onHide(QPlatformDialogHelper *dialog) override; void accept() override; private: @@ -149,6 +150,43 @@ private: FileMode m_fileMode; QList<QUrl> m_files; QSharedPointer<QFileDialogOptions> m_options; + mutable QQuickPlatformFileNameFilter *m_selectedNameFilter; +}; + +class QQuickPlatformFileNameFilter : public QObject +{ + Q_OBJECT + Q_PROPERTY(int index READ index WRITE setIndex NOTIFY indexChanged FINAL) + Q_PROPERTY(QString name READ name NOTIFY nameChanged FINAL) + Q_PROPERTY(QStringList extensions READ extensions NOTIFY extensionsChanged FINAL) + +public: + explicit QQuickPlatformFileNameFilter(QObject *parent = nullptr); + + int index() const; + void setIndex(int index); + + QString name() const; + QStringList extensions() const; + + QSharedPointer<QFileDialogOptions> options() const; + void setOptions(const QSharedPointer<QFileDialogOptions> &options); + + void update(const QString &filter); + +Q_SIGNALS: + void indexChanged(int index); + void nameChanged(const QString &name); + void extensionsChanged(const QStringList &extensions); + +private: + QStringList nameFilters() const; + QString nameFilter(int index) const; + + int m_index; + QString m_name; + QStringList m_extensions; + QSharedPointer<QFileDialogOptions> m_options; }; QT_END_NAMESPACE |