repos
/
qt.gui
/ annotate_shade
summary
|
shortlog
|
log
|
tree
|
commit
|
commitdiff
|
headdiff
|
annotate
|
filehistory
normal
|
plain
|
shade
|
zebra
cleanup
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
08:52:49 '
106
(defun make-lisp-object (object)
2009-07-22 tobias
107
(smoke::make-cleanup-pointer (make-cxx-lisp-object object)
22:21:01 '
108
#'qt-smoke-free-lisp-object))
2010-01-10 tobias
109
08:52:49 '
110
'
111
(defun convert-arguments (arguments types)
'
112
"Returns a list of ARGUMENTS converted to TYPES."
'
113
(mapcar #'(lambda (argument type)
'
114
(if (typep type 'smoke::smoke-type)
'
115
(smoke::convert-argument argument type)
'
116
(progn (assert (typep argument type)
'
117
()
'
118
"The argument ~S is not of type ~S.")
'
119
(make-lisp-object argument))))
'
120
arguments types))
'
121
'
122
(defun emit (qsignal &rest arguments)
'
123
"Emits the signal QSIGNAL."
2009-07-22 tobias
124
;;; The first element of args would be used for the return value
22:21:01 '
125
;;; by QMetaObject::invokeMethod(), but for signal-slot connection
'
126
;;; it is ignored.
2009-07-02 tobias
127
(let ((types (argument-types qsignal)))
19:12:45 '
128
(smoke::with-stack (stack (convert-arguments arguments types)
'
129
types)
'
130
(cffi:with-foreign-object (args :pointer (1+ (length arguments)))
'
131
(loop for i from 1 to (smoke::size stack)
'
132
for type in (argument-types qsignal)
'
133
do
2010-01-10 tobias
134
(setf (mem-aref args :pointer i)
08:52:49 '
135
(if (or (not (typep type (find-class 'smoke::smoke-type)))
'
136
(= 0 (smoke::type-id type))
'
137
(= 13 (smoke::type-id type)))
'
138
(foreign-slot-value
2009-07-08 tobias
139
(mem-aref (pointer stack)
2010-01-10 tobias
140
'smoke::smoke-stack-item
08:52:49 '
141
i)
'
142
'smoke::smoke-stack-item 'smoke::voidp)
'
143
(foreign-slot-pointer
2009-07-08 tobias
144
(mem-aref (pointer stack)
2010-01-10 tobias
145
'smoke::smoke-stack-item
08:52:49 '
146
i)
'
147
'smoke::smoke-stack-item 'smoke::voidp))))
2009-07-02 tobias
148
(setf (mem-aref args :pointer 0)
19:12:45 '
149
(null-pointer))
2009-06-11 tobias
150
(meta-object.activate qsignal (cxx:meta-object qsignal)
2009-07-02 tobias
151
(id qsignal)
19:12:45 '
152
args)))))
2010-01-10 tobias
153
2009-06-11 tobias
154
(defmethod disconnect-all ((qsignal qsignal))
2010-01-10 tobias
155
(unless (disconnect-id (signal-object qsignal)
08:52:49 '
156
(id (signal-object qsignal))
'
157
0
'
158
0)))