diff --git a/src/lisp/package.lisp b/src/lisp/package.lisp index 5d9d148..cafce21 100644 --- a/src/lisp/package.lisp +++ b/src/lisp/package.lisp @@ -122,6 +122,7 @@ (:export #:*quick-view* #:*root* + #:*root-item* #:*caller* #:children #:file-to-url diff --git a/src/lisp/qml.lisp b/src/lisp/qml.lisp index 67ee609..b8e5d1c 100644 --- a/src/lisp/qml.lisp +++ b/src/lisp/qml.lisp @@ -10,6 +10,7 @@ (defvar *quick-view* nil) (defvar *caller* nil) (defvar *root* nil) +(defvar *root-item* nil) ; see note in 'find-quick-item' (defun string-to-symbol (name) (let ((upper (string-upcase name)) @@ -76,13 +77,30 @@ (when *quick-view* (|rootContext| *quick-view*))) -(defun find-quick-item (object-name) - "Finds the first QQuickItem matching OBJECT-NAME." - (let ((root (root-item))) - (unless (qnull root) - (if (string= (|objectName| root) object-name) - (root-item) - (qt-object-? (qfind-child root object-name)))))) +(defun find-quick-item (object-name &optional (parent *root-item*)) + "Finds the first QQuickItem matching OBJECT-NAME. Optionally pass a QQuickItem as parent, which defaults to *ROOT-ITEM*, which is defined but NIL, and meant to be used as special variable (in case of multiple items with the same OBJECT-NAME, e.g. in QML 'Repeater')." + ;; + ;; when to use *ROOT-ITEM* + ;; + ;; say you have a Repeater QML item with multiple instances of the same + ;; QQuickItem. The children of those QQuickItems all have the same object + ;; names, respectively. In order to access those child items, we need to + ;; search in the specific item of the Repeater. + ;; + ;; So, we locally bind *ROOT-ITEM* in order to find a specific child item + ;; inside the Repeater: + ;; + ;; (let ((qml:*root-item* (q! |itemAt| ui:*repeater* 0))) + ;; ;; everything we do here will only affect children of the first item + ;; ;: in ui:*repeater* (see index 0 above) + ;; (q< |text| ui:*edit*) + ;; + (unless parent + (setf parent (root-item))) + (unless (qnull parent) + (if (string= (|objectName| parent) object-name) + parent + (qt-object-? (qfind-child parent object-name))))) (defun quick-item (item/name) (cond ((stringp item/name)