2 #include "EngaugeAssert.h"
4 #include "GraphicsItemType.h"
5 #include "GraphicsLinesForCurve.h"
6 #include "GraphicsPoint.h"
7 #include "GraphicsScene.h"
11 #include "PointStyle.h"
12 #include <QGraphicsItem>
15 #include <QTextStream>
16 #include "QtToString.h"
18 #include "Transformation.h"
22 typedef QMap<double, double> XOrThetaToOrdinal;
25 m_curveName (curveName)
27 setData (DATA_KEY_GRAPHICS_ITEM_TYPE,
28 GRAPHICS_ITEM_TYPE_LINE);
29 setData (DATA_KEY_IDENTIFIER,
30 QVariant (m_curveName));
33 GraphicsLinesForCurve::~GraphicsLinesForCurve()
35 OrdinalToGraphicsPoint::iterator itr;
36 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
41 m_graphicsPoints.clear();
48 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::addPoint"
49 <<
" curve=" << m_curveName.toLatin1().data()
50 <<
" identifier=" << pointIdentifier.toLatin1().data()
51 <<
" ordinal=" << ordinal
52 <<
" pos=" << QPointFToString (graphicsPoint.
pos()).toLatin1().data()
53 <<
" newPointCount=" << (m_graphicsPoints.count() + 1);
55 m_graphicsPoints [ordinal] = &graphicsPoint;
58 QPainterPath GraphicsLinesForCurve::drawLinesSmooth ()
60 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::drawLinesSmooth"
61 <<
" curve=" << m_curveName.toLatin1().data();
67 vector<SplinePair> xy;
68 OrdinalToGraphicsPoint::const_iterator itr;
69 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
71 double ordinal = itr.key();
74 t.push_back (ordinal);
83 int segmentEndingAtPointI = 0;
87 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
93 path.moveTo (point->
pos());
96 QPointF p1 (spline.p1 (segmentEndingAtPointI).x(),
97 spline.p1 (segmentEndingAtPointI).y());
98 QPointF p2 (spline.p2 (segmentEndingAtPointI).x(),
99 spline.p2 (segmentEndingAtPointI).y());
105 ++segmentEndingAtPointI;
112 QPainterPath GraphicsLinesForCurve::drawLinesStraight ()
114 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::drawLinesStraight"
115 <<
" curve=" << m_curveName.toLatin1().data();
121 OrdinalToGraphicsPoint::const_iterator itr;
122 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
128 path.moveTo (point->
pos ());
130 path.lineTo (point->
pos ());
139 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::identifierToOrdinal"
140 <<
" identifier=" << identifier.toLatin1().data();
142 OrdinalToGraphicsPoint::const_iterator itr;
143 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
147 if (point->
data (DATA_KEY_IDENTIFIER) == identifier) {
152 ENGAUGE_ASSERT (
false);
159 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::lineMembershipPurge"
160 <<
" curve=" << m_curveName.toLatin1().data();
162 OrdinalToGraphicsPoint::iterator itr, itrNext;
163 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr = itrNext) {
172 double ordinal = itr.key ();
175 m_graphicsPoints.remove (ordinal);
181 if (lineStyle.
paletteColor() == COLOR_PALETTE_TRANSPARENT) {
183 pen = QPen (Qt::NoPen);
187 pen = QPen (QBrush (ColorPaletteToQColor (lineStyle.
paletteColor())),
199 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::lineMembershipReset"
200 <<
" curve=" << m_curveName.toLatin1().data();
202 OrdinalToGraphicsPoint::iterator itr;
203 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
211 bool GraphicsLinesForCurve::needOrdinalRenumbering ()
const
214 bool needRenumbering =
false;
215 for (
int ordinalKeyWanted = 0; ordinalKeyWanted < m_graphicsPoints.count(); ordinalKeyWanted++) {
217 double ordinalKeyGot = m_graphicsPoints.keys().at (ordinalKeyWanted);
222 if (ordinalKeyWanted != ordinalKeyGot) {
223 needRenumbering =
true;
228 return needRenumbering;
232 QTextStream &str)
const
234 DataKey type = (DataKey) data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt();
236 str << indentation <<
"GraphicsLinesForCurve=" << m_curveName
237 <<
" dataIdentifier=" << data (DATA_KEY_IDENTIFIER).toString().toLatin1().data()
238 <<
" dataType=" << dataKeyToString (type).toLatin1().data() <<
"\n";
240 indentation += INDENTATION_DELTA;
242 OrdinalToGraphicsPoint::const_iterator itr;
243 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
245 double ordinalKey = itr.key();
256 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::removePoint"
257 <<
" point=" << ordinal
258 <<
" pointCount=" << m_graphicsPoints.count();
260 ENGAUGE_ASSERT (m_graphicsPoints.contains (ordinal));
263 m_graphicsPoints.remove (ordinal);
265 delete graphicsPoint;
270 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::removeTemporaryPointIfExists";
272 OrdinalToGraphicsPoint::iterator itr;
273 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
277 m_graphicsPoints.remove (itr.key());
279 delete graphicsPoint;
285 void GraphicsLinesForCurve::renumberOrdinals ()
287 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::renumberOrdinals";
289 int ordinalKeyWanted;
293 QList<GraphicsPoint*> points;
294 for (ordinalKeyWanted = 0; ordinalKeyWanted < m_graphicsPoints.count(); ordinalKeyWanted++) {
296 GraphicsPoint *graphicsPoint = m_graphicsPoints.values().at (ordinalKeyWanted);
297 points << graphicsPoint;
300 m_graphicsPoints.clear ();
302 for (ordinalKeyWanted = 0; ordinalKeyWanted < points.count(); ordinalKeyWanted++) {
305 m_graphicsPoints [ordinalKeyWanted] = graphicsPoint;
313 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateAfterCommand"
314 <<
" curve=" << m_curveName.toLatin1().data()
315 <<
" pointCount=" << m_graphicsPoints.count();
318 if (m_graphicsPoints.contains (point.
ordinal())) {
320 graphicsPoint = m_graphicsPoints [point.
ordinal()];
335 m_graphicsPoints [point.
ordinal ()] = graphicsPoint;
340 ENGAUGE_CHECK_PTR (graphicsPoint);
346 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateCurveStyle";
348 OrdinalToGraphicsPoint::const_iterator itr;
349 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
360 bool needRenumbering = needOrdinalRenumbering ();
361 if (needRenumbering) {
367 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateGraphicsLinesToMatchGraphicsPoints"
368 <<
" numberPoints=" << m_graphicsPoints.count()
369 <<
" ordinalRenumbering=" << (needRenumbering ?
"true" :
"false");
378 m_graphicsPoints.count () < 3) {
380 path = drawLinesStraight ();
382 path = drawLinesSmooth ();
394 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateGraphicsLinesToMatchGraphicsPoints"
395 <<
" curve=" << m_curveName.toLatin1().data()
396 <<
" curveConnectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
398 if (curveConnectAs == CONNECT_AS_FUNCTION_SMOOTH ||
399 curveConnectAs == CONNECT_AS_FUNCTION_STRAIGHT) {
404 XOrThetaToOrdinal xOrThetaToOrdinal;
405 OrdinalToGraphicsPoint::iterator itrP;
406 for (itrP = m_graphicsPoints.begin(); itrP != m_graphicsPoints.end(); itrP++) {
408 double ordinal = itrP.key();
416 xOrThetaToOrdinal [pointGraph.x()] = ordinal;
420 OrdinalToGraphicsPoint temporaryList;
422 XOrThetaToOrdinal::const_iterator itrX;
423 for (itrX = xOrThetaToOrdinal.begin(); itrX != xOrThetaToOrdinal.end(); itrX++) {
425 double ordinalOld = *itrX;
428 temporaryList [ordinalNew++] = point;
432 m_graphicsPoints.clear();
433 for (itrP = temporaryList.begin(); itrP != temporaryList.end(); itrP++) {
435 double ordinal = itrP.key();
438 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.