Engauge Digitizer 2
Loading...
Searching...
No Matches
Segment.h
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#ifndef SEGMENT_H
8#define SEGMENT_H
9
10#include <QList>
11#include <QObject>
12#include <QPointF>
13
15class QGraphicsScene;
16class QTextStream;
17class SegmentLine;
18
21class Segment : public QObject
22{
23 Q_OBJECT;
24
25public:
27 Segment(QGraphicsScene &scene,
28 int yLast,
29 bool isGnuplot);
30 ~Segment();
31
33 void appendColumn(int x, int y, const DocumentModelSegments &modelSegments);
34
36 QList<QPoint> fillPoints(const DocumentModelSegments &modelSegments);
37
40 QPointF firstPoint () const;
41
43 void forwardMousePress ();
44
46 double length() const;
47
49 int lineCount() const;
50
52 void lockHoverState ();
53
58 void removeUnneededLines(int *foldedLines);
59
61 void updateModelSegment(const DocumentModelSegments &modelSegments);
62
63public slots:
64
66 void slotHover (bool hover);
67
68signals:
69
71 void signalMouseClickOnSegment (QPointF posSegmentStart);
72
73private:
74 Segment();
75
76 // While filling corners, create a point if any of the following are true:
77 // -it is the first point of the any line segment
78 // -it is different than the previous point
79 // While not filling corners, create a point if any of the following are true:
80 // -it is the first point of the first line segment
81 // -it is different than the previous point
82 void createAcceptablePoint(bool *pFirst,
83 QList<QPoint> *pList,
84 double *xPrev,
85 double *yPrev,
86 double x,
87 double y);
88
95 void dumpToGnuplot (QTextStream &strDump,
96 int xInt,
97 int yInt,
98 const SegmentLine *lineOld,
99 const SegmentLine *lineNew) const;
100
101 // Create evenly spaced points along the segment, with extra points to fill in corners.This algorithm is the
102 // same as fillPointsWithoutFillingCorners except extra points are inserted at the corners
103 QList<QPoint> fillPointsFillingCorners(const DocumentModelSegments &modelSegments);
104
105 // Create evenly spaced points along the segment, without extra points in corners
106 QList<QPoint> fillPointsWithoutFillingCorners(const DocumentModelSegments &modelSegments);
107
108 // A corner is defined as a point where the incoming slope is positive and the outgoing slope is zero
109 // or negative, or incoming slope is negative and the outgoing slope is zero or positive
110 bool isCorner (double yLast,
111 double yPrev,
112 double yNext) const;
113
114 // Return true if point are a half pixel or less away from a line
115 bool pointIsCloseToLine(double xLeft, double yLeft, double xInt, double yInt,
116 double xRight, double yRight);
117
118 // Return true if points are a half pixel or less away from a line
119 bool pointsAreCloseToLine(double xLeft, double yLeft, QList<QPoint> removedPoints,
120 double xRight, double yRight);
121
122 QGraphicsScene &m_scene;
123
124 // Y value of last point which is in previous column
125 int m_yLast;
126
127 // Total length of lines owned by this segment, as floating point to allow fractional increments
128 double m_length;
129
130 // This segment is drawn as a series of line segments
131 QList<SegmentLine*> m_lines;
132
133 // True for gnuplot input files for debugging
134 bool m_isGnuplot;
135};
136
137#endif // SEGMENT_H
Model for DlgSettingsSegments and CmdSettingsSegments.
This class is a special case of the standard QGraphicsLineItem for segments.
Definition SegmentLine.h:18
void lockHoverState()
Disable hover events. This is used only by DlgSettingsSegments to stop hover events in the preview wi...
Definition Segment.cpp:386
void signalMouseClickOnSegment(QPointF posSegmentStart)
Pass mouse press event, with coordinates of first point in the Segment since that info uniquely ident...
double length() const
Get method for length in pixels.
Definition Segment.cpp:376
int lineCount() const
Get method for number of lines.
Definition Segment.cpp:381
QList< QPoint > fillPoints(const DocumentModelSegments &modelSegments)
Create evenly spaced points along the segment.
Definition Segment.cpp:206
Segment(QGraphicsScene &scene, int yLast, bool isGnuplot)
Single constructor.
Definition Segment.cpp:23
void forwardMousePress()
Forward mouse press event from a component SegmentLine that was just clicked on.
Definition Segment.cpp:299
void slotHover(bool hover)
Slot for hover enter/leave events in the associated SegmentLines.
Definition Segment.cpp:539
void updateModelSegment(const DocumentModelSegments &modelSegments)
Update this segment given the new settings.
Definition Segment.cpp:551
~Segment()
Definition Segment.cpp:33
void appendColumn(int x, int y, const DocumentModelSegments &modelSegments)
Add some more pixels in a new column to an active segment.
Definition Segment.cpp:43
QPointF firstPoint() const
Coordinates of first point in Segment.
Definition Segment.cpp:282
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:432