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: Frederik Gladhorn <frederik.gladhorn@digia.com>
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
}
}
}
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
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")))
}
})
}
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"
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)
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" }
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 }
}
Method {
name: "setFolder"
- Parameter { name: "f"; type: "string" }
+ Parameter { name: "f"; type: "QUrl" }
}
Method {
name: "setNameFilters"
Method {
name: "addSelection"
type: "bool"
- Parameter { name: "path"; type: "string" }
+ Parameter { name: "path"; type: "QUrl" }
}
}
}
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);
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);
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);
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);
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();
}
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);
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)
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();
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();
QList<QUrl> QQuickFileDialog::fileUrls()
{
- QList<QUrl> ret;
- foreach (QString path, m_selections)
- ret << QUrl::fromLocalFile(path);
- return ret;
+ return m_selections;
}
/*!
/*!
\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;
public Q_SLOTS:
void clearSelection();
- bool addSelection(QString path);
+ bool addSelection(const QUrl &path);
protected:
virtual QPlatformFileDialogHelper *helper() { return 0; }
Q_INVOKABLE QUrl pathFolder(const QString &path);
private:
- QStringList m_selections;
+ QList<QUrl> m_selections;
Q_DISABLE_COPY(QQuickFileDialog)
};
*/
/*!
- \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
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" }
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 }
}
Method {
name: "setFolder"
- Parameter { name: "f"; type: "string" }
+ Parameter { name: "f"; type: "QUrl" }
}
Method {
name: "setNameFilters"