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);
89 int segmentEndingAtPointI = 0;
93 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
99 path.moveTo (point->
pos());
102 QPointF p1 (spline.
p1 (segmentEndingAtPointI).
x(),
103 spline.
p1 (segmentEndingAtPointI).
y());
104 QPointF p2 (spline.
p2 (segmentEndingAtPointI).
x(),
105 spline.
p2 (segmentEndingAtPointI).
y());
111 ++segmentEndingAtPointI;
118 QPainterPath GraphicsLinesForCurve::drawLinesStraight ()
120 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::drawLinesStraight" 121 <<
" curve=" << m_curveName.toLatin1().data();
127 OrdinalToGraphicsPoint::const_iterator itr;
128 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
134 path.moveTo (point->
pos ());
136 path.lineTo (point->
pos ());
145 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::identifierToOrdinal" 146 <<
" identifier=" << identifier.toLatin1().data();
148 OrdinalToGraphicsPoint::const_iterator itr;
149 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
153 if (point->
data (DATA_KEY_IDENTIFIER) == identifier) {
158 ENGAUGE_ASSERT (
false);
165 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::lineMembershipPurge" 166 <<
" curve=" << m_curveName.toLatin1().data();
168 OrdinalToGraphicsPoint::iterator itr, itrNext;
169 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr = itrNext) {
178 double ordinal = itr.key ();
181 m_graphicsPoints.remove (ordinal);
187 if (lineStyle.
paletteColor() == COLOR_PALETTE_TRANSPARENT) {
189 pen = QPen (Qt::NoPen);
193 pen = QPen (QBrush (ColorPaletteToQColor (lineStyle.
paletteColor())),
205 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::lineMembershipReset" 206 <<
" curve=" << m_curveName.toLatin1().data();
208 OrdinalToGraphicsPoint::iterator itr;
209 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
217 bool GraphicsLinesForCurve::needOrdinalRenumbering ()
const 220 bool needRenumbering =
false;
221 for (
int ordinalKeyWanted = 0; ordinalKeyWanted < m_graphicsPoints.count(); ordinalKeyWanted++) {
223 double ordinalKeyGot = m_graphicsPoints.keys().at (ordinalKeyWanted);
228 if (ordinalKeyWanted != ordinalKeyGot) {
229 needRenumbering =
true;
234 return needRenumbering;
238 QTextStream &str)
const 240 DataKey type = (DataKey) data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt();
242 str << indentation <<
"GraphicsLinesForCurve=" << m_curveName
243 <<
" dataIdentifier=" << data (DATA_KEY_IDENTIFIER).toString().toLatin1().data()
244 <<
" dataType=" << dataKeyToString (type).toLatin1().data() <<
"\n";
246 indentation += INDENTATION_DELTA;
248 OrdinalToGraphicsPoint::const_iterator itr;
249 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
251 double ordinalKey = itr.key();
262 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::removePoint" 263 <<
" point=" << ordinal
264 <<
" pointCount=" << m_graphicsPoints.count();
266 ENGAUGE_ASSERT (m_graphicsPoints.contains (ordinal));
269 m_graphicsPoints.remove (ordinal);
271 delete graphicsPoint;
276 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::removeTemporaryPointIfExists";
278 OrdinalToGraphicsPoint::iterator itr;
279 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
283 m_graphicsPoints.remove (itr.key());
285 delete graphicsPoint;
291 void GraphicsLinesForCurve::renumberOrdinals ()
293 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::renumberOrdinals";
295 int ordinalKeyWanted;
299 QList<GraphicsPoint*> points;
300 for (ordinalKeyWanted = 0; ordinalKeyWanted < m_graphicsPoints.count(); ordinalKeyWanted++) {
302 GraphicsPoint *graphicsPoint = m_graphicsPoints.values().at (ordinalKeyWanted);
303 points << graphicsPoint;
306 m_graphicsPoints.clear ();
308 for (ordinalKeyWanted = 0; ordinalKeyWanted < points.count(); ordinalKeyWanted++) {
311 m_graphicsPoints [ordinalKeyWanted] = graphicsPoint;
319 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateAfterCommand" 320 <<
" curve=" << m_curveName.toLatin1().data()
321 <<
" pointCount=" << m_graphicsPoints.count();
324 if (m_graphicsPoints.contains (point.
ordinal())) {
326 graphicsPoint = m_graphicsPoints [point.
ordinal()];
341 m_graphicsPoints [point.
ordinal ()] = graphicsPoint;
346 ENGAUGE_CHECK_PTR (graphicsPoint);
352 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateCurveStyle";
354 OrdinalToGraphicsPoint::const_iterator itr;
355 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
366 bool needRenumbering = needOrdinalRenumbering ();
367 if (needRenumbering) {
373 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateGraphicsLinesToMatchGraphicsPoints" 374 <<
" numberPoints=" << m_graphicsPoints.count()
375 <<
" ordinalRenumbering=" << (needRenumbering ?
"true" :
"false");
384 m_graphicsPoints.count () < 3) {
386 path = drawLinesStraight ();
388 path = drawLinesSmooth ();
400 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateGraphicsLinesToMatchGraphicsPoints" 401 <<
" curve=" << m_curveName.toLatin1().data()
402 <<
" curveConnectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
404 if (curveConnectAs == CONNECT_AS_FUNCTION_SMOOTH ||
405 curveConnectAs == CONNECT_AS_FUNCTION_STRAIGHT) {
410 XOrThetaToOrdinal xOrThetaToOrdinal;
411 OrdinalToGraphicsPoint::iterator itrP;
412 for (itrP = m_graphicsPoints.begin(); itrP != m_graphicsPoints.end(); itrP++) {
414 double ordinal = itrP.key();
422 xOrThetaToOrdinal [pointGraph.x()] = ordinal;
426 OrdinalToGraphicsPoint temporaryList;
428 XOrThetaToOrdinal::const_iterator itrX;
429 for (itrX = xOrThetaToOrdinal.begin(); itrX != xOrThetaToOrdinal.end(); itrX++) {
431 double ordinalOld = *itrX;
434 temporaryList [ordinalNew++] = point;
438 m_graphicsPoints.clear();
439 for (itrP = temporaryList.begin(); itrP != temporaryList.end(); itrP++) {
441 double ordinal = itrP.key();
444 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(...
double y() const
Get method for y.
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...
SplinePair p1(unsigned int i) const
Bezier p1 control point for specified interval. P0 is m_xy[i] and P3 is m_xy[i+1].
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.
double x() const
Get method for x.
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.
SplinePair p2(unsigned int i) const
Bezier p2 control point for specified interval. P0 is m_xy[i] and P3 is m_xy[i+1].
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.