diff options
author | Shawn Rutledge <shawn.rutledge@theqtcompany.com> | 2016-01-26 13:40:40 +0100 |
---|---|---|
committer | Jani Heikkinen <jani.heikkinen@theqtcompany.com> | 2016-02-02 12:58:23 +0000 |
commit | 4849fd5a81593b09f046073d9cd5be9742d45326 (patch) | |
tree | 5b770ccb9f1ae419098e45039643657a346d200a /src | |
parent | 033156406844e786e2cf5c9c177ac02e0d617ed4 (diff) | |
download | qtquickcontrols-4849fd5a81593b09f046073d9cd5be9742d45326.tar.gz |
FileDialog: create FolderListModel asynchronously when first opened
This is only for the QML dialog implementation.
The incubator should be able to do this without any UI freeze, however
there can still be a delay when opening the dialog. It's better to
delay at that time instead of during application startup.
Task-number: QTBUG-46477
Change-Id: I31bada236ecbcfeb98ab98c511c65f95f1a1f83c
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/dialogs/DefaultFileDialog.qml | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/src/dialogs/DefaultFileDialog.qml b/src/dialogs/DefaultFileDialog.qml index 4c59381e..02815f17 100644 --- a/src/dialogs/DefaultFileDialog.qml +++ b/src/dialogs/DefaultFileDialog.qml @@ -48,10 +48,39 @@ import "qml" AbstractFileDialog { id: root - folder: view.model.folder + Component { + id: modelComponent + FolderListModel { + showFiles: !root.selectFolder + nameFilters: root.selectedNameFilterExtensions + sortField: (view.sortIndicatorColumn === 0 ? FolderListModel.Name : + (view.sortIndicatorColumn === 1 ? FolderListModel.Type : + (view.sortIndicatorColumn === 2 ? FolderListModel.Size : FolderListModel.LastModified))) + sortReversed: view.sortIndicatorOrder === Qt.DescendingOrder + } + } onVisibleChanged: { if (visible) { + // If the TableView doesn't have a model yet, create it asynchronously to avoid a UI freeze + if (!view.model) { + var incubator = modelComponent.incubateObject(null, { }) + function init(model) { + view.model = model + model.nameFilters = root.selectedNameFilterExtensions + root.folder = model.folder + } + + if (incubator.status === Component.Ready) { + init(incubator.object) + } else { + incubator.onStatusChanged = function(status) { + if (status === Component.Ready) + init(incubator.object) + } + } + } + view.needsWidthAdjustment = true view.selection.clear() view.focus = true @@ -59,7 +88,6 @@ AbstractFileDialog { } Component.onCompleted: { - view.model.nameFilters = root.selectedNameFilterExtensions filterField.currentIndex = root.selectedNameFilterIndex root.favoriteFolders = settings.favoriteFolders } @@ -300,14 +328,7 @@ AbstractFileDialog { resizeColumnsToContents() needsWidthAdjustment = false } - model: FolderListModel { - showFiles: !root.selectFolder - nameFilters: root.selectedNameFilterExtensions - sortField: (view.sortIndicatorColumn === 0 ? FolderListModel.Name : - (view.sortIndicatorColumn === 1 ? FolderListModel.Type : - (view.sortIndicatorColumn === 2 ? FolderListModel.Size : FolderListModel.LastModified))) - sortReversed: view.sortIndicatorOrder === Qt.DescendingOrder - } + model: null onActivated: if (view.focus) { if (view.selection.count > 0 && view.model.isFolder(row)) { @@ -435,7 +456,8 @@ AbstractFileDialog { anchors.verticalCenter: parent.verticalCenter onCurrentTextChanged: { root.selectNameFilter(currentText) - view.model.nameFilters = root.selectedNameFilterExtensions + if (view.model) + view.model.nameFilters = root.selectedNameFilterExtensions } } Button { |