1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QSignalMapper Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QSignalMapper Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1><p>The QSignalMapper class bundles signals from identifiable
senders. <a href="#details">More...</a></p>
<p>Inherits <a href="qobject.html">QObject</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qsignalmapper.html#QSignalMapper">__init__</a></b> (<i>self</i>, QObject <i>parent</i> = None)</li><li><div class="fn" /><b><a href="qsignalmapper.html#map">map</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qsignalmapper.html#map-2">map</a></b> (<i>self</i>, QObject <i>sender</i>)</li><li><div class="fn" />QObject <b><a href="qsignalmapper.html#mapping">mapping</a></b> (<i>self</i>, int <i>id</i>)</li><li><div class="fn" />QObject <b><a href="qsignalmapper.html#mapping-2">mapping</a></b> (<i>self</i>, QString <i>text</i>)</li><li><div class="fn" />QObject <b><a href="qsignalmapper.html#mapping-3">mapping</a></b> (<i>self</i>, QWidget <i>widget</i>)</li><li><div class="fn" />QObject <b><a href="qsignalmapper.html#mapping-4">mapping</a></b> (<i>self</i>, QObject <i>object</i>)</li><li><div class="fn" /><b><a href="qsignalmapper.html#removeMappings">removeMappings</a></b> (<i>self</i>, QObject <i>sender</i>)</li><li><div class="fn" /><b><a href="qsignalmapper.html#setMapping">setMapping</a></b> (<i>self</i>, QObject <i>sender</i>, int <i>id</i>)</li><li><div class="fn" /><b><a href="qsignalmapper.html#setMapping-2">setMapping</a></b> (<i>self</i>, QObject <i>sender</i>, QString <i>text</i>)</li><li><div class="fn" /><b><a href="qsignalmapper.html#setMapping-3">setMapping</a></b> (<i>self</i>, QObject <i>sender</i>, QWidget <i>widget</i>)</li><li><div class="fn" /><b><a href="qsignalmapper.html#setMapping-4">setMapping</a></b> (<i>self</i>, QObject <i>sender</i>, QObject <i>object</i>)</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qsignalmapper.html#mapped">mapped</a></b> (int)</li><li><div class="fn" />void <b><a href="qsignalmapper.html#mapped-2">mapped</a></b> (const QString&)</li><li><div class="fn" />void <b><a href="qsignalmapper.html#mapped-3">mapped</a></b> (QWidget*)</li><li><div class="fn" />void <b><a href="qsignalmapper.html#mapped-4">mapped</a></b> (QObject*)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QSignalMapper class bundles signals from identifiable
senders.</p>
<p>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.</p>
<p>The class supports the mapping of particular strings or integers
with particular objects using <a href="qsignalmapper.html#setMapping">setMapping</a>(). The objects'
signals can then be connected to the <a href="qsignalmapper.html#map">map</a>() slot which will emit the
<a href="qsignalmapper.html#mapped">mapped</a>() signal with the
string or integer associated with the original signalling object.
Mappings can be removed later using <a href="qsignalmapper.html#removeMappings">removeMappings</a>().</p>
<p>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 <tt>clicked()</tt> 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.</p>
<p>Here's the definition of a simple custom widget that has a
single signal, <tt>clicked()</tt>, which is emitted with the text
of the button that was clicked:</p>
<pre class="cpp">
<span class="keyword">class</span> ButtonWidget : <span class="keyword">public</span> <span class="type"><a href="qwidget.html">QWidget</a></span>
{
Q_OBJECT
<span class="keyword">public</span>:
ButtonWidget(<span class="type"><a href="qstringlist.html">QStringList</a></span> texts<span class="operator">,</span> <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent <span class="operator">=</span> <span class="number">0</span>);
<span class="keyword">signals</span>:
<span class="type">void</span> clicked(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&</span>text);
<span class="keyword">private</span>:
<span class="type">QSignalMapper</span> <span class="operator">*</span>signalMapper;
};
</pre>
<p>The only function that we need to implement is the
constructor:</p>
<pre class="cpp">
ButtonWidget<span class="operator">.</span>ButtonWidget(<span class="type"><a href="qstringlist.html">QStringList</a></span> texts<span class="operator">,</span> <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent)
: <span class="type"><a href="qwidget.html">QWidget</a></span>(parent)
{
signalMapper <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QSignalMapper</span>(<span class="keyword">this</span>);
<span class="type"><a href="qgridlayout.html">QGridLayout</a></span> <span class="operator">*</span>gridLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgridlayout.html">QGridLayout</a></span>;
<span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator"><</span> texts<span class="operator">.</span>size(); <span class="operator">+</span><span class="operator">+</span>i) {
<span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>button <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(texts<span class="operator">[</span>i<span class="operator">]</span>);
connect(button<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> signalMapper<span class="operator">,</span> SLOT(map()));
signalMapper<span class="operator">-</span><span class="operator">></span>setMapping(button<span class="operator">,</span> texts<span class="operator">[</span>i<span class="operator">]</span>);
gridLayout<span class="operator">-</span><span class="operator">></span>addWidget(button<span class="operator">,</span> i <span class="operator">/</span> <span class="number">3</span><span class="operator">,</span> i <span class="operator">%</span> <span class="number">3</span>);
}
connect(signalMapper<span class="operator">,</span> SIGNAL(mapped(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&</span>))<span class="operator">,</span>
<span class="keyword">this</span><span class="operator">,</span> SIGNAL(clicked(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&</span>)));
setLayout(gridLayout);
}
</pre>
<p>A list of texts is passed to the constructor. A signal mapper is
constructed and for each text in the list a <a href="qpushbutton.html">QPushButton</a> is created. We connect each
button's <tt>clicked()</tt> signal to the signal mapper's <a href="qsignalmapper.html#map">map</a>() slot, and create a mapping in
the signal mapper from each button to the button's text. Finally we
connect the signal mapper's <a href="qsignalmapper.html#mapped">mapped</a>() signal to the custom
widget's <tt>clicked()</tt> signal. When the user clicks a button,
the custom widget will emit a single <tt>clicked()</tt> signal
whose argument is the text of the button the user clicked.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QSignalMapper" />QSignalMapper.__init__ (<i>self</i>, <a href="qobject.html">QObject</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a <a href="qsignalmapper.html">QSignalMapper</a> with
parent <i>parent</i>.</p>
<h3 class="fn"><a name="map" />QSignalMapper.map (<i>self</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void map()</tt>.</p><p>This slot emits signals based on which object sends signals to
it.</p>
<h3 class="fn"><a name="map-2" />QSignalMapper.map (<i>self</i>, <a href="qobject.html">QObject</a> <i>sender</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void map(QObject*)</tt>.</p><p>This slot emits signals based on the <i>sender</i> object.</p>
<h3 class="fn"><a name="mapping" /><a href="qobject.html">QObject</a> QSignalMapper.mapping (<i>self</i>, int <i>id</i>)</h3><p>Returns the sender <a href="qobject.html">QObject</a> that is
associated with the <i>id</i>.</p>
<p><b>See also</b> <a href="qsignalmapper.html#setMapping">setMapping</a>().</p>
<h3 class="fn"><a name="mapping-2" /><a href="qobject.html">QObject</a> QSignalMapper.mapping (<i>self</i>, QString <i>text</i>)</h3><p>This function overloads <a href="qsignalmapper.html#mapping">mapping</a>().</p>
<h3 class="fn"><a name="mapping-3" /><a href="qobject.html">QObject</a> QSignalMapper.mapping (<i>self</i>, QWidget <i>widget</i>)</h3><p>This function overloads <a href="qsignalmapper.html#mapping">mapping</a>().</p>
<p>Returns the sender <a href="qobject.html">QObject</a> that is
associated with the <i>widget</i>.</p>
<h3 class="fn"><a name="mapping-4" /><a href="qobject.html">QObject</a> QSignalMapper.mapping (<i>self</i>, <a href="qobject.html">QObject</a> <i>object</i>)</h3><p>This function overloads <a href="qsignalmapper.html#mapping">mapping</a>().</p>
<p>Returns the sender <a href="qobject.html">QObject</a> that is
associated with the <i>object</i>.</p>
<h3 class="fn"><a name="removeMappings" />QSignalMapper.removeMappings (<i>self</i>, <a href="qobject.html">QObject</a> <i>sender</i>)</h3><p>Removes all mappings for <i>sender</i>.</p>
<p>This is done automatically when mapped objects are
destroyed.</p>
<h3 class="fn"><a name="setMapping" />QSignalMapper.setMapping (<i>self</i>, <a href="qobject.html">QObject</a> <i>sender</i>, int <i>id</i>)</h3><p>Adds a mapping so that when <a href="qsignalmapper.html#map">map</a>() is signalled from the given
<i>sender</i>, the signal mapped(<i>id</i>) is emitted.</p>
<p>There may be at most one integer ID for each sender.</p>
<p><b>See also</b> <a href="qsignalmapper.html#mapping">mapping</a>().</p>
<h3 class="fn"><a name="setMapping-2" />QSignalMapper.setMapping (<i>self</i>, <a href="qobject.html">QObject</a> <i>sender</i>, QString <i>text</i>)</h3><p>Adds a mapping so that when <a href="qsignalmapper.html#map">map</a>() is signalled from the
<i>sender</i>, the signal mapped(<i>text</i> ) is emitted.</p>
<p>There may be at most one text for each sender.</p>
<h3 class="fn"><a name="setMapping-3" />QSignalMapper.setMapping (<i>self</i>, <a href="qobject.html">QObject</a> <i>sender</i>, QWidget <i>widget</i>)</h3><p>Adds a mapping so that when <a href="qsignalmapper.html#map">map</a>() is signalled from the
<i>sender</i>, the signal mapped(<i>widget</i> ) is emitted.</p>
<p>There may be at most one widget for each sender.</p>
<h3 class="fn"><a name="setMapping-4" />QSignalMapper.setMapping (<i>self</i>, <a href="qobject.html">QObject</a> <i>sender</i>, <a href="qobject.html">QObject</a> <i>object</i>)</h3><p>Adds a mapping so that when <a href="qsignalmapper.html#map">map</a>() is signalled from the
<i>sender</i>, the signal mapped(<i>object</i> ) is emitted.</p>
<p>There may be at most one object for each sender.</p>
<hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="mapped" />void mapped (int)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted when <a href="qsignalmapper.html#map">map</a>() is signalled from an object that
has an integer mapping set. The object's mapped integer is passed
in <i>i</i>.</p>
<p><b>See also</b> <a href="qsignalmapper.html#setMapping">setMapping</a>().</p>
<h3 class="fn"><a name="mapped-2" />void mapped (const QString&)</h3><p>This signal is emitted when <a href="qsignalmapper.html#map">map</a>() is signalled from an object that
has a string mapping set. The object's mapped string is passed in
<i>text</i>.</p>
<p><b>See also</b> <a href="qsignalmapper.html#setMapping">setMapping</a>().</p>
<h3 class="fn"><a name="mapped-3" />void mapped (QWidget*)</h3><p>This signal is emitted when <a href="qsignalmapper.html#map">map</a>() is signalled from an object that
has a widget mapping set. The object's mapped widget is passed in
<i>widget</i>.</p>
<p><b>See also</b> <a href="qsignalmapper.html#setMapping">setMapping</a>().</p>
<h3 class="fn"><a name="mapped-4" />void mapped (QObject*)</h3><p>This signal is emitted when <a href="qsignalmapper.html#map">map</a>() is signalled from an object that
has an object mapping set. The object provided by the map is passed
in <i>object</i>.</p>
<p><b>See also</b> <a href="qsignalmapper.html#setMapping">setMapping</a>().</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.11.4 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qt.io">The Qt Company</a> 2015</td><td align="right" width="25%">Qt 4.8.7</td></tr></table></div></address></body></html>
|