You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tqt3/doc/html/chart-element-cpp.html

170 lines
6.1 KiB

<!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&nbsp;Classes</font></a>
| <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
| <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
| <a href="groups.html">
<font color="#004faf">Grouped&nbsp;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 &lt;<a href="qstringlist-h.html">ntqstringlist.h</a>&gt;
#include &lt;<a href="qtextstream-h.html">ntqtextstream.h</a>&gt;
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>&amp; label, TQColor labelColor )
{
m_value = value;
m_valueColor = valueColor;
if ( valuePattern &lt; TQt::SolidPattern || valuePattern &gt; TQt::DiagCrossPattern )
valuePattern = TQt::SolidPattern;
m_valuePattern = valuePattern;
m_label = label;
m_labelColor = labelColor;
}
void Element::setValuePattern( int valuePattern )
{
if ( valuePattern &lt; TQt::SolidPattern || valuePattern &gt; TQt::DiagCrossPattern )
valuePattern = TQt::SolidPattern;
m_valuePattern = valuePattern;
}
double Element::proX( int index ) const
{
<a href="ntqapplication.html#Q_ASSERT">Q_ASSERT</a>(index &gt;= 0 &amp;&amp; index &lt; MAX_PROPOINTS);
return m_propoints[2 * index];
}
double Element::proY( int index ) const
{
<a href="ntqapplication.html#Q_ASSERT">Q_ASSERT</a>(index &gt;= 0 &amp;&amp; index &lt; 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 &gt;= 0 &amp;&amp; index &lt; MAX_PROPOINTS);
m_propoints[2 * index] = value;
}
void Element::setProY( int index, double value )
{
<a href="ntqapplication.html#Q_ASSERT">Q_ASSERT</a>(index &gt;= 0 &amp;&amp; index &lt; MAX_PROPOINTS);
m_propoints[(2 * index) + 1] = value;
}
TQTextStream &amp;operator&lt;&lt;( <a href="ntqtextstream.html">TQTextStream</a> &amp;s, const Element &amp;element )
{
s &lt;&lt; element.value() &lt;&lt; FIELD_SEP
&lt;&lt; element.valueColor().name() &lt;&lt; FIELD_SEP
&lt;&lt; element.valuePattern() &lt;&lt; FIELD_SEP
&lt;&lt; element.labelColor().name() &lt;&lt; FIELD_SEP;
for ( int i = 0; i &lt; Element::MAX_PROPOINTS; ++i ) {
s &lt;&lt; element.proX( i ) &lt;&lt; XY_SEP &lt;&lt; element.proY( i );
s &lt;&lt; ( i == Element::MAX_PROPOINTS - 1 ? FIELD_SEP : PROPOINT_SEP );
}
s &lt;&lt; element.label() &lt;&lt; '\n';
return s;
}
TQTextStream &amp;operator&gt;&gt;( <a href="ntqtextstream.html">TQTextStream</a> &amp;s, Element &amp;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="ntqvaluelist.html#count">count</a>() &gt;= 4 ) {
double value = fields[0].toDouble( &amp;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( &amp;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="ntqvaluelist.html#begin">begin</a>();
i &lt; Element::MAX_PROPOINTS &amp;&amp; point != propoints.<a href="ntqvaluelist.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( &amp;ok );
if ( !ok || x &lt;= 0.0 || x &gt;= 1.0 )
errors++;
double y = xy[1].toDouble( &amp;ok );
if ( !ok || y &lt;= 0.0 || y &gt;= 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 &copy; 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>