source: trunk/doc/html/chart-setdataform-cpp.html@ 203

Last change on this file since 203 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 12.3 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/doc/tutorial2.doc:15 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>chart/setdataform.cpp Example File</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { background: #ffffff; color: black; }
12--></style>
13</head>
14<body>
15
16<table border="0" cellpadding="0" cellspacing="0" width="100%">
17<tr bgcolor="#E5E5E5">
18<td valign=center>
19 <a href="index.html">
20<font color="#004faf">Home</font></a>
21 | <a href="classes.html">
22<font color="#004faf">All&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;Classes</font></a>
25 | <a href="annotated.html">
26<font color="#004faf">Annotated</font></a>
27 | <a href="groups.html">
28<font color="#004faf">Grouped&nbsp;Classes</font></a>
29 | <a href="functions.html">
30<font color="#004faf">Functions</font></a>
31</td>
32<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>chart/setdataform.cpp Example File</h1>
33
34
35<pre>#include "setdataform.h"
36#include "chartform.h"
37
38#include &lt;<a href="qcolordialog-h.html">qcolordialog.h</a>&gt;
39#include &lt;<a href="qcombobox-h.html">qcombobox.h</a>&gt;
40#include &lt;<a href="qlayout-h.html">qlayout.h</a>&gt;
41#include &lt;<a href="qpixmap-h.html">qpixmap.h</a>&gt;
42#include &lt;<a href="qpushbutton-h.html">qpushbutton.h</a>&gt;
43#include &lt;<a href="qtable-h.html">qtable.h</a>&gt;
44
45#include "images/pattern01.xpm"
46#include "images/pattern02.xpm"
47#include "images/pattern03.xpm"
48#include "images/pattern04.xpm"
49#include "images/pattern05.xpm"
50#include "images/pattern06.xpm"
51#include "images/pattern07.xpm"
52#include "images/pattern08.xpm"
53#include "images/pattern09.xpm"
54#include "images/pattern10.xpm"
55#include "images/pattern11.xpm"
56#include "images/pattern12.xpm"
57#include "images/pattern13.xpm"
58#include "images/pattern14.xpm"
59
60const int MAX_PATTERNS = 14;
61
62
63<a name="f178"></a>SetDataForm::SetDataForm( ElementVector *elements, int decimalPlaces,
64 <a href="qwidget.html">QWidget</a>* parent, const char* name,
65 bool modal, WFlags f )
66 : <a href="qdialog.html">QDialog</a>( parent, name, modal, f )
67
68{
69 m_elements = elements;
70 m_decimalPlaces = decimalPlaces;
71
72 <a href="qwidget.html#setCaption">setCaption</a>( "Chart -- Set Data" );
73 <a href="qwidget.html#resize">resize</a>( 540, 440 );
74
75 tableButtonBox = new <a href="qvboxlayout.html">QVBoxLayout</a>( this, 11, 6, "table button box layout" );
76
77 table = new <a href="qtable.html">QTable</a>( this, "data table" );
78 table-&gt;<a href="qtable.html#setNumCols">setNumCols</a>( 5 );
79 table-&gt;<a href="qtable.html#setNumRows">setNumRows</a>( ChartForm::MAX_ELEMENTS );
80 table-&gt;<a href="qtable.html#setColumnReadOnly">setColumnReadOnly</a>( 1, TRUE );
81 table-&gt;<a href="qtable.html#setColumnReadOnly">setColumnReadOnly</a>( 2, TRUE );
82 table-&gt;<a href="qtable.html#setColumnReadOnly">setColumnReadOnly</a>( 4, TRUE );
83 table-&gt;<a href="qtable.html#setColumnWidth">setColumnWidth</a>( 0, 80 );
84 table-&gt;<a href="qtable.html#setColumnWidth">setColumnWidth</a>( 1, 60 ); // Columns 1 and 4 must be equal
85 table-&gt;<a href="qtable.html#setColumnWidth">setColumnWidth</a>( 2, 60 );
86 table-&gt;<a href="qtable.html#setColumnWidth">setColumnWidth</a>( 3, 200 );
87 table-&gt;<a href="qtable.html#setColumnWidth">setColumnWidth</a>( 4, 60 );
88 <a href="qheader.html">QHeader</a> *th = table-&gt;<a href="qtable.html#horizontalHeader">horizontalHeader</a>();
89 th-&gt;<a href="qheader.html#setLabel">setLabel</a>( 0, "Value" );
90 th-&gt;<a href="qheader.html#setLabel">setLabel</a>( 1, "Color" );
91 th-&gt;<a href="qheader.html#setLabel">setLabel</a>( 2, "Pattern" );
92 th-&gt;<a href="qheader.html#setLabel">setLabel</a>( 3, "Label" );
93 th-&gt;<a href="qheader.html#setLabel">setLabel</a>( 4, "Color" );
94 tableButtonBox-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( table );
95
96 buttonBox = new <a href="qhboxlayout.html">QHBoxLayout</a>( 0, 0, 6, "button box layout" );
97
98 colorPushButton = new <a href="qpushbutton.html">QPushButton</a>( this, "color button" );
99 colorPushButton-&gt;<a href="qbutton.html#setText">setText</a>( "&amp;Color..." );
100 colorPushButton-&gt;<a href="qwidget.html#setEnabled">setEnabled</a>( FALSE );
101 buttonBox-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( colorPushButton );
102
103 <a href="qspaceritem.html">QSpacerItem</a> *spacer = new <a href="qspaceritem.html">QSpacerItem</a>( 0, 0, QSizePolicy::Expanding,
104 QSizePolicy::Minimum );
105 buttonBox-&gt;<a href="qboxlayout.html#addItem">addItem</a>( spacer );
106
107 okPushButton = new <a href="qpushbutton.html">QPushButton</a>( this, "ok button" );
108 okPushButton-&gt;<a href="qbutton.html#setText">setText</a>( "OK" );
109 okPushButton-&gt;<a href="qpushbutton.html#setDefault">setDefault</a>( TRUE );
110 buttonBox-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( okPushButton );
111
112 cancelPushButton = new <a href="qpushbutton.html">QPushButton</a>( this, "cancel button" );
113 cancelPushButton-&gt;<a href="qbutton.html#setText">setText</a>( "Cancel" );
114 cancelPushButton-&gt;<a href="qbutton.html#setAccel">setAccel</a>( Key_Escape );
115 buttonBox-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( cancelPushButton );
116
117 tableButtonBox-&gt;<a href="qboxlayout.html#addLayout">addLayout</a>( buttonBox );
118
119 <a href="qobject.html#connect">connect</a>( table, SIGNAL( <a href="qtable.html#clicked">clicked</a>(int,int,int,const <a href="qpoint.html">QPoint</a>&amp;) ),
120 this, SLOT( setColor(int,int) ) );
121 <a href="qobject.html#connect">connect</a>( table, SIGNAL( <a href="qtable.html#currentChanged">currentChanged</a>(int,int) ),
122 this, SLOT( currentChanged(int,int) ) );
123 <a href="qobject.html#connect">connect</a>( table, SIGNAL( <a href="qtable.html#valueChanged">valueChanged</a>(int,int) ),
124 this, SLOT( valueChanged(int,int) ) );
125 <a href="qobject.html#connect">connect</a>( colorPushButton, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( setColor() ) );
126 <a href="qobject.html#connect">connect</a>( okPushButton, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( <a href="qdialog.html#accept">accept</a>() ) );
127 <a href="qobject.html#connect">connect</a>( cancelPushButton, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( <a href="qdialog.html#reject">reject</a>() ) );
128
129 QPixmap patterns[MAX_PATTERNS];
130 patterns[0] = QPixmap( pattern01 );
131 patterns[1] = QPixmap( pattern02 );
132 patterns[2] = QPixmap( pattern03 );
133 patterns[3] = QPixmap( pattern04 );
134 patterns[4] = QPixmap( pattern05 );
135 patterns[5] = QPixmap( pattern06 );
136 patterns[6] = QPixmap( pattern07 );
137 patterns[7] = QPixmap( pattern08 );
138 patterns[8] = QPixmap( pattern09 );
139 patterns[9] = QPixmap( pattern10 );
140 patterns[10] = QPixmap( pattern11 );
141 patterns[11] = QPixmap( pattern12 );
142 patterns[12] = QPixmap( pattern13 );
143 patterns[13] = QPixmap( pattern14 );
144
145 <a href="qrect.html">QRect</a> rect = table-&gt;<a href="qtable.html#cellRect">cellRect</a>( 0, 1 );
146 <a href="qpixmap.html">QPixmap</a> pix( rect.<a href="qrect.html#width">width</a>(), rect.<a href="qrect.html#height">height</a>() );
147
148 for ( int i = 0; i &lt; ChartForm::MAX_ELEMENTS; ++i ) {
149 Element element = (*m_elements)[i];
150
151 if ( element.isValid() )
152 table-&gt;<a href="qtable.html#setText">setText</a>(
153 i, 0,
154 QString( "%1" ).arg( element.value(), 0, 'f',
155 m_decimalPlaces ) );
156
157 <a href="qcolor.html">QColor</a> color = element.valueColor();
158 pix.<a href="qpixmap.html#fill">fill</a>( color );
159 table-&gt;<a href="qtable.html#setPixmap">setPixmap</a>( i, 1, pix );
160 table-&gt;<a href="qtable.html#setText">setText</a>( i, 1, color.<a href="qcolor.html#name">name</a>() );
161
162 <a href="qcombobox.html">QComboBox</a> *combobox = new <a href="qcombobox.html">QComboBox</a>;
163 for ( int j = 0; j &lt; MAX_PATTERNS; ++j )
164 combobox-&gt;<a href="qcombobox.html#insertItem">insertItem</a>( patterns[j] );
165 combobox-&gt;<a href="qcombobox.html#setCurrentItem">setCurrentItem</a>( element.valuePattern() - 1 );
166 table-&gt;<a href="qtable.html#setCellWidget">setCellWidget</a>( i, 2, combobox );
167
168 table-&gt;<a href="qtable.html#setText">setText</a>( i, 3, element.label() );
169
170 color = element.labelColor();
171 pix.<a href="qpixmap.html#fill">fill</a>( color );
172 table-&gt;<a href="qtable.html#setPixmap">setPixmap</a>( i, 4, pix );
173 table-&gt;<a href="qtable.html#setText">setText</a>( i, 4, color.<a href="qcolor.html#name">name</a>() );
174 }
175
176}
177
178
179void <a name="f179"></a>SetDataForm::currentChanged( int, int col )
180{
181 colorPushButton-&gt;<a href="qwidget.html#setEnabled">setEnabled</a>( col == 1 || col == 4 );
182}
183
184
185void <a name="f180"></a>SetDataForm::valueChanged( int row, int col )
186{
187 if ( col == 0 ) {
188 bool ok;
189 double d = table-&gt;<a href="qtable.html#text">text</a>( row, col ).toDouble( &amp;ok );
190 if ( ok &amp;&amp; d &gt; EPSILON )
191 table-&gt;<a href="qtable.html#setText">setText</a>(
192 row, col, QString( "%1" ).arg(
193 d, 0, 'f', m_decimalPlaces ) );
194 else if ( !table-&gt;<a href="qtable.html#text">text</a>( row, col ).isEmpty() )
195 table-&gt;<a href="qtable.html#setText">setText</a>( row, col, table-&gt;<a href="qtable.html#text">text</a>( row, col ) + "?" );
196 }
197}
198
199
200void <a name="f181"></a>SetDataForm::setColor()
201{
202 setColor( table-&gt;<a href="qtable.html#currentRow">currentRow</a>(), table-&gt;<a href="qtable.html#currentColumn">currentColumn</a>() );
203 table-&gt;<a href="qwidget.html#setFocus">setFocus</a>();
204}
205
206
207void SetDataForm::setColor( int row, int col )
208{
209 if ( !( col == 1 || col == 4 ) )
210 return;
211
212 <a href="qcolor.html">QColor</a> color = QColorDialog::<a href="qcolordialog.html#getColor">getColor</a>(
213 QColor( table-&gt;<a href="qtable.html#text">text</a>( row, col ) ),
214 this, "color dialog" );
215 if ( color.<a href="qcolor.html#isValid">isValid</a>() ) {
216 <a href="qpixmap.html">QPixmap</a> pix = table-&gt;<a href="qtable.html#pixmap">pixmap</a>( row, col );
217 pix.<a href="qpixmap.html#fill">fill</a>( color );
218 table-&gt;<a href="qtable.html#setPixmap">setPixmap</a>( row, col, pix );
219 table-&gt;<a href="qtable.html#setText">setText</a>( row, col, color.<a href="qcolor.html#name">name</a>() );
220 }
221}
222
223
224void SetDataForm::<a href="qdialog.html#accept">accept</a>()
225{
226 bool ok;
227 for ( int i = 0; i &lt; ChartForm::MAX_ELEMENTS; ++i ) {
228 Element &amp;element = (*m_elements)[i];
229 double d = table-&gt;<a href="qtable.html#text">text</a>( i, 0 ).toDouble( &amp;ok );
230 if ( ok )
231 element.setValue( d );
232 else
233 element.setValue( Element::INVALID );
234 element.setValueColor( QColor( table-&gt;<a href="qtable.html#text">text</a>( i, 1 ) ) );
235 element.setValuePattern(
236 ((QComboBox*)table-&gt;<a href="qtable.html#cellWidget">cellWidget</a>( i, 2 ))-&gt;currentItem() + 1 );
237 element.setLabel( table-&gt;<a href="qtable.html#text">text</a>( i, 3 ) );
238 element.setLabelColor( QColor( table-&gt;<a href="qtable.html#text">text</a>( i, 4 ) ) );
239 }
240
241 QDialog::<a href="qdialog.html#accept">accept</a>();
242}
243</pre><!-- eof -->
244<p><address><hr><div align=center>
245<table width=100% cellspacing=0 border=0><tr>
246<td>Copyright &copy; 2007
247<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
248<td align=right><div align=right>Qt 3.3.8</div>
249</table></div></address></body>
250</html>
Note: See TracBrowser for help on using the repository browser.