<!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:3 -->
< html >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=ISO-8859-1" >
< title > chart/element.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/element.cpp Example File< / h1 >
< pre > #include "element.h"
#include < < a href = "qstringlist-h.html" > ntqstringlist.h< / a > >
#include < < a href = "qtextstream-h.html" > ntqtextstream.h< / a > >
const char FIELD_SEP = ':';
const char PROPOINT_SEP = ';';
const char XY_SEP = ',';
void Element::init( double value, TQColor valueColor, int valuePattern,
const < a href = "ntqstring.html" > TQString< / a > & label, TQColor labelColor )
{
m_value = value;
m_valueColor = valueColor;
if ( valuePattern < TQt::SolidPattern || valuePattern > TQt::DiagCrossPattern )
valuePattern = TQt::SolidPattern;
m_valuePattern = valuePattern;
m_label = label;
m_labelColor = labelColor;
}
void Element::setValuePattern( int valuePattern )
{
if ( valuePattern < TQt::SolidPattern || valuePattern > TQt::DiagCrossPattern )
valuePattern = TQt::SolidPattern;
m_valuePattern = valuePattern;
}
double Element::proX( int index ) const
{
< a href = "ntqapplication.html#Q_ASSERT" > Q_ASSERT< / a > (index > = 0 & & index < MAX_PROPOINTS);
return m_propoints[2 * index];
}
double Element::proY( int index ) const
{
< a href = "ntqapplication.html#Q_ASSERT" > Q_ASSERT< / a > (index > = 0 & & index < MAX_PROPOINTS);
return m_propoints[(2 * index) + 1];
}
void Element::setProX( int index, double value )
{
< a href = "ntqapplication.html#Q_ASSERT" > Q_ASSERT< / a > (index > = 0 & & index < MAX_PROPOINTS);
m_propoints[2 * index] = value;
}
void Element::setProY( int index, double value )
{
< a href = "ntqapplication.html#Q_ASSERT" > Q_ASSERT< / a > (index > = 0 & & index < MAX_PROPOINTS);
m_propoints[(2 * index) + 1] = value;
}
TQTextStream & operator< < ( < a href = "ntqtextstream.html" > TQTextStream< / a > & s, const Element & element )
{
s < < element.value() < < FIELD_SEP
< < element.valueColor().name() < < FIELD_SEP
< < element.valuePattern() < < FIELD_SEP
< < element.labelColor().name() < < FIELD_SEP;
for ( int i = 0; i < Element::MAX_PROPOINTS; ++i ) {
s < < element.proX( i ) < < XY_SEP < < element.proY( i );
s < < ( i == Element::MAX_PROPOINTS - 1 ? FIELD_SEP : PROPOINT_SEP );
}
s < < element.label() < < '\n';
return s;
}
TQTextStream & operator> > ( < a href = "ntqtextstream.html" > TQTextStream< / a > & s, Element & element )
{
< a href = "ntqstring.html" > TQString< / a > data = s.< a href = "ntqtextstream.html#readLine" > readLine< / a > ();
element.setValue( Element::INVALID );
int errors = 0;
bool ok;
< a href = "ntqstringlist.html" > TQStringList< / a > fields = TQStringList::< a href = "ntqstringlist.html#split" > split< / a > ( FIELD_SEP, data );
if ( fields.< a href = "tqvaluelist.html#count" > count< / a > () > = 4 ) {
double value = fields[0].toDouble( & ok );
if ( !ok )
errors++;
< a href = "ntqcolor.html" > TQColor< / a > valueColor = TQColor( fields[1] );
if ( !valueColor.< a href = "ntqcolor.html#isValid" > isValid< / a > () )
errors++;
int valuePattern = fields[2].toInt( & ok );
if ( !ok )
errors++;
< a href = "ntqcolor.html" > TQColor< / a > labelColor = TQColor( fields[3] );
if ( !labelColor.< a href = "ntqcolor.html#isValid" > isValid< / a > () )
errors++;
< a href = "ntqstringlist.html" > TQStringList< / a > propoints = TQStringList::< a href = "ntqstringlist.html#split" > split< / a > ( PROPOINT_SEP, fields[4] );
< a href = "ntqstring.html" > TQString< / a > label = data.< a href = "ntqstring.html#section" > section< / a > ( FIELD_SEP, 5 );
if ( !errors ) {
element.set( value, valueColor, valuePattern, label, labelColor );
int i = 0;
for ( TQStringList::iterator point = propoints.< a href = "tqvaluelist.html#begin" > begin< / a > ();
i < Element::MAX_PROPOINTS & & point != propoints.< a href = "tqvaluelist.html#end" > end< / a > ();
++i, ++point ) {
errors = 0;
< a href = "ntqstringlist.html" > TQStringList< / a > xy = TQStringList::< a href = "ntqstringlist.html#split" > split< / a > ( XY_SEP, *point );
double x = xy[0].toDouble( & ok );
if ( !ok || x < = 0.0 || x > = 1.0 )
errors++;
double y = xy[1].toDouble( & ok );
if ( !ok || y < = 0.0 || y > = 1.0 )
errors++;
if ( errors )
x = y = Element::NO_PROPORTION;
element.setProX( i, x );
element.setProY( i, y );
}
}
}
return s;
}
< / 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 >