cleanup
Annotate for file src/signal-slot/slot.lisp
2009-06-11 tobias 1 (in-package :qt)
14:59:48 ' 2 (declaim (optimize (debug 3)))
2010-01-10 tobias 3
2009-06-11 tobias 4 (defclass qslot (object)
2010-01-10 tobias 5 ((arguments :reader arguments :initarg :argument-types
08:52:49 ' 6 :documentation "List of the argument types for the slot.")
' 7 (function :reader slot-function :initarg :slot-function
2009-08-02 tobias 8 :initform (error "no function specified")
2010-01-10 tobias 9 :documentation "The function called when the slot is invoked."))
2009-05-31 tobias 10 (:metaclass smoke::smoke-wrapper-class)
2010-01-10 tobias 11 (:documentation "A Qt slot that calls its associated function"))
08:52:49 ' 12
2009-06-11 tobias 13 (defun make-slot (function &optional (arguments nil arguments-p))
2010-01-10 tobias 14 "Returns a slot that calls FUNCTION when it receives a signal."
08:52:49 ' 15 (if arguments-p
' 16 (make-instance 'qslot
' 17 :slot-function function
' 18 :argument-types arguments)
' 19 (make-instance 'qslot
' 20 :slot-function function)))
' 21
' 22 (defmethod id ((slot qslot))
' 23 (cxx:method-count (cxx:meta-object slot)))
' 24
2009-06-05 tobias 25 (defparameter *sender* nil)
2009-06-11 tobias 26 (defmacro sender ()
2010-01-10 tobias 27 "Returns the sender that invoked the slot."
08:52:49 ' 28 `*sender*)
' 29
' 30 (defmethod cxx:qt-metacall ((slot qslot) call id arguments)
' 31 "Invoke the slots function when it is called. The return value
' 32 of the invoked slot function is ignored."
' 33 (let ((id (call-next-method)))
' 34 (if (< id 0)
' 35 id
2009-06-11 tobias 36 (if (enum= call meta-object.+invoke-meta-method+)
2010-01-10 tobias 37 (progn
2009-06-03 tobias 38 (case id
2009-06-05 tobias 39 (0 (let ((*sender* (cxx:sender slot)))
2009-06-03 tobias 40 (apply (slot-function slot)
22:02:12 ' 41 (arguments-to-lisp arguments (arguments slot))))))
2010-01-10 tobias 42 (1- id))
08:52:49 ' 43 id))))
' 44
' 45 (defun find-signal-id (sender signal)
' 46 "Returns the ID of SIGNAL from SENDER."
' 47 (let ((id (cxx:index-of-signal (cxx:meta-object sender)
2009-06-04 tobias 48 (cxx:data (meta-object.normalized-signature signal)))))
2010-01-10 tobias 49 (when (< id 0)
08:52:49 ' 50 (error "No signal ~S for class ~S."
' 51 signal (class-of sender)))
' 52 id))
' 53
2009-06-05 tobias 54 (defun connect-function (sender signal function &optional (type 0))
07:45:07 ' 55 "Connects FUNCTION to the SIGNAL of SENDER.
' 56 The return value of FUNCTION is ignored."
' 57 (let* ((signal-id (find-signal-id sender signal))
' 58 (slot (make-instance 'qslot
' 59 :args (list sender)
' 60 :slot-function function
' 61 :argument-types (method-arguments-type
' 62 (cxx:meta-object sender)
' 63 signal-id))))
' 64 (let ((ret (meta-object.connect sender signal-id
' 65 slot (id slot)
' 66 type (types (arguments slot)))))
' 67 (if ret
' 68 (cxx:connect-notify sender signal)
' 69 (cerror "Failed to connect the signal ~S of ~S to the function ~S."
' 70 signal sender function)))))