diff --git a/doc/help.htm b/doc/help.htm index 2d39f63..6d7351e 100644 --- a/doc/help.htm +++ b/doc/help.htm @@ -250,6 +250,16 @@ For the PLURAL-NUMBER, see Qt Assistant. +view-status-changed (status) + + Redefine this function if you want to be notified on status changes of + QQuickView, e.g. after a RELOAD. + + (defun qml:view-status-changed (status) + (when (= 1 status) + (populate-item-model))) + + diff --git a/examples/app-template/auto-reload-qml.lisp b/examples/app-template/auto-reload-qml.lisp index 09d8e26..44b7ba7 100644 --- a/examples/app-template/auto-reload-qml.lisp +++ b/examples/app-template/auto-reload-qml.lisp @@ -4,11 +4,11 @@ (in-package :qml-user) -(defun reload-qml () - (qml:reload) - ;; any ini code goes here: - ;;(qsingle-shot 250 'populate-item-model) - ) +(defun qml:view-status-changed (status) + (when (= 1 status) + ;; any ini code goes here + ;;(app:populate-item-model)) + )) (let ((secs 0) files) @@ -21,7 +21,7 @@ (incf curr (file-write-date file))) (when (/= secs curr) (unless (zerop secs) - (reload-qml)) + (qml:reload)) (setf secs curr))) (qsingle-shot 250 'watch-files))) diff --git a/src/cpp/ecl_ext.cpp b/src/cpp/ecl_ext.cpp index 47a1307..edbe8a8 100644 --- a/src/cpp/ecl_ext.cpp +++ b/src/cpp/ecl_ext.cpp @@ -58,6 +58,14 @@ void iniCLFunctions() { DEFUN ("%reload", reload2, 0) DEFUN ("root-item", root_item, 0) DEFUN ("%set-shutdown-p", set_shutdown_p, 1) + + STATIC_SYMBOL_PKG (s_view_status_changed, "VIEW-STATUS-CHANGED", "QML") + LQML::quickView->connect(LQML::quickView, &QQuickView::statusChanged, + [](QQuickView::Status status) { + cl_funcall(2, + s_view_status_changed, + ecl_make_fixnum(static_cast(status))); + }); } diff --git a/src/lisp/package.lisp b/src/lisp/package.lisp index cce5f9c..ef5cb47 100644 --- a/src/lisp/package.lisp +++ b/src/lisp/package.lisp @@ -50,6 +50,7 @@ #:reload #:root-item #:tr + #:view-status-changed #:!)) (defpackage :qml-user diff --git a/src/lisp/qml.lisp b/src/lisp/qml.lisp index 7724573..29ee21c 100644 --- a/src/lisp/qml.lisp +++ b/src/lisp/qml.lisp @@ -71,6 +71,15 @@ Reloads all QML files, clearing the cache." (qrun* (%reload))) +(defun view-status-changed (status) + "args: (status) + Redefine this function if you want to be notified on status changes of + QQuickView, e.g. after a RELOAD. + (defun qml:view-status-changed (status) + (when (= 1 status) + (populate-item-model)))" + nil) + ;;; get/set QML properties, call QML methods (through JS) (defun qml-get (item/name property-name)