repos
/
qt.gui
/ annotate_shade
summary
|
shortlog
|
log
|
tree
|
commit
|
commitdiff
|
headdiff
|
annotate
|
filehistory
normal
|
plain
|
shade
|
zebra
Use overload resolution instead of static-call
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
2009-05-27 tobias
30
(defun method-argument-count (metaobject index)
12:26:25 '
31
"Returns the number of arguments for the method INDEX of METAOBJECT."
'
32
(let ((signature (cxx:signature (cxx:method metaobject index))))
'
33
(setf signature (subseq signature (1+ (position #\( signature))
'
34
(position #\) signature :from-end t)))
'
35
(if (= 0 (length signature))
'
36
0
'
37
(1+ (count #\, signature)))))
'
38
2010-01-10 tobias
39
(defmethod cxx:qt-metacall ((slot qslot) call id arguments)
08:52:49 '
40
"Invoke the slots function when it is called. The return value
'
41
of the invoked slot function is ignored."
'
42
(let ((id (call-next-method)))
'
43
(if (< id 0)
'
44
id
2009-06-11 tobias
45
(if (enum= call meta-object.+invoke-meta-method+)
2010-01-10 tobias
46
(progn
2009-06-03 tobias
47
(case id
2009-06-05 tobias
48
(0 (let ((*sender* (cxx:sender slot)))
2009-06-03 tobias
49
(apply (slot-function slot)
22:02:12 '
50
(arguments-to-lisp arguments (arguments slot))))))
2010-01-10 tobias
51
(1- id))
08:52:49 '
52
id))))
'
53
'
54
(defun find-signal-id (sender signal)
'
55
"Returns the ID of SIGNAL from SENDER."
'
56
(let ((id (cxx:index-of-signal (cxx:meta-object sender)
2009-06-04 tobias
57
(cxx:data (meta-object.normalized-signature signal)))))
2010-01-10 tobias
58
(when (< id 0)
08:52:49 '
59
(error "No signal ~S for class ~S."
'
60
signal (class-of sender)))
'
61
id))
'
62
2009-06-05 tobias
63
(defun connect-function (sender signal function &optional (type 0))
07:45:07 '
64
"Connects FUNCTION to the SIGNAL of SENDER.
'
65
The return value of FUNCTION is ignored."
'
66
(let* ((signal-id (find-signal-id sender signal))
'
67
(slot (make-instance 'qslot
'
68
:args (list sender)
'
69
:slot-function function
'
70
:argument-types (method-arguments-type
'
71
(cxx:meta-object sender)
'
72
signal-id))))
2009-05-24 tobias
73
(let ((ret (meta-object.connect sender signal-id
14:40:11 '
74
slot (id slot)
'
75
type (types (arguments slot)))))
2009-06-05 tobias
76
(if ret
2009-05-24 tobias
77
(cxx:connect-notify sender signal)
14:40:11 '
78
(cerror "Failed to connect the signal ~S of ~S to the function ~S."
'
79
signal sender function)))))