Auto status change to "Under Review"
@@ -1,442 +1,440 | |||||
1 | #include "Visualization/VisualizationSelectionZoneItem.h" |
|
1 | #include "Visualization/VisualizationSelectionZoneItem.h" | |
2 | #include "Visualization/VisualizationGraphWidget.h" |
|
2 | #include "Visualization/VisualizationGraphWidget.h" | |
3 | #include "Visualization/VisualizationSelectionZoneManager.h" |
|
3 | #include "Visualization/VisualizationSelectionZoneManager.h" | |
4 | #include "Visualization/VisualizationWidget.h" |
|
4 | #include "Visualization/VisualizationWidget.h" | |
5 |
|
5 | |||
6 | const QString &DEFAULT_COLOR = QStringLiteral("#E79D41"); |
|
6 | const QString &DEFAULT_COLOR = QStringLiteral("#E79D41"); | |
7 |
|
7 | |||
8 | struct VisualizationSelectionZoneItem::VisualizationSelectionZoneItemPrivate { |
|
8 | struct VisualizationSelectionZoneItem::VisualizationSelectionZoneItemPrivate { | |
9 |
|
9 | |||
10 | QCustomPlot *m_Plot; |
|
10 | QCustomPlot *m_Plot; | |
11 | double m_T1 = 0; |
|
11 | double m_T1 = 0; | |
12 | double m_T2 = 0; |
|
12 | double m_T2 = 0; | |
13 | QColor m_Color; |
|
13 | QColor m_Color; | |
14 |
|
14 | |||
15 | bool m_IsEditionEnabled = true; |
|
15 | bool m_IsEditionEnabled = true; | |
16 | double m_MovedOrinalT1 = 0; |
|
16 | double m_MovedOrinalT1 = 0; | |
17 | double m_MovedOrinalT2 = 0; |
|
17 | double m_MovedOrinalT2 = 0; | |
18 |
|
18 | |||
19 | QCPItemStraightLine *m_LeftLine; |
|
19 | QCPItemStraightLine *m_LeftLine; | |
20 | QCPItemStraightLine *m_RightLine; |
|
20 | QCPItemStraightLine *m_RightLine; | |
21 | QCPItemText *m_NameLabelItem = nullptr; |
|
21 | QCPItemText *m_NameLabelItem = nullptr; | |
22 |
|
22 | |||
23 | enum class EditionMode { NoEdition, ResizeLeft, ResizeRight, Move }; |
|
23 | enum class EditionMode { NoEdition, ResizeLeft, ResizeRight, Move }; | |
24 | EditionMode m_CurrentEditionMode; |
|
24 | EditionMode m_CurrentEditionMode; | |
25 |
|
25 | |||
26 | QVector<VisualizationSelectionZoneItem *> m_AssociatedEditedZones; |
|
26 | QVector<VisualizationSelectionZoneItem *> m_AssociatedEditedZones; | |
27 |
|
27 | |||
28 | VisualizationSelectionZoneItemPrivate(QCustomPlot *plot) |
|
28 | VisualizationSelectionZoneItemPrivate(QCustomPlot *plot) | |
29 | : m_Plot(plot), m_Color(Qt::blue), m_CurrentEditionMode(EditionMode::NoEdition) |
|
29 | : m_Plot(plot), m_Color(Qt::blue), m_CurrentEditionMode(EditionMode::NoEdition) | |
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | void updatePosition(VisualizationSelectionZoneItem *item) |
|
33 | void updatePosition(VisualizationSelectionZoneItem *item) | |
34 | { |
|
34 | { | |
35 | item->topLeft->setCoords(m_T1, 0); |
|
35 | item->topLeft->setCoords(m_T1, 0); | |
36 | item->bottomRight->setCoords(m_T2, 1); |
|
36 | item->bottomRight->setCoords(m_T2, 1); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | EditionMode getEditionMode(const QPoint &pos, const VisualizationSelectionZoneItem *zoneItem) |
|
39 | EditionMode getEditionMode(const QPoint &pos, const VisualizationSelectionZoneItem *zoneItem) | |
40 | { |
|
40 | { | |
41 | auto distanceLeft = m_LeftLine->selectTest(pos, false); |
|
41 | auto distanceLeft = m_LeftLine->selectTest(pos, false); | |
42 | auto distanceRight = m_RightLine->selectTest(pos, false); |
|
42 | auto distanceRight = m_RightLine->selectTest(pos, false); | |
43 | auto distance = zoneItem->selectTest(pos, false); |
|
43 | auto distance = zoneItem->selectTest(pos, false); | |
44 |
|
44 | |||
45 | if (distanceRight <= distance) { |
|
45 | if (distanceRight <= distance) { | |
46 | return VisualizationSelectionZoneItemPrivate::EditionMode::ResizeRight; |
|
46 | return VisualizationSelectionZoneItemPrivate::EditionMode::ResizeRight; | |
47 | } |
|
47 | } | |
48 | else if (distanceLeft <= distance) { |
|
48 | else if (distanceLeft <= distance) { | |
49 | return VisualizationSelectionZoneItemPrivate::EditionMode::ResizeLeft; |
|
49 | return VisualizationSelectionZoneItemPrivate::EditionMode::ResizeLeft; | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | return VisualizationSelectionZoneItemPrivate::EditionMode::Move; |
|
52 | return VisualizationSelectionZoneItemPrivate::EditionMode::Move; | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | double pixelSizeToAxisXSize(double pixels) |
|
55 | double pixelSizeToAxisXSize(double pixels) | |
56 | { |
|
56 | { | |
57 | auto axis = m_Plot->axisRect()->axis(QCPAxis::atBottom); |
|
57 | auto axis = m_Plot->axisRect()->axis(QCPAxis::atBottom); | |
58 | return axis->pixelToCoord(pixels) - axis->pixelToCoord(0); |
|
58 | return axis->pixelToCoord(pixels) - axis->pixelToCoord(0); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | bool alignZones(VisualizationSelectionZoneItem *referenceZone, |
|
61 | bool alignZones(VisualizationSelectionZoneItem *referenceZone, | |
62 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool alignOnLeft, |
|
62 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool alignOnLeft, | |
63 | bool allowResize, bool vertically) |
|
63 | bool allowResize, bool vertically) | |
64 | { |
|
64 | { | |
65 | auto result = false; |
|
65 | auto result = false; | |
66 |
|
66 | |||
67 | auto referenceTime |
|
67 | auto referenceTime | |
68 | = alignOnLeft ? referenceZone->range().m_TStart : referenceZone->range().m_TEnd; |
|
68 | = alignOnLeft ? referenceZone->range().m_TStart : referenceZone->range().m_TEnd; | |
69 |
|
69 | |||
70 | auto referenceBottomAxis = m_Plot->axisRect()->axis(QCPAxis::atBottom); |
|
70 | auto referenceBottomAxis = m_Plot->axisRect()->axis(QCPAxis::atBottom); | |
71 | auto referenceVerticalPosition = referenceBottomAxis->coordToPixel(referenceTime); |
|
71 | auto referenceVerticalPosition = referenceBottomAxis->coordToPixel(referenceTime); | |
72 |
|
72 | |||
73 | for (auto otherZone : zonesToAlign) { |
|
73 | for (auto otherZone : zonesToAlign) { | |
74 |
|
74 | |||
75 | auto otherZoneRange = otherZone->range(); |
|
75 | auto otherZoneRange = otherZone->range(); | |
76 | auto newZoneStart = otherZoneRange.m_TStart; |
|
76 | auto newZoneStart = otherZoneRange.m_TStart; | |
77 | auto newZoneEnd = otherZoneRange.m_TEnd; |
|
77 | auto newZoneEnd = otherZoneRange.m_TEnd; | |
78 |
|
78 | |||
79 | auto alignedTime = referenceTime; |
|
79 | auto alignedTime = referenceTime; | |
80 | if (vertically) { |
|
80 | if (vertically) { | |
81 | auto otherZoneAxis = otherZone->parentPlot()->axisRect()->axis(QCPAxis::atBottom); |
|
81 | auto otherZoneAxis = otherZone->parentPlot()->axisRect()->axis(QCPAxis::atBottom); | |
82 | alignedTime = otherZoneAxis->pixelToCoord(referenceVerticalPosition); |
|
82 | alignedTime = otherZoneAxis->pixelToCoord(referenceVerticalPosition); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | if (alignOnLeft) { |
|
85 | if (alignOnLeft) { | |
86 | newZoneStart = alignedTime; |
|
86 | newZoneStart = alignedTime; | |
87 | if (!allowResize) { |
|
87 | if (!allowResize) { | |
88 | newZoneEnd = alignedTime + (otherZoneRange.m_TEnd - otherZoneRange.m_TStart); |
|
88 | newZoneEnd = alignedTime + (otherZoneRange.m_TEnd - otherZoneRange.m_TStart); | |
89 | } |
|
89 | } | |
90 | } |
|
90 | } | |
91 | else { // align on right |
|
91 | else { // align on right | |
92 | newZoneEnd = alignedTime; |
|
92 | newZoneEnd = alignedTime; | |
93 | if (!allowResize) { |
|
93 | if (!allowResize) { | |
94 | newZoneStart = alignedTime - (otherZoneRange.m_TEnd - otherZoneRange.m_TStart); |
|
94 | newZoneStart = alignedTime - (otherZoneRange.m_TEnd - otherZoneRange.m_TStart); | |
95 | } |
|
95 | } | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | if (newZoneStart < newZoneEnd) { |
|
98 | if (newZoneStart < newZoneEnd) { | |
99 | result = true; |
|
99 | result = true; | |
100 | otherZone->setRange(newZoneStart, newZoneEnd); |
|
100 | otherZone->setRange(newZoneStart, newZoneEnd); | |
101 | otherZone->parentPlot()->replot(); |
|
101 | otherZone->parentPlot()->replot(); | |
102 | } |
|
102 | } | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | return result; |
|
105 | return result; | |
106 | } |
|
106 | } | |
107 | }; |
|
107 | }; | |
108 |
|
108 | |||
109 | VisualizationSelectionZoneItem::VisualizationSelectionZoneItem(QCustomPlot *plot) |
|
109 | VisualizationSelectionZoneItem::VisualizationSelectionZoneItem(QCustomPlot *plot) | |
110 | : QCPItemRect(plot), |
|
110 | : QCPItemRect(plot), | |
111 | impl{spimpl::make_unique_impl<VisualizationSelectionZoneItemPrivate>(plot)} |
|
111 | impl{spimpl::make_unique_impl<VisualizationSelectionZoneItemPrivate>(plot)} | |
112 | { |
|
112 | { | |
113 | topLeft->setTypeX(QCPItemPosition::ptPlotCoords); |
|
113 | topLeft->setTypeX(QCPItemPosition::ptPlotCoords); | |
114 | topLeft->setTypeY(QCPItemPosition::ptAxisRectRatio); |
|
114 | topLeft->setTypeY(QCPItemPosition::ptAxisRectRatio); | |
115 | bottomRight->setTypeX(QCPItemPosition::ptPlotCoords); |
|
115 | bottomRight->setTypeX(QCPItemPosition::ptPlotCoords); | |
116 | bottomRight->setTypeY(QCPItemPosition::ptAxisRectRatio); |
|
116 | bottomRight->setTypeY(QCPItemPosition::ptAxisRectRatio); | |
117 | setSelectable(false); |
|
117 | setSelectable(false); | |
118 |
|
118 | |||
119 | impl->m_RightLine = new QCPItemStraightLine(plot); |
|
119 | impl->m_RightLine = new QCPItemStraightLine(plot); | |
120 | impl->m_RightLine->point1->setParentAnchor(topRight); |
|
120 | impl->m_RightLine->point1->setParentAnchor(topRight); | |
121 | impl->m_RightLine->point2->setParentAnchor(bottomRight); |
|
121 | impl->m_RightLine->point2->setParentAnchor(bottomRight); | |
122 | impl->m_RightLine->point1->setTypeX(QCPItemPosition::ptAbsolute); |
|
122 | impl->m_RightLine->point1->setTypeX(QCPItemPosition::ptAbsolute); | |
123 | impl->m_RightLine->point1->setTypeY(QCPItemPosition::ptAbsolute); |
|
123 | impl->m_RightLine->point1->setTypeY(QCPItemPosition::ptAbsolute); | |
124 | impl->m_RightLine->point2->setTypeX(QCPItemPosition::ptAbsolute); |
|
124 | impl->m_RightLine->point2->setTypeX(QCPItemPosition::ptAbsolute); | |
125 | impl->m_RightLine->point2->setTypeY(QCPItemPosition::ptAbsolute); |
|
125 | impl->m_RightLine->point2->setTypeY(QCPItemPosition::ptAbsolute); | |
126 | impl->m_RightLine->setSelectable(false); |
|
126 | impl->m_RightLine->setSelectable(false); | |
127 |
|
127 | |||
128 | impl->m_LeftLine = new QCPItemStraightLine(plot); |
|
128 | impl->m_LeftLine = new QCPItemStraightLine(plot); | |
129 | impl->m_LeftLine->point1->setParentAnchor(topLeft); |
|
129 | impl->m_LeftLine->point1->setParentAnchor(topLeft); | |
130 | impl->m_LeftLine->point2->setParentAnchor(bottomLeft); |
|
130 | impl->m_LeftLine->point2->setParentAnchor(bottomLeft); | |
131 | impl->m_LeftLine->point1->setTypeX(QCPItemPosition::ptAbsolute); |
|
131 | impl->m_LeftLine->point1->setTypeX(QCPItemPosition::ptAbsolute); | |
132 | impl->m_LeftLine->point1->setTypeY(QCPItemPosition::ptAbsolute); |
|
132 | impl->m_LeftLine->point1->setTypeY(QCPItemPosition::ptAbsolute); | |
133 | impl->m_LeftLine->point2->setTypeX(QCPItemPosition::ptAbsolute); |
|
133 | impl->m_LeftLine->point2->setTypeX(QCPItemPosition::ptAbsolute); | |
134 | impl->m_LeftLine->point2->setTypeY(QCPItemPosition::ptAbsolute); |
|
134 | impl->m_LeftLine->point2->setTypeY(QCPItemPosition::ptAbsolute); | |
135 | impl->m_LeftLine->setSelectable(false); |
|
135 | impl->m_LeftLine->setSelectable(false); | |
136 |
|
136 | |||
137 | connect(this, &VisualizationSelectionZoneItem::selectionChanged, impl->m_RightLine, |
|
137 | connect(this, &VisualizationSelectionZoneItem::selectionChanged, impl->m_RightLine, | |
138 | &QCPItemStraightLine::setSelected); |
|
138 | &QCPItemStraightLine::setSelected); | |
139 | connect(this, &VisualizationSelectionZoneItem::selectionChanged, impl->m_LeftLine, |
|
139 | connect(this, &VisualizationSelectionZoneItem::selectionChanged, impl->m_LeftLine, | |
140 | &QCPItemStraightLine::setSelected); |
|
140 | &QCPItemStraightLine::setSelected); | |
141 |
|
141 | |||
142 | setColor(QColor(DEFAULT_COLOR)); |
|
142 | setColor(QColor(DEFAULT_COLOR)); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | VisualizationSelectionZoneItem::~VisualizationSelectionZoneItem() |
|
145 | VisualizationSelectionZoneItem::~VisualizationSelectionZoneItem() | |
146 | { |
|
146 | { | |
147 | impl->m_Plot->removeItem(impl->m_RightLine); |
|
|||
148 | impl->m_Plot->removeItem(impl->m_LeftLine); |
|
|||
149 | } |
|
147 | } | |
150 |
|
148 | |||
151 | VisualizationGraphWidget *VisualizationSelectionZoneItem::parentGraphWidget() const noexcept |
|
149 | VisualizationGraphWidget *VisualizationSelectionZoneItem::parentGraphWidget() const noexcept | |
152 | { |
|
150 | { | |
153 | auto parent = impl->m_Plot->parentWidget(); |
|
151 | auto parent = impl->m_Plot->parentWidget(); | |
154 | while (parent != nullptr && !qobject_cast<VisualizationGraphWidget *>(parent)) { |
|
152 | while (parent != nullptr && !qobject_cast<VisualizationGraphWidget *>(parent)) { | |
155 | parent = parent->parentWidget(); |
|
153 | parent = parent->parentWidget(); | |
156 | } |
|
154 | } | |
157 |
|
155 | |||
158 | return qobject_cast<VisualizationGraphWidget *>(parent); |
|
156 | return qobject_cast<VisualizationGraphWidget *>(parent); | |
159 | } |
|
157 | } | |
160 |
|
158 | |||
161 | void VisualizationSelectionZoneItem::setName(const QString &name) |
|
159 | void VisualizationSelectionZoneItem::setName(const QString &name) | |
162 | { |
|
160 | { | |
163 | if (name.isEmpty() && impl->m_NameLabelItem) { |
|
161 | if (name.isEmpty() && impl->m_NameLabelItem) { | |
164 | impl->m_Plot->removeItem(impl->m_NameLabelItem); |
|
162 | impl->m_Plot->removeItem(impl->m_NameLabelItem); | |
165 | impl->m_NameLabelItem = nullptr; |
|
163 | impl->m_NameLabelItem = nullptr; | |
166 | } |
|
164 | } | |
167 | else if (!impl->m_NameLabelItem) { |
|
165 | else if (!impl->m_NameLabelItem) { | |
168 | impl->m_NameLabelItem = new QCPItemText(impl->m_Plot); |
|
166 | impl->m_NameLabelItem = new QCPItemText(impl->m_Plot); | |
169 | impl->m_NameLabelItem->setText(name); |
|
167 | impl->m_NameLabelItem->setText(name); | |
170 | impl->m_NameLabelItem->setPositionAlignment(Qt::AlignHCenter | Qt::AlignTop); |
|
168 | impl->m_NameLabelItem->setPositionAlignment(Qt::AlignHCenter | Qt::AlignTop); | |
171 | impl->m_NameLabelItem->setColor(impl->m_Color); |
|
169 | impl->m_NameLabelItem->setColor(impl->m_Color); | |
172 | impl->m_NameLabelItem->position->setParentAnchor(top); |
|
170 | impl->m_NameLabelItem->position->setParentAnchor(top); | |
173 | } |
|
171 | } | |
174 | } |
|
172 | } | |
175 |
|
173 | |||
176 | QString VisualizationSelectionZoneItem::name() const |
|
174 | QString VisualizationSelectionZoneItem::name() const | |
177 | { |
|
175 | { | |
178 | if (!impl->m_NameLabelItem) { |
|
176 | if (!impl->m_NameLabelItem) { | |
179 | return QString(); |
|
177 | return QString(); | |
180 | } |
|
178 | } | |
181 |
|
179 | |||
182 | return impl->m_NameLabelItem->text(); |
|
180 | return impl->m_NameLabelItem->text(); | |
183 | } |
|
181 | } | |
184 |
|
182 | |||
185 | SqpRange VisualizationSelectionZoneItem::range() const |
|
183 | SqpRange VisualizationSelectionZoneItem::range() const | |
186 | { |
|
184 | { | |
187 | SqpRange range; |
|
185 | SqpRange range; | |
188 | range.m_TStart = impl->m_T1 <= impl->m_T2 ? impl->m_T1 : impl->m_T2; |
|
186 | range.m_TStart = impl->m_T1 <= impl->m_T2 ? impl->m_T1 : impl->m_T2; | |
189 | range.m_TEnd = impl->m_T1 > impl->m_T2 ? impl->m_T1 : impl->m_T2; |
|
187 | range.m_TEnd = impl->m_T1 > impl->m_T2 ? impl->m_T1 : impl->m_T2; | |
190 | return range; |
|
188 | return range; | |
191 | } |
|
189 | } | |
192 |
|
190 | |||
193 | void VisualizationSelectionZoneItem::setRange(double tstart, double tend) |
|
191 | void VisualizationSelectionZoneItem::setRange(double tstart, double tend) | |
194 | { |
|
192 | { | |
195 | impl->m_T1 = tstart; |
|
193 | impl->m_T1 = tstart; | |
196 | impl->m_T2 = tend; |
|
194 | impl->m_T2 = tend; | |
197 | impl->updatePosition(this); |
|
195 | impl->updatePosition(this); | |
198 | } |
|
196 | } | |
199 |
|
197 | |||
200 | void VisualizationSelectionZoneItem::setStart(double tstart) |
|
198 | void VisualizationSelectionZoneItem::setStart(double tstart) | |
201 | { |
|
199 | { | |
202 | impl->m_T1 = tstart; |
|
200 | impl->m_T1 = tstart; | |
203 | impl->updatePosition(this); |
|
201 | impl->updatePosition(this); | |
204 | } |
|
202 | } | |
205 |
|
203 | |||
206 | void VisualizationSelectionZoneItem::setEnd(double tend) |
|
204 | void VisualizationSelectionZoneItem::setEnd(double tend) | |
207 | { |
|
205 | { | |
208 | impl->m_T2 = tend; |
|
206 | impl->m_T2 = tend; | |
209 | impl->updatePosition(this); |
|
207 | impl->updatePosition(this); | |
210 | } |
|
208 | } | |
211 |
|
209 | |||
212 | void VisualizationSelectionZoneItem::setColor(const QColor &color) |
|
210 | void VisualizationSelectionZoneItem::setColor(const QColor &color) | |
213 | { |
|
211 | { | |
214 | impl->m_Color = color; |
|
212 | impl->m_Color = color; | |
215 |
|
213 | |||
216 | auto brushColor = color; |
|
214 | auto brushColor = color; | |
217 | brushColor.setAlpha(80); |
|
215 | brushColor.setAlpha(80); | |
218 | setBrush(QBrush(brushColor)); |
|
216 | setBrush(QBrush(brushColor)); | |
219 | setPen(QPen(Qt::NoPen)); |
|
217 | setPen(QPen(Qt::NoPen)); | |
220 |
|
218 | |||
221 | auto selectedBrushColor = brushColor; |
|
219 | auto selectedBrushColor = brushColor; | |
222 | selectedBrushColor.setAlpha(150); |
|
220 | selectedBrushColor.setAlpha(150); | |
223 | setSelectedBrush(QBrush(selectedBrushColor)); |
|
221 | setSelectedBrush(QBrush(selectedBrushColor)); | |
224 | setSelectedPen(QPen(Qt::NoPen)); |
|
222 | setSelectedPen(QPen(Qt::NoPen)); | |
225 |
|
223 | |||
226 | auto linePen = QPen(color); |
|
224 | auto linePen = QPen(color); | |
227 | linePen.setStyle(Qt::SolidLine); |
|
225 | linePen.setStyle(Qt::SolidLine); | |
228 | linePen.setWidth(4); |
|
226 | linePen.setWidth(4); | |
229 |
|
227 | |||
230 | auto selectedLinePen = linePen; |
|
228 | auto selectedLinePen = linePen; | |
231 | selectedLinePen.setColor(color.darker(120)); |
|
229 | selectedLinePen.setColor(color.darker(120)); | |
232 | selectedLinePen.setWidth(4); |
|
230 | selectedLinePen.setWidth(4); | |
233 |
|
231 | |||
234 | impl->m_LeftLine->setPen(linePen); |
|
232 | impl->m_LeftLine->setPen(linePen); | |
235 | impl->m_RightLine->setPen(linePen); |
|
233 | impl->m_RightLine->setPen(linePen); | |
236 |
|
234 | |||
237 | impl->m_LeftLine->setSelectedPen(selectedLinePen); |
|
235 | impl->m_LeftLine->setSelectedPen(selectedLinePen); | |
238 | impl->m_RightLine->setSelectedPen(selectedLinePen); |
|
236 | impl->m_RightLine->setSelectedPen(selectedLinePen); | |
239 | } |
|
237 | } | |
240 |
|
238 | |||
241 | void VisualizationSelectionZoneItem::setEditionEnabled(bool value) |
|
239 | void VisualizationSelectionZoneItem::setEditionEnabled(bool value) | |
242 | { |
|
240 | { | |
243 | impl->m_IsEditionEnabled = value; |
|
241 | impl->m_IsEditionEnabled = value; | |
244 | setSelectable(value); |
|
242 | setSelectable(value); | |
245 | if (!value) { |
|
243 | if (!value) { | |
246 | setSelected(false); |
|
244 | setSelected(false); | |
247 | impl->m_CurrentEditionMode = VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition; |
|
245 | impl->m_CurrentEditionMode = VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition; | |
248 | } |
|
246 | } | |
249 | } |
|
247 | } | |
250 |
|
248 | |||
251 | bool VisualizationSelectionZoneItem::isEditionEnabled() const |
|
249 | bool VisualizationSelectionZoneItem::isEditionEnabled() const | |
252 | { |
|
250 | { | |
253 | return impl->m_IsEditionEnabled; |
|
251 | return impl->m_IsEditionEnabled; | |
254 | } |
|
252 | } | |
255 |
|
253 | |||
256 | void VisualizationSelectionZoneItem::moveToTop() |
|
254 | void VisualizationSelectionZoneItem::moveToTop() | |
257 | { |
|
255 | { | |
258 | moveToLayer(layer(), false); |
|
256 | moveToLayer(layer(), false); | |
259 | } |
|
257 | } | |
260 |
|
258 | |||
261 | Qt::CursorShape |
|
259 | Qt::CursorShape | |
262 | VisualizationSelectionZoneItem::curshorShapeForPosition(const QPoint &position) const |
|
260 | VisualizationSelectionZoneItem::curshorShapeForPosition(const QPoint &position) const | |
263 | { |
|
261 | { | |
264 | auto mode = impl->m_CurrentEditionMode |
|
262 | auto mode = impl->m_CurrentEditionMode | |
265 | == VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition |
|
263 | == VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition | |
266 | ? impl->getEditionMode(position, this) |
|
264 | ? impl->getEditionMode(position, this) | |
267 | : impl->m_CurrentEditionMode; |
|
265 | : impl->m_CurrentEditionMode; | |
268 | switch (mode) { |
|
266 | switch (mode) { | |
269 | case VisualizationSelectionZoneItemPrivate::EditionMode::Move: |
|
267 | case VisualizationSelectionZoneItemPrivate::EditionMode::Move: | |
270 | return Qt::SizeAllCursor; |
|
268 | return Qt::SizeAllCursor; | |
271 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeLeft: |
|
269 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeLeft: | |
272 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeRight: // fallthrough |
|
270 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeRight: // fallthrough | |
273 | return Qt::SizeHorCursor; |
|
271 | return Qt::SizeHorCursor; | |
274 | default: |
|
272 | default: | |
275 | return Qt::ArrowCursor; |
|
273 | return Qt::ArrowCursor; | |
276 | } |
|
274 | } | |
277 | } |
|
275 | } | |
278 |
|
276 | |||
279 | void VisualizationSelectionZoneItem::setHovered(bool value) |
|
277 | void VisualizationSelectionZoneItem::setHovered(bool value) | |
280 | { |
|
278 | { | |
281 | if (value) { |
|
279 | if (value) { | |
282 | auto linePen = impl->m_LeftLine->pen(); |
|
280 | auto linePen = impl->m_LeftLine->pen(); | |
283 | linePen.setStyle(Qt::DotLine); |
|
281 | linePen.setStyle(Qt::DotLine); | |
284 | linePen.setWidth(3); |
|
282 | linePen.setWidth(3); | |
285 |
|
283 | |||
286 | auto selectedLinePen = impl->m_LeftLine->selectedPen(); |
|
284 | auto selectedLinePen = impl->m_LeftLine->selectedPen(); | |
287 | ; |
|
285 | ; | |
288 | selectedLinePen.setStyle(Qt::DotLine); |
|
286 | selectedLinePen.setStyle(Qt::DotLine); | |
289 | selectedLinePen.setWidth(3); |
|
287 | selectedLinePen.setWidth(3); | |
290 |
|
288 | |||
291 | impl->m_LeftLine->setPen(linePen); |
|
289 | impl->m_LeftLine->setPen(linePen); | |
292 | impl->m_RightLine->setPen(linePen); |
|
290 | impl->m_RightLine->setPen(linePen); | |
293 |
|
291 | |||
294 | impl->m_LeftLine->setSelectedPen(selectedLinePen); |
|
292 | impl->m_LeftLine->setSelectedPen(selectedLinePen); | |
295 | impl->m_RightLine->setSelectedPen(selectedLinePen); |
|
293 | impl->m_RightLine->setSelectedPen(selectedLinePen); | |
296 | } |
|
294 | } | |
297 | else { |
|
295 | else { | |
298 | setColor(impl->m_Color); |
|
296 | setColor(impl->m_Color); | |
299 | } |
|
297 | } | |
300 | } |
|
298 | } | |
301 |
|
299 | |||
302 | void VisualizationSelectionZoneItem::setAssociatedEditedZones( |
|
300 | void VisualizationSelectionZoneItem::setAssociatedEditedZones( | |
303 | const QVector<VisualizationSelectionZoneItem *> &associatedZones) |
|
301 | const QVector<VisualizationSelectionZoneItem *> &associatedZones) | |
304 | { |
|
302 | { | |
305 | impl->m_AssociatedEditedZones = associatedZones; |
|
303 | impl->m_AssociatedEditedZones = associatedZones; | |
306 | impl->m_AssociatedEditedZones.removeAll(this); |
|
304 | impl->m_AssociatedEditedZones.removeAll(this); | |
307 | } |
|
305 | } | |
308 |
|
306 | |||
309 | bool VisualizationSelectionZoneItem::alignZonesVerticallyOnLeft( |
|
307 | bool VisualizationSelectionZoneItem::alignZonesVerticallyOnLeft( | |
310 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool allowResize) |
|
308 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool allowResize) | |
311 | { |
|
309 | { | |
312 | return impl->alignZones(this, zonesToAlign, true, allowResize, true); |
|
310 | return impl->alignZones(this, zonesToAlign, true, allowResize, true); | |
313 | } |
|
311 | } | |
314 |
|
312 | |||
315 | bool VisualizationSelectionZoneItem::alignZonesVerticallyOnRight( |
|
313 | bool VisualizationSelectionZoneItem::alignZonesVerticallyOnRight( | |
316 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool allowResize) |
|
314 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool allowResize) | |
317 | { |
|
315 | { | |
318 | return impl->alignZones(this, zonesToAlign, false, allowResize, true); |
|
316 | return impl->alignZones(this, zonesToAlign, false, allowResize, true); | |
319 | } |
|
317 | } | |
320 |
|
318 | |||
321 | bool VisualizationSelectionZoneItem::alignZonesTemporallyOnLeft( |
|
319 | bool VisualizationSelectionZoneItem::alignZonesTemporallyOnLeft( | |
322 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool allowResize) |
|
320 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool allowResize) | |
323 | { |
|
321 | { | |
324 | return impl->alignZones(this, zonesToAlign, true, allowResize, false); |
|
322 | return impl->alignZones(this, zonesToAlign, true, allowResize, false); | |
325 | } |
|
323 | } | |
326 |
|
324 | |||
327 | bool VisualizationSelectionZoneItem::alignZonesTemporallyOnRight( |
|
325 | bool VisualizationSelectionZoneItem::alignZonesTemporallyOnRight( | |
328 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool allowResize) |
|
326 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool allowResize) | |
329 | { |
|
327 | { | |
330 | return impl->alignZones(this, zonesToAlign, false, allowResize, false); |
|
328 | return impl->alignZones(this, zonesToAlign, false, allowResize, false); | |
331 | } |
|
329 | } | |
332 |
|
330 | |||
333 | void VisualizationSelectionZoneItem::mousePressEvent(QMouseEvent *event, const QVariant &details) |
|
331 | void VisualizationSelectionZoneItem::mousePressEvent(QMouseEvent *event, const QVariant &details) | |
334 | { |
|
332 | { | |
335 | Q_UNUSED(details); |
|
333 | Q_UNUSED(details); | |
336 |
|
334 | |||
337 | if (isEditionEnabled() && event->button() == Qt::LeftButton) { |
|
335 | if (isEditionEnabled() && event->button() == Qt::LeftButton) { | |
338 | impl->m_CurrentEditionMode = impl->getEditionMode(event->pos(), this); |
|
336 | impl->m_CurrentEditionMode = impl->getEditionMode(event->pos(), this); | |
339 |
|
337 | |||
340 | impl->m_MovedOrinalT1 = impl->m_T1; |
|
338 | impl->m_MovedOrinalT1 = impl->m_T1; | |
341 | impl->m_MovedOrinalT2 = impl->m_T2; |
|
339 | impl->m_MovedOrinalT2 = impl->m_T2; | |
342 | for (auto associatedZone : impl->m_AssociatedEditedZones) { |
|
340 | for (auto associatedZone : impl->m_AssociatedEditedZones) { | |
343 | associatedZone->impl->m_MovedOrinalT1 = associatedZone->impl->m_T1; |
|
341 | associatedZone->impl->m_MovedOrinalT1 = associatedZone->impl->m_T1; | |
344 | associatedZone->impl->m_MovedOrinalT2 = associatedZone->impl->m_T2; |
|
342 | associatedZone->impl->m_MovedOrinalT2 = associatedZone->impl->m_T2; | |
345 | } |
|
343 | } | |
346 | } |
|
344 | } | |
347 | else { |
|
345 | else { | |
348 | impl->m_CurrentEditionMode = VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition; |
|
346 | impl->m_CurrentEditionMode = VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition; | |
349 | event->ignore(); |
|
347 | event->ignore(); | |
350 | } |
|
348 | } | |
351 | } |
|
349 | } | |
352 |
|
350 | |||
353 | void VisualizationSelectionZoneItem::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) |
|
351 | void VisualizationSelectionZoneItem::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) | |
354 | { |
|
352 | { | |
355 | if (isEditionEnabled()) { |
|
353 | if (isEditionEnabled()) { | |
356 | if (!selected()) { |
|
354 | if (!selected()) { | |
357 | // Force the item to be selected during the edition |
|
355 | // Force the item to be selected during the edition | |
358 | parentGraphWidget()->parentVisualizationWidget()->selectionZoneManager().setSelected( |
|
356 | parentGraphWidget()->parentVisualizationWidget()->selectionZoneManager().setSelected( | |
359 | this, true); |
|
357 | this, true); | |
360 | } |
|
358 | } | |
361 |
|
359 | |||
362 | auto axis = impl->m_Plot->axisRect()->axis(QCPAxis::atBottom); |
|
360 | auto axis = impl->m_Plot->axisRect()->axis(QCPAxis::atBottom); | |
363 | auto pixelDiff = event->pos().x() - startPos.x(); |
|
361 | auto pixelDiff = event->pos().x() - startPos.x(); | |
364 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); |
|
362 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); | |
365 |
|
363 | |||
366 | switch (impl->m_CurrentEditionMode) { |
|
364 | switch (impl->m_CurrentEditionMode) { | |
367 | case VisualizationSelectionZoneItemPrivate::EditionMode::Move: |
|
365 | case VisualizationSelectionZoneItemPrivate::EditionMode::Move: | |
368 | setRange(impl->m_MovedOrinalT1 + diff, impl->m_MovedOrinalT2 + diff); |
|
366 | setRange(impl->m_MovedOrinalT1 + diff, impl->m_MovedOrinalT2 + diff); | |
369 | for (auto associatedZone : impl->m_AssociatedEditedZones) { |
|
367 | for (auto associatedZone : impl->m_AssociatedEditedZones) { | |
370 | associatedZone->move(pixelDiff); |
|
368 | associatedZone->move(pixelDiff); | |
371 | } |
|
369 | } | |
372 | break; |
|
370 | break; | |
373 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeLeft: |
|
371 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeLeft: | |
374 | setStart(impl->m_MovedOrinalT1 + diff); |
|
372 | setStart(impl->m_MovedOrinalT1 + diff); | |
375 | for (auto associatedZone : impl->m_AssociatedEditedZones) { |
|
373 | for (auto associatedZone : impl->m_AssociatedEditedZones) { | |
376 | impl->m_MovedOrinalT1 < impl->m_MovedOrinalT2 |
|
374 | impl->m_MovedOrinalT1 < impl->m_MovedOrinalT2 | |
377 | ? associatedZone->resizeLeft(pixelDiff) |
|
375 | ? associatedZone->resizeLeft(pixelDiff) | |
378 | : associatedZone->resizeRight(pixelDiff); |
|
376 | : associatedZone->resizeRight(pixelDiff); | |
379 | } |
|
377 | } | |
380 | break; |
|
378 | break; | |
381 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeRight: |
|
379 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeRight: | |
382 | setEnd(impl->m_MovedOrinalT2 + diff); |
|
380 | setEnd(impl->m_MovedOrinalT2 + diff); | |
383 | for (auto associatedZone : impl->m_AssociatedEditedZones) { |
|
381 | for (auto associatedZone : impl->m_AssociatedEditedZones) { | |
384 | impl->m_MovedOrinalT1 < impl->m_MovedOrinalT2 |
|
382 | impl->m_MovedOrinalT1 < impl->m_MovedOrinalT2 | |
385 | ? associatedZone->resizeRight(pixelDiff) |
|
383 | ? associatedZone->resizeRight(pixelDiff) | |
386 | : associatedZone->resizeLeft(pixelDiff); |
|
384 | : associatedZone->resizeLeft(pixelDiff); | |
387 | } |
|
385 | } | |
388 | break; |
|
386 | break; | |
389 | default: |
|
387 | default: | |
390 | break; |
|
388 | break; | |
391 | } |
|
389 | } | |
392 |
|
390 | |||
393 | for (auto associatedZone : impl->m_AssociatedEditedZones) { |
|
391 | for (auto associatedZone : impl->m_AssociatedEditedZones) { | |
394 | associatedZone->parentPlot()->replot(); |
|
392 | associatedZone->parentPlot()->replot(); | |
395 | } |
|
393 | } | |
396 | } |
|
394 | } | |
397 | else { |
|
395 | else { | |
398 | event->ignore(); |
|
396 | event->ignore(); | |
399 | } |
|
397 | } | |
400 | } |
|
398 | } | |
401 |
|
399 | |||
402 | void VisualizationSelectionZoneItem::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) |
|
400 | void VisualizationSelectionZoneItem::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) | |
403 | { |
|
401 | { | |
404 | Q_UNUSED(startPos); |
|
402 | Q_UNUSED(startPos); | |
405 |
|
403 | |||
406 | if (isEditionEnabled()) { |
|
404 | if (isEditionEnabled()) { | |
407 | impl->m_CurrentEditionMode = VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition; |
|
405 | impl->m_CurrentEditionMode = VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition; | |
408 | } |
|
406 | } | |
409 | else { |
|
407 | else { | |
410 | event->ignore(); |
|
408 | event->ignore(); | |
411 | } |
|
409 | } | |
412 |
|
410 | |||
413 | impl->m_AssociatedEditedZones.clear(); |
|
411 | impl->m_AssociatedEditedZones.clear(); | |
414 | } |
|
412 | } | |
415 |
|
413 | |||
416 | void VisualizationSelectionZoneItem::resizeLeft(double pixelDiff) |
|
414 | void VisualizationSelectionZoneItem::resizeLeft(double pixelDiff) | |
417 | { |
|
415 | { | |
418 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); |
|
416 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); | |
419 | if (impl->m_MovedOrinalT1 <= impl->m_MovedOrinalT2) { |
|
417 | if (impl->m_MovedOrinalT1 <= impl->m_MovedOrinalT2) { | |
420 | setStart(impl->m_MovedOrinalT1 + diff); |
|
418 | setStart(impl->m_MovedOrinalT1 + diff); | |
421 | } |
|
419 | } | |
422 | else { |
|
420 | else { | |
423 | setEnd(impl->m_MovedOrinalT2 + diff); |
|
421 | setEnd(impl->m_MovedOrinalT2 + diff); | |
424 | } |
|
422 | } | |
425 | } |
|
423 | } | |
426 |
|
424 | |||
427 | void VisualizationSelectionZoneItem::resizeRight(double pixelDiff) |
|
425 | void VisualizationSelectionZoneItem::resizeRight(double pixelDiff) | |
428 | { |
|
426 | { | |
429 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); |
|
427 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); | |
430 | if (impl->m_MovedOrinalT1 > impl->m_MovedOrinalT2) { |
|
428 | if (impl->m_MovedOrinalT1 > impl->m_MovedOrinalT2) { | |
431 | setStart(impl->m_MovedOrinalT1 + diff); |
|
429 | setStart(impl->m_MovedOrinalT1 + diff); | |
432 | } |
|
430 | } | |
433 | else { |
|
431 | else { | |
434 | setEnd(impl->m_MovedOrinalT2 + diff); |
|
432 | setEnd(impl->m_MovedOrinalT2 + diff); | |
435 | } |
|
433 | } | |
436 | } |
|
434 | } | |
437 |
|
435 | |||
438 | void VisualizationSelectionZoneItem::move(double pixelDiff) |
|
436 | void VisualizationSelectionZoneItem::move(double pixelDiff) | |
439 | { |
|
437 | { | |
440 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); |
|
438 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); | |
441 | setRange(impl->m_MovedOrinalT1 + diff, impl->m_MovedOrinalT2 + diff); |
|
439 | setRange(impl->m_MovedOrinalT1 + diff, impl->m_MovedOrinalT2 + diff); | |
442 | } |
|
440 | } |
General Comments 4
Status change > Approved
Status change > Approved
You need to be logged in to leave comments.
Login now