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/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))
2009-05-24 tobias
79
(or (meta-object.connect qsignal (id qsignal)
14:40:11 '
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))))
2009-06-05 tobias
90
07:45:07 '
91
(defun disconnect-signal (qsignal receiver slot)
'
92
(let ((qsignal (signal-object qsignal))
'
93
(slot-id (cxx:index-of-slot (cxx:meta-object receiver)
2009-05-24 tobias
94
(cxx:data
14:40:11 '
95
(meta-object.normalized-signature slot)))))
2009-06-05 tobias
96
(assert (>= slot-id 0)
07:45:07 '
97
()
'
98
"No slot ~S for class ~S."
'
99
slot (class-name receiver))
2009-05-24 tobias
100
(or (meta-object.disconnect qsignal (id qsignal)
14:40:11 '
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)))
2010-01-10 tobias
115
08:52:49 '
116
'
117
(defun emit (qsignal &rest arguments)
'
118
"Emits the signal QSIGNAL."
2009-07-22 tobias
119
;;; The first element of args would be used for the return value
22:21:01 '
120
;;; by QMetaObject::invokeMethod(), but for signal-slot connection
'
121
;;; it is ignored.
2009-05-26 tobias
122
(smoke::with-stack (stack arguments
09:57:44 '
123
(argument-types qsignal))
'
124
(cffi:with-foreign-object (args :pointer (1+ (length arguments)))
'
125
(loop for i from 1 to (smoke::size stack)
'
126
for type in (argument-types qsignal)
'
127
do
'
128
(setf (mem-aref args :pointer i)
'
129
(if (or (not (typep type (find-class 'smoke::smoke-type)))
'
130
(= 0 (smoke::type-id type))
'
131
(= 13 (smoke::type-id type)))
'
132
(foreign-slot-value
'
133
(mem-aref (pointer stack)
'
134
'smoke::smoke-stack-item
'
135
i)
'
136
'smoke::smoke-stack-item 'smoke::voidp)
'
137
(foreign-slot-pointer
'
138
(mem-aref (pointer stack)
'
139
'smoke::smoke-stack-item
'
140
i)
'
141
'smoke::smoke-stack-item 'smoke::voidp))))
'
142
(setf (mem-aref args :pointer 0)
'
143
(null-pointer))
2009-05-24 tobias
144
(meta-object.activate qsignal (cxx:meta-object qsignal)
2009-05-26 tobias
145
(id qsignal)
09:57:44 '
146
args))))
2010-01-10 tobias
147
2009-06-11 tobias
148
(defmethod disconnect-all ((qsignal qsignal))
2010-01-10 tobias
149
(unless (disconnect-id (signal-object qsignal)
08:52:49 '
150
(id (signal-object qsignal))
'
151
0
'
152
0)))