|
Krita Source Code Documentation
|
The KisSignalMapper class bundles signals from identifiable senders. More...
#include <KisSignalMapper.h>
Inheritance diagram for KisSignalMapper:Classes | |
| class | Private |
Public Slots | |
| void | map () |
| void | map (QObject *sender) |
Signals | |
| void | mapped (const QString &) |
| void | mapped (int) |
| void | mapped (QObject *) |
| void | mapped (QWidget *) |
Public Member Functions | |
| KisSignalMapper (QObject *parent=nullptr) | |
| 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) |
| ~KisSignalMapper () | |
Private Attributes | |
| QScopedPointer< Private > | d |
Related Symbols | |
(Note that these are not member symbols.) | |
| mapping | |
| mapping | |
| mapping | |
The KisSignalMapper class bundles signals from identifiable senders.
\inmodule QtCore \obsolete The recommended solution is connecting the signal to a lambda.
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 Q_EMIT the mapped() signal with the string or integer associated with the original signaling object. Mappings can be removed later using removeMappings().
Example: 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's 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 Q_EMIT a single clicked() signal whose argument is the text of the button the user clicked.
This class was mostly useful before lambda functions could be used as slots. The example above can be rewritten simpler without KisSignalMapper by connecting to a lambda function.
\inmodule QtCore \obsolete The recommended solution is connecting the signal to a lambda.
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 Q_EMIT the mapped() signal with the string or integer associated with the original signaling object. Mappings can be removed later using removeMappings().
Example: 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's 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 Q_EMIT a single clicked() signal whose argument is the text of the button the user clicked.
This class was mostly useful before lambda functions could be used as slots. The example above can be rewritten simpler without KisSignalMapper by connecting to a lambda function.
Definition at line 78 of file KisSignalMapper.h.
|
explicit |
Constructs a KisSignalMapper with parent parent.
Definition at line 97 of file KisSignalMapper.cpp.
| KisSignalMapper::~KisSignalMapper | ( | ) |
|
slot |
This slot emits signals based on which object sends signals to it.
Definition at line 217 of file KisSignalMapper.cpp.
References map().
|
slot |
This slot emits signals based on the sender object.
Definition at line 222 of file KisSignalMapper.cpp.
|
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 i.
|
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.
| QObject * KisSignalMapper::mapping | ( | const QString & | text | ) | const |
Definition at line 173 of file KisSignalMapper.cpp.
References d.
| QObject * KisSignalMapper::mapping | ( | int | id | ) | const |
Returns the sender QObject that is associated with the id.
Definition at line 165 of file KisSignalMapper.cpp.
References d.
| QObject * KisSignalMapper::mapping | ( | QObject * | object | ) | const |
Returns the sender QObject that is associated with the id.
Definition at line 193 of file KisSignalMapper.cpp.
References d.
| QObject * KisSignalMapper::mapping | ( | QWidget * | widget | ) | const |
Definition at line 183 of file KisSignalMapper.cpp.
References d.
| void KisSignalMapper::removeMappings | ( | QObject * | sender | ) |
Removes all mappings for sender.
This is done automatically when mapped objects are destroyed.
Definition at line 206 of file KisSignalMapper.cpp.
References d.
| void KisSignalMapper::setMapping | ( | QObject * | sender, |
| const QString & | text ) |
Adds a mapping so that when map() is signalled from the sender, the signal mapped(text ) is emitted.
There may be at most one text for each sender.
Definition at line 130 of file KisSignalMapper.cpp.
| void KisSignalMapper::setMapping | ( | QObject * | sender, |
| int | id ) |
Adds a mapping so that when map() is signalled from the given sender, the signal mapped(id) is emitted.
There may be at most one integer ID for each sender.
Definition at line 118 of file KisSignalMapper.cpp.
| void KisSignalMapper::setMapping | ( | QObject * | sender, |
| QObject * | object ) |
Adds a mapping so that when map() is signalled from the sender, the signal mapped(object ) is emitted.
There may be at most one object for each sender.
Definition at line 154 of file KisSignalMapper.cpp.
| void KisSignalMapper::setMapping | ( | QObject * | sender, |
| QWidget * | widget ) |
Adds a mapping so that when map() is signalled from the sender, the signal mapped(widget ) is emitted.
There may be at most one widget for each sender.
Definition at line 142 of file KisSignalMapper.cpp.
|
related |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the sender QObject that is associated with the widget.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the sender QObject that is associated with the object.
|
related |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the sender QObject that is associated with the widget.
|
related |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the sender QObject that is associated with the object.
|
private |
Definition at line 220 of file KisSignalMapper.h.