8 #include "CurvesGraphs.h" 9 #include "CurveStyle.h" 10 #include "DocumentSerialize.h" 11 #include "EngaugeAssert.h" 13 #include "MigrateToVersion6.h" 15 #include "PointComparator.h" 16 #include <QDataStream> 19 #include <QTextStream> 20 #include <QXmlStreamReader> 21 #include <QXmlStreamWriter> 22 #include "Transformation.h" 25 const QString AXIS_CURVE_NAME (
"Axes");
26 const QString DEFAULT_GRAPH_CURVE_NAME (
"Curve1");
27 const QString DUMMY_CURVE_NAME (
"dummy");
28 const QString TAB_DELIMITER (
"\t");
30 typedef QMap<double, QString> XOrThetaToPointIdentifier;
35 m_curveName (curveName),
36 m_colorFilterSettings (colorFilterSettings),
37 m_curveStyle (curveStyle)
43 m_points (curve.
points ()),
51 const int CONVERT_ENUM_TO_RADIUS = 6;
54 qint32 int32, xScreen, yScreen;
55 double xGraph, yGraph;
70 if (m_curveName == AXIS_CURVE_NAME) {
81 for (
int i = 0; i < count; i++) {
87 if (m_curveName == AXIS_CURVE_NAME) {
90 Point point (m_curveName,
91 QPointF (xScreen, yScreen),
92 QPointF (xGraph, yGraph),
100 Point point (m_curveName,
101 QPointF (xScreen, yScreen));
117 m_points = curve.
points ();
126 m_points.push_back (point);
131 return m_colorFilterSettings;
145 const QString &identifier)
148 QList<Point>::iterator itr;
149 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
165 const QStringList &identifiers,
168 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::editPointGraph" 169 <<
" identifiers=" << identifiers.join(
" ").toLatin1().data();
174 QList<Point>::iterator itr;
175 for (itr = m_points.begin(); itr != m_points.end(); itr++) {
179 if (identifiers.contains (point.
identifier ())) {
213 QTextStream &strHtml,
216 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::exportToClipboard" 217 <<
" hashCount=" << selectedHash.count();
222 QList<Point>::const_iterator itr;
223 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
225 const Point &point = *itr;
226 if (selectedHash.contains (point.
identifier ())) {
232 strCsv <<
"X" << TAB_DELIMITER << m_curveName <<
"\n";
233 strHtml <<
"<table>\n" 234 <<
"<tr><th>X</th><th>" << m_curveName <<
"</th></tr>\n";
244 Curve curve(m_curveName,
262 strCsv << pos.x() << TAB_DELIMITER << pos.y() <<
"\n";
263 strHtml <<
"<tr><td>" << pos.x() <<
"</td><td>" << pos.y() <<
"</td></tr>\n";
271 strHtml <<
"</table>\n";
278 Points::const_iterator itr;
279 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
280 const Point &point = *itr;
287 ENGAUGE_ASSERT (
false);
294 QList<Point>::const_iterator itr;
295 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
297 const Point &point = *itr;
311 QList<Point>::const_iterator itr;
312 const Point *pointBefore = 0;
313 for (itr = m_points.begin(); itr != m_points.end(); itr++) {
315 const Point &point = *itr;
317 if (pointBefore != 0) {
327 pointBefore = &point;
331 void Curve::loadCurvePoints(QXmlStreamReader &reader)
333 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::loadCurvePoints";
337 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
338 (reader.name() != DOCUMENT_SERIALIZE_CURVE_POINTS)) {
340 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
342 if (reader.atEnd()) {
347 if (tokenType == QXmlStreamReader::StartElement) {
349 if (reader.name () == DOCUMENT_SERIALIZE_POINT) {
351 Point point (reader);
352 m_points.push_back (point);
358 reader.raiseError(QObject::tr (
"Cannot read curve data"));
362 void Curve::loadXml(QXmlStreamReader &reader)
364 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::loadXml";
368 QXmlStreamAttributes attributes = reader.attributes();
370 if (attributes.hasAttribute (DOCUMENT_SERIALIZE_CURVE_NAME)) {
372 setCurveName (attributes.value (DOCUMENT_SERIALIZE_CURVE_NAME).toString());
375 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
376 (reader.name() != DOCUMENT_SERIALIZE_CURVE)){
378 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
380 if (reader.atEnd()) {
385 if (tokenType == QXmlStreamReader::StartElement) {
387 if (reader.name() == DOCUMENT_SERIALIZE_COLOR_FILTER) {
388 m_colorFilterSettings.
loadXml(reader);
389 }
else if (reader.name() == DOCUMENT_SERIALIZE_CURVE_POINTS) {
390 loadCurvePoints(reader);
391 }
else if (reader.name() == DOCUMENT_SERIALIZE_CURVE_STYLE) {
399 if (reader.hasError()) {
410 reader.raiseError (QObject::tr (
"Cannot read curve data"));
415 const QPointF &deltaScreen)
417 Point *point = pointForPointIdentifier (pointIdentifier);
419 QPointF posScreen = deltaScreen + point->
posScreen ();
425 return m_points.count ();
428 Point *Curve::pointForPointIdentifier (
const QString pointIdentifier)
430 Points::iterator itr;
431 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
438 ENGAUGE_ASSERT (
false);
452 Points::const_iterator itr;
453 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
454 const Point &point = *itr;
469 Points::const_iterator itr;
470 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
471 const Point &point = *itr;
482 QTextStream &str)
const 484 str << indentation <<
"Curve=" << m_curveName <<
"\n";
486 indentation += INDENTATION_DELTA;
488 Points::const_iterator itr;
489 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
490 const Point &point = *itr;
504 Points::iterator itr;
505 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
508 m_points.erase (itr);
516 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::saveXml";
518 writer.writeStartElement(DOCUMENT_SERIALIZE_CURVE);
519 writer.writeAttribute(DOCUMENT_SERIALIZE_CURVE_NAME, m_curveName);
520 m_colorFilterSettings.
saveXml (writer,
526 writer.writeStartElement(DOCUMENT_SERIALIZE_CURVE_POINTS);
527 Points::const_iterator itr;
528 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
529 const Point &point = *itr;
532 writer.writeEndElement();
534 writer.writeEndElement();
547 QList<Point>::iterator itr;
548 for (itr = m_points.begin(); itr != m_points.end(); itr++) {
563 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::updatePointOrdinals" 564 <<
" curve=" << m_curveName.toLatin1().data()
565 <<
" connectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
569 if (curveConnectAs == CONNECT_AS_FUNCTION_SMOOTH ||
570 curveConnectAs == CONNECT_AS_FUNCTION_STRAIGHT) {
572 updatePointOrdinalsFunctions (transformation);
574 }
else if (curveConnectAs == CONNECT_AS_RELATION_SMOOTH ||
575 curveConnectAs == CONNECT_AS_RELATION_STRAIGHT) {
577 updatePointOrdinalsRelations ();
581 LOG4CPP_ERROR_S ((*mainCat)) <<
"Curve::updatePointOrdinals";
582 ENGAUGE_ASSERT (
false);
586 qSort (m_points.begin(),
591 void Curve::updatePointOrdinalsFunctions (
const Transformation &transformation)
595 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::updatePointOrdinalsFunctions" 596 <<
" curve=" << m_curveName.toLatin1().data()
597 <<
" connectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
600 XOrThetaToPointIdentifier xOrThetaToPointIdentifier;
601 Points::iterator itr;
602 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
618 xOrThetaToPointIdentifier [posGraph.x()] = point.
identifier();
623 QMap<QString, double> pointIdentifierToOrdinal;
625 XOrThetaToPointIdentifier::const_iterator itrX;
626 for (itrX = xOrThetaToPointIdentifier.begin(); itrX != xOrThetaToPointIdentifier.end(); itrX++) {
628 QString pointIdentifier = itrX.value();
629 pointIdentifierToOrdinal [pointIdentifier] = ordinal++;
633 for (itr = m_points.begin(); itr != m_points.end(); itr++) {
635 int ordinalNew = pointIdentifierToOrdinal [point.
identifier()];
640 void Curve::updatePointOrdinalsRelations ()
644 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::updatePointOrdinalsRelations" 645 <<
" curve=" << m_curveName.toLatin1().data()
646 <<
" connectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
649 Points::iterator itr;
651 for (itr = m_points.begin(); itr != m_points.end(); itr++) {
void removePoint(const QString &identifier)
Perform the opposite of addPointAtEnd.
QPointF positionScreen(const QString &pointIdentifier) const
Return the position, in screen coordinates, of the specified Point.
QPointF posGraph(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Accessor for graph position. Skip check if copying one instance to another.
Comparator for sorting Point class.
void saveXml(QXmlStreamWriter &writer, const QString &curveName) const
Serialize to xml.
Color filter parameters for one curve. For a class, this is handled the same as LineStyle and PointSt...
void exportToClipboard(const QHash< QString, bool > &selectedHash, const Transformation &transformation, QTextStream &strCsv, QTextStream &strHtml, CurvesGraphs &curvesGraphs) const
Export points in this Curve found in the specified point list.
const Points points() const
Return a shallow copy of the Points.
void setCurveStyle(const CurveStyle &curveStyle)
Set curve style.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void addPoint(Point point)
Add Point to this Curve.
void setColorFilterSettings(const ColorFilterSettings &colorFilterSettings)
Set color filter.
void saveXml(QXmlStreamWriter &writer) const
Serialize to stream.
Curve * curveForCurveName(const QString &curveName)
Return the axis or graph curve for the specified curve name.
int numCurves() const
Current number of graphs curves.
int numPoints() const
Number of points.
void updatePointOrdinals(const Transformation &transformation)
See CurveGraphs::updatePointOrdinals.
LineStyle lineStyle() const
Get method for LineStyle.
void setPointShape(PointShape shape)
Set method for curve point shape in specified curve.
void editPointAxis(const QPointF &posGraph, const QString &identifier)
Edit the graph coordinates of an axis point. This method does not apply to a graph point...
bool isXOnly(const QString &pointIdentifier) const
Determine if specified point has just x coordinate. Otherwise has just y coordinate, or both x and y coordinates.
void addGraphCurveAtEnd(Curve curve)
Append new graph Curve to end of Curve list.
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
static LineStyle defaultAxesCurve()
Initial default for axes curve.
QPointF posScreen() const
Accessor for screen position.
void setLineConnectAs(CurveConnectAs curveConnectAs)
Set method for connect as method for lines in specified curve.
QPointF positionGraph(const QString &pointIdentifier) const
Return the position, in graph coordinates, of the specified Point.
void setLineStyle(const LineStyle &lineStyle)
Set method for LineStyle.
Curve(const QString &curveName, const ColorFilterSettings &colorFilterSettings, const CurveStyle &curveStyle)
Constructor from scratch.
void setPosGraph(const QPointF &posGraph)
Set method for position in graph coordinates.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
ColorPalette colorPalette(int preVersion6) const
Color from color palette.
Curve & operator=(const Curve &curve)
Assignment constructor.
CallbackSearchReturn
Return values for search callback methods.
QString identifier() const
Unique identifier for a specific Point.
Converts old (=pre version 6) enums to new (=version 6) enums, for reading of old document files...
PointShape pointShape(int preVersion6) const
Point shape.
void saveXml(QXmlStreamWriter &writer, const QString &curveName) const
Save curve filter to stream.
void movePoint(const QString &pointIdentifier, const QPointF &deltaScreen)
Translate the position of a point by the specified distance vector.
void setPointRadius(int radius)
Set method for curve point radius.
void setPointLineWidth(int width)
Set method for curve point perimeter line width.
static ColorFilterSettings defaultFilter()
Initial default for any Curve.
QString loadXml(QXmlStreamReader &reader)
Load from serialized xml. Returns the curve name.
Container for all graph curves. The axes point curve is external to this class.
bool isXOnly() const
In DOCUMENT_AXES_POINTS_REQUIRED_4 modes, this is true/false if y/x coordinate is undefined...
void iterateThroughCurvePoints(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback) const
Apply functor to Points on Curve.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void setCurveName(const QString &curveName)
Change the curve name.
Container for LineStyle and PointStyle for one Curve.
void setPosScreen(const QPointF &posScreen)
Set method for position in screen coordinates.
Container for one set of digitized Points.
void editPointGraph(bool isX, bool isY, double x, double y, const QStringList &identifiers, const Transformation &transformation)
Edit the graph coordinates of one or more graph points. This method does not apply to an axis point...
void setLineColor(ColorPalette lineColor)
Set method for line color in specified curve.
void loadXml(QXmlStreamReader &reader)
Load curve filter to stream.
void setPointColor(ColorPalette curveColor)
Set method curve point color in specified curve.
Immediately terminate the current search.
CurveStyle curveStyle() const
Return the curve style.
CurveConnectAs curveConnectAs() const
Get method for connect type.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void setLineWidth(int width)
Set method for line width in specified curve.
void setPointStyle(const PointStyle &pointStyle)
Set method for PointStyle.
void iterateThroughCurveSegments(const Functor2wRet< const Point &, const Point &, CallbackSearchReturn > &ftorWithCallback) const
Apply functor to successive Points, as line segments, on Curve. This could be a bit slow...
void saveXml(QXmlStreamWriter &writer) const
Serialize curve.
void setOrdinal(double ordinal)
Set the ordinal used for ordering Points.
static PointStyle defaultGraphCurve(int index)
Initial default for index'th graph curve.
CurveConnectAs curveConnectAs(int preVersion6) const
Line drawn between points.
void setCurveName(const QString &curveName)
Update the point identifer to match the specified curve name.
ColorFilterSettings colorFilterSettings() const
Return the color filter.
QString curveName() const
Name of this Curve.