Qt 4.8
qsignalmapper.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qsignalmapper.h"
43 #ifndef QT_NO_SIGNALMAPPER
44 #include "qhash.h"
45 #include "qobject_p.h"
46 
48 
50 {
52 public:
55  q->removeMappings(q->sender());
56  }
61 
62 };
63 
64 
123  : QObject(*new QSignalMapperPrivate, parent)
124 {
125 }
126 
127 #ifdef QT3_SUPPORT
128 
133  : QObject(*new QSignalMapperPrivate, parent)
134 {
136 }
137 #endif
138 
143 {
144 }
145 
155 {
157  d->intHash.insert(sender, id);
158  connect(sender, SIGNAL(destroyed()), this, SLOT(_q_senderDestroyed()));
159 }
160 
168 {
170  d->stringHash.insert(sender, text);
171  connect(sender, SIGNAL(destroyed()), this, SLOT(_q_senderDestroyed()));
172 }
173 
181 {
183  d->widgetHash.insert(sender, widget);
184  connect(sender, SIGNAL(destroyed()), this, SLOT(_q_senderDestroyed()));
185 }
186 
194 {
196  d->objectHash.insert(sender, object);
197  connect(sender, SIGNAL(destroyed()), this, SLOT(_q_senderDestroyed()));
198 }
199 
206 {
207  Q_D(const QSignalMapper);
208  return d->intHash.key(id);
209 }
210 
215 {
216  Q_D(const QSignalMapper);
217  return d->stringHash.key(id);
218 }
219 
229 {
230  Q_D(const QSignalMapper);
231  return d->widgetHash.key(widget);
232 }
233 
243 {
244  Q_D(const QSignalMapper);
245  return d->objectHash.key(object);
246 }
247 
254 {
256 
257  d->intHash.remove(sender);
258  d->stringHash.remove(sender);
259  d->widgetHash.remove(sender);
260  d->objectHash.remove(sender);
261 }
262 
267 
272 {
274  if (d->intHash.contains(sender))
275  emit mapped(d->intHash.value(sender));
276  if (d->stringHash.contains(sender))
277  emit mapped(d->stringHash.value(sender));
278  if (d->widgetHash.contains(sender))
279  emit mapped(d->widgetHash.value(sender));
280  if (d->objectHash.contains(sender))
281  emit mapped(d->objectHash.value(sender));
282 }
283 
284 
332 
333 #include "moc_qsignalmapper.cpp"
334 
335 #endif // QT_NO_SIGNALMAPPER
336 
double d
Definition: qnumeric_p.h:62
void removeMappings(QObject *sender)
Removes all mappings for sender.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
QHash< QObject *, QObject * > objectHash
#define SLOT(a)
Definition: qobjectdefs.h:226
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QSignalMapper class bundles signals from identifiable senders.
Definition: qsignalmapper.h:56
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
QObject * mapping(int id) const
Returns the sender QObject that is associated with the id.
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition: qobject.cpp:2327
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define Q_Q(Class)
Definition: qglobal.h:2483
void setMapping(QObject *sender, int id)
Adds a mapping so that when map() is signalled from the given sender, the signal mapped(id) is emitte...
#define SIGNAL(a)
Definition: qobjectdefs.h:227
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
~QSignalMapper()
Destroys the QSignalMapper.
const char * name
#define emit
Definition: qobjectdefs.h:76
void mapped(int)
This signal is emitted when map() is signalled from an object that has an integer mapping set...
QHash< QObject *, QWidget * > widgetHash
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
void map()
This slot emits signals based on which object sends signals to it.
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QObject * parent
Definition: qobject.h:92
QHash< QObject *, int > intHash
QSignalMapper(QObject *parent=0)
Constructs a QSignalMapper with parent parent.
QHash< QObject *, QString > stringHash
#define text
Definition: qobjectdefs.h:80