CopperSpice API
1.9.2
|
The QSignalMapper class bundles signals from identifiable senders. More...
Public Signals | |
void | mapped (const QString &text) |
void | mapped (int index) |
void | mapped (QObject *object) |
void | mapped (QWidget *widget) |
Public Signals inherited from QObject | |
void | destroyed (QObject *obj=nullptr) |
void | objectNameChanged (const QString &objectName) |
Public Slots | |
void | map () |
void | map (QObject *sender) |
Public Slots inherited from QObject | |
void | deleteLater () |
Public Methods | |
QSignalMapper (QObject *parent=nullptr) | |
~QSignalMapper () | |
QObject * | mapping (const QString &text) const |
QObject * | mapping (int id) const |
QObject * | mapping (QObject *object) const |
QObject * | mapping (QWidget *widget) const |
void | removeMappings (QObject *sender) |
void | setMapping (QObject *sender, const QString &text) |
void | setMapping (QObject *sender, int id) |
void | setMapping (QObject *sender, QObject *object) |
void | setMapping (QObject *sender, QWidget *widget) |
Public Methods inherited from QObject | |
QObject (QObject *parent=nullptr) | |
~QObject () | |
bool | blockSignals (bool block) |
const QList< QObject * > & | children () const |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
void | dumpObjectInfo () |
void | dumpObjectTree () |
QList< QString > | dynamicPropertyNames () const |
virtual bool | event (QEvent *event) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
template<typename T > | |
T | findChild (const QString &childName=QString ()) const |
template<class T > | |
QList< T > | findChildren (const QRegularExpression ®Exp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
template<class T > | |
QList< T > | findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
bool | inherits (const QString &className) const |
void | installEventFilter (QObject *filterObj) |
bool | isWidgetType () const |
bool | isWindowType () const |
void | killTimer (int id) |
const QMetaObject * | metaObject () const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const |
QObject * | parent () const |
template<class T = QVariant> | |
T | property (const QString &name) const |
void | removeEventFilter (QObject *obj) |
void | setObjectName (const QString &name) |
void | setParent (QObject *parent) |
bool | setProperty (const QString &name, const QVariant &value) |
bool | signalsBlocked () const |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
QThread * | thread () const |
Additional Inherited Members | |
Static Public Methods inherited from QObject | |
static bool | connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ()) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...)) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod) |
static QMetaObject & | staticMetaObject () |
static QString | tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >()) |
Protected Methods inherited from QObject | |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const QMetaMethod &signalMethod) const |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const QMetaMethod &signalMethod) const |
bool | isSignalConnected (const QMetaMethod &signalMethod) const |
int | receivers (const QString &signal) const |
QObject * | sender () const |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *event) |
Properties inherited from QObject | |
objectName | |
Related Functions inherited from QObject | |
T | qobject_cast (QObject *object) |
QObjectList | |
The QSignalMapper class bundles signals from identifiable senders. This class collects a set of parameterless signals, and re-emits them with integer, string or widget parameters corresponding to the object that sent the signal.
The class supports the mapping of particular strings or integers with particular objects using setMapping(). The objects' signals can then be connected to the map() slot which will emit the mapped() signal with the string or integer associated with the original signaling object. Mappings can be removed later using removeMappings().
Suppose we want to create a custom widget that contains a group of buttons (like a tool palette). One approach is to connect each button's clicked()
signal to its own custom slot; but in this example we want to connect all the buttons to a single slot and parameterize the slot by the button that was clicked.
Here is the definition of a simple custom widget that has a single signal, clicked()
, which is emitted with the text of the button that was clicked.
The only function that we need to implement is the constructor:
A list of texts is passed to the constructor. A signal mapper is constructed and for each text in the list a QPushButton is created. We connect each button's clicked()
signal to the signal mapper's map() slot, and create a mapping in the signal mapper from each button to the button's text. Finally we connect the signal mapper's mapped() signal to the custom widget's clicked()
signal. When the user clicks a button, the custom widget will emit a single clicked()
signal whose argument is the text of the button the user clicked.
|
explicit |
Constructs a QSignalMapper with the given parent.
QSignalMapper::~QSignalMapper | ( | ) |
Destroys the QSignalMapper.
|
slot |
This slot emits signals based on which object sends signals to it.
|
slot |
This slot emits signals based on the sender object.
|
signal |
This signal is emitted when map() is signalled from an object that has a string mapping set. The object's mapped string is passed in text.
|
signal |
This signal is emitted when map() is signalled from an object that has an integer mapping set. The object's mapped integer is passed in index.
|
signal |
This signal is emitted when map() is signalled from an object that has an object mapping set. The object provided by the map is passed in object.
|
signal |
This signal is emitted when map() is signalled from an object that has a widget mapping set. The object's mapped widget is passed in widget.
Returns the sender QObject associated with the given text.
QObject * QSignalMapper::mapping | ( | int | id | ) | const |
Returns the sender QObject associated with the given id.
Returns the sender QObject that is associated with the object.
Returns the sender QObject that is associated with the widget.
void QSignalMapper::removeMappings | ( | QObject * | sender | ) |
Removes all mappings for sender. This is done automatically when mapped objects are destroyed.
Adds a mapping so when map() is triggered from the sender, the signal mapped(text) is emitted. There may be at most one text for each sender.
void QSignalMapper::setMapping | ( | QObject * | sender, |
int | id | ||
) |
Adds a mapping so when map() is triggered from the sender, the signal mapped(object) is emitted. There may be at most one object for each sender.