File: classWt_1_1WViewWidget.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 (217 lines) | stat: -rw-r--r-- 15,191 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
<!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::WViewWidget 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_1WViewWidget.html">WViewWidget</a>
  </div>
</div>
<div class="contents">
<h1>Wt::WViewWidget Class Reference</h1><!-- doxytag: class="Wt::WViewWidget" --><!-- doxytag: inherits="Wt::WWebWidget" -->An abstract base class for an MVC view that is rendered using a widget.  
<a href="#_details">More...</a>
<p>
<code>#include &lt;Wt/WViewWidget&gt;</code>
<p>
<div class="dynheader">
Inheritance diagram for Wt::WViewWidget:</div>
<div class="dynsection">
<p><center><img src="classWt_1_1WViewWidget__inherit__graph.png" border="0" usemap="#Wt_1_1WViewWidget__inherit__map" alt="Inheritance graph"></center>
<map name="Wt_1_1WViewWidget__inherit__map">
<area shape="rect" href="classWt_1_1WStaticModelView.html" title="A widget that implements a view for a non&#45;changing model." alt="" coords="5,304,235,331"><area shape="rect" href="classWt_1_1WWebWidget.html" title="A base class for widgets with an HTML counterpart." alt="" coords="59,155,181,181"><area shape="rect" href="classWt_1_1WWidget.html" title="The abstract base class for a user&#45;interface component." alt="" coords="72,80,168,107"><area shape="rect" href="classWt_1_1WObject.html" title="A base class for objects that participate in the signal/slot system." alt="" coords="72,5,168,32"></map>
<center><font size="2">[<a href="graph_legend.html">legend</a>]</font></center></div>

<p>
<a href="classWt_1_1WViewWidget-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="3537a36594d1a8135d63027d6679f279"></a><!-- doxytag: member="Wt::WViewWidget::WViewWidget" ref="3537a36594d1a8135d63027d6679f279" args="(WContainerWidget *parent=0)" -->
&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WViewWidget.html#3537a36594d1a8135d63027d6679f279">WViewWidget</a> (<a class="el" href="classWt_1_1WContainerWidget.html">WContainerWidget</a> *parent=0)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Creates a new view widget. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WViewWidget.html#7dcbc05eb15c4d4168141871d5908e37">update</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Updates the view.  <a href="#7dcbc05eb15c4d4168141871d5908e37"></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_1WViewWidget.html#a7865b89645f229c4dbfc6eb9ddf46d4">load</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Loads content just before the widget is used.  <a href="#a7865b89645f229c4dbfc6eb9ddf46d4"></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_1WViewWidget.html#3481f6ab6f0db72c4489f31216b40c8b">refresh</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Refresh the widget.  <a href="#3481f6ab6f0db72c4489f31216b40c8b"></a><br></td></tr>
<tr><td colspan="2"><br><h2>Protected Member Functions</h2></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_1WViewWidget.html#f7df983ff1ca6e1368579f254b85fcd6">renderView</a> ()=0</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Creates a widget that renders the View.  <a href="#f7df983ff1ca6e1368579f254b85fcd6"></a><br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
An abstract base class for an MVC view that is rendered using a widget. 
<p>
In principle, Wt widgets are self-contained and manage both their content, behavior and layout. From the point of view of a Model-View-Controller (MVC) design pattern, they implement each of these, except for the view widgets that work in conjunction with <a class="el" href="classWt_1_1WAbstractItemModel.html" title="An abstract model for use with Wt&#39;s view classes.">WAbstractItemModel</a>. As a developer you can chose to keep Model, View and Controller together or separate them as you wish.<p>
This widget facilitates separation of the View from the Model and Controller in a particular way. The View is rendered as a Wt widget. The use of this widget provides two benefits. The classic MVC benefit is a decoupling between view and model, which may allow easier maintainance of code. In addition, this widget enforces the View to be stateless, as it is only created transiently on the server. Therefore the View does not require session resources. This may increase scalability for Internet-deployments.<p>
The rendered View widget returned by <a class="el" href="classWt_1_1WViewWidget.html#f7df983ff1ca6e1368579f254b85fcd6" title="Creates a widget that renders the View.">renderView()</a> should reflect the current model state. Whenever the model changes, rerendering can be triggered by calling <a class="el" href="classWt_1_1WViewWidget.html#7dcbc05eb15c4d4168141871d5908e37" title="Updates the view.">update()</a>.<p>
Currently, the View cannot enclose <a class="el" href="classWt_1_1WFormWidget.html">WFormWidgets</a> which would allow direct manipulation of the model (but we are working to remove this limitation in the future, and let the Model/Controller handle editing changes) and the View may only be updated by a complete rerendering of the entire view.<p>
The View widget may contain event handling code, but only in one of the following ways: <ul>
<li>
event handling implemented directly in JavaScript code </li>
<li>
event handling implemented in pre-learned stateless slot implementations </li>
</ul>
Thus, currently, event handling code related to the View cannot be implemented at server-side (but we are thinking about a solution for this as well...).<p>
Implementation example: <div class="fragment"><pre class="fragment"> <span class="comment">// Shows the contents for a specific role of a model index in a WText widget</span>
 <span class="keyword">class </span>SourceView : <span class="keyword">public</span> Wt::<a class="code" href="classWt_1_1WViewWidget.html#3537a36594d1a8135d63027d6679f279" title="Creates a new view widget.">WViewWidget</a>
 {
 <span class="keyword">public</span>:
   <span class="comment">// role is the ItemDataRole</span>
   SourceView(<span class="keywordtype">int</span> role)
     : role_(role)
   { }

   <span class="comment">// set an index</span>
   <span class="keywordtype">void</span> setIndex(<span class="keyword">const</span> <a class="code" href="classWt_1_1WModelIndex.html" title="An index to a data item in a data model.">Wt::WModelIndex</a>&amp; index) {
     <span class="keywordflow">if</span> (index != index_
         &amp;&amp; (!index.<a class="code" href="classWt_1_1WModelIndex.html#1d4b05ee51c5c6961d6123565fd77c82" title="Returns whether the index is a real valid index.">isValid</a>() || !index.<a class="code" href="classWt_1_1WModelIndex.html#7f05920329ca4b7fdbb10931afdb634e" title="Returns data in the model at this index.">data</a>(role_).empty())) {
       index_ = index;
       <a class="code" href="classWt_1_1WViewWidget.html#7dcbc05eb15c4d4168141871d5908e37" title="Updates the view.">update</a>(); <span class="comment">// trigger rerendering of the view</span>
     }
   }

 <span class="keyword">private</span>:
   <a class="code" href="classWt_1_1WModelIndex.html" title="An index to a data item in a data model.">Wt::WModelIndex</a> index_;
   <span class="keywordtype">int</span>             role_;

 <span class="keyword">protected</span>:
   <span class="keyword">virtual</span> <a class="code" href="classWt_1_1WWidget.html" title="The abstract base class for a user-interface component.">Wt::WWidget</a> *<a class="code" href="classWt_1_1WViewWidget.html#f7df983ff1ca6e1368579f254b85fcd6" title="Creates a widget that renders the View.">renderView</a>() {
     <a class="code" href="classWt_1_1WText.html" title="A widget that renders (XHTML) text.">Wt::WText</a> *result = <span class="keyword">new</span> <a class="code" href="classWt_1_1WText.html" title="A widget that renders (XHTML) text.">Wt::WText</a>();
     result-&gt;<a class="code" href="classWt_1_1WWebWidget.html#73c0244d363cd2f8bd4814fe1ebee2b1" title="Sets whether the widget is displayed inline or as a block.">setInline</a>(<span class="keyword">false</span>);

     <span class="keywordflow">if</span> (!index_.isValid())
       <span class="keywordflow">return</span> result;

     boost::any d = index_.data(role_);
     <span class="keyword">const</span> std::string&amp; t = boost::any_cast&lt;<span class="keyword">const</span> std::string&amp;&gt;(d);

     result-&gt;<a class="code" href="classWt_1_1WText.html#f22c64c4c5fed3d2aef0915a7e5c5866" title="Sets the text format.">setTextFormat</a>(<a class="code" href="namespaceWt.html#140dea437d52d3d7c438ea3bd16a1480e06bb9ae9a26d13c3dcf9f20d5067885" title="Format text as plain text.">Wt::PlainText</a>);
     result-&gt;<a class="code" href="classWt_1_1WText.html#2f788aa524d51b3962642c9f565e66e6" title="Sets the text.">setText</a>(t);

     <span class="keywordflow">return</span> result;
   }
 };
</pre></div><p>
<h3>CSS</h3>
<p>
This widget does not provide styling, and can be styled using inline or external CSS as appropriate. <hr><h2>Member Function Documentation</h2>
<a class="anchor" name="7dcbc05eb15c4d4168141871d5908e37"></a><!-- doxytag: member="Wt::WViewWidget::update" ref="7dcbc05eb15c4d4168141871d5908e37" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::WViewWidget::update           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Updates the view. 
<p>
Typically, the model will want to update the view when the model has changed.<p>
This will trigger a call to <a class="el" href="classWt_1_1WViewWidget.html#f7df983ff1ca6e1368579f254b85fcd6" title="Creates a widget that renders the View.">renderView()</a> to ask for a new rendering of the view. 
</div>
</div><p>
<a class="anchor" name="a7865b89645f229c4dbfc6eb9ddf46d4"></a><!-- doxytag: member="Wt::WViewWidget::load" ref="a7865b89645f229c4dbfc6eb9ddf46d4" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::WViewWidget::load           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Loads content just before the widget is used. 
<p>
When the widget is inserted in the widget hierarchy, this method is called. Widgets that get inserted in the widget hierarchy will be rendered. Visible widgets are rendered immediately, and invisible widgets in the back-ground (or not for a plain HTML session). This method is called when the widget is directly or indirectly inserted into the widget tree.<p>
The default implementation simply propagates the load signal to its children. You may want to override this method to delay loading of resource-intensive contents. 
<p>Reimplemented from <a class="el" href="classWt_1_1WWebWidget.html#9204a57ea6fb213be5845c01007bb944">Wt::WWebWidget</a>.</p>

</div>
</div><p>
<a class="anchor" name="3481f6ab6f0db72c4489f31216b40c8b"></a><!-- doxytag: member="Wt::WViewWidget::refresh" ref="3481f6ab6f0db72c4489f31216b40c8b" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::WViewWidget::refresh           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Refresh the widget. 
<p>
The refresh method is invoked when the locale is changed using <a class="el" href="classWt_1_1WApplication.html#5c9cc1350019d69f154a2b44cdaf2596" title="Changes the locale.">WApplication::setLocale()</a> or when the user hit the refresh button.<p>
The widget must actualize its contents in response. 
<p>Reimplemented from <a class="el" href="classWt_1_1WWebWidget.html#8d0b7883f2f77a0c24b8fb911a8086a8">Wt::WWebWidget</a>.</p>

</div>
</div><p>
<a class="anchor" name="f7df983ff1ca6e1368579f254b85fcd6"></a><!-- doxytag: member="Wt::WViewWidget::renderView" ref="f7df983ff1ca6e1368579f254b85fcd6" args="()=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::WViewWidget::renderView           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td><code> [protected, pure virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Creates a widget that renders the View. 
<p>
This method must be reimplemented to return a widget that renders the view. The returned widget will be deleted by WViewWidget. 
<p>Implemented in <a class="el" href="classWt_1_1WStaticModelView.html#07efb77007dc9311e47ee15244770426">Wt::WStaticModelView&lt; Renderer &gt;</a>.</p>

</div>
</div><p>
</div>
<hr size="1"><address style="align: right;"><small>
Generated on Fri Mar 26 17:12:08 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>