summaryrefslogtreecommitdiffstats
path: root/examples/chart/element.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-11-08 12:31:36 -0600
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-11-08 12:31:36 -0600
commitd796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch)
tree6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/chart/element.cpp
downloadtqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz
tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/chart/element.cpp')
-rw-r--r--examples/chart/element.cpp127
1 files changed, 127 insertions, 0 deletions
diff --git a/examples/chart/element.cpp b/examples/chart/element.cpp
new file mode 100644
index 000000000..570fccce8
--- /dev/null
+++ b/examples/chart/element.cpp
@@ -0,0 +1,127 @@
+#include "element.h"
+
+#include <qstringlist.h>
+#include <qtextstream.h>
+
+const char FIELD_SEP = ':';
+const char PROPOINT_SEP = ';';
+const char XY_SEP = ',';
+
+
+void Element::init( double value, TQColor valueColor, int valuePattern,
+ const TQString& 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
+{
+ Q_ASSERT(index >= 0 && index < MAX_PROPOINTS);
+ return m_propoints[2 * index];
+}
+
+
+double Element::proY( int index ) const
+{
+ Q_ASSERT(index >= 0 && index < MAX_PROPOINTS);
+ return m_propoints[(2 * index) + 1];
+}
+
+
+void Element::setProX( int index, double value )
+{
+ Q_ASSERT(index >= 0 && index < MAX_PROPOINTS);
+ m_propoints[2 * index] = value;
+}
+
+
+void Element::setProY( int index, double value )
+{
+ Q_ASSERT(index >= 0 && index < MAX_PROPOINTS);
+ m_propoints[(2 * index) + 1] = value;
+}
+
+
+TQTextStream &operator<<( TQTextStream &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>>( TQTextStream &s, Element &element )
+{
+ TQString data = s.readLine();
+ element.setValue( Element::INVALID );
+
+ int errors = 0;
+ bool ok;
+
+ TQStringList fields = TQStringList::split( FIELD_SEP, data );
+ if ( fields.count() >= 4 ) {
+ double value = fields[0].toDouble( &ok );
+ if ( !ok )
+ errors++;
+ TQColor valueColor = TQColor( fields[1] );
+ if ( !valueColor.isValid() )
+ errors++;
+ int valuePattern = fields[2].toInt( &ok );
+ if ( !ok )
+ errors++;
+ TQColor labelColor = TQColor( fields[3] );
+ if ( !labelColor.isValid() )
+ errors++;
+ TQStringList propoints = TQStringList::split( PROPOINT_SEP, fields[4] );
+ TQString label = data.section( FIELD_SEP, 5 );
+
+ if ( !errors ) {
+ element.set( value, valueColor, valuePattern, label, labelColor );
+ int i = 0;
+ for ( TQStringList::iterator point = propoints.begin();
+ i < Element::MAX_PROPOINTS && point != propoints.end();
+ ++i, ++point ) {
+ errors = 0;
+ TQStringList xy = TQStringList::split( 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;
+}
+