Wed Sep 2 14:00:35 CEST 2009 Tobias Rautenkranz * Better Lisp vector to QList<*> conversion. diff -rN -u old-qt.gui/src/list.lisp new-qt.gui/src/list.lisp --- old-qt.gui/src/list.lisp 2014-10-30 07:43:28.000000000 +0100 +++ new-qt.gui/src/list.lisp 2014-10-30 07:43:28.000000000 +0100 @@ -1,6 +1,6 @@ (in-package :cl-smoke.qt-impl) -(defmacro define-qlist-wrapper (type-name &optional c-name) +(defmacro define-qlist-wrapper (type-name element-type &optional c-name) (let* ((c-name (or c-name type-name)) (type (string-upcase c-name)) (list-type (symbolicate 'qlist- type))) @@ -46,18 +46,27 @@ ;; From Lisp (defun ,(symbolicate 'coerce- list-type) (list) (let ((qlist (,(symbolicate 'qt-smoke-make-list- type)))) - (loop for element in list do + (loop for element across list do (,(symbolicate 'qt-smoke-list- type '-append) - qlist (pointer (make-instance ',type :args (list element))))) + qlist (pointer (make-instance ',element-type :args (list element))))) (make-cleanup-pointer qlist (function ,(symbolicate 'qt-smoke-free-list- type))))) + (defun ,(symbolicate list-type '-p) (list) + (every #'(lambda (element) + (typep element ',element-type)) + list)) ,@(loop for type-name in (ensure-list type-name) collect `(define-from-lisp-translation (,(format nil "const QList<~A>&" type-name) ,(format nil "QList<~A>" type-name)) - list ;; FIXME allow sequence and define element type + ;; FIXME allow sequence + (and (vector ,element-type) + (satisfies ,(symbolicate list-type '-p))) ,(symbolicate 'coerce- list-type)))))) -(define-qlist-wrapper "QVariant") -(define-qlist-wrapper ("QObject*" "QWidget*") "void") -(define-qlist-wrapper "QByteArray") +;; FIXME it would be nice to have QList as fallback for any +;; list we can not convert otherwise. e.g.: '("a" 1) +(define-qlist-wrapper "QVariant" qt:variant) + +(define-qlist-wrapper ("QObject*" "QWidget*") qt:object "void") +(define-qlist-wrapper "QByteArray" qt:byte-array) diff -rN -u old-qt.gui/src/signal-slot/signal.lisp new-qt.gui/src/signal-slot/signal.lisp --- old-qt.gui/src/signal-slot/signal.lisp 2014-10-30 07:43:28.000000000 +0100 +++ new-qt.gui/src/signal-slot/signal.lisp 2014-10-30 07:43:28.000000000 +0100 @@ -88,12 +88,12 @@ (activate qsignal (id qsignal) (argument-types qsignal) arguments)) (defun activate (object id types arguments) -;;; The first element of args would be used for the return value by -;;; QMetaObject::invokeMethod(), but for signal-slot connection it is -;;; ignored. + ;;; The first element of args would be used for the return value by + ;;; QMetaObject::invokeMethod(), but for signal-slot connection it is + ;;; ignored. (smoke::with-stack (stack (convert-arguments arguments types) types) - (cffi:with-foreign-object (args :pointer (1+ (length arguments))) + (with-foreign-object (args :pointer (1+ (length arguments))) (loop for i from 1 to (smoke::size stack) for type in types do diff -rN -u old-qt.gui/src/string-list.lisp new-qt.gui/src/string-list.lisp --- old-qt.gui/src/string-list.lisp 2014-10-30 07:43:28.000000000 +0100 +++ new-qt.gui/src/string-list.lisp 2014-10-30 07:43:28.000000000 +0100 @@ -40,5 +40,10 @@ (make-cleanup-pointer string-list #'qt-smoke-free-string-list))) +(defun string-list-p (sequence) + (every #'stringp sequence)) + (define-from-lisp-translation "const QStringList&" - (vector string) coerce-string-list) + (and (vector string) + (satisfies string-list-p)) + coerce-string-list)