aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@digia.com>2015-04-21 17:57:40 +0200
committerShawn Rutledge <shawn.rutledge@digia.com>2015-04-23 07:17:23 +0000
commit2dbf8e01035f3979b32d82590a362a56d2429ea1 (patch)
treebaef54893b19436f5508b56fd81efedc9d81814d /src/imports
parent50fcdfd705c2ad9560641986bf4152b017ee8bb6 (diff)
FolderListModel: add indexOf(file) function
Needed in QtQuick.Dialogs FileDialog implementation to help with pre-selecting files. Task-number: QTBUG-42814 Change-Id: Iaa7be083c238e214a12819b722cbd12f94b27965 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/folderlistmodel/qquickfolderlistmodel.cpp14
-rw-r--r--src/imports/folderlistmodel/qquickfolderlistmodel.h1
2 files changed, 15 insertions, 0 deletions
diff --git a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp
index 80b32e64ef..0f4a5bda54 100644
--- a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp
+++ b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp
@@ -788,6 +788,20 @@ QVariant QQuickFolderListModel::get(int idx, const QString &property) const
return QVariant();
}
+/*!
+ \qmlmethod int FolderListModel::indexOf(url file)
+ \since 5.6
+
+ Get the index of the given file URL if the model contains it,
+ or -1 if not.
+*/
+int QQuickFolderListModel::indexOf(const QUrl &file) const
+{
+ Q_D(const QQuickFolderListModel);
+ FileProperty toFind(QFileInfo(file.toLocalFile()));
+ return d->data.indexOf(toFind);
+}
+
#include "moc_qquickfolderlistmodel.cpp"
//![code]
diff --git a/src/imports/folderlistmodel/qquickfolderlistmodel.h b/src/imports/folderlistmodel/qquickfolderlistmodel.h
index 63ed528556..0001b2fdf3 100644
--- a/src/imports/folderlistmodel/qquickfolderlistmodel.h
+++ b/src/imports/folderlistmodel/qquickfolderlistmodel.h
@@ -132,6 +132,7 @@ public:
Q_INVOKABLE bool isFolder(int index) const;
Q_INVOKABLE QVariant get(int idx, const QString &property) const;
+ Q_INVOKABLE int indexOf(const QUrl &file) const;
//![parserstatus]
virtual void classBegin();