Engauge Digitizer  2
Segment.h
1 #ifndef SEGMENT_H
2 #define SEGMENT_H
3 
4 #include <QList>
5 #include <QObject>
6 #include <QPointF>
7 
9 class QGraphicsScene;
10 class QTextStream;
11 class SegmentLine;
12 
15 class Segment : public QObject
16 {
17  Q_OBJECT;
18 
19 public:
21  Segment(QGraphicsScene &scene,
22  int yLast,
23  bool isGnuplot);
24  ~Segment();
25 
27  void appendColumn(int x, int y, const DocumentModelSegments &modelSegments);
28 
30  QList<QPoint> fillPoints(const DocumentModelSegments &modelSegments);
31 
34  QPointF firstPoint () const;
35 
37  void forwardMousePress ();
38 
40  double length() const;
41 
43  int lineCount() const;
44 
49  void removeUnneededLines(int *foldedLines);
50 
52  void updateModelSegment(const DocumentModelSegments &modelSegments);
53 
54 public slots:
55 
57  void slotHover (bool hover);
58 
59 signals:
60 
62  void signalMouseClickOnSegment (QPointF posSegmentStart);
63 
64 private:
65  Segment();
66 
67  // While filling corners, create a point if any of the following are true:
68  // -it is the first point of the any line segment
69  // -it is different than the previous point
70  // While not filling corners, create a point if any of the following are true:
71  // -it is the first point of the first line segment
72  // -it is different than the previous point
73  void createAcceptablePoint(bool *pFirst,
74  QList<QPoint> *pList,
75  double *xPrev,
76  double *yPrev,
77  double x,
78  double y);
79 
86  void dumpToGnuplot (QTextStream &strDump,
87  int xInt,
88  int yInt,
89  const SegmentLine *lineOld,
90  const SegmentLine *lineNew) const;
91 
92  // Create evenly spaced points along the segment, with extra points to fill in corners.This algorithm is the
93  // same as fillPointsWithoutFillingCorners except extra points are inserted at the corners
94  QList<QPoint> fillPointsFillingCorners(const DocumentModelSegments &modelSegments);
95 
96  // Create evenly spaced points along the segment, without extra points in corners
97  QList<QPoint> fillPointsWithoutFillingCorners(const DocumentModelSegments &modelSegments);
98 
99  // A corner is defined as a point where the incoming slope is positive and the outgoing slope is zero
100  // or negative, or incoming slope is negative and the outgoing slope is zero or positive
101  bool isCorner (double yLast,
102  double yPrev,
103  double yNext) const;
104 
105  // Return true if point are a half pixel or less away from a line
106  bool pointIsCloseToLine(double xLeft, double yLeft, double xInt, double yInt,
107  double xRight, double yRight);
108 
109  // Return true if points are a half pixel or less away from a line
110  bool pointsAreCloseToLine(double xLeft, double yLeft, QList<QPoint> removedPoints,
111  double xRight, double yRight);
112 
113  QGraphicsScene &m_scene;
114 
115  // Y value of last point which is in previous column
116  int m_yLast;
117 
118  // Total length of lines owned by this segment, as floating point to allow fractional increments
119  double m_length;
120 
121  // This segment is drawn as a series of line segments
122  QList<SegmentLine*> m_lines;
123 
124  // True for gnuplot input files for debugging
125  bool m_isGnuplot;
126 };
127 
128 #endif // SEGMENT_H
int lineCount() const
Get method for number of lines.
Definition: Segment.cpp:377
void removeUnneededLines(int *foldedLines)
Try to compress a segment that was just completed, by folding together line from point i to point i+1...
Definition: Segment.cpp:413
void slotHover(bool hover)
Slot for hover enter/leave events in the associated SegmentLines.
Definition: Segment.cpp:519
void forwardMousePress()
Forward mouse press event from a component SegmentLine that was just clicked on.
Definition: Segment.cpp:295
void appendColumn(int x, int y, const DocumentModelSegments &modelSegments)
Add some more pixels in a new column to an active segment.
Definition: Segment.cpp:39
double length() const
Get method for length in pixels.
Definition: Segment.cpp:372
Selectable piecewise-defined line that follows a filtered line in the image.
Definition: Segment.h:15
QList< QPoint > fillPoints(const DocumentModelSegments &modelSegments)
Create evenly spaced points along the segment.
Definition: Segment.cpp:202
void signalMouseClickOnSegment(QPointF posSegmentStart)
Pass mouse press event, with coordinates of first point in the Segment since that info uniquely ident...
void updateModelSegment(const DocumentModelSegments &modelSegments)
Update this segment given the new settings.
Definition: Segment.cpp:531
QPointF firstPoint() const
Coordinates of first point in Segment.
Definition: Segment.cpp:278
Model for DlgSettingsSegments and CmdSettingsSegments.
This class is a special case of the standard QGraphicsLineItem for segments.
Definition: SegmentLine.h:11