Commit 811337a7 by Shawn Rutledge Committed by The Qt Project

FileDialog.folder property should also be a QUrl, for consistency

In QtQuick we never use plain file paths, because URL is more general.
Also use const references for string and URL setters, and fixed the
dependency between the FolderListModel's folder, the field for editing it,
and the folder property of the AbstractFileDialog.

Change-Id: I6e965b80b73d4eb2473712a4f4d4f816b768d802
Reviewed-by: 's avatarFrederik Gladhorn <frederik.gladhorn@digia.com>
parent 87a4a3d0
......@@ -162,7 +162,7 @@ Rectangle {
text: "go to /tmp"
anchors.verticalCenter: parent.verticalCenter
// TODO: QTBUG-29814 This isn't portable, but we don't expose QDir::tempPath to QML yet.
onClicked: fileDialog.folder = "/tmp"
onClicked: fileDialog.folder = "/tmp" // file:///tmp would also be OK
}
}
}
......
......@@ -53,13 +53,13 @@ AbstractFileDialog {
currentPathField.visible = false
}
}
onFolderChanged: view.model.folder = folder
property bool showFocusHighlight: false
property real textX: titleBar.height
property SystemPalette palette
property var selectedIndices: []
property int lastClickedIdx: -1
folder: urlToPath(view.model.folder)
function dirDown(path) {
view.model.folder = path
......@@ -107,10 +107,11 @@ AbstractFileDialog {
selectedIndices.map(function(idx) {
if (view.model.isFolder(idx)) {
if (selectFolder)
addSelection(view.model.get(idx, "filePath"))
// TODO after QTBUG-32039: should not need to convert pathToUrl here
addSelection(pathToUrl(view.model.get(idx, "filePath")))
} else {
if (!selectFolder)
addSelection(view.model.get(idx, "filePath"))
addSelection(pathToUrl(view.model.get(idx, "filePath")))
}
})
}
......@@ -211,7 +212,12 @@ AbstractFileDialog {
clip: true
x: 0
width: parent.width
model: FolderListModel { }
model: FolderListModel {
onFolderChanged: {
root.folder = folder
currentPathField.text = root.urlToPath(view.model.folder)
}
}
delegate: folderDelegate
highlight: Rectangle {
color: "transparent"
......@@ -305,10 +311,9 @@ AbstractFileDialog {
anchors.leftMargin: textX; anchors.rightMargin: 4
visible: false
focus: visible
text: root.urlToPath(view.model.folder)
onAccepted: {
root.clearSelection()
if (root.addSelection(text))
if (root.addSelection(root.pathToUrl(text)))
root.accept()
else
view.model.folder = root.pathFolder(text)
......
......@@ -39,6 +39,7 @@ Module {
Property { name: "visible"; type: "bool" }
Property { name: "modality"; type: "Qt::WindowModality" }
Property { name: "title"; type: "string" }
Property { name: "isWindow"; type: "bool"; isReadonly: true }
Property { name: "x"; type: "int" }
Property { name: "y"; type: "int" }
Property { name: "width"; type: "int" }
......@@ -56,7 +57,7 @@ Module {
Property { name: "selectExisting"; type: "bool" }
Property { name: "selectMultiple"; type: "bool" }
Property { name: "selectFolder"; type: "bool" }
Property { name: "folder"; type: "string" }
Property { name: "folder"; type: "QUrl" }
Property { name: "nameFilters"; type: "QStringList" }
Property { name: "selectedNameFilter"; type: "string" }
Property { name: "fileUrl"; type: "QUrl"; isReadonly: true }
......@@ -86,7 +87,7 @@ Module {
}
Method {
name: "setFolder"
Parameter { name: "f"; type: "string" }
Parameter { name: "f"; type: "QUrl" }
}
Method {
name: "setNameFilters"
......@@ -116,7 +117,7 @@ Module {
Method {
name: "addSelection"
type: "bool"
Parameter { name: "path"; type: "string" }
Parameter { name: "path"; type: "QUrl" }
}
}
}
......@@ -91,7 +91,7 @@ bool QQuickAbstractColorDialog::showAlphaChannel() const
return m_options->testOption(QColorDialogOptions::ShowAlphaChannel);
}
void QQuickAbstractColorDialog::setTitle(QString t)
void QQuickAbstractColorDialog::setTitle(const QString &t)
{
if (m_options->windowTitle() == t) return;
m_options->setWindowTitle(t);
......
......@@ -78,7 +78,7 @@ public:
public Q_SLOTS:
void setVisible(bool v);
void setModality(Qt::WindowModality m);
void setTitle(QString t);
void setTitle(const QString &t);
void setColor(QColor arg);
void setShowAlphaChannel(bool arg);
......
......@@ -88,7 +88,7 @@ public:
virtual void setVisible(bool v);
virtual void setModality(Qt::WindowModality m);
virtual void setTitle(QString t) = 0;
virtual void setTitle(const QString &t) = 0;
void setQmlImplementation(QObject* obj);
bool isWindow() const { return m_hasNativeWindows; }
void setX(int arg);
......
......@@ -78,7 +78,7 @@ QString QQuickAbstractFileDialog::title() const
return m_options->windowTitle();
}
void QQuickAbstractFileDialog::setTitle(QString t)
void QQuickAbstractFileDialog::setTitle(const QString &t)
{
if (m_options->windowTitle() == t) return;
m_options->setWindowTitle(t);
......@@ -106,18 +106,19 @@ void QQuickAbstractFileDialog::setSelectFolder(bool selectFolder)
updateModes();
}
QString QQuickAbstractFileDialog::folder()
QUrl QQuickAbstractFileDialog::folder()
{
if (m_dlgHelper && !m_dlgHelper->directory().isEmpty())
return m_dlgHelper->directory();
return m_options->initialDirectory();
return QUrl::fromLocalFile(m_dlgHelper->directory());
return QUrl::fromLocalFile(m_options->initialDirectory());
}
void QQuickAbstractFileDialog::setFolder(QString f)
void QQuickAbstractFileDialog::setFolder(const QUrl &f)
{
QString dir = f.path();
if (m_dlgHelper)
m_dlgHelper->setDirectory(f);
m_options->setInitialDirectory(f);
m_dlgHelper->setDirectory(dir);
m_options->setInitialDirectory(dir);
emit folderChanged();
}
......@@ -141,7 +142,7 @@ QString QQuickAbstractFileDialog::selectedNameFilter()
return ret;
}
void QQuickAbstractFileDialog::selectNameFilter(QString f)
void QQuickAbstractFileDialog::selectNameFilter(const QString &f)
{
// This should work whether the dialog is currently being shown already, or ahead of time.
m_options->setInitiallySelectedNameFilter(f);
......
......@@ -67,7 +67,7 @@ class QQuickAbstractFileDialog : public QQuickAbstractDialog
Q_PROPERTY(bool selectExisting READ selectExisting WRITE setSelectExisting NOTIFY fileModeChanged)
Q_PROPERTY(bool selectMultiple READ selectMultiple WRITE setSelectMultiple NOTIFY fileModeChanged)
Q_PROPERTY(bool selectFolder READ selectFolder WRITE setSelectFolder NOTIFY fileModeChanged)
Q_PROPERTY(QString folder READ folder WRITE setFolder NOTIFY folderChanged)
Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged)
Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters NOTIFY nameFiltersChanged)
Q_PROPERTY(QString selectedNameFilter READ selectedNameFilter WRITE selectNameFilter NOTIFY filterSelected)
Q_PROPERTY(QUrl fileUrl READ fileUrl NOTIFY selectionAccepted)
......@@ -81,7 +81,7 @@ public:
bool selectExisting() const { return m_selectExisting; }
bool selectMultiple() const { return m_selectMultiple; }
bool selectFolder() const { return m_selectFolder; }
QString folder();
QUrl folder();
QStringList nameFilters() const { return m_options->nameFilters(); }
QString selectedNameFilter();
QUrl fileUrl();
......@@ -89,13 +89,13 @@ public:
public Q_SLOTS:
void setVisible(bool v);
void setTitle(QString t);
void setTitle(const QString &t);
void setSelectExisting(bool s);
void setSelectMultiple(bool s);
void setSelectFolder(bool s);
void setFolder(QString f);
void setFolder(const QUrl &f);
void setNameFilters(const QStringList &f);
void selectNameFilter(QString f);
void selectNameFilter(const QString &f);
Q_SIGNALS:
void folderChanged();
......
......@@ -105,10 +105,7 @@ QQuickFileDialog::~QQuickFileDialog()
QList<QUrl> QQuickFileDialog::fileUrls()
{
QList<QUrl> ret;
foreach (QString path, m_selections)
ret << QUrl::fromLocalFile(path);
return ret;
return m_selections;
}
/*!
......@@ -134,18 +131,16 @@ void QQuickFileDialog::clearSelection()
/*!
\brief Adds one file to \l fileUrls
\l path should be given as an absolute file system path. If it is given as a
file:// URL, it will be converted to a path. Returns true on success,
false if the given path is not valid given the current setting properties.
\l path should be given as an absolute file:// path URL.
Returns true on success, false if the given path is
not valid given the current property settings.
*/
bool QQuickFileDialog::addSelection(QString path)
bool QQuickFileDialog::addSelection(const QUrl &path)
{
if (path.startsWith("file:"))
path = QUrl(path).toLocalFile();
QFileInfo info(path);
QFileInfo info(path.toLocalFile());
if (info.exists() && ((info.isDir() && m_selectFolder) || !info.isDir())) {
if (m_selectFolder)
m_selections.append(pathFolder(path).toLocalFile());
m_selections.append(pathFolder(path.toLocalFile()));
else
m_selections.append(path);
return true;
......
......@@ -72,7 +72,7 @@ signals:
public Q_SLOTS:
void clearSelection();
bool addSelection(QString path);
bool addSelection(const QUrl &path);
protected:
virtual QPlatformFileDialogHelper *helper() { return 0; }
......@@ -81,7 +81,7 @@ protected:
Q_INVOKABLE QUrl pathFolder(const QString &path);
private:
QStringList m_selections;
QList<QUrl> m_selections;
Q_DISABLE_COPY(QQuickFileDialog)
};
......
......@@ -252,7 +252,7 @@ QPlatformFileDialogHelper *QQuickPlatformFileDialog::helper()
*/
/*!
\qmlproperty string FileDialog::folder
\qmlproperty url FileDialog::folder
The path to the currently selected folder. Setting this property before
invoking open() will cause the file browser to be initially positioned on
......
......@@ -39,6 +39,7 @@ Module {
Property { name: "visible"; type: "bool" }
Property { name: "modality"; type: "Qt::WindowModality" }
Property { name: "title"; type: "string" }
Property { name: "isWindow"; type: "bool"; isReadonly: true }
Property { name: "x"; type: "int" }
Property { name: "y"; type: "int" }
Property { name: "width"; type: "int" }
......@@ -56,7 +57,7 @@ Module {
Property { name: "selectExisting"; type: "bool" }
Property { name: "selectMultiple"; type: "bool" }
Property { name: "selectFolder"; type: "bool" }
Property { name: "folder"; type: "string" }
Property { name: "folder"; type: "QUrl" }
Property { name: "nameFilters"; type: "QStringList" }
Property { name: "selectedNameFilter"; type: "string" }
Property { name: "fileUrl"; type: "QUrl"; isReadonly: true }
......@@ -86,7 +87,7 @@ Module {
}
Method {
name: "setFolder"
Parameter { name: "f"; type: "string" }
Parameter { name: "f"; type: "QUrl" }
}
Method {
name: "setNameFilters"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment