source: trunk/src/qt3support/tools/q3signal.cpp@ 345

Last change on this file since 345 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 6.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the Qt3Support module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "q3signal.h"
43#include "qmetaobject.h"
44#include "qpointer.h"
45#include "q3cstring.h"
46
47QT_BEGIN_NAMESPACE
48
49/*!
50 \class Q3Signal
51 \brief The Q3Signal class can be used to send signals for classes
52 that don't inherit QObject.
53
54 \compat
55
56 If you want to send signals from a class that does not inherit
57 QObject, you can create an internal Q3Signal object to emit the
58 signal. You must also provide a function that connects the signal
59 to an outside object slot. This is how we used to implement
60 signals in Qt 3's QMenuData class, which was not a QObject. In Qt
61 4, menus contain actions, which are QObjects.
62
63 In general, we recommend inheriting QObject instead. QObject
64 provides much more functionality.
65
66 You can set a single QVariant parameter for the signal with
67 setValue().
68
69 Note that QObject is a \e private base class of Q3Signal, i.e. you
70 cannot call any QObject member functions from a Q3Signal object.
71
72 Example:
73 \snippet doc/src/snippets/code/src_qt3support_tools_q3signal.cpp 0
74*/
75
76/*!
77 Constructs a signal object called \a name, with the parent object
78 \a parent. These arguments are passed directly to QObject.
79*/
80
81Q3Signal::Q3Signal(QObject *parent, const char *name)
82 : QObject(parent, name)
83{
84#ifndef QT_NO_VARIANT
85 val = 0;
86#endif
87}
88
89/*!
90 Destroys the signal. All connections are removed, as is the case
91 with all QObjects.
92*/
93Q3Signal::~Q3Signal()
94{
95}
96#ifndef QT_NO_VARIANT
97// Returns true if it matches ".+(.*int.*"
98static inline bool intSignature(const char *member)
99{
100 Q3CString s(member);
101 int p = s.find('(');
102 return p > 0 && p < s.findRev("int");
103}
104#endif
105/*!
106 Connects the signal to \a member in object \a receiver.
107 Returns true if the connection is successful.
108
109 \sa disconnect(), QObject::connect()
110*/
111
112bool Q3Signal::connect(const QObject *receiver, const char *member)
113{
114#ifndef QT_NO_VARIANT
115 if (intSignature(member))
116#endif
117 return QObject::connect((QObject *)this, SIGNAL(intSignal(int)), receiver, member);
118#ifndef QT_NO_VARIANT
119 return QObject::connect((QObject *)this, SIGNAL(signal(QVariant)),
120 receiver, member);
121#endif
122}
123
124/*!
125 Disonnects the signal from \a member in object \a receiver.
126 Returns true if the connection existed and the disconnect
127 was successful.
128
129 \sa connect(), QObject::disconnect()
130*/
131
132bool Q3Signal::disconnect(const QObject *receiver, const char *member)
133{
134 if (!member)
135 return QObject::disconnect((QObject *)this, 0, receiver, member);
136#ifndef QT_NO_VARIANT
137 if (intSignature(member))
138#endif
139 return QObject::disconnect((QObject *)this, SIGNAL(intSignal(int)), receiver, member);
140#ifndef QT_NO_VARIANT
141 return QObject::disconnect((QObject *)this, SIGNAL(signal(QVariant)),
142 receiver, member);
143#endif
144}
145
146
147/*!
148 \fn bool Q3Signal::isBlocked() const
149 \obsolete
150 Returns true if the signal is blocked, or false if it is not blocked.
151
152 The signal is not blocked by default.
153
154 \sa block(), QObject::signalsBlocked()
155*/
156
157/*!
158 \fn void Q3Signal::block(bool b)
159 \obsolete
160 Blocks the signal if \a b is true, or unblocks the signal if \a b is false.
161
162 An activated signal disappears into hyperspace if it is blocked.
163
164 \sa isBlocked(), activate(), QObject::blockSignals()
165*/
166
167
168/*!
169 \fn void Q3Signal::activate()
170
171 Emits the signal. If the platform supports QVariant and a
172 parameter has been set with setValue(), this value is passed in
173 the signal.
174*/
175void Q3Signal::activate()
176{
177#ifndef QT_NO_VARIANT
178 /* Create this Q3GuardedPtr on this, if we get destroyed after the intSignal (but before the variant signal)
179 we cannot just emit the signal (because val has been destroyed already) */
180 QPointer<Q3Signal> me = this;
181 if(me)
182 emit intSignal(val.toInt());
183 if(me)
184 emit signal(val);
185#else
186 emit intSignal(0);
187#endif
188}
189
190#ifndef QT_NO_VARIANT
191/*!
192 Sets the signal's parameter to \a value
193*/
194void Q3Signal::setValue(const QVariant &value)
195{
196 val = value;
197}
198
199/*!
200 Returns the signal's parameter
201*/
202QVariant Q3Signal::value() const
203{
204 return val;
205}
206/*! \fn void Q3Signal::signal(const QVariant &)
207 \internal
208*/
209/*! \fn void Q3Signal::intSignal(int)
210 \internal
211*/
212
213/*! \obsolete */
214void Q3Signal::setParameter(int value)
215{
216 val = value;
217}
218
219/*! \obsolete */
220int Q3Signal::parameter() const
221{
222 return val.toInt();
223}
224#endif //QT_NO_VARIANT
225
226QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.