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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/doc/tutorial2.doc:15 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>chart/setdataform.cpp Example File</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td 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="mainclasses.html">
<font color="#004faf">Main Classes</font></a>
| <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
| <a href="groups.html">
<font color="#004faf">Grouped Classes</font></a>
| <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<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>
<pre>#include "setdataform.h"
#include "chartform.h"
#include <<a href="tqcolordialog-h.html">tqcolordialog.h</a>>
#include <<a href="tqcombobox-h.html">tqcombobox.h</a>>
#include <<a href="qlayout-h.html">ntqlayout.h</a>>
#include <<a href="tqpixmap-h.html">tqpixmap.h</a>>
#include <<a href="tqpushbutton-h.html">tqpushbutton.h</a>>
#include <<a href="tqtable-h.html">tqtable.h</a>>
#include "images/pattern01.xpm"
#include "images/pattern02.xpm"
#include "images/pattern03.xpm"
#include "images/pattern04.xpm"
#include "images/pattern05.xpm"
#include "images/pattern06.xpm"
#include "images/pattern07.xpm"
#include "images/pattern08.xpm"
#include "images/pattern09.xpm"
#include "images/pattern10.xpm"
#include "images/pattern11.xpm"
#include "images/pattern12.xpm"
#include "images/pattern13.xpm"
#include "images/pattern14.xpm"
const int MAX_PATTERNS = 14;
<a name="f178"></a>SetDataForm::SetDataForm( ElementVector *elements, int decimalPlaces,
<a href="tqwidget.html">TQWidget</a>* parent, const char* name,
bool modal, WFlags f )
: <a href="tqdialog.html">TQDialog</a>( parent, name, modal, f )
{
m_elements = elements;
m_decimalPlaces = decimalPlaces;
<a href="tqwidget.html#setCaption">setCaption</a>( "Chart -- Set Data" );
<a href="tqwidget.html#resize">resize</a>( 540, 440 );
tableButtonBox = new <a href="qvboxlayout.html">TQVBoxLayout</a>( this, 11, 6, "table button box layout" );
table = new <a href="tqtable.html">TQTable</a>( this, "data table" );
table-><a href="tqtable.html#setNumCols">setNumCols</a>( 5 );
table-><a href="tqtable.html#setNumRows">setNumRows</a>( ChartForm::MAX_ELEMENTS );
table-><a href="tqtable.html#setColumnReadOnly">setColumnReadOnly</a>( 1, TRUE );
table-><a href="tqtable.html#setColumnReadOnly">setColumnReadOnly</a>( 2, TRUE );
table-><a href="tqtable.html#setColumnReadOnly">setColumnReadOnly</a>( 4, TRUE );
table-><a href="tqtable.html#setColumnWidth">setColumnWidth</a>( 0, 80 );
table-><a href="tqtable.html#setColumnWidth">setColumnWidth</a>( 1, 60 ); // Columns 1 and 4 must be equal
table-><a href="tqtable.html#setColumnWidth">setColumnWidth</a>( 2, 60 );
table-><a href="tqtable.html#setColumnWidth">setColumnWidth</a>( 3, 200 );
table-><a href="tqtable.html#setColumnWidth">setColumnWidth</a>( 4, 60 );
<a href="tqheader.html">TQHeader</a> *th = table-><a href="tqtable.html#horizontalHeader">horizontalHeader</a>();
th-><a href="tqheader.html#setLabel">setLabel</a>( 0, "Value" );
th-><a href="tqheader.html#setLabel">setLabel</a>( 1, "Color" );
th-><a href="tqheader.html#setLabel">setLabel</a>( 2, "Pattern" );
th-><a href="tqheader.html#setLabel">setLabel</a>( 3, "Label" );
th-><a href="tqheader.html#setLabel">setLabel</a>( 4, "Color" );
tableButtonBox-><a href="qboxlayout.html#addWidget">addWidget</a>( table );
buttonBox = new <a href="qhboxlayout.html">TQHBoxLayout</a>( 0, 0, 6, "button box layout" );
colorPushButton = new <a href="tqpushbutton.html">TQPushButton</a>( this, "color button" );
colorPushButton-><a href="tqbutton.html#setText">setText</a>( "&Color..." );
colorPushButton-><a href="tqwidget.html#setEnabled">setEnabled</a>( FALSE );
buttonBox-><a href="qboxlayout.html#addWidget">addWidget</a>( colorPushButton );
<a href="qspaceritem.html">TQSpacerItem</a> *spacer = new <a href="qspaceritem.html">TQSpacerItem</a>( 0, 0, TQSizePolicy::Expanding,
TQSizePolicy::Minimum );
buttonBox-><a href="qboxlayout.html#addItem">addItem</a>( spacer );
okPushButton = new <a href="tqpushbutton.html">TQPushButton</a>( this, "ok button" );
okPushButton-><a href="tqbutton.html#setText">setText</a>( "OK" );
okPushButton-><a href="tqpushbutton.html#setDefault">setDefault</a>( TRUE );
buttonBox-><a href="qboxlayout.html#addWidget">addWidget</a>( okPushButton );
cancelPushButton = new <a href="tqpushbutton.html">TQPushButton</a>( this, "cancel button" );
cancelPushButton-><a href="tqbutton.html#setText">setText</a>( "Cancel" );
cancelPushButton-><a href="tqbutton.html#setAccel">setAccel</a>( Key_Escape );
buttonBox-><a href="qboxlayout.html#addWidget">addWidget</a>( cancelPushButton );
tableButtonBox-><a href="qboxlayout.html#addLayout">addLayout</a>( buttonBox );
<a href="tqobject.html#connect">connect</a>( table, TQ_SIGNAL( <a href="tqtable.html#clicked">clicked</a>(int,int,int,const <a href="tqpoint.html">TQPoint</a>&) ),
this, TQ_SLOT( setColor(int,int) ) );
<a href="tqobject.html#connect">connect</a>( table, TQ_SIGNAL( <a href="tqtable.html#currentChanged">currentChanged</a>(int,int) ),
this, TQ_SLOT( currentChanged(int,int) ) );
<a href="tqobject.html#connect">connect</a>( table, TQ_SIGNAL( <a href="tqtable.html#valueChanged">valueChanged</a>(int,int) ),
this, TQ_SLOT( valueChanged(int,int) ) );
<a href="tqobject.html#connect">connect</a>( colorPushButton, TQ_SIGNAL( <a href="tqbutton.html#clicked">clicked</a>() ), this, TQ_SLOT( setColor() ) );
<a href="tqobject.html#connect">connect</a>( okPushButton, TQ_SIGNAL( <a href="tqbutton.html#clicked">clicked</a>() ), this, TQ_SLOT( <a href="tqdialog.html#accept">accept</a>() ) );
<a href="tqobject.html#connect">connect</a>( cancelPushButton, TQ_SIGNAL( <a href="tqbutton.html#clicked">clicked</a>() ), this, TQ_SLOT( <a href="tqdialog.html#reject">reject</a>() ) );
TQPixmap patterns[MAX_PATTERNS];
patterns[0] = TQPixmap( pattern01 );
patterns[1] = TQPixmap( pattern02 );
patterns[2] = TQPixmap( pattern03 );
patterns[3] = TQPixmap( pattern04 );
patterns[4] = TQPixmap( pattern05 );
patterns[5] = TQPixmap( pattern06 );
patterns[6] = TQPixmap( pattern07 );
patterns[7] = TQPixmap( pattern08 );
patterns[8] = TQPixmap( pattern09 );
patterns[9] = TQPixmap( pattern10 );
patterns[10] = TQPixmap( pattern11 );
patterns[11] = TQPixmap( pattern12 );
patterns[12] = TQPixmap( pattern13 );
patterns[13] = TQPixmap( pattern14 );
<a href="tqrect.html">TQRect</a> rect = table-><a href="tqtable.html#cellRect">cellRect</a>( 0, 1 );
<a href="tqpixmap.html">TQPixmap</a> pix( rect.<a href="tqrect.html#width">width</a>(), rect.<a href="tqrect.html#height">height</a>() );
for ( int i = 0; i < ChartForm::MAX_ELEMENTS; ++i ) {
Element element = (*m_elements)[i];
if ( element.isValid() )
table-><a href="tqtable.html#setText">setText</a>(
i, 0,
TQString( "%1" ).arg( element.value(), 0, 'f',
m_decimalPlaces ) );
<a href="tqcolor.html">TQColor</a> color = element.valueColor();
pix.<a href="tqpixmap.html#fill">fill</a>( color );
table-><a href="tqtable.html#setPixmap">setPixmap</a>( i, 1, pix );
table-><a href="tqtable.html#setText">setText</a>( i, 1, color.<a href="tqcolor.html#name">name</a>() );
<a href="tqcombobox.html">TQComboBox</a> *combobox = new <a href="tqcombobox.html">TQComboBox</a>;
for ( int j = 0; j < MAX_PATTERNS; ++j )
combobox-><a href="tqcombobox.html#insertItem">insertItem</a>( patterns[j] );
combobox-><a href="tqcombobox.html#setCurrentItem">setCurrentItem</a>( element.valuePattern() - 1 );
table-><a href="tqtable.html#setCellWidget">setCellWidget</a>( i, 2, combobox );
table-><a href="tqtable.html#setText">setText</a>( i, 3, element.label() );
color = element.labelColor();
pix.<a href="tqpixmap.html#fill">fill</a>( color );
table-><a href="tqtable.html#setPixmap">setPixmap</a>( i, 4, pix );
table-><a href="tqtable.html#setText">setText</a>( i, 4, color.<a href="tqcolor.html#name">name</a>() );
}
}
void <a name="f179"></a>SetDataForm::currentChanged( int, int col )
{
colorPushButton-><a href="tqwidget.html#setEnabled">setEnabled</a>( col == 1 || col == 4 );
}
void <a name="f180"></a>SetDataForm::valueChanged( int row, int col )
{
if ( col == 0 ) {
bool ok;
double d = table-><a href="tqtable.html#text">text</a>( row, col ).toDouble( &ok );
if ( ok && d > EPSILON )
table-><a href="tqtable.html#setText">setText</a>(
row, col, TQString( "%1" ).arg(
d, 0, 'f', m_decimalPlaces ) );
else if ( !table-><a href="tqtable.html#text">text</a>( row, col ).isEmpty() )
table-><a href="tqtable.html#setText">setText</a>( row, col, table-><a href="tqtable.html#text">text</a>( row, col ) + "?" );
}
}
void <a name="f181"></a>SetDataForm::setColor()
{
setColor( table-><a href="tqtable.html#currentRow">currentRow</a>(), table-><a href="tqtable.html#currentColumn">currentColumn</a>() );
table-><a href="tqwidget.html#setFocus">setFocus</a>();
}
void SetDataForm::setColor( int row, int col )
{
if ( !( col == 1 || col == 4 ) )
return;
<a href="tqcolor.html">TQColor</a> color = TQColorDialog::<a href="tqcolordialog.html#getColor">getColor</a>(
TQColor( table-><a href="tqtable.html#text">text</a>( row, col ) ),
this, "color dialog" );
if ( color.<a href="tqcolor.html#isValid">isValid</a>() ) {
<a href="tqpixmap.html">TQPixmap</a> pix = table-><a href="tqtable.html#pixmap">pixmap</a>( row, col );
pix.<a href="tqpixmap.html#fill">fill</a>( color );
table-><a href="tqtable.html#setPixmap">setPixmap</a>( row, col, pix );
table-><a href="tqtable.html#setText">setText</a>( row, col, color.<a href="tqcolor.html#name">name</a>() );
}
}
void SetDataForm::<a href="tqdialog.html#accept">accept</a>()
{
bool ok;
for ( int i = 0; i < ChartForm::MAX_ELEMENTS; ++i ) {
Element &element = (*m_elements)[i];
double d = table-><a href="tqtable.html#text">text</a>( i, 0 ).toDouble( &ok );
if ( ok )
element.setValue( d );
else
element.setValue( Element::INVALID );
element.setValueColor( TQColor( table-><a href="tqtable.html#text">text</a>( i, 1 ) ) );
element.setValuePattern(
((TQComboBox*)table-><a href="tqtable.html#cellWidget">cellWidget</a>( i, 2 ))->currentItem() + 1 );
element.setLabel( table-><a href="tqtable.html#text">text</a>( i, 3 ) );
element.setLabelColor( TQColor( table-><a href="tqtable.html#text">text</a>( i, 4 ) ) );
}
TQDialog::<a href="tqdialog.html#accept">accept</a>();
}
</pre><!-- eof -->
<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright © 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>TQt 3.3.8</div>
</table></div></address></body>
</html>
|