~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/qsignalmapper.html

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="iso-8859-1"?>
 
2
<!DOCTYPE html
 
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
 
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/src/corelib/kernel/qsignalmapper.cpp -->
 
6
<head>
 
7
    <title>Qt 4.0: QSignalMapper Class Reference</title>
 
8
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
 
9
a:link { color: #004faf; text-decoration: none }
 
10
a:visited { color: #672967; text-decoration: none }
 
11
td.postheader { font-family: sans-serif }
 
12
tr.address { font-family: sans-serif }
 
13
body { background: #ffffff; color: black; }</style>
 
14
</head>
 
15
<body>
 
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 
17
<tr>
 
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
19
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="annotated.html"><font color="#004faf">Annotated</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
 
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">QSignalMapper Class Reference</h1>
 
21
<p>The QSignalMapper class bundles signals from identifiable senders. <a href="#details">More...</a></p>
 
22
<pre>#include &lt;QSignalMapper&gt;</pre><p>Part of the <a href="qtcore.html">QtCore</a> module.</p>
 
23
<p>Inherits <a href="qobject.html">QObject</a>.</p>
 
24
<ul>
 
25
<li><a href="qsignalmapper-members.html">List of all members, including inherited members</a></li>
 
26
<li><a href="qsignalmapper-qt3.html">Qt 3 support members</a></li>
 
27
</ul>
 
28
<a name="public-functions"></a>
 
29
<h3>Public Functions</h3>
 
30
<ul>
 
31
<li><div class="fn"/><b><a href="qsignalmapper.html#QSignalMapper">QSignalMapper</a></b> ( QObject * <i>parent</i> = 0 )</li>
 
32
<li><div class="fn"/><b><a href="qsignalmapper.html#dtor.QSignalMapper">~QSignalMapper</a></b> ()</li>
 
33
<li><div class="fn"/>QObject * <b><a href="qsignalmapper.html#mapping">mapping</a></b> ( int <i>id</i> ) const</li>
 
34
<li><div class="fn"/>QObject * <b><a href="qsignalmapper.html#mapping-2">mapping</a></b> ( const QString &amp; <i>id</i> ) const</li>
 
35
<li><div class="fn"/>QObject * <b><a href="qsignalmapper.html#mapping-3">mapping</a></b> ( QWidget * <i>widget</i> ) const</li>
 
36
<li><div class="fn"/>void <b><a href="qsignalmapper.html#removeMappings">removeMappings</a></b> ( QObject * <i>sender</i> )</li>
 
37
<li><div class="fn"/>void <b><a href="qsignalmapper.html#setMapping">setMapping</a></b> ( QObject * <i>sender</i>, int <i>id</i> )</li>
 
38
<li><div class="fn"/>void <b><a href="qsignalmapper.html#setMapping-2">setMapping</a></b> ( QObject * <i>sender</i>, const QString &amp; <i>text</i> )</li>
 
39
<li><div class="fn"/>void <b><a href="qsignalmapper.html#setMapping-3">setMapping</a></b> ( QObject * <i>sender</i>, QWidget * <i>widget</i> )</li>
 
40
</ul>
 
41
<ul>
 
42
<li><div class="fn"/>28 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
 
43
</ul>
 
44
<a name="public-slots"></a>
 
45
<h3>Public Slots</h3>
 
46
<ul>
 
47
<li><div class="fn"/>void <b><a href="qsignalmapper.html#map">map</a></b> ()</li>
 
48
<li><div class="fn"/>void <b><a href="qsignalmapper.html#map-2">map</a></b> ( QObject * <i>sender</i> )</li>
 
49
</ul>
 
50
<ul>
 
51
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
 
52
</ul>
 
53
<a name="signals"></a>
 
54
<h3>Signals</h3>
 
55
<ul>
 
56
<li><div class="fn"/>void <b><a href="qsignalmapper.html#mapped">mapped</a></b> ( int <i>i</i> )</li>
 
57
<li><div class="fn"/>void <b><a href="qsignalmapper.html#mapped-2">mapped</a></b> ( const QString &amp; <i>text</i> )</li>
 
58
<li><div class="fn"/>void <b><a href="qsignalmapper.html#mapped-3">mapped</a></b> ( QWidget * <i>widget</i> )</li>
 
59
</ul>
 
60
<ul>
 
61
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
 
62
</ul>
 
63
<h3>Additional Inherited Members</h3>
 
64
<ul>
 
65
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
 
66
<li><div class="fn"/>4 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
 
67
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
 
68
</ul>
 
69
<a name="details"></a>
 
70
<hr />
 
71
<h2>Detailed Description</h2>
 
72
<p>The QSignalMapper class bundles signals from identifiable senders.</p>
 
73
<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>
 
74
<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>
 
75
<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>
 
76
<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>
 
77
<pre>&nbsp;   class ButtonWidget : public QWidget
 
78
    {
 
79
        Q_OBJECT
 
80
 
 
81
    public:
 
82
        ButtonWidget(QStringList texts, QWidget *parent = 0);
 
83
 
 
84
    signals:
 
85
        void clicked(const QString &amp;text);
 
86
 
 
87
    private:
 
88
        QSignalMapper *signalMapper;
 
89
    };</pre>
 
90
<p>The only function that we need to implement is the constructor:</p>
 
91
<pre>&nbsp;   ButtonWidget::ButtonWidget(QStringList texts, QWidget *parent)
 
92
        : QWidget(parent)
 
93
    {
 
94
        signalMapper = new QSignalMapper(this);
 
95
 
 
96
        QGridLayout *gridLayout = new QGridLayout;
 
97
        for (int i = 0; i &lt; texts.size(); ++i) {
 
98
            QPushButton *button = new QPushButton(texts[i]);
 
99
            connect(button, SIGNAL(clicked()), signalMapper, SLOT(map()));
 
100
            signalMapper-&gt;setMapping(button, texts[i]);
 
101
            gridLayout-&gt;addWidget(button, i / 3, i % 3);
 
102
        }
 
103
 
 
104
        connect(signalMapper, SIGNAL(mapped(const QString &amp;)),
 
105
                this, SIGNAL(clicked(const QString &amp;)));
 
106
 
 
107
        setLayout(gridLayout);
 
108
    }</pre>
 
109
<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>
 
110
<p>See also <a href="qobject.html">QObject</a>, <a href="qbuttongroup.html">QButtonGroup</a>, and <a href="qactiongroup.html">QActionGroup</a>.</p>
 
111
<hr />
 
112
<h2>Member Function Documentation</h2>
 
113
<h3 class="fn"><a name="QSignalMapper"></a>QSignalMapper::QSignalMapper ( <a href="qobject.html">QObject</a> * <i>parent</i> = 0 )</h3>
 
114
<p>Constructs a <a href="qsignalmapper.html">QSignalMapper</a> with parent <i>parent</i>.</p>
 
115
<h3 class="fn"><a name="dtor.QSignalMapper"></a>QSignalMapper::~QSignalMapper ()</h3>
 
116
<p>Destroys the <a href="qsignalmapper.html">QSignalMapper</a>.</p>
 
117
<h3 class="fn"><a name="map"></a>void QSignalMapper::map ()&nbsp;&nbsp;<tt> [slot]</tt></h3>
 
118
<p>This slot emits signals based on which object sends signals to it.</p>
 
119
<h3 class="fn"><a name="map-2"></a>void QSignalMapper::map ( <a href="qobject.html">QObject</a> * <i>sender</i> )&nbsp;&nbsp;<tt> [slot]</tt></h3>
 
120
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
121
<p>This slot emits signals based on the <i>sender</i> object.</p>
 
122
<h3 class="fn"><a name="mapped"></a>void QSignalMapper::mapped ( int <i>i</i> )&nbsp;&nbsp;<tt> [signal]</tt></h3>
 
123
<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>
 
124
<p>See also <a href="qsignalmapper.html#setMapping">setMapping</a>().</p>
 
125
<h3 class="fn"><a name="mapped-2"></a>void QSignalMapper::mapped ( const <a href="qstring.html">QString</a> &amp; <i>text</i> )&nbsp;&nbsp;<tt> [signal]</tt></h3>
 
126
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
127
<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>
 
128
<p>See also <a href="qsignalmapper.html#setMapping">setMapping</a>().</p>
 
129
<h3 class="fn"><a name="mapped-3"></a>void QSignalMapper::mapped ( <a href="qwidget.html">QWidget</a> * <i>widget</i> )&nbsp;&nbsp;<tt> [signal]</tt></h3>
 
130
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
131
<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>
 
132
<p>See also <a href="qsignalmapper.html#setMapping">setMapping</a>().</p>
 
133
<h3 class="fn"><a name="mapping"></a><a href="qobject.html">QObject</a> * QSignalMapper::mapping ( int <i>id</i> ) const</h3>
 
134
<p>Returns the sender <a href="qobject.html">QObject</a> that is associated with the given <i>id</i>.</p>
 
135
<p>See also <a href="qsignalmapper.html#setMapping">setMapping</a>().</p>
 
136
<h3 class="fn"><a name="mapping-2"></a><a href="qobject.html">QObject</a> * QSignalMapper::mapping ( const <a href="qstring.html">QString</a> &amp; <i>id</i> ) const</h3>
 
137
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
138
<h3 class="fn"><a name="mapping-3"></a><a href="qobject.html">QObject</a> * QSignalMapper::mapping ( <a href="qwidget.html">QWidget</a> * <i>widget</i> ) const</h3>
 
139
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
140
<p>Returns the sender <a href="qobject.html">QObject</a> that is associated with the given <i>widget</i>.</p>
 
141
<h3 class="fn"><a name="removeMappings"></a>void QSignalMapper::removeMappings ( <a href="qobject.html">QObject</a> * <i>sender</i> )</h3>
 
142
<p>Removes all mappings for <i>sender</i>.</p>
 
143
<p>This is done automatically when mapped objects are destroyed.</p>
 
144
<h3 class="fn"><a name="setMapping"></a>void QSignalMapper::setMapping ( <a href="qobject.html">QObject</a> * <i>sender</i>, int <i>id</i> )</h3>
 
145
<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>
 
146
<p>There may be at most one integer ID for each object.</p>
 
147
<p>See also <a href="qsignalmapper.html#mapping">mapping</a>().</p>
 
148
<h3 class="fn"><a name="setMapping-2"></a>void QSignalMapper::setMapping ( <a href="qobject.html">QObject</a> * <i>sender</i>, const <a href="qstring.html">QString</a> &amp; <i>text</i> )</h3>
 
149
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
150
<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>text</i> ) is emitted.</p>
 
151
<p>There may be at most one text for each object.</p>
 
152
<h3 class="fn"><a name="setMapping-3"></a>void QSignalMapper::setMapping ( <a href="qobject.html">QObject</a> * <i>sender</i>, <a href="qwidget.html">QWidget</a> * <i>widget</i> )</h3>
 
153
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
154
<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>widget</i> ) is emitted.</p>
 
155
<p>There may be at most one widget for each object.</p>
 
156
<p /><address><hr /><div align="center">
 
157
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
158
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
159
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
160
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
161
</tr></table></div></address></body>
 
162
</html>