repos
/
qt.gui
/ annotate_shade
summary
|
shortlog
|
log
|
tree
|
commit
|
commitdiff
|
headdiff
|
annotate
|
filehistory
normal
|
plain
|
shade
|
zebra
Use argument conversion/promotion when emiting signals
Annotate for file src/signal-slot/signal.lisp
2009-06-11 tobias
1
(in-package :qt)
2009-07-01 tobias
2
(declaim (optimize (debug 3)))
2010-01-10 tobias
3
08:52:49 '
4
(defclass qsignal-mixin ()
'
5
((signal-object :accessor signal-object
'
6
:initarg :signal-object
'
7
:initform (make-instance 'signal-object)))
'
8
(:documentation "in SB-PCL you can not have both
'
9
FUNCALLABLE-STANDARD-CLASS and STANDARD-CLASS,
'
10
thus QSIGNAL is split in three classes.
'
11
'
12
See:
'
13
http://www.sbcl.org/manual/Metaobject-Protocol.html#index-validate_002dsuperclass-164"))
'
14
2009-06-11 tobias
15
(defclass signal-object (object)
2010-01-10 tobias
16
((argument-types :accessor argument-types
08:52:49 '
17
:initarg :argument-types
'
18
:documentation "List of the argument types"))
'
19
(:documentation "Qt Signal object.")
'
20
(:metaclass cxx:class))
'
21
'
22
#+cmu (defmethod closer-mop:validate-superclass ((class closer-mop:funcallable-standard-class)
'
23
(superclass standard-class))
'
24
t)
'
25
'
26
(defclass qsignal (closer-mop:funcallable-standard-object qsignal-mixin)
'
27
()
'
28
(:metaclass closer-mop:funcallable-standard-class)
'
29
(:documentation "A funcallable Qt signal.
'
30
The argument types can be supplied by the :METHOD-TYPES initarg.
'
31
Calling an instance emits the signal."))
'
32
2009-06-11 tobias
33
(defun make-signal (&rest argument-types)
2010-01-10 tobias
34
"Returns a funcallable signal. When ARGUMENT-TYPES are not
08:52:49 '
35
specified, they are determined when the first connection is made."
'
36
(if argument-types
'
37
(make-instance 'qsignal :argument-types argument-types)
'
38
(make-instance 'qsignal)))
'
39
'
40
(defmethod id ((qsignal signal-object))
'
41
(cxx:method-count (cxx:meta-object qsignal)))
'
42
'
43
(defmethod initialize-instance :after ((object qsignal) &rest initargs
'
44
&key (argument-types nil arg-types-p)
'
45
&allow-other-keys)
'
46
(declare (ignore initargs))
'
47
(when arg-types-p
'
48
(setf (argument-types (signal-object object))
'
49
argument-types))
'
50
(closer-mop:set-funcallable-instance-function object
'
51
#'(lambda (&rest args)
2009-07-22 tobias
52
(apply #'emit (signal-object object) args)))
22:21:01 '
53
)
2010-01-10 tobias
54
08:52:49 '
55
(defun find-slot-id (receiver slot)
'
56
"Returns the ID of RECEIVER from SLOT."
'
57
(let ((id (cxx:index-of-slot (cxx:meta-object receiver)
2009-06-04 tobias
58
(cxx:data (meta-object.normalized-signature slot)))))
2010-01-10 tobias
59
(when (< id 0)
08:52:49 '
60
(error "No slot ~S for class ~S.
'
61
The valid slots are: ~{~<~%~T~0,75:;~A ~>~}"
'
62
slot (class-of receiver)
'
63
(class-slots (class-of receiver))))
'
64
id))
'
65
2009-06-05 tobias
66
(defun connect-signal (qsignal receiver slot &optional (type 0))
07:45:07 '
67
"Connects a signal to a slot. Returns T on success and NIL otherwise."
'
68
'
69
(let ((qsignal (signal-object qsignal))
'
70
(slot-id (find-slot-id receiver slot)))
'
71
(when (not (slot-boundp qsignal 'argument-types))
'
72
(setf (argument-types qsignal)
'
73
(method-arguments-type (cxx:meta-object receiver)
'
74
slot-id)))
'
75
(assert (>= slot-id 0)
'
76
()
'
77
"No slot ~S for class ~S."
'
78
slot (class-name receiver))
'
79
(or (meta-object.connect qsignal (id qsignal)
'
80
receiver slot-id
'
81
type
'
82
;; QMetaObject::connect is responsible
'
83
;; for freeing the types array.
'
84
(types (method-arguments-type
'
85
(cxx:meta-object receiver)
'
86
slot-id)))
'
87
(cerror "Ignore"
'
88
"Failed to connect ~S to the slot ~S of ~S."
'
89
qsignal slot receiver))))
'
90
'
91
(defun disconnect-signal (qsignal receiver slot)
'
92
(let ((qsignal (signal-object qsignal))
'
93
(slot-id (cxx:index-of-slot (cxx:meta-object receiver)
'
94
(cxx:data
'
95
(meta-object.normalized-signature slot)))))
'
96
(assert (>= slot-id 0)
'
97
()
'
98
"No slot ~S for class ~S."
'
99
slot (class-name receiver))
'
100
(or (meta-object.disconnect qsignal (id qsignal)
'
101
receiver slot-id)
'
102
(cerror "Ignore"
'
103
"Failed to disconnect ~S to the slot ~S of ~S."
'
104
qsignal slot receiver))))
2010-01-10 tobias
105
2009-05-27 tobias
106
(defmethod smoke::push-lisp-object (stack object class)
12:26:25 '
107
(let ((cxx-object (make-cxx-lisp-object object)))
'
108
(smoke::push-cleanup stack
'
109
'
110
#'(lambda ()
'
111
(qt-smoke-free-lisp-object cxx-object)))
'
112
(smoke::push-stack2 stack
'
113
cxx-object
'
114
0)))
2009-05-26 tobias
115
09:57:44 '
116
(defun make-lisp-object (object)
'
117
(smoke::make-cleanup-pointer (make-cxx-lisp-object object)
'
118
#'qt-smoke-free-lisp-object))
2010-01-10 tobias
119
08:52:49 '
120
2009-05-26 tobias
121
(defun convert-arguments (arguments types)
09:57:44 '
122
"Returns a list of ARGUMENTS converted to TYPES."
'
123
(mapcar #'(lambda (argument type)
'
124
(if (typep type 'smoke::smoke-type)
'
125
(smoke::convert-argument argument type)
'
126
(progn (assert (typep argument type)
'
127
()
'
128
"The argument ~S is not of type ~S.")
'
129
(make-lisp-object argument))))
'
130
arguments types))
'
131
2010-01-10 tobias
132
(defun emit (qsignal &rest arguments)
08:52:49 '
133
"Emits the signal QSIGNAL."
2009-07-22 tobias
134
;;; The first element of args would be used for the return value
22:21:01 '
135
;;; by QMetaObject::invokeMethod(), but for signal-slot connection
'
136
;;; it is ignored.
2009-05-26 tobias
137
(let ((types (argument-types qsignal)))
09:57:44 '
138
(smoke::with-stack (stack (convert-arguments arguments types)
'
139
types)
'
140
(cffi:with-foreign-object (args :pointer (1+ (length arguments)))
'
141
(loop for i from 1 to (smoke::size stack)
'
142
for type in (argument-types qsignal)
'
143
do
'
144
(setf (mem-aref args :pointer i)
'
145
(if (or (not (typep type (find-class 'smoke::smoke-type)))
'
146
(= 0 (smoke::type-id type))
'
147
(= 13 (smoke::type-id type)))
'
148
(foreign-slot-value
'
149
(mem-aref (pointer stack)
'
150
'smoke::smoke-stack-item
'
151
i)
'
152
'smoke::smoke-stack-item 'smoke::voidp)
'
153
(foreign-slot-pointer
'
154
(mem-aref (pointer stack)
'
155
'smoke::smoke-stack-item
'
156
i)
'
157
'smoke::smoke-stack-item 'smoke::voidp))))
'
158
(setf (mem-aref args :pointer 0)
'
159
(null-pointer))
'
160
(meta-object.activate qsignal (cxx:meta-object qsignal)
'
161
(id qsignal)
'
162
args)))))
2010-01-10 tobias
163
2009-06-11 tobias
164
(defmethod disconnect-all ((qsignal qsignal))
2010-01-10 tobias
165
(unless (disconnect-id (signal-object qsignal)
08:52:49 '
166
(id (signal-object qsignal))
'
167
0
'
168
0)))