From fea05bb0dba069c82b9dbe2a71b31f88cf54a712 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 28 Feb 2017 19:51:52 +0100 Subject: Avoid "Unable to assign...." errors i.e. "Unable to assign [undefined] to Sink::ApplicationDomain::Folder::Ptr" Because qml does not know how to assign a default-constructed value we have to use conditional bindings. The !! operator checks for availability of the property which then triggers the binding. I assume an alternative viable approach would be to expose all controller properties as QVariants only, in which case an assignment from null would work (it doesn't for Folder::Ptr). --- components/mail/contents/ui/Mail.qml | 12 ++++++++++-- components/package/contents/ui/FolderListView.qml | 8 ++++++-- components/package/contents/ui/MailListView.qml | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/components/mail/contents/ui/Mail.qml b/components/mail/contents/ui/Mail.qml index b88e846d..c400d8f3 100644 --- a/components/mail/contents/ui/Mail.qml +++ b/components/mail/contents/ui/Mail.qml @@ -84,12 +84,20 @@ Controls2.ApplicationWindow { //Controller KubeFramework.MailController { id: mailController - threadLeader: mailListView.currentMail + Binding on threadLeader { + //!! checks for the availability of the type + when: !!mailListView.currentMail + value: mailListView.currentMail + } } KubeFramework.FolderController { id: folderController - folder: folderListView.currentFolder + Binding on folder { + //!! checks for the availability of the type + when: !!folderListView.currentFolder + value: folderListView.currentFolder + } } //BEGIN Shortcuts diff --git a/components/package/contents/ui/FolderListView.qml b/components/package/contents/ui/FolderListView.qml index 9ac73fb4..a4d25e02 100644 --- a/components/package/contents/ui/FolderListView.qml +++ b/components/package/contents/ui/FolderListView.qml @@ -28,14 +28,18 @@ import org.kube.framework.domain 1.0 as KubeFramework Rectangle { id: root - property variant currentFolder + property variant currentFolder: null property variant accountId color: Kirigami.Theme.textColor KubeFramework.FolderController { id: folderController - folder: root.currentFolder + Binding on folder { + //!! checks for the availability of the type + when: !!root.currentFolder + value: root.currentFolder + } } Menu { diff --git a/components/package/contents/ui/MailListView.qml b/components/package/contents/ui/MailListView.qml index 1467979a..35fd4ec9 100644 --- a/components/package/contents/ui/MailListView.qml +++ b/components/package/contents/ui/MailListView.qml @@ -28,7 +28,7 @@ import org.kube.framework.domain 1.0 as KubeFramework Item { id: root property variant parentFolder - property variant currentMail + property variant currentMail: null property bool isDraft : false property int currentIndex -- cgit v1.2.3