Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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:
16
17 template <class Signal, class Container>
18 void emitMappedValue(QObject *sender, Signal signal, const Container &mappedValues)
19 {
20 Q_Q(QSignalMapper);
21
22 auto it = mappedValues.find(sender);
23 if (it != mappedValues.end())
24 Q_EMIT(q->*signal)(*it);
25 }
26
33
34 QHash<QObject *, int> intHash;
35 QHash<QObject *, QString> stringHash;
36 QHash<QObject *, QObject *> objectHash;
37};
38
107
114
124{
125 Q_D(QSignalMapper);
126 d->intHash.insert(sender, id);
128}
129
137{
138 Q_D(QSignalMapper);
139 d->stringHash.insert(sender, text);
141}
142
150{
151 Q_D(QSignalMapper);
152 d->objectHash.insert(sender, object);
154}
155
162{
163 Q_D(const QSignalMapper);
164 return d->intHash.key(id);
165}
166
171{
172 Q_D(const QSignalMapper);
173 return d->stringHash.key(id);
174}
175
182{
183 Q_D(const QSignalMapper);
184 return d->objectHash.key(object);
185}
186
196{
197 Q_D(QSignalMapper);
198
199 d->intHash.remove(sender);
200 d->stringHash.remove(sender);
201 d->objectHash.remove(sender);
202}
203
208
213{
214 d_func()->emitMappedValues(sender);
215}
216
251
252#include "moc_qsignalmapper.cpp"
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
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:2658
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:129
QString text
QSet< QString >::iterator it
auto signal
Combined button and popup list for selecting options.
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
#define Q_EMIT