Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qsignalmapper.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qglobal.h"
5
6#include "qsignalmapper.h"
7#include "qhash.h"
8#include "qobject_p.h"
9
11
13{
14 Q_DECLARE_PUBLIC(QSignalMapper)
15public:
17 {
18 Q_Q(QSignalMapper);
19 q->removeMappings(q->sender());
20 }
21
22 template <class Signal, class Container>
23 void emitMappedValue(QObject *sender, Signal signal, const Container &mappedValues)
24 {
25 Q_Q(QSignalMapper);
26
27 auto it = mappedValues.find(sender);
28 if (it != mappedValues.end())
29 Q_EMIT(q->*signal)(*it);
30 }
31
33 {
37 }
38
42};
43
110{
111}
112
117{
118}
119
129{
130 Q_D(QSignalMapper);
131 d->intHash.insert(sender, id);
132 connect(sender, SIGNAL(destroyed()), this, SLOT(_q_senderDestroyed()));
133}
134
142{
143 Q_D(QSignalMapper);
144 d->stringHash.insert(sender, text);
145 connect(sender, SIGNAL(destroyed()), this, SLOT(_q_senderDestroyed()));
146}
147
155{
156 Q_D(QSignalMapper);
157 d->objectHash.insert(sender, object);
158 connect(sender, SIGNAL(destroyed()), this, SLOT(_q_senderDestroyed()));
159}
160
167{
168 Q_D(const QSignalMapper);
169 return d->intHash.key(id);
170}
171
176{
177 Q_D(const QSignalMapper);
178 return d->stringHash.key(id);
179}
180
187{
188 Q_D(const QSignalMapper);
189 return d->objectHash.key(object);
190}
191
201{
202 Q_D(QSignalMapper);
203
204 d->intHash.remove(sender);
205 d->stringHash.remove(sender);
206 d->objectHash.remove(sender);
207}
208
213
218{
219 d_func()->emitMappedValues(sender);
220}
221
256
257#include "moc_qsignalmapper.cpp"
\inmodule QtCore
Definition qhash.h:818
\inmodule QtCore
Definition qobject.h:90
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
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:2521
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
iterator end()
Definition qset.h:140
iterator find(const T &value)
Definition qset.h:159
QHash< QObject *, QObject * > objectHash
QHash< QObject *, int > intHash
void emitMappedValue(QObject *sender, Signal signal, const Container &mappedValues)
QHash< QObject *, QString > stringHash
void emitMappedValues(QObject *sender)
\inmodule QtCore
void mappedString(const QString &)
void map()
This slot emits signals based on which object sends signals to it.
void mappedObject(QObject *)
QSignalMapper(QObject *parent=nullptr)
Constructs a QSignalMapper with parent parent.
QObject * mapping(int id) const
Returns the sender QObject that is associated with the id.
void removeMappings(QObject *sender)
Removes all mappings for sender.
void setMapping(QObject *sender, int id)
Adds a mapping so that when map() is signalled from the given sender, the signal mappedInt(id) is emi...
~QSignalMapper()
Destroys the QSignalMapper.
void mappedInt(int)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
QString text
QSet< QString >::iterator it
auto signal
Combined button and popup list for selecting options.
#define SLOT(a)
Definition qobjectdefs.h:51
#define SIGNAL(a)
Definition qobjectdefs.h:52
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
#define Q_EMIT
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent