QList<QByteArray> and QList<QVariant> conversion & use cxx:operator== and qt:operator== in cxx:=
src/list.lisp
Wed May 27 19:18:41 CEST 2009 Tobias Rautenkranz <tobias@rautenkranz.ch>
* QList<QByteArray> and QList<QVariant> conversion & use cxx:operator== and qt:operator== in cxx:=
--- old-qt.gui/src/list.lisp 1970-01-01 01:00:00.000000000 +0100
+++ new-qt.gui/src/list.lisp 2014-10-30 07:49:02.000000000 +0100
@@ -0,0 +1,64 @@
+(in-package :qt)
+
+(defmacro define-qlist-wrapper (type-name)
+ (let* ((type (string-upcase type-name))
+ (list-type (symbolicate 'qlist- type)))
+ `(progn
+ (defcfun ,(concatenate 'string "qt_smoke_list_" type-name "_size") :int
+ "Returns the size of LIST."
+ (list :pointer))
+ (defcfun ,(concatenate 'string "qt_smoke_free_list_" type-name) :void
+ "Frees LIST."
+ (list :pointer))
+ (defcfun ,(concatenate 'string "qt_smoke_make_list_" type-name) :pointer
+ "Makes a list.")
+ (defcfun ,(concatenate 'string "qt_smoke_list_" type-name "_at") :pointer
+ "Returns the a newly constructed copy of the element at position AT of LIST."
+ (list :pointer)
+ (index :int))
+ (defcfun ,(concatenate 'string "qt_smoke_list_" type-name "_append") :pointer
+ "Appends NEW-ELEMENT to LIST."
+ (list :pointer)
+ (new-element :pointer))
+ (define-foreign-type ,list-type ()
+ ()
+ (:actual-type :pointer))
+ (define-parse-method ,list-type ()
+ (make-instance ',list-type))
+ (eval-when (:load-toplevel :execute)
+ (smoke::add-type ,(format nil "const QList<~A>&" type-name)
+ ',list-type)
+ (smoke::add-type ,(format nil "QList<~A>" type-name) ',list-type))
+ (defmethod translate-from-foreign (list (type ,list-type))
+ (let ((vector (make-array (,(symbolicate 'qt-smoke-list-
+ type '-size)
+ list))))
+ (dotimes (index (length vector) vector)
+ (setf (aref vector index)
+ ;; FIXME the retuned object is not wrapped by Smoke
+ ;; -> change this?
+ (smoke::object-to-lisp
+ (,(symbolicate 'qt-smoke-list-
+ type '-at)
+ list index)
+ (smoke::make-smoke-type *qt-smoke* ,type-name))))))
+ (defmethod free-translated-object (pointer (type ,list-type) param)
+ (declare (ignore param))
+ (,(symbolicate 'qt-smoke-free-list- type)
+ pointer))
+ (defun ,(symbolicate 'coerce- list-type) (list)
+ (let ((qlist (,(symbolicate 'qt-smoke-make-list- type))))
+ (loop for element in list do
+ (,(symbolicate 'qt-smoke-list- type '-append)
+ qlist (pointer (make-instance ',type :args (list element)))))
+ (smoke::make-cleanup-pointer
+ qlist
+ (function ,(symbolicate 'qt-smoke-free-list- type)))))
+ (define-from-lisp-translation (,(format nil "const QList<~A>&" type-name)
+ ,(format nil "QLIst<~A>" type-name))
+ list ;; FIXME allow seqence and define element type
+ ,(symbolicate 'coerce- list-type)))))
+
+(define-qlist-wrapper "QVariant")
+;(define-qlist-wrapper "void")
+(define-qlist-wrapper "QByteArray")