File: classWt_1_1WAbstractItemDelegate.html

package info (click to toggle)
witty 3.1.2-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 45,512 kB
  • ctags: 35,832
  • sloc: cpp: 69,469; ansic: 66,945; xml: 4,383; sh: 594; perl: 108; makefile: 106
file content (223 lines) | stat: -rw-r--r-- 14,502 bytes parent folder | download
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Wt: Wt::WAbstractItemDelegate Class Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
      <li><a href="hierarchy.html"><span>Class&nbsp;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="namespaceWt.html">Wt</a>::<a class="el" href="classWt_1_1WAbstractItemDelegate.html">WAbstractItemDelegate</a>
  </div>
</div>
<div class="contents">
<h1>Wt::WAbstractItemDelegate Class Reference<br>
<small>
[<a class="el" href="group__modelview.html">Model/view system</a>]</small>
</h1><!-- doxytag: class="Wt::WAbstractItemDelegate" --><!-- doxytag: inherits="Wt::WObject" -->Abstract delegate class for rendering a view item.  
<a href="#_details">More...</a>
<p>
<code>#include &lt;Wt/WAbstractItemDelegate&gt;</code>
<p>
<div class="dynheader">
Inheritance diagram for Wt::WAbstractItemDelegate:</div>
<div class="dynsection">
<p><center><img src="classWt_1_1WAbstractItemDelegate__inherit__graph.png" border="0" usemap="#Wt_1_1WAbstractItemDelegate__inherit__map" alt="Inheritance graph"></center>
<map name="Wt_1_1WAbstractItemDelegate__inherit__map">
<area shape="rect" href="classWt_1_1WItemDelegate.html" title="Standard delegate class for rendering a view item." alt="" coords="29,155,163,181"><area shape="rect" href="classWt_1_1WObject.html" title="A base class for objects that participate in the signal/slot system." alt="" coords="48,5,144,32"></map>
<center><font size="2">[<a href="graph_legend.html">legend</a>]</font></center></div>

<p>
<a href="classWt_1_1WAbstractItemDelegate-members.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="9187627f08a21042eb10443ff7b8d27f"></a><!-- doxytag: member="Wt::WAbstractItemDelegate::WAbstractItemDelegate" ref="9187627f08a21042eb10443ff7b8d27f" args="(WObject *parent=0)" -->
&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WAbstractItemDelegate.html#9187627f08a21042eb10443ff7b8d27f">WAbstractItemDelegate</a> (<a class="el" href="classWt_1_1WObject.html">WObject</a> *parent=0)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Constructor. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="1503db9b186ba0f21bde4852f1bcbf8a"></a><!-- doxytag: member="Wt::WAbstractItemDelegate::~WAbstractItemDelegate" ref="1503db9b186ba0f21bde4852f1bcbf8a" args="()" -->
virtual&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WAbstractItemDelegate.html#1503db9b186ba0f21bde4852f1bcbf8a">~WAbstractItemDelegate</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Destructor. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual <a class="el" href="classWt_1_1WWidget.html">WWidget</a> *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WAbstractItemDelegate.html#dc95cc43b119f4e8ebeb36a39c015fa4">update</a> (<a class="el" href="classWt_1_1WWidget.html">WWidget</a> *widget, const <a class="el" href="classWt_1_1WModelIndex.html">WModelIndex</a> &amp;index, WFlags&lt; <a class="el" href="namespaceWt.html#8df2183a957c453839f3382e3db167d6">ViewItemRenderFlag</a> &gt; flags)=0</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Creates or updates a widget that renders an item.  <a href="#dc95cc43b119f4e8ebeb36a39c015fa4"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WAbstractItemDelegate.html#c5aefa0246f0fed2dcbf9493a98205c5">updateModelIndex</a> (<a class="el" href="classWt_1_1WWidget.html">WWidget</a> *widget, const <a class="el" href="classWt_1_1WModelIndex.html">WModelIndex</a> &amp;index)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Updates the model index of a widget.  <a href="#c5aefa0246f0fed2dcbf9493a98205c5"></a><br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
Abstract delegate class for rendering a view item. 
<p>
Rendering of an item in a <a class="el" href="classWt_1_1WTreeView.html" title="A view class that displays a model as a tree or tree table.">WTreeView</a> is delegated to an implementation of this delegate class. The default implementation used by <a class="el" href="classWt_1_1WTreeView.html" title="A view class that displays a model as a tree or tree table.">WTreeView</a> is <a class="el" href="classWt_1_1WItemDelegate.html" title="Standard delegate class for rendering a view item.">WItemDelegate</a>. To provide specialized rendering support, you can reimplement this class, and indicate to the treeview to use this delegate for rendering items.<p>
As a delegate is used for rendering multiple items, the class should not keep state about one specific item.<p>
An example of a delegate that always renders the text in a line-edit, and saves the modified value back to the (editable) model.<p>
<div class="fragment"><pre class="fragment"><span class="comment">// A custom delegate that uses an EditItem</span>
<span class="keyword">class </span>EditItemDelegate : <span class="keyword">public</span> <a class="code" href="classWt_1_1WAbstractItemDelegate.html#9187627f08a21042eb10443ff7b8d27f" title="Constructor.">WAbstractItemDelegate</a>
{
  <span class="keyword">class </span>EditItem;

<span class="keyword">public</span>:
  EditItemDelegate(<a class="code" href="classWt_1_1WObject.html#1da12f5d82488adcca912c596b9398ea" title="Create a WObject with a given parent object.">WObject</a> *parent = 0)
    : <a class="code" href="classWt_1_1WAbstractItemDelegate.html#9187627f08a21042eb10443ff7b8d27f" title="Constructor.">WAbstractItemDelegate</a>(parent)
  { }

  <span class="comment">// Creates or updates an EditItem</span>
  WWidget *<a class="code" href="classWt_1_1WAbstractItemDelegate.html#dc95cc43b119f4e8ebeb36a39c015fa4" title="Creates or updates a widget that renders an item.">update</a>(WWidget *widget, <span class="keyword">const</span> WModelIndex&amp; index,
                  WFlags&lt;ViewItemRenderFlag&gt; flags)
  {
    EditItem *item;

    <span class="keywordflow">if</span> (widget) {
      item = <span class="keyword">dynamic_cast&lt;</span>EditItem *<span class="keyword">&gt;</span>(widget);
    } <span class="keywordflow">else</span> {
      item = <span class="keyword">new</span> EditItem(index);
      widget = item;
    }

    boost::any text = index.data(<a class="code" href="group__modelview.html#gg0ae864e12320f9f89172735e075ed0685ed17aded8a0e3b712698cf85a218f1f" title="Role for textual representation.">DisplayRole</a>);
    item-&gt;edit()-&gt;setText(asString(text));

    <span class="keywordflow">return</span> widget;
  }

  <span class="comment">// Updates the model index of the EditItem</span>
  <span class="keywordtype">void</span> <a class="code" href="classWt_1_1WAbstractItemDelegate.html#c5aefa0246f0fed2dcbf9493a98205c5" title="Updates the model index of a widget.">updateModelIndex</a>(WWidget *widget, <span class="keyword">const</span> WModelIndex&amp; index)
  {
    EditItem *item = <span class="keyword">dynamic_cast&lt;</span>EditItem *<span class="keyword">&gt;</span>(widget);
    item-&gt;setIndex(index);
  }

<span class="keyword">private</span>:

  <span class="comment">// A custom item widget that contains only a WLineEdit</span>
  <span class="keyword">class </span>EditItem : <span class="keyword">public</span> WContainerWidget
  {
  <span class="keyword">public</span>:
    EditItem(<span class="keyword">const</span> WModelIndex&amp; index)
      : index_(index)
    {
      edit_ = <span class="keyword">new</span> WLineEdit(<span class="keyword">this</span>);
      edit_-&gt;changed().connect(SLOT(<span class="keyword">this</span>, EditItem::onEdit));

      setAttributeValue(<span class="stringliteral">"style"</span>, <span class="stringliteral">"line-height: 1em;"</span>); <span class="comment">// Otherwise the line edit overflows the cell</span>
      setSelectable(<span class="keyword">true</span>);                             <span class="comment">// WTreeView by default disables selection</span>
    }

    <span class="comment">// Updates the model index</span>
    <span class="keywordtype">void</span> setIndex(<span class="keyword">const</span> WModelIndex&amp; index) { index_ = index; }

    <span class="comment">// Returns the editor</span>
    WLineEdit *edit()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> edit_; }

  <span class="keyword">private</span>:
    WLineEdit  *edit_;
    WModelIndex index_;

    <span class="comment">// Updates the model with the edited value</span>
    <span class="keywordtype">void</span> onEdit() {
      WAbstractItemModel *model
        = <span class="keyword">const_cast&lt;</span>WAbstractItemModel *<span class="keyword">&gt;</span>(index_.model());

      model-&gt;setData(index_, edit_-&gt;text());
    }
  };
};
</pre></div><p>
<dl class="see" compact><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1WAbstractItemView.html#2954ce5999e6ca683fef576777973496" title="Sets the default item delegate.">WTreeView::setItemDelegate()</a>, <a class="el" href="classWt_1_1WAbstractItemView.html#574bc36ec752012ba4a613e0e11e064e" title="Sets the delegate for a column.">WTreeView::setItemDelegateForColumn()</a> </dd></dl>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="dc95cc43b119f4e8ebeb36a39c015fa4"></a><!-- doxytag: member="Wt::WAbstractItemDelegate::update" ref="dc95cc43b119f4e8ebeb36a39c015fa4" args="(WWidget *widget, const WModelIndex &amp;index, WFlags&lt; ViewItemRenderFlag &gt; flags)=0" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">virtual <a class="el" href="classWt_1_1WWidget.html">WWidget</a>* Wt::WAbstractItemDelegate::update           </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classWt_1_1WWidget.html">WWidget</a> *&nbsp;</td>
          <td class="paramname"> <em>widget</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="classWt_1_1WModelIndex.html">WModelIndex</a> &amp;&nbsp;</td>
          <td class="paramname"> <em>index</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">WFlags&lt; <a class="el" href="namespaceWt.html#8df2183a957c453839f3382e3db167d6">ViewItemRenderFlag</a> &gt;&nbsp;</td>
          <td class="paramname"> <em>flags</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td><code> [pure virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Creates or updates a widget that renders an item. 
<p>
The item is specified by its model <code>index</code>, which also indicates the model. If an existing widget already renders the item, but needs to be updated, it is passed as the <code>widget</code> parameter. You may decide to create a new widget, in which case you are responsible to delete the previous <code>widget</code> if it is not reused.<p>
When <code>widget</code> is <code>0</code>, a new widget needs to be created.<p>
The <code>flags</code> parameter indicates options for rendering the item. 
<p>Implemented in <a class="el" href="classWt_1_1WItemDelegate.html#2cbc2240449a1000650f3c3b5e64bc8f">Wt::WItemDelegate</a>.</p>

</div>
</div><p>
<a class="anchor" name="c5aefa0246f0fed2dcbf9493a98205c5"></a><!-- doxytag: member="Wt::WAbstractItemDelegate::updateModelIndex" ref="c5aefa0246f0fed2dcbf9493a98205c5" args="(WWidget *widget, const WModelIndex &amp;index)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::WAbstractItemDelegate::updateModelIndex           </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classWt_1_1WWidget.html">WWidget</a> *&nbsp;</td>
          <td class="paramname"> <em>widget</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="classWt_1_1WModelIndex.html">WModelIndex</a> &amp;&nbsp;</td>
          <td class="paramname"> <em>index</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Updates the model index of a widget. 
<p>
This method is invoked by the view when due to row/column insertions or removals, an index was modified for a widget.<p>
You should reimplement this method if you are storing the model index (e.g. for editing purposes) in the <code>widget</code>, which you should update to the new <code>index</code>.<p>
The default implementation does nothing. 
<p>Reimplemented in <a class="el" href="classWt_1_1WItemDelegate.html#8d97be988b846205f61b646c3a424040">Wt::WItemDelegate</a>.</p>

</div>
</div><p>
</div>
<hr size="1"><address style="align: right;"><small>
Generated on Fri Mar 26 17:12:06 2010 for <a href="http://www.webtoolkit.eu/wt/">Wt</a> by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6</small></address>
</body>
</html>