8 #include "EngaugeAssert.h"
10 #include "GraphicsItemType.h"
11 #include "GraphicsLinesForCurve.h"
12 #include "GraphicsPoint.h"
13 #include "GraphicsScene.h"
14 #include "LineStyle.h"
17 #include "PointStyle.h"
18 #include <QGraphicsItem>
21 #include <QTextStream>
22 #include "QtToString.h"
24 #include "Transformation.h"
28 typedef QMap<double, double> XOrThetaToOrdinal;
31 m_curveName (curveName)
33 setData (DATA_KEY_GRAPHICS_ITEM_TYPE,
34 GRAPHICS_ITEM_TYPE_LINE);
35 setData (DATA_KEY_IDENTIFIER,
36 QVariant (m_curveName));
39 GraphicsLinesForCurve::~GraphicsLinesForCurve()
41 OrdinalToGraphicsPoint::iterator itr;
42 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
47 m_graphicsPoints.clear();
54 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::addPoint"
55 <<
" curve=" << m_curveName.toLatin1().data()
56 <<
" identifier=" << pointIdentifier.toLatin1().data()
57 <<
" ordinal=" << ordinal
58 <<
" pos=" << QPointFToString (graphicsPoint.
pos()).toLatin1().data()
59 <<
" newPointCount=" << (m_graphicsPoints.count() + 1);
61 m_graphicsPoints [ordinal] = &graphicsPoint;
64 QPainterPath GraphicsLinesForCurve::drawLinesSmooth ()
66 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::drawLinesSmooth"
67 <<
" curve=" << m_curveName.toLatin1().data();
73 vector<SplinePair> xy;
74 OrdinalToGraphicsPoint::const_iterator itr;
75 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
77 double ordinal = itr.key();
80 t.push_back (ordinal);
92 int segmentEndingAtPointI = 0;
96 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
102 path.moveTo (point->
pos());
105 QPointF p1 (spline.p1 (segmentEndingAtPointI).x(),
106 spline.p1 (segmentEndingAtPointI).y());
107 QPointF p2 (spline.p2 (segmentEndingAtPointI).x(),
108 spline.p2 (segmentEndingAtPointI).y());
114 ++segmentEndingAtPointI;
122 QPainterPath GraphicsLinesForCurve::drawLinesStraight ()
124 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::drawLinesStraight"
125 <<
" curve=" << m_curveName.toLatin1().data();
131 OrdinalToGraphicsPoint::const_iterator itr;
132 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
138 path.moveTo (point->
pos ());
140 path.lineTo (point->
pos ());
149 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::identifierToOrdinal"
150 <<
" identifier=" << identifier.toLatin1().data();
152 OrdinalToGraphicsPoint::const_iterator itr;
153 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
157 if (point->
data (DATA_KEY_IDENTIFIER) == identifier) {
162 ENGAUGE_ASSERT (
false);
169 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::lineMembershipPurge"
170 <<
" curve=" << m_curveName.toLatin1().data();
172 OrdinalToGraphicsPoint::iterator itr, itrNext;
173 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr = itrNext) {
182 double ordinal = itr.key ();
185 m_graphicsPoints.remove (ordinal);
191 if (lineStyle.
paletteColor() == COLOR_PALETTE_TRANSPARENT) {
193 pen = QPen (Qt::NoPen);
197 pen = QPen (QBrush (ColorPaletteToQColor (lineStyle.
paletteColor())),
209 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::lineMembershipReset"
210 <<
" curve=" << m_curveName.toLatin1().data();
212 OrdinalToGraphicsPoint::iterator itr;
213 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
221 bool GraphicsLinesForCurve::needOrdinalRenumbering ()
const
224 bool needRenumbering =
false;
225 for (
int ordinalKeyWanted = 0; ordinalKeyWanted < m_graphicsPoints.count(); ordinalKeyWanted++) {
227 double ordinalKeyGot = m_graphicsPoints.keys().at (ordinalKeyWanted);
232 if (ordinalKeyWanted != ordinalKeyGot) {
233 needRenumbering =
true;
238 return needRenumbering;
242 QTextStream &str)
const
244 DataKey type = (DataKey) data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt();
246 str << indentation <<
"GraphicsLinesForCurve=" << m_curveName
247 <<
" dataIdentifier=" << data (DATA_KEY_IDENTIFIER).toString().toLatin1().data()
248 <<
" dataType=" << dataKeyToString (type).toLatin1().data() <<
"\n";
250 indentation += INDENTATION_DELTA;
252 OrdinalToGraphicsPoint::const_iterator itr;
253 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
255 double ordinalKey = itr.key();
266 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::removePoint"
267 <<
" point=" << ordinal
268 <<
" pointCount=" << m_graphicsPoints.count();
270 ENGAUGE_ASSERT (m_graphicsPoints.contains (ordinal));
273 m_graphicsPoints.remove (ordinal);
275 delete graphicsPoint;
280 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::removeTemporaryPointIfExists";
282 OrdinalToGraphicsPoint::iterator itr;
283 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
287 m_graphicsPoints.remove (itr.key());
289 delete graphicsPoint;
295 void GraphicsLinesForCurve::renumberOrdinals ()
297 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::renumberOrdinals";
299 int ordinalKeyWanted;
303 QList<GraphicsPoint*> points;
304 for (ordinalKeyWanted = 0; ordinalKeyWanted < m_graphicsPoints.count(); ordinalKeyWanted++) {
306 GraphicsPoint *graphicsPoint = m_graphicsPoints.values().at (ordinalKeyWanted);
307 points << graphicsPoint;
310 m_graphicsPoints.clear ();
312 for (ordinalKeyWanted = 0; ordinalKeyWanted < points.count(); ordinalKeyWanted++) {
315 m_graphicsPoints [ordinalKeyWanted] = graphicsPoint;
323 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateAfterCommand"
324 <<
" curve=" << m_curveName.toLatin1().data()
325 <<
" pointCount=" << m_graphicsPoints.count();
328 if (m_graphicsPoints.contains (point.
ordinal())) {
330 graphicsPoint = m_graphicsPoints [point.
ordinal()];
345 m_graphicsPoints [point.
ordinal ()] = graphicsPoint;
350 ENGAUGE_CHECK_PTR (graphicsPoint);
356 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateCurveStyle";
358 OrdinalToGraphicsPoint::const_iterator itr;
359 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
370 bool needRenumbering = needOrdinalRenumbering ();
371 if (needRenumbering) {
377 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateGraphicsLinesToMatchGraphicsPoints"
378 <<
" numberPoints=" << m_graphicsPoints.count()
379 <<
" ordinalRenumbering=" << (needRenumbering ?
"true" :
"false");
388 m_graphicsPoints.count () < 3) {
390 path = drawLinesStraight ();
392 path = drawLinesSmooth ();
404 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateGraphicsLinesToMatchGraphicsPoints"
405 <<
" curve=" << m_curveName.toLatin1().data()
406 <<
" curveConnectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
408 if (curveConnectAs == CONNECT_AS_FUNCTION_SMOOTH ||
409 curveConnectAs == CONNECT_AS_FUNCTION_STRAIGHT) {
414 XOrThetaToOrdinal xOrThetaToOrdinal;
415 OrdinalToGraphicsPoint::iterator itrP;
416 for (itrP = m_graphicsPoints.begin(); itrP != m_graphicsPoints.end(); itrP++) {
418 double ordinal = itrP.key();
426 xOrThetaToOrdinal [pointGraph.x()] = ordinal;
430 OrdinalToGraphicsPoint temporaryList;
432 XOrThetaToOrdinal::const_iterator itrX;
433 for (itrX = xOrThetaToOrdinal.begin(); itrX != xOrThetaToOrdinal.end(); itrX++) {
435 double ordinalOld = *itrX;
438 temporaryList [ordinalNew++] = point;
442 m_graphicsPoints.clear();
443 for (itrP = temporaryList.begin(); itrP != temporaryList.end(); itrP++) {
445 double ordinal = itrP.key();
448 m_graphicsPoints [ordinal] = point;
void lineMembershipReset()
Mark points as unwanted. Afterwards, lineMembershipPurge gets called.
unsigned int width() const
Width of line.
Cubic interpolation given independent and dependent value vectors.
void setWanted()
Mark point as wanted. Marking as unwanted is done by the reset function.
void updateCurveStyle(const CurveStyle &curveStyle)
Update the curve style for this curve.
double identifierToOrdinal(const QString &identifier) const
Get ordinal for specified identifier.
void printStream(QString indentation, QTextStream &str, double ordinalKey) const
Debugging method that supports print method of this class and printStream method of some other class(...
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
void setData(int key, const QVariant &data)
Proxy method for QGraphicsItem::setData.
QPointF posScreen() const
Accessor for screen position.
void setPos(const QPointF pos)
Update the position.
bool wanted() const
Identify point as wanted//unwanted.
GraphicsLinesForCurve(const QString &curveName)
Single constructor.
void updateGraphicsLinesToMatchGraphicsPoints(const LineStyle &lineStyle)
Calls to moveLinesWithDraggedPoint have finished so update the lines correspondingly.
void updateCurveStyle(const CurveStyle &curveStyle)
Update point and line styles that comprise the curve style.
QString identifier() const
Unique identifier for a specific Point.
void updatePointOrdinalsAfterDrag(const LineStyle &lineStyle, const Transformation &transformation)
See GraphicsScene::updateOrdinalsAfterDrag. Pretty much the same steps as Curve::updatePointOrdinals...
Details for a specific Point.
void removeTemporaryPointIfExists()
Remove temporary point if it exists.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
static double UNDEFINED_ORDINAL()
Get method for undefined ordinal constant.
Container for LineStyle and PointStyle for one Curve.
Details for a specific Line.
Graphics item for drawing a circular or polygonal Point.
void updateAfterCommand(GraphicsScene &scene, const PointStyle &pointStyle, const Point &point)
Update the GraphicsScene with the specified Point from the Document. If it does not exist yet in the ...
ColorPalette paletteColor() const
Line color.
void addPoint(const QString &pointIdentifier, double ordinal, GraphicsPoint &point)
Add new line.
double ordinal(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Get method for ordinal. Skip check if copying one instance to another.
GraphicsPoint * createPoint(const QString &identifier, const PointStyle &pointStyle, const QPointF &posScreen)
Create one QGraphicsItem-based object that represents one Point. It is NOT added to m_graphicsLinesFo...
QPointF pos() const
Proxy method for QGraphicsItem::pos.
QVariant data(int key) const
Proxy method for QGraphicsItem::data.
CurveConnectAs curveConnectAs() const
Get method for connect type.
Add point and line handling to generic QGraphicsScene.
void lineMembershipPurge(const LineStyle &lineStyle)
Mark the end of addPoint calls. Remove stale lines, insert missing lines, and draw the graphics lines...
void removePoint(double ordinal)
Remove the specified point. The act of deleting it will automatically remove it from the GraphicsScen...
Single X/Y pair for cubic spline interpolation initialization and calculations.
void reset()
Mark point as unwanted, and unbind any bound lines.