Chris@58
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@59
|
4 Sonic Visualiser
|
Chris@59
|
5 An audio file viewer and annotation editor.
|
Chris@59
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@59
|
7 This file copyright 2006 Chris Cannam.
|
Chris@0
|
8
|
Chris@59
|
9 This program is free software; you can redistribute it and/or
|
Chris@59
|
10 modify it under the terms of the GNU General Public License as
|
Chris@59
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@59
|
12 License, or (at your option) any later version. See the file
|
Chris@59
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@0
|
16 #include "TimeValueLayer.h"
|
Chris@0
|
17
|
Chris@128
|
18 #include "data/model/Model.h"
|
Chris@0
|
19 #include "base/RealTime.h"
|
Chris@0
|
20 #include "base/Profiler.h"
|
Chris@197
|
21 #include "base/LogRange.h"
|
Chris@437
|
22 #include "base/RangeMapper.h"
|
Chris@376
|
23 #include "ColourDatabase.h"
|
Chris@128
|
24 #include "view/View.h"
|
Chris@0
|
25
|
Chris@128
|
26 #include "data/model/SparseTimeValueModel.h"
|
Chris@340
|
27 #include "data/model/Labeller.h"
|
Chris@0
|
28
|
Chris@70
|
29 #include "widgets/ItemEditDialog.h"
|
Chris@125
|
30 #include "widgets/ListInputDialog.h"
|
Chris@70
|
31
|
Chris@376
|
32 #include "ColourMapper.h"
|
Chris@66
|
33
|
Chris@0
|
34 #include <QPainter>
|
Chris@6
|
35 #include <QPainterPath>
|
Chris@21
|
36 #include <QMouseEvent>
|
Chris@125
|
37 #include <QRegExp>
|
Chris@316
|
38 #include <QTextStream>
|
Chris@360
|
39 #include <QMessageBox>
|
Chris@340
|
40 #include <QInputDialog>
|
Chris@0
|
41
|
Chris@0
|
42 #include <iostream>
|
Chris@0
|
43 #include <cmath>
|
Chris@0
|
44
|
Chris@526
|
45 //#define DEBUG_TIME_VALUE_LAYER 1
|
Chris@526
|
46
|
Chris@44
|
47 TimeValueLayer::TimeValueLayer() :
|
Chris@287
|
48 SingleColourLayer(),
|
Chris@0
|
49 m_model(0),
|
Chris@21
|
50 m_editing(false),
|
Chris@23
|
51 m_originalPoint(0, 0.0, tr("New Point")),
|
Chris@21
|
52 m_editingPoint(0, 0.0, tr("New Point")),
|
Chris@22
|
53 m_editingCommand(0),
|
Chris@197
|
54 m_colourMap(0),
|
Chris@66
|
55 m_plotStyle(PlotConnectedPoints),
|
Chris@437
|
56 m_verticalScale(AutoAlignScale),
|
Chris@513
|
57 m_drawSegmentDivisions(true),
|
Chris@437
|
58 m_scaleMinimum(0),
|
Chris@437
|
59 m_scaleMaximum(0)
|
Chris@0
|
60 {
|
Chris@44
|
61
|
Chris@0
|
62 }
|
Chris@0
|
63
|
Chris@0
|
64 void
|
Chris@0
|
65 TimeValueLayer::setModel(SparseTimeValueModel *model)
|
Chris@0
|
66 {
|
Chris@0
|
67 if (m_model == model) return;
|
Chris@0
|
68 m_model = model;
|
Chris@0
|
69
|
Chris@320
|
70 connectSignals(m_model);
|
Chris@0
|
71
|
Chris@438
|
72 m_scaleMinimum = 0;
|
Chris@438
|
73 m_scaleMaximum = 0;
|
Chris@438
|
74
|
Chris@494
|
75 if (m_model && m_model->getRDFTypeURI().endsWith("Segment")) {
|
Chris@494
|
76 setPlotStyle(PlotSegmentation);
|
Chris@494
|
77 }
|
Chris@494
|
78 if (m_model && m_model->getRDFTypeURI().endsWith("Change")) {
|
Chris@494
|
79 setPlotStyle(PlotSegmentation);
|
Chris@494
|
80 }
|
Chris@494
|
81
|
Chris@526
|
82 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
83 std::cerr << "TimeValueLayer::setModel(" << model << ")" << std::endl;
|
Chris@526
|
84 #endif
|
Chris@0
|
85
|
Chris@0
|
86 emit modelReplaced();
|
Chris@0
|
87 }
|
Chris@0
|
88
|
Chris@0
|
89 Layer::PropertyList
|
Chris@0
|
90 TimeValueLayer::getProperties() const
|
Chris@0
|
91 {
|
Chris@287
|
92 PropertyList list = SingleColourLayer::getProperties();
|
Chris@87
|
93 list.push_back("Plot Type");
|
Chris@87
|
94 list.push_back("Vertical Scale");
|
Chris@100
|
95 list.push_back("Scale Units");
|
Chris@513
|
96 list.push_back("Draw Segment Division Lines");
|
Chris@0
|
97 return list;
|
Chris@0
|
98 }
|
Chris@0
|
99
|
Chris@87
|
100 QString
|
Chris@87
|
101 TimeValueLayer::getPropertyLabel(const PropertyName &name) const
|
Chris@87
|
102 {
|
Chris@87
|
103 if (name == "Plot Type") return tr("Plot Type");
|
Chris@87
|
104 if (name == "Vertical Scale") return tr("Vertical Scale");
|
Chris@100
|
105 if (name == "Scale Units") return tr("Scale Units");
|
Chris@513
|
106 if (name == "Draw Segment Division Lines") return tr("Draw Segment Division Lines");
|
Chris@287
|
107 return SingleColourLayer::getPropertyLabel(name);
|
Chris@87
|
108 }
|
Chris@87
|
109
|
Chris@515
|
110 QString
|
Chris@515
|
111 TimeValueLayer::getPropertyIconName(const PropertyName &name) const
|
Chris@515
|
112 {
|
Chris@515
|
113 if (name == "Draw Segment Division Lines") return "lines";
|
Chris@515
|
114 return "";
|
Chris@515
|
115 }
|
Chris@515
|
116
|
Chris@0
|
117 Layer::PropertyType
|
Chris@0
|
118 TimeValueLayer::getPropertyType(const PropertyName &name) const
|
Chris@0
|
119 {
|
Chris@287
|
120 if (name == "Plot Type") return ValueProperty;
|
Chris@287
|
121 if (name == "Vertical Scale") return ValueProperty;
|
Chris@100
|
122 if (name == "Scale Units") return UnitsProperty;
|
Chris@287
|
123 if (name == "Colour" && m_plotStyle == PlotSegmentation) return ValueProperty;
|
Chris@513
|
124 if (name == "Draw Segment Division Lines") return ToggleProperty;
|
Chris@287
|
125 return SingleColourLayer::getPropertyType(name);
|
Chris@0
|
126 }
|
Chris@0
|
127
|
Chris@198
|
128 QString
|
Chris@198
|
129 TimeValueLayer::getPropertyGroupName(const PropertyName &name) const
|
Chris@198
|
130 {
|
Chris@198
|
131 if (name == "Vertical Scale" || name == "Scale Units") {
|
Chris@198
|
132 return tr("Scale");
|
Chris@198
|
133 }
|
Chris@513
|
134 if (name == "Plot Type" || name == "Draw Segment Division Lines") {
|
Chris@513
|
135 return tr("Plot Type");
|
Chris@513
|
136 }
|
Chris@287
|
137 return SingleColourLayer::getPropertyGroupName(name);
|
Chris@198
|
138 }
|
Chris@198
|
139
|
Chris@0
|
140 int
|
Chris@0
|
141 TimeValueLayer::getPropertyRangeAndValue(const PropertyName &name,
|
Chris@216
|
142 int *min, int *max, int *deflt) const
|
Chris@0
|
143 {
|
Chris@216
|
144 int val = 0;
|
Chris@0
|
145
|
Chris@287
|
146 if (name == "Colour" && m_plotStyle == PlotSegmentation) {
|
Chris@197
|
147
|
Chris@287
|
148 if (min) *min = 0;
|
Chris@287
|
149 if (max) *max = ColourMapper::getColourMapCount() - 1;
|
Chris@287
|
150 if (deflt) *deflt = 0;
|
Chris@197
|
151
|
Chris@287
|
152 val = m_colourMap;
|
Chris@0
|
153
|
Chris@87
|
154 } else if (name == "Plot Type") {
|
Chris@0
|
155
|
Chris@10
|
156 if (min) *min = 0;
|
Chris@26
|
157 if (max) *max = 5;
|
Chris@216
|
158 if (deflt) *deflt = int(PlotConnectedPoints);
|
Chris@0
|
159
|
Chris@216
|
160 val = int(m_plotStyle);
|
Chris@0
|
161
|
Chris@87
|
162 } else if (name == "Vertical Scale") {
|
Chris@66
|
163
|
Chris@66
|
164 if (min) *min = 0;
|
Chris@66
|
165 if (max) *max = 3;
|
Chris@216
|
166 if (deflt) *deflt = int(AutoAlignScale);
|
Chris@66
|
167
|
Chris@216
|
168 val = int(m_verticalScale);
|
Chris@66
|
169
|
Chris@100
|
170 } else if (name == "Scale Units") {
|
Chris@100
|
171
|
Chris@216
|
172 if (deflt) *deflt = 0;
|
Chris@100
|
173 if (m_model) {
|
Chris@216
|
174 val = UnitDatabase::getInstance()->getUnitId
|
Chris@100
|
175 (m_model->getScaleUnits());
|
Chris@100
|
176 }
|
Chris@100
|
177
|
Chris@513
|
178 } else if (name == "Draw Segment Division Lines") {
|
Chris@513
|
179
|
Chris@513
|
180 if (min) *min = 0;
|
Chris@513
|
181 if (max) *max = 0;
|
Chris@513
|
182 if (deflt) *deflt = 1;
|
Chris@513
|
183 val = (m_drawSegmentDivisions ? 1.0 : 0.0);
|
Chris@513
|
184
|
Chris@0
|
185 } else {
|
Chris@0
|
186
|
Chris@287
|
187 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt);
|
Chris@0
|
188 }
|
Chris@0
|
189
|
Chris@216
|
190 return val;
|
Chris@0
|
191 }
|
Chris@0
|
192
|
Chris@0
|
193 QString
|
Chris@0
|
194 TimeValueLayer::getPropertyValueLabel(const PropertyName &name,
|
Chris@0
|
195 int value) const
|
Chris@0
|
196 {
|
Chris@287
|
197 if (name == "Colour" && m_plotStyle == PlotSegmentation) {
|
Chris@287
|
198 return ColourMapper::getColourMapName(value);
|
Chris@87
|
199 } else if (name == "Plot Type") {
|
Chris@0
|
200 switch (value) {
|
Chris@0
|
201 default:
|
Chris@0
|
202 case 0: return tr("Points");
|
Chris@0
|
203 case 1: return tr("Stems");
|
Chris@6
|
204 case 2: return tr("Connected Points");
|
Chris@6
|
205 case 3: return tr("Lines");
|
Chris@6
|
206 case 4: return tr("Curve");
|
Chris@26
|
207 case 5: return tr("Segmentation");
|
Chris@0
|
208 }
|
Chris@87
|
209 } else if (name == "Vertical Scale") {
|
Chris@66
|
210 switch (value) {
|
Chris@66
|
211 default:
|
Chris@101
|
212 case 0: return tr("Auto-Align");
|
Chris@198
|
213 case 1: return tr("Linear");
|
Chris@198
|
214 case 2: return tr("Log");
|
Chris@198
|
215 case 3: return tr("+/-1");
|
Chris@66
|
216 }
|
Chris@0
|
217 }
|
Chris@287
|
218 return SingleColourLayer::getPropertyValueLabel(name, value);
|
Chris@0
|
219 }
|
Chris@0
|
220
|
Chris@0
|
221 void
|
Chris@0
|
222 TimeValueLayer::setProperty(const PropertyName &name, int value)
|
Chris@0
|
223 {
|
Chris@287
|
224 if (name == "Colour" && m_plotStyle == PlotSegmentation) {
|
Chris@287
|
225 setFillColourMap(value);
|
Chris@87
|
226 } else if (name == "Plot Type") {
|
Chris@0
|
227 setPlotStyle(PlotStyle(value));
|
Chris@87
|
228 } else if (name == "Vertical Scale") {
|
Chris@66
|
229 setVerticalScale(VerticalScale(value));
|
Chris@100
|
230 } else if (name == "Scale Units") {
|
Chris@100
|
231 if (m_model) {
|
Chris@100
|
232 m_model->setScaleUnits
|
Chris@100
|
233 (UnitDatabase::getInstance()->getUnitById(value));
|
Chris@100
|
234 emit modelChanged();
|
Chris@100
|
235 }
|
Chris@513
|
236 } else if (name == "Draw Segment Division Lines") {
|
Chris@513
|
237 setDrawSegmentDivisions(value > 0.5);
|
Chris@287
|
238 } else {
|
Chris@287
|
239 SingleColourLayer::setProperty(name, value);
|
Chris@0
|
240 }
|
Chris@0
|
241 }
|
Chris@0
|
242
|
Chris@0
|
243 void
|
Chris@197
|
244 TimeValueLayer::setFillColourMap(int map)
|
Chris@197
|
245 {
|
Chris@197
|
246 if (m_colourMap == map) return;
|
Chris@197
|
247 m_colourMap = map;
|
Chris@197
|
248 emit layerParametersChanged();
|
Chris@197
|
249 }
|
Chris@197
|
250
|
Chris@197
|
251 void
|
Chris@0
|
252 TimeValueLayer::setPlotStyle(PlotStyle style)
|
Chris@0
|
253 {
|
Chris@0
|
254 if (m_plotStyle == style) return;
|
Chris@197
|
255 bool colourTypeChanged = (style == PlotSegmentation ||
|
Chris@197
|
256 m_plotStyle == PlotSegmentation);
|
Chris@0
|
257 m_plotStyle = style;
|
Chris@197
|
258 if (colourTypeChanged) {
|
Chris@197
|
259 emit layerParameterRangesChanged();
|
Chris@197
|
260 }
|
Chris@0
|
261 emit layerParametersChanged();
|
Chris@0
|
262 }
|
Chris@0
|
263
|
Chris@66
|
264 void
|
Chris@66
|
265 TimeValueLayer::setVerticalScale(VerticalScale scale)
|
Chris@66
|
266 {
|
Chris@66
|
267 if (m_verticalScale == scale) return;
|
Chris@66
|
268 m_verticalScale = scale;
|
Chris@66
|
269 emit layerParametersChanged();
|
Chris@66
|
270 }
|
Chris@66
|
271
|
Chris@513
|
272 void
|
Chris@513
|
273 TimeValueLayer::setDrawSegmentDivisions(bool draw)
|
Chris@513
|
274 {
|
Chris@513
|
275 if (m_drawSegmentDivisions == draw) return;
|
Chris@513
|
276 m_drawSegmentDivisions = draw;
|
Chris@513
|
277 emit layerParametersChanged();
|
Chris@513
|
278 }
|
Chris@513
|
279
|
Chris@0
|
280 bool
|
Chris@44
|
281 TimeValueLayer::isLayerScrollable(const View *v) const
|
Chris@0
|
282 {
|
Chris@6
|
283 // We don't illuminate sections in the line or curve modes, so
|
Chris@6
|
284 // they're always scrollable
|
Chris@6
|
285
|
Chris@6
|
286 if (m_plotStyle == PlotLines ||
|
Chris@6
|
287 m_plotStyle == PlotCurve) return true;
|
Chris@6
|
288
|
Chris@0
|
289 QPoint discard;
|
Chris@44
|
290 return !v->shouldIlluminateLocalFeatures(this, discard);
|
Chris@0
|
291 }
|
Chris@0
|
292
|
Chris@79
|
293 bool
|
Chris@101
|
294 TimeValueLayer::getValueExtents(float &min, float &max,
|
Chris@101
|
295 bool &logarithmic, QString &unit) const
|
Chris@79
|
296 {
|
Chris@101
|
297 if (!m_model) return false;
|
Chris@79
|
298 min = m_model->getValueMinimum();
|
Chris@79
|
299 max = m_model->getValueMaximum();
|
Chris@101
|
300 logarithmic = (m_verticalScale == LogScale);
|
Chris@79
|
301 unit = m_model->getScaleUnits();
|
Chris@79
|
302 return true;
|
Chris@79
|
303 }
|
Chris@79
|
304
|
Chris@101
|
305 bool
|
Chris@101
|
306 TimeValueLayer::getDisplayExtents(float &min, float &max) const
|
Chris@101
|
307 {
|
Chris@296
|
308 if (!m_model || shouldAutoAlign()) return false;
|
Chris@101
|
309
|
Chris@437
|
310 if (m_scaleMinimum == m_scaleMaximum) {
|
Chris@455
|
311 min = m_model->getValueMinimum();
|
Chris@455
|
312 max = m_model->getValueMaximum();
|
Chris@455
|
313 return true;
|
Chris@437
|
314 }
|
Chris@437
|
315
|
Chris@437
|
316 min = m_scaleMinimum;
|
Chris@437
|
317 max = m_scaleMaximum;
|
Chris@437
|
318
|
Chris@526
|
319 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
320 std::cerr << "TimeValueLayer::getDisplayExtents: min = " << min << ", max = " << max << std::endl;
|
Chris@526
|
321 #endif
|
Chris@437
|
322
|
Chris@101
|
323 return true;
|
Chris@101
|
324 }
|
Chris@101
|
325
|
Chris@437
|
326 bool
|
Chris@437
|
327 TimeValueLayer::setDisplayExtents(float min, float max)
|
Chris@437
|
328 {
|
Chris@437
|
329 if (!m_model) return false;
|
Chris@437
|
330
|
Chris@437
|
331 if (min == max) {
|
Chris@437
|
332 if (min == 0.f) {
|
Chris@437
|
333 max = 1.f;
|
Chris@437
|
334 } else {
|
Chris@437
|
335 max = min * 1.0001;
|
Chris@437
|
336 }
|
Chris@437
|
337 }
|
Chris@437
|
338
|
Chris@437
|
339 m_scaleMinimum = min;
|
Chris@437
|
340 m_scaleMaximum = max;
|
Chris@437
|
341
|
Chris@526
|
342 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
343 std::cerr << "TimeValueLayer::setDisplayExtents: min = " << min << ", max = " << max << std::endl;
|
Chris@526
|
344 #endif
|
Chris@437
|
345
|
Chris@437
|
346 emit layerParametersChanged();
|
Chris@437
|
347 return true;
|
Chris@437
|
348 }
|
Chris@437
|
349
|
Chris@437
|
350 int
|
Chris@437
|
351 TimeValueLayer::getVerticalZoomSteps(int &defaultStep) const
|
Chris@437
|
352 {
|
Chris@437
|
353 if (shouldAutoAlign()) return 0;
|
Chris@437
|
354 if (!m_model) return 0;
|
Chris@437
|
355
|
Chris@439
|
356 defaultStep = 0;
|
Chris@437
|
357 return 100;
|
Chris@437
|
358 }
|
Chris@437
|
359
|
Chris@437
|
360 int
|
Chris@437
|
361 TimeValueLayer::getCurrentVerticalZoomStep() const
|
Chris@437
|
362 {
|
Chris@437
|
363 if (shouldAutoAlign()) return 0;
|
Chris@437
|
364 if (!m_model) return 0;
|
Chris@437
|
365
|
Chris@437
|
366 RangeMapper *mapper = getNewVerticalZoomRangeMapper();
|
Chris@437
|
367 if (!mapper) return 0;
|
Chris@437
|
368
|
Chris@437
|
369 float dmin, dmax;
|
Chris@437
|
370 getDisplayExtents(dmin, dmax);
|
Chris@437
|
371
|
Chris@437
|
372 int nr = mapper->getPositionForValue(dmax - dmin);
|
Chris@526
|
373
|
Chris@526
|
374 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@437
|
375 int n0 = mapper->getPositionForValue(dmax);
|
Chris@437
|
376 int n1 = mapper->getPositionForValue(dmin);
|
Chris@437
|
377 int nr = n1 - n0;
|
Chris@437
|
378 if (nr < 0) nr = -nr;
|
Chris@437
|
379
|
Chris@437
|
380 std::cerr << "TimeValueLayer::getCurrentVerticalZoomStep: dmin = " << dmin << ", dmax = " << dmax << ", n0 = " << n0 << ", n1 = " << n1 << ", nr = " << nr << std::endl;
|
Chris@526
|
381 #endif
|
Chris@526
|
382
|
Chris@437
|
383 delete mapper;
|
Chris@437
|
384
|
Chris@437
|
385 return 100 - nr;
|
Chris@437
|
386 }
|
Chris@437
|
387
|
Chris@437
|
388 void
|
Chris@437
|
389 TimeValueLayer::setVerticalZoomStep(int step)
|
Chris@437
|
390 {
|
Chris@437
|
391 if (shouldAutoAlign()) return;
|
Chris@437
|
392 if (!m_model) return;
|
Chris@437
|
393
|
Chris@437
|
394 RangeMapper *mapper = getNewVerticalZoomRangeMapper();
|
Chris@437
|
395 if (!mapper) return;
|
Chris@437
|
396
|
Chris@437
|
397 float min, max;
|
Chris@437
|
398 bool logarithmic;
|
Chris@437
|
399 QString unit;
|
Chris@437
|
400 getValueExtents(min, max, logarithmic, unit);
|
Chris@437
|
401
|
Chris@437
|
402 float dmin, dmax;
|
Chris@437
|
403 getDisplayExtents(dmin, dmax);
|
Chris@437
|
404
|
Chris@437
|
405 float newdist = mapper->getValueForPosition(100 - step);
|
Chris@437
|
406
|
Chris@437
|
407 float newmin, newmax;
|
Chris@437
|
408
|
Chris@437
|
409 if (logarithmic) {
|
Chris@437
|
410
|
Chris@437
|
411 // see SpectrogramLayer::setVerticalZoomStep
|
Chris@437
|
412
|
Chris@437
|
413 newmax = (newdist + sqrtf(newdist*newdist + 4*dmin*dmax)) / 2;
|
Chris@437
|
414 newmin = newmax - newdist;
|
Chris@437
|
415
|
Chris@526
|
416 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
417 std::cerr << "newmin = " << newmin << ", newmax = " << newmax << std::endl;
|
Chris@526
|
418 #endif
|
Chris@437
|
419
|
Chris@437
|
420 } else {
|
Chris@437
|
421 float dmid = (dmax + dmin) / 2;
|
Chris@437
|
422 newmin = dmid - newdist / 2;
|
Chris@437
|
423 newmax = dmid + newdist / 2;
|
Chris@437
|
424 }
|
Chris@437
|
425
|
Chris@437
|
426 if (newmin < min) {
|
Chris@437
|
427 newmax += (min - newmin);
|
Chris@437
|
428 newmin = min;
|
Chris@437
|
429 }
|
Chris@437
|
430 if (newmax > max) {
|
Chris@437
|
431 newmax = max;
|
Chris@437
|
432 }
|
Chris@437
|
433
|
Chris@526
|
434 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@437
|
435 std::cerr << "TimeValueLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << newdist << ")" << std::endl;
|
Chris@526
|
436 #endif
|
Chris@437
|
437
|
Chris@437
|
438 setDisplayExtents(newmin, newmax);
|
Chris@437
|
439 }
|
Chris@437
|
440
|
Chris@437
|
441 RangeMapper *
|
Chris@437
|
442 TimeValueLayer::getNewVerticalZoomRangeMapper() const
|
Chris@437
|
443 {
|
Chris@437
|
444 if (!m_model) return 0;
|
Chris@437
|
445
|
Chris@437
|
446 RangeMapper *mapper;
|
Chris@437
|
447
|
Chris@437
|
448 float min, max;
|
Chris@437
|
449 bool logarithmic;
|
Chris@437
|
450 QString unit;
|
Chris@437
|
451 getValueExtents(min, max, logarithmic, unit);
|
Chris@437
|
452
|
Chris@437
|
453 if (min == max) return 0;
|
Chris@437
|
454
|
Chris@437
|
455 if (logarithmic) {
|
Chris@437
|
456 mapper = new LogRangeMapper(0, 100, min, max, unit);
|
Chris@437
|
457 } else {
|
Chris@437
|
458 mapper = new LinearRangeMapper(0, 100, min, max, unit);
|
Chris@437
|
459 }
|
Chris@437
|
460
|
Chris@437
|
461 return mapper;
|
Chris@437
|
462 }
|
Chris@437
|
463
|
Chris@0
|
464 SparseTimeValueModel::PointList
|
Chris@44
|
465 TimeValueLayer::getLocalPoints(View *v, int x) const
|
Chris@0
|
466 {
|
Chris@0
|
467 if (!m_model) return SparseTimeValueModel::PointList();
|
Chris@0
|
468
|
Chris@44
|
469 long frame = v->getFrameForX(x);
|
Chris@0
|
470
|
Chris@0
|
471 SparseTimeValueModel::PointList onPoints =
|
Chris@0
|
472 m_model->getPoints(frame);
|
Chris@0
|
473
|
Chris@0
|
474 if (!onPoints.empty()) {
|
Chris@0
|
475 return onPoints;
|
Chris@0
|
476 }
|
Chris@0
|
477
|
Chris@0
|
478 SparseTimeValueModel::PointList prevPoints =
|
Chris@0
|
479 m_model->getPreviousPoints(frame);
|
Chris@0
|
480 SparseTimeValueModel::PointList nextPoints =
|
Chris@0
|
481 m_model->getNextPoints(frame);
|
Chris@0
|
482
|
Chris@0
|
483 SparseTimeValueModel::PointList usePoints = prevPoints;
|
Chris@0
|
484
|
Chris@0
|
485 if (prevPoints.empty()) {
|
Chris@0
|
486 usePoints = nextPoints;
|
Chris@248
|
487 } else if (long(prevPoints.begin()->frame) < v->getStartFrame() &&
|
Chris@44
|
488 !(nextPoints.begin()->frame > v->getEndFrame())) {
|
Chris@0
|
489 usePoints = nextPoints;
|
Chris@0
|
490 } else if (nextPoints.begin()->frame - frame <
|
Chris@0
|
491 frame - prevPoints.begin()->frame) {
|
Chris@0
|
492 usePoints = nextPoints;
|
Chris@0
|
493 }
|
Chris@0
|
494
|
Chris@28
|
495 if (!usePoints.empty()) {
|
Chris@28
|
496 int fuzz = 2;
|
Chris@44
|
497 int px = v->getXForFrame(usePoints.begin()->frame);
|
Chris@28
|
498 if ((px > x && px - x > fuzz) ||
|
Chris@28
|
499 (px < x && x - px > fuzz + 1)) {
|
Chris@28
|
500 usePoints.clear();
|
Chris@28
|
501 }
|
Chris@28
|
502 }
|
Chris@28
|
503
|
Chris@0
|
504 return usePoints;
|
Chris@0
|
505 }
|
Chris@0
|
506
|
Chris@25
|
507 QString
|
Chris@552
|
508 TimeValueLayer::getLabelPreceding(size_t frame) const
|
Chris@552
|
509 {
|
Chris@552
|
510 if (!m_model) return "";
|
Chris@552
|
511 SparseTimeValueModel::PointList points = m_model->getPreviousPoints(frame);
|
Chris@552
|
512 for (SparseTimeValueModel::PointList::const_iterator i = points.begin();
|
Chris@552
|
513 i != points.end(); ++i) {
|
Chris@552
|
514 if (i->label != "") return i->label;
|
Chris@552
|
515 }
|
Chris@552
|
516 return "";
|
Chris@552
|
517 }
|
Chris@552
|
518
|
Chris@552
|
519 QString
|
Chris@44
|
520 TimeValueLayer::getFeatureDescription(View *v, QPoint &pos) const
|
Chris@0
|
521 {
|
Chris@25
|
522 int x = pos.x();
|
Chris@0
|
523
|
Chris@25
|
524 if (!m_model || !m_model->getSampleRate()) return "";
|
Chris@0
|
525
|
Chris@44
|
526 SparseTimeValueModel::PointList points = getLocalPoints(v, x);
|
Chris@0
|
527
|
Chris@0
|
528 if (points.empty()) {
|
Chris@0
|
529 if (!m_model->isReady()) {
|
Chris@25
|
530 return tr("In progress");
|
Chris@25
|
531 } else {
|
Chris@25
|
532 return tr("No local points");
|
Chris@0
|
533 }
|
Chris@0
|
534 }
|
Chris@0
|
535
|
Chris@0
|
536 long useFrame = points.begin()->frame;
|
Chris@0
|
537
|
Chris@0
|
538 RealTime rt = RealTime::frame2RealTime(useFrame, m_model->getSampleRate());
|
Chris@25
|
539
|
Chris@25
|
540 QString text;
|
Chris@101
|
541 QString unit = m_model->getScaleUnits();
|
Chris@101
|
542 if (unit != "") unit = " " + unit;
|
Chris@0
|
543
|
Chris@25
|
544 if (points.begin()->label == "") {
|
Chris@101
|
545 text = QString(tr("Time:\t%1\nValue:\t%2%3\nNo label"))
|
Chris@25
|
546 .arg(rt.toText(true).c_str())
|
Chris@25
|
547 .arg(points.begin()->value)
|
Chris@101
|
548 .arg(unit);
|
Chris@101
|
549 } else {
|
Chris@101
|
550 text = QString(tr("Time:\t%1\nValue:\t%2%3\nLabel:\t%4"))
|
Chris@101
|
551 .arg(rt.toText(true).c_str())
|
Chris@101
|
552 .arg(points.begin()->value)
|
Chris@101
|
553 .arg(unit)
|
Chris@25
|
554 .arg(points.begin()->label);
|
Chris@25
|
555 }
|
Chris@0
|
556
|
Chris@44
|
557 pos = QPoint(v->getXForFrame(useFrame),
|
Chris@44
|
558 getYForValue(v, points.begin()->value));
|
Chris@25
|
559 return text;
|
Chris@0
|
560 }
|
Chris@0
|
561
|
Chris@28
|
562 bool
|
Chris@44
|
563 TimeValueLayer::snapToFeatureFrame(View *v, int &frame,
|
Chris@28
|
564 size_t &resolution,
|
Chris@28
|
565 SnapType snap) const
|
Chris@13
|
566 {
|
Chris@13
|
567 if (!m_model) {
|
Chris@44
|
568 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
|
Chris@13
|
569 }
|
Chris@13
|
570
|
Chris@13
|
571 resolution = m_model->getResolution();
|
Chris@28
|
572 SparseTimeValueModel::PointList points;
|
Chris@13
|
573
|
Chris@28
|
574 if (snap == SnapNeighbouring) {
|
Chris@28
|
575
|
Chris@44
|
576 points = getLocalPoints(v, v->getXForFrame(frame));
|
Chris@28
|
577 if (points.empty()) return false;
|
Chris@28
|
578 frame = points.begin()->frame;
|
Chris@28
|
579 return true;
|
Chris@28
|
580 }
|
Chris@28
|
581
|
Chris@28
|
582 points = m_model->getPoints(frame, frame);
|
Chris@28
|
583 int snapped = frame;
|
Chris@28
|
584 bool found = false;
|
Chris@13
|
585
|
Chris@13
|
586 for (SparseTimeValueModel::PointList::const_iterator i = points.begin();
|
Chris@13
|
587 i != points.end(); ++i) {
|
Chris@13
|
588
|
Chris@28
|
589 if (snap == SnapRight) {
|
Chris@28
|
590
|
Chris@13
|
591 if (i->frame > frame) {
|
Chris@28
|
592 snapped = i->frame;
|
Chris@28
|
593 found = true;
|
Chris@13
|
594 break;
|
Chris@13
|
595 }
|
Chris@28
|
596
|
Chris@28
|
597 } else if (snap == SnapLeft) {
|
Chris@28
|
598
|
Chris@13
|
599 if (i->frame <= frame) {
|
Chris@28
|
600 snapped = i->frame;
|
Chris@28
|
601 found = true; // don't break, as the next may be better
|
Chris@28
|
602 } else {
|
Chris@28
|
603 break;
|
Chris@28
|
604 }
|
Chris@28
|
605
|
Chris@28
|
606 } else { // nearest
|
Chris@28
|
607
|
Chris@28
|
608 SparseTimeValueModel::PointList::const_iterator j = i;
|
Chris@28
|
609 ++j;
|
Chris@28
|
610
|
Chris@28
|
611 if (j == points.end()) {
|
Chris@28
|
612
|
Chris@28
|
613 snapped = i->frame;
|
Chris@28
|
614 found = true;
|
Chris@28
|
615 break;
|
Chris@28
|
616
|
Chris@28
|
617 } else if (j->frame >= frame) {
|
Chris@28
|
618
|
Chris@28
|
619 if (j->frame - frame < frame - i->frame) {
|
Chris@28
|
620 snapped = j->frame;
|
Chris@28
|
621 } else {
|
Chris@28
|
622 snapped = i->frame;
|
Chris@28
|
623 }
|
Chris@28
|
624 found = true;
|
Chris@28
|
625 break;
|
Chris@13
|
626 }
|
Chris@13
|
627 }
|
Chris@13
|
628 }
|
Chris@13
|
629
|
Chris@28
|
630 frame = snapped;
|
Chris@28
|
631 return found;
|
Chris@13
|
632 }
|
Chris@13
|
633
|
Chris@517
|
634 bool
|
Chris@517
|
635 TimeValueLayer::snapToSimilarFeature(View *v, int &frame,
|
Chris@517
|
636 size_t &resolution,
|
Chris@517
|
637 SnapType snap) const
|
Chris@517
|
638 {
|
Chris@517
|
639 if (!m_model) {
|
Chris@517
|
640 return Layer::snapToSimilarFeature(v, frame, resolution, snap);
|
Chris@517
|
641 }
|
Chris@517
|
642
|
Chris@517
|
643 resolution = m_model->getResolution();
|
Chris@517
|
644
|
Chris@517
|
645 const SparseTimeValueModel::PointList &points = m_model->getPoints();
|
Chris@517
|
646 SparseTimeValueModel::PointList close = m_model->getPoints(frame, frame);
|
Chris@517
|
647
|
Chris@517
|
648 SparseTimeValueModel::PointList::const_iterator i;
|
Chris@517
|
649
|
Chris@517
|
650 int matchframe = frame;
|
Chris@517
|
651 float matchvalue = 0.f;
|
Chris@517
|
652
|
Chris@517
|
653 for (i = close.begin(); i != close.end(); ++i) {
|
Chris@517
|
654 if (i->frame > frame) break;
|
Chris@517
|
655 matchvalue = i->value;
|
Chris@517
|
656 matchframe = i->frame;
|
Chris@517
|
657 }
|
Chris@517
|
658
|
Chris@517
|
659 int snapped = frame;
|
Chris@517
|
660 bool found = false;
|
Chris@517
|
661 bool distant = false;
|
Chris@517
|
662 float epsilon = 0.0001;
|
Chris@517
|
663
|
Chris@517
|
664 i = close.begin();
|
Chris@517
|
665
|
Chris@517
|
666 // Scan through the close points first, then the more distant ones
|
Chris@517
|
667 // if no suitable close one is found
|
Chris@517
|
668
|
Chris@517
|
669 while (i != points.end()) {
|
Chris@517
|
670
|
Chris@517
|
671 if (i == close.end()) {
|
Chris@517
|
672 i = points.begin();
|
Chris@517
|
673 distant = true;
|
Chris@517
|
674 }
|
Chris@517
|
675
|
Chris@517
|
676 if (snap == SnapRight) {
|
Chris@517
|
677
|
Chris@517
|
678 if (i->frame > matchframe &&
|
Chris@517
|
679 fabsf(i->value - matchvalue) < epsilon) {
|
Chris@517
|
680 snapped = i->frame;
|
Chris@517
|
681 found = true;
|
Chris@517
|
682 break;
|
Chris@517
|
683 }
|
Chris@517
|
684
|
Chris@517
|
685 } else if (snap == SnapLeft) {
|
Chris@517
|
686
|
Chris@517
|
687 if (i->frame < matchframe) {
|
Chris@517
|
688 if (fabsf(i->value - matchvalue) < epsilon) {
|
Chris@517
|
689 snapped = i->frame;
|
Chris@517
|
690 found = true; // don't break, as the next may be better
|
Chris@517
|
691 }
|
Chris@517
|
692 } else if (found || distant) {
|
Chris@517
|
693 break;
|
Chris@517
|
694 }
|
Chris@517
|
695
|
Chris@517
|
696 } else {
|
Chris@517
|
697 // no other snap types supported
|
Chris@517
|
698 }
|
Chris@517
|
699
|
Chris@517
|
700 ++i;
|
Chris@517
|
701 }
|
Chris@517
|
702
|
Chris@517
|
703 frame = snapped;
|
Chris@517
|
704 return found;
|
Chris@517
|
705 }
|
Chris@517
|
706
|
Chris@101
|
707 void
|
Chris@101
|
708 TimeValueLayer::getScaleExtents(View *v, float &min, float &max, bool &log) const
|
Chris@101
|
709 {
|
Chris@101
|
710 min = 0.0;
|
Chris@101
|
711 max = 0.0;
|
Chris@101
|
712 log = false;
|
Chris@101
|
713
|
Chris@296
|
714 if (shouldAutoAlign()) {
|
Chris@101
|
715
|
Chris@101
|
716 if (!v->getValueExtents(m_model->getScaleUnits(), min, max, log)) {
|
Chris@101
|
717 min = m_model->getValueMinimum();
|
Chris@101
|
718 max = m_model->getValueMaximum();
|
Chris@101
|
719 } else if (log) {
|
Chris@197
|
720 LogRange::mapRange(min, max);
|
Chris@101
|
721 }
|
Chris@101
|
722
|
Chris@101
|
723 } else if (m_verticalScale == PlusMinusOneScale) {
|
Chris@101
|
724
|
Chris@101
|
725 min = -1.0;
|
Chris@101
|
726 max = 1.0;
|
Chris@101
|
727
|
Chris@101
|
728 } else {
|
Chris@101
|
729
|
Chris@437
|
730 getDisplayExtents(min, max);
|
Chris@101
|
731
|
Chris@101
|
732 if (m_verticalScale == LogScale) {
|
Chris@197
|
733 LogRange::mapRange(min, max);
|
Chris@101
|
734 log = true;
|
Chris@101
|
735 }
|
Chris@101
|
736 }
|
Chris@101
|
737
|
Chris@101
|
738 if (max == min) max = min + 1.0;
|
Chris@101
|
739 }
|
Chris@101
|
740
|
Chris@21
|
741 int
|
Chris@66
|
742 TimeValueLayer::getYForValue(View *v, float val) const
|
Chris@21
|
743 {
|
Chris@79
|
744 float min = 0.0, max = 0.0;
|
Chris@101
|
745 bool logarithmic = false;
|
Chris@79
|
746 int h = v->height();
|
Chris@79
|
747
|
Chris@101
|
748 getScaleExtents(v, min, max, logarithmic);
|
Chris@101
|
749
|
Chris@526
|
750 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
751 std::cerr << "getYForValue(" << val << "): min " << min << ", max "
|
Chris@526
|
752 << max << ", log " << logarithmic << std::endl;
|
Chris@526
|
753 #endif
|
Chris@101
|
754
|
Chris@101
|
755 if (logarithmic) {
|
Chris@197
|
756 val = LogRange::map(val);
|
Chris@79
|
757 }
|
Chris@79
|
758
|
Chris@66
|
759 return int(h - ((val - min) * h) / (max - min));
|
Chris@21
|
760 }
|
Chris@21
|
761
|
Chris@21
|
762 float
|
Chris@44
|
763 TimeValueLayer::getValueForY(View *v, int y) const
|
Chris@21
|
764 {
|
Chris@101
|
765 float min = 0.0, max = 0.0;
|
Chris@101
|
766 bool logarithmic = false;
|
Chris@44
|
767 int h = v->height();
|
Chris@21
|
768
|
Chris@101
|
769 getScaleExtents(v, min, max, logarithmic);
|
Chris@101
|
770
|
Chris@101
|
771 float val = min + (float(h - y) * float(max - min)) / h;
|
Chris@101
|
772
|
Chris@101
|
773 if (logarithmic) {
|
Chris@437
|
774 val = LogRange::map(val);
|
Chris@101
|
775 }
|
Chris@101
|
776
|
Chris@101
|
777 return val;
|
Chris@21
|
778 }
|
Chris@21
|
779
|
Chris@296
|
780 bool
|
Chris@296
|
781 TimeValueLayer::shouldAutoAlign() const
|
Chris@296
|
782 {
|
Chris@296
|
783 if (!m_model) return false;
|
Chris@296
|
784 QString unit = m_model->getScaleUnits();
|
Chris@296
|
785 return (m_verticalScale == AutoAlignScale && unit != "");
|
Chris@296
|
786 }
|
Chris@296
|
787
|
Chris@68
|
788 QColor
|
Chris@101
|
789 TimeValueLayer::getColourForValue(View *v, float val) const
|
Chris@68
|
790 {
|
Chris@101
|
791 float min, max;
|
Chris@101
|
792 bool log;
|
Chris@101
|
793 getScaleExtents(v, min, max, log);
|
Chris@68
|
794
|
Chris@197
|
795 if (min > max) std::swap(min, max);
|
Chris@197
|
796 if (max == min) max = min + 1;
|
Chris@197
|
797
|
Chris@101
|
798 if (log) {
|
Chris@197
|
799 val = LogRange::map(val);
|
Chris@68
|
800 }
|
Chris@68
|
801
|
Chris@526
|
802 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
803 std::cerr << "TimeValueLayer::getColourForValue: min " << min << ", max "
|
Chris@526
|
804 << max << ", log " << log << ", value " << val << std::endl;
|
Chris@526
|
805 #endif
|
Chris@68
|
806
|
Chris@197
|
807 QColor solid = ColourMapper(m_colourMap, min, max).map(val);
|
Chris@197
|
808 return QColor(solid.red(), solid.green(), solid.blue(), 120);
|
Chris@68
|
809 }
|
Chris@68
|
810
|
Chris@287
|
811 int
|
Chris@287
|
812 TimeValueLayer::getDefaultColourHint(bool darkbg, bool &impose)
|
Chris@287
|
813 {
|
Chris@287
|
814 impose = false;
|
Chris@287
|
815 return ColourDatabase::getInstance()->getColourIndex
|
Chris@287
|
816 (QString(darkbg ? "Bright Green" : "Green"));
|
Chris@287
|
817 }
|
Chris@287
|
818
|
Chris@0
|
819 void
|
Chris@44
|
820 TimeValueLayer::paint(View *v, QPainter &paint, QRect rect) const
|
Chris@0
|
821 {
|
Chris@0
|
822 if (!m_model || !m_model->isOK()) return;
|
Chris@0
|
823
|
Chris@0
|
824 int sampleRate = m_model->getSampleRate();
|
Chris@0
|
825 if (!sampleRate) return;
|
Chris@0
|
826
|
Chris@353
|
827 paint.setRenderHint(QPainter::Antialiasing, false);
|
Chris@353
|
828
|
Chris@0
|
829 // Profiler profiler("TimeValueLayer::paint", true);
|
Chris@0
|
830
|
Chris@0
|
831 int x0 = rect.left(), x1 = rect.right();
|
Chris@44
|
832 long frame0 = v->getFrameForX(x0);
|
Chris@44
|
833 long frame1 = v->getFrameForX(x1);
|
Chris@0
|
834
|
Chris@0
|
835 SparseTimeValueModel::PointList points(m_model->getPoints
|
Chris@0
|
836 (frame0, frame1));
|
Chris@11
|
837 if (points.empty()) return;
|
Chris@0
|
838
|
Chris@287
|
839 paint.setPen(getBaseQColor());
|
Chris@0
|
840
|
Chris@287
|
841 QColor brushColour(getBaseQColor());
|
Chris@0
|
842 brushColour.setAlpha(80);
|
Chris@0
|
843 paint.setBrush(brushColour);
|
Chris@0
|
844
|
Chris@526
|
845 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
846 std::cerr << "TimeValueLayer::paint: resolution is "
|
Chris@526
|
847 << m_model->getResolution() << " frames" << std::endl;
|
Chris@526
|
848 #endif
|
Chris@0
|
849
|
Chris@0
|
850 float min = m_model->getValueMinimum();
|
Chris@0
|
851 float max = m_model->getValueMaximum();
|
Chris@0
|
852 if (max == min) max = min + 1.0;
|
Chris@0
|
853
|
Chris@44
|
854 int origin = int(nearbyint(v->height() -
|
Chris@44
|
855 (-min * v->height()) / (max - min)));
|
Chris@0
|
856
|
Chris@0
|
857 QPoint localPos;
|
Chris@0
|
858 long illuminateFrame = -1;
|
Chris@0
|
859
|
Chris@44
|
860 if (v->shouldIlluminateLocalFeatures(this, localPos)) {
|
Chris@0
|
861 SparseTimeValueModel::PointList localPoints =
|
Chris@44
|
862 getLocalPoints(v, localPos.x());
|
Chris@526
|
863 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
864 std::cerr << "TimeValueLayer: " << localPoints.size() << " local points" << std::endl;
|
Chris@526
|
865 #endif
|
Chris@0
|
866 if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame;
|
Chris@0
|
867 }
|
Chris@6
|
868
|
Chris@20
|
869 int w =
|
Chris@44
|
870 v->getXForFrame(frame0 + m_model->getResolution()) -
|
Chris@44
|
871 v->getXForFrame(frame0);
|
Chris@7
|
872
|
Chris@6
|
873 paint.save();
|
Chris@6
|
874
|
Chris@6
|
875 QPainterPath path;
|
Chris@55
|
876 int pointCount = 0;
|
Chris@79
|
877
|
Chris@79
|
878 int textY = 0;
|
Chris@79
|
879 if (m_plotStyle == PlotSegmentation) {
|
Chris@79
|
880 textY = v->getTextLabelHeight(this, paint);
|
Chris@79
|
881 }
|
Chris@6
|
882
|
Chris@0
|
883 for (SparseTimeValueModel::PointList::const_iterator i = points.begin();
|
Chris@0
|
884 i != points.end(); ++i) {
|
Chris@0
|
885
|
Chris@0
|
886 const SparseTimeValueModel::Point &p(*i);
|
Chris@0
|
887
|
Chris@44
|
888 int x = v->getXForFrame(p.frame);
|
Chris@44
|
889 int y = getYForValue(v, p.value);
|
Chris@0
|
890
|
Chris@79
|
891 if (m_plotStyle != PlotSegmentation) {
|
Chris@79
|
892 textY = y - paint.fontMetrics().height()
|
Chris@79
|
893 + paint.fontMetrics().ascent();
|
Chris@372
|
894 if (textY < paint.fontMetrics().ascent() + 1) {
|
Chris@372
|
895 textY = paint.fontMetrics().ascent() + 1;
|
Chris@372
|
896 }
|
Chris@79
|
897 }
|
Chris@79
|
898
|
Chris@34
|
899 bool haveNext = false;
|
Chris@76
|
900 int nx = v->getXForFrame(v->getModelsEndFrame());
|
Chris@34
|
901 int ny = y;
|
Chris@34
|
902
|
Chris@34
|
903 SparseTimeValueModel::PointList::const_iterator j = i;
|
Chris@34
|
904 ++j;
|
Chris@34
|
905
|
Chris@34
|
906 if (j != points.end()) {
|
Chris@34
|
907 const SparseTimeValueModel::Point &q(*j);
|
Chris@44
|
908 nx = v->getXForFrame(q.frame);
|
Chris@44
|
909 ny = getYForValue(v, q.value);
|
Chris@34
|
910 haveNext = true;
|
Chris@76
|
911 }
|
Chris@76
|
912
|
Chris@76
|
913 // std::cout << "frame = " << p.frame << ", x = " << x << ", haveNext = " << haveNext
|
Chris@76
|
914 // << ", nx = " << nx << std::endl;
|
Chris@34
|
915
|
Chris@0
|
916 if (w < 1) w = 1;
|
Chris@287
|
917 paint.setPen(getBaseQColor());
|
Chris@0
|
918
|
Chris@26
|
919 if (m_plotStyle == PlotSegmentation) {
|
Chris@287
|
920 paint.setPen(getForegroundQColor(v));
|
Chris@101
|
921 paint.setBrush(getColourForValue(v, p.value));
|
Chris@26
|
922 } else if (m_plotStyle == PlotLines ||
|
Chris@26
|
923 m_plotStyle == PlotCurve) {
|
Chris@6
|
924 paint.setBrush(Qt::NoBrush);
|
Chris@3
|
925 } else {
|
Chris@6
|
926 paint.setBrush(brushColour);
|
Chris@3
|
927 }
|
Chris@0
|
928
|
Chris@0
|
929 if (m_plotStyle == PlotStems) {
|
Chris@430
|
930 /*
|
Chris@0
|
931 paint.setPen(brushColour);
|
Chris@0
|
932 if (y < origin - 1) {
|
Chris@0
|
933 paint.drawRect(x + w/2, y + 1, 1, origin - y);
|
Chris@0
|
934 } else if (y > origin + 1) {
|
Chris@0
|
935 paint.drawRect(x + w/2, origin, 1, y - origin - 1);
|
Chris@0
|
936 }
|
Chris@430
|
937 */
|
Chris@287
|
938 paint.setPen(getBaseQColor());
|
Chris@430
|
939 if (y < origin - 1) {
|
Chris@430
|
940 paint.drawLine(x + w/2, y + 1, x + w/2, origin);
|
Chris@430
|
941 } else if (y > origin + 1) {
|
Chris@430
|
942 paint.drawLine(x + w/2, origin, x + w/2, y - 1);
|
Chris@430
|
943 }
|
Chris@0
|
944 }
|
Chris@0
|
945
|
Chris@0
|
946 if (illuminateFrame == p.frame) {
|
Chris@6
|
947
|
Chris@0
|
948 //!!! aside from the problem of choosing a colour, it'd be
|
Chris@0
|
949 //better to save the highlighted rects and draw them at
|
Chris@0
|
950 //the end perhaps
|
Chris@6
|
951
|
Chris@6
|
952 //!!! not equipped to illuminate the right section in line
|
Chris@6
|
953 //or curve mode
|
Chris@6
|
954
|
Chris@6
|
955 if (m_plotStyle != PlotCurve &&
|
Chris@6
|
956 m_plotStyle != PlotLines) {
|
Chris@287
|
957 paint.setPen(getForegroundQColor(v));
|
Chris@6
|
958 }
|
Chris@0
|
959 }
|
Chris@0
|
960
|
Chris@6
|
961 if (m_plotStyle != PlotLines &&
|
Chris@26
|
962 m_plotStyle != PlotCurve &&
|
Chris@26
|
963 m_plotStyle != PlotSegmentation) {
|
Chris@326
|
964 if (m_plotStyle != PlotStems ||
|
Chris@326
|
965 w > 1) {
|
Chris@326
|
966 paint.drawRect(x, y - 1, w, 2);
|
Chris@326
|
967 }
|
Chris@3
|
968 }
|
Chris@0
|
969
|
Chris@6
|
970 if (m_plotStyle == PlotConnectedPoints ||
|
Chris@6
|
971 m_plotStyle == PlotLines ||
|
Chris@6
|
972 m_plotStyle == PlotCurve) {
|
Chris@0
|
973
|
Chris@34
|
974 if (haveNext) {
|
Chris@3
|
975
|
Chris@6
|
976 if (m_plotStyle == PlotConnectedPoints) {
|
Chris@34
|
977
|
Chris@79
|
978 paint.save();
|
Chris@3
|
979 paint.setPen(brushColour);
|
Chris@3
|
980 paint.drawLine(x + w, y, nx, ny);
|
Chris@79
|
981 paint.restore();
|
Chris@6
|
982
|
Chris@6
|
983 } else if (m_plotStyle == PlotLines) {
|
Chris@430
|
984
|
Chris@430
|
985 if (pointCount == 0) {
|
Chris@430
|
986 path.moveTo(x + w/2, y);
|
Chris@430
|
987 }
|
Chris@430
|
988 ++pointCount;
|
Chris@6
|
989
|
Chris@430
|
990 // paint.drawLine(x + w/2, y, nx + w/2, ny);
|
Chris@430
|
991 path.lineTo(nx + w/2, ny);
|
Chris@6
|
992
|
Chris@3
|
993 } else {
|
Chris@6
|
994
|
Chris@55
|
995 float x0 = x + float(w)/2;
|
Chris@55
|
996 float x1 = nx + float(w)/2;
|
Chris@55
|
997
|
Chris@55
|
998 float y0 = y;
|
Chris@55
|
999 float y1 = ny;
|
Chris@55
|
1000
|
Chris@55
|
1001 if (pointCount == 0) {
|
Chris@55
|
1002 path.moveTo((x0 + x1) / 2, (y0 + y1) / 2);
|
Chris@6
|
1003 }
|
Chris@55
|
1004 ++pointCount;
|
Chris@6
|
1005
|
Chris@6
|
1006 if (nx - x > 5) {
|
Chris@55
|
1007 path.cubicTo(x0, y0,
|
Chris@55
|
1008 x0, y0,
|
Chris@55
|
1009 (x0 + x1) / 2, (y0 + y1) / 2);
|
Chris@55
|
1010
|
Chris@55
|
1011 // // or
|
Chris@55
|
1012 // path.quadTo(x0, y0, (x0 + x1) / 2, (y0 + y1) / 2);
|
Chris@55
|
1013
|
Chris@6
|
1014 } else {
|
Chris@55
|
1015 path.lineTo((x0 + x1) / 2, (y0 + y1) / 2);
|
Chris@6
|
1016 }
|
Chris@3
|
1017 }
|
Chris@0
|
1018 }
|
Chris@0
|
1019 }
|
Chris@0
|
1020
|
Chris@26
|
1021 if (m_plotStyle == PlotSegmentation) {
|
Chris@76
|
1022
|
Chris@526
|
1023 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
1024 std::cerr << "drawing rect" << std::endl;
|
Chris@526
|
1025 #endif
|
Chris@26
|
1026
|
Chris@27
|
1027 if (nx <= x) continue;
|
Chris@26
|
1028
|
Chris@513
|
1029 if (illuminateFrame != p.frame) {
|
Chris@513
|
1030 if (!m_drawSegmentDivisions ||
|
Chris@513
|
1031 nx < x + 5 ||
|
Chris@513
|
1032 x >= v->width() - 1) {
|
Chris@513
|
1033 paint.setPen(Qt::NoPen);
|
Chris@513
|
1034 }
|
Chris@27
|
1035 }
|
Chris@26
|
1036
|
Chris@44
|
1037 paint.drawRect(x, -1, nx - x, v->height() + 1);
|
Chris@26
|
1038 }
|
Chris@26
|
1039
|
Chris@55
|
1040 if (p.label != "") {
|
Chris@79
|
1041 if (!haveNext || nx > x + 6 + paint.fontMetrics().width(p.label)) {
|
Chris@79
|
1042 paint.drawText(x + 5, textY, p.label);
|
Chris@79
|
1043 }
|
Chris@55
|
1044 }
|
Chris@0
|
1045 }
|
Chris@6
|
1046
|
Chris@430
|
1047 if ((m_plotStyle == PlotCurve || m_plotStyle == PlotLines)
|
Chris@430
|
1048 && !path.isEmpty()) {
|
Chris@55
|
1049 paint.setRenderHint(QPainter::Antialiasing, pointCount <= v->width());
|
Chris@6
|
1050 paint.drawPath(path);
|
Chris@6
|
1051 }
|
Chris@6
|
1052
|
Chris@6
|
1053 paint.restore();
|
Chris@6
|
1054
|
Chris@6
|
1055 // looks like save/restore doesn't deal with this:
|
Chris@6
|
1056 paint.setRenderHint(QPainter::Antialiasing, false);
|
Chris@6
|
1057 }
|
Chris@6
|
1058
|
Chris@42
|
1059 int
|
Chris@248
|
1060 TimeValueLayer::getVerticalScaleWidth(View *, QPainter &paint) const
|
Chris@42
|
1061 {
|
Chris@68
|
1062 int w = paint.fontMetrics().width("-000.000");
|
Chris@68
|
1063 if (m_plotStyle == PlotSegmentation) return w + 20;
|
Chris@68
|
1064 else return w + 10;
|
Chris@42
|
1065 }
|
Chris@42
|
1066
|
Chris@42
|
1067 void
|
Chris@248
|
1068 TimeValueLayer::paintVerticalScale(View *v, QPainter &paint, QRect) const
|
Chris@42
|
1069 {
|
Chris@42
|
1070 if (!m_model) return;
|
Chris@42
|
1071
|
Chris@68
|
1072 int h = v->height();
|
Chris@68
|
1073
|
Chris@68
|
1074 int n = 10;
|
Chris@68
|
1075
|
Chris@437
|
1076 float min, max;
|
Chris@437
|
1077 bool logarithmic;
|
Chris@437
|
1078 getScaleExtents(v, min, max, logarithmic);
|
Chris@437
|
1079
|
Chris@437
|
1080 if (m_plotStyle == PlotSegmentation) {
|
Chris@437
|
1081 QString unit;
|
Chris@437
|
1082 getValueExtents(min, max, logarithmic, unit);
|
Chris@437
|
1083 if (logarithmic) {
|
Chris@437
|
1084 LogRange::mapRange(min, max);
|
Chris@437
|
1085 }
|
Chris@437
|
1086 }
|
Chris@437
|
1087
|
Chris@68
|
1088 float val = min;
|
Chris@68
|
1089 float inc = (max - val) / n;
|
Chris@42
|
1090
|
Chris@55
|
1091 char buffer[40];
|
Chris@55
|
1092
|
Chris@55
|
1093 int w = getVerticalScaleWidth(v, paint);
|
Chris@55
|
1094
|
Chris@68
|
1095 int tx = 5;
|
Chris@68
|
1096
|
Chris@68
|
1097 int boxx = 5, boxy = 5;
|
Chris@68
|
1098 if (m_model->getScaleUnits() != "") {
|
Chris@68
|
1099 boxy += paint.fontMetrics().height();
|
Chris@68
|
1100 }
|
Chris@68
|
1101 int boxw = 10, boxh = h - boxy - 5;
|
Chris@68
|
1102
|
Chris@68
|
1103 if (m_plotStyle == PlotSegmentation) {
|
Chris@68
|
1104 tx += boxx + boxw;
|
Chris@68
|
1105 paint.drawRect(boxx, boxy, boxw, boxh);
|
Chris@68
|
1106 }
|
Chris@68
|
1107
|
Chris@68
|
1108 if (m_plotStyle == PlotSegmentation) {
|
Chris@68
|
1109 paint.save();
|
Chris@68
|
1110 for (int y = 0; y < boxh; ++y) {
|
Chris@68
|
1111 float val = ((boxh - y) * (max - min)) / boxh + min;
|
Chris@437
|
1112 if (logarithmic) {
|
Chris@437
|
1113 paint.setPen(getColourForValue(v, LogRange::unmap(val)));
|
Chris@437
|
1114 } else {
|
Chris@437
|
1115 paint.setPen(getColourForValue(v, val));
|
Chris@437
|
1116 }
|
Chris@68
|
1117 paint.drawLine(boxx + 1, y + boxy + 1, boxx + boxw, y + boxy + 1);
|
Chris@68
|
1118 }
|
Chris@68
|
1119 paint.restore();
|
Chris@68
|
1120 }
|
Chris@434
|
1121
|
Chris@434
|
1122 float round = 1.f;
|
Chris@434
|
1123 int dp = 0;
|
Chris@434
|
1124 if (inc > 0) {
|
Chris@434
|
1125 int prec = trunc(log10f(inc));
|
Chris@434
|
1126 prec -= 1;
|
Chris@434
|
1127 if (prec < 0) dp = -prec;
|
Chris@434
|
1128 round = powf(10.f, prec);
|
Chris@526
|
1129 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
1130 std::cerr << "inc = " << inc << ", round = " << round << std::endl;
|
Chris@526
|
1131 #endif
|
Chris@434
|
1132 }
|
Chris@68
|
1133
|
Chris@434
|
1134 int prevy = -1;
|
Chris@434
|
1135
|
Chris@68
|
1136 for (int i = 0; i < n; ++i) {
|
Chris@68
|
1137
|
Chris@68
|
1138 int y, ty;
|
Chris@68
|
1139 bool drawText = true;
|
Chris@68
|
1140
|
Chris@434
|
1141 float dispval = val;
|
Chris@434
|
1142
|
Chris@68
|
1143 if (m_plotStyle == PlotSegmentation) {
|
Chris@68
|
1144 y = boxy + int(boxh - ((val - min) * boxh) / (max - min));
|
Chris@68
|
1145 ty = y;
|
Chris@68
|
1146 } else {
|
Chris@437
|
1147 if (i == n-1 &&
|
Chris@437
|
1148 v->height() < paint.fontMetrics().height() * (n*2)) {
|
Chris@68
|
1149 if (m_model->getScaleUnits() != "") drawText = false;
|
Chris@68
|
1150 }
|
Chris@434
|
1151 dispval = lrintf(val / round) * round;
|
Chris@526
|
1152 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
1153 std::cerr << "val = " << val << ", dispval = " << dispval << std::endl;
|
Chris@526
|
1154 #endif
|
Chris@437
|
1155 if (logarithmic) {
|
Chris@437
|
1156 y = getYForValue(v, LogRange::unmap(dispval));
|
Chris@437
|
1157 } else {
|
Chris@437
|
1158 y = getYForValue(v, dispval);
|
Chris@437
|
1159 }
|
Chris@68
|
1160 ty = y - paint.fontMetrics().height() +
|
Chris@434
|
1161 paint.fontMetrics().ascent() + 2;
|
Chris@434
|
1162
|
Chris@434
|
1163 if (prevy >= 0 && (prevy - y) < paint.fontMetrics().height()) {
|
Chris@434
|
1164 val += inc;
|
Chris@434
|
1165 continue;
|
Chris@434
|
1166 }
|
Chris@68
|
1167 }
|
Chris@68
|
1168
|
Chris@437
|
1169 if (logarithmic) {
|
Chris@437
|
1170 sprintf(buffer, "%.*g", dp < 2 ? 2 : dp, LogRange::unmap(dispval));
|
Chris@437
|
1171 } else {
|
Chris@437
|
1172 sprintf(buffer, "%.*f", dp, dispval);
|
Chris@437
|
1173 }
|
Chris@55
|
1174 QString label = QString(buffer);
|
Chris@68
|
1175
|
Chris@68
|
1176 if (m_plotStyle != PlotSegmentation) {
|
Chris@68
|
1177 paint.drawLine(w - 5, y, w, y);
|
Chris@68
|
1178 } else {
|
Chris@68
|
1179 paint.drawLine(boxx + boxw - boxw/3, y, boxx + boxw, y);
|
Chris@68
|
1180 }
|
Chris@68
|
1181
|
Chris@434
|
1182 if (drawText) {
|
Chris@435
|
1183 if (m_plotStyle != PlotSegmentation) {
|
Chris@435
|
1184 paint.drawText(tx + w - paint.fontMetrics().width(label) - 8,
|
Chris@435
|
1185 ty, label);
|
Chris@435
|
1186 } else {
|
Chris@435
|
1187 paint.drawText(tx, ty, label);
|
Chris@435
|
1188 }
|
Chris@434
|
1189 }
|
Chris@434
|
1190
|
Chris@434
|
1191 prevy = y;
|
Chris@44
|
1192 val += inc;
|
Chris@42
|
1193 }
|
Chris@68
|
1194
|
Chris@67
|
1195 if (m_model->getScaleUnits() != "") {
|
Chris@67
|
1196 paint.drawText(5, 5 + paint.fontMetrics().ascent(),
|
Chris@67
|
1197 m_model->getScaleUnits());
|
Chris@67
|
1198 }
|
Chris@42
|
1199 }
|
Chris@42
|
1200
|
Chris@21
|
1201 void
|
Chris@44
|
1202 TimeValueLayer::drawStart(View *v, QMouseEvent *e)
|
Chris@21
|
1203 {
|
Chris@526
|
1204 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
1205 std::cerr << "TimeValueLayer::drawStart(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@526
|
1206 #endif
|
Chris@21
|
1207
|
Chris@21
|
1208 if (!m_model) return;
|
Chris@21
|
1209
|
Chris@44
|
1210 long frame = v->getFrameForX(e->x());
|
Chris@76
|
1211 long resolution = m_model->getResolution();
|
Chris@21
|
1212 if (frame < 0) frame = 0;
|
Chris@76
|
1213 frame = (frame / resolution) * resolution;
|
Chris@21
|
1214
|
Chris@44
|
1215 float value = getValueForY(v, e->y());
|
Chris@21
|
1216
|
Chris@76
|
1217 bool havePoint = false;
|
Chris@76
|
1218
|
Chris@76
|
1219 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
|
Chris@76
|
1220 if (!points.empty()) {
|
Chris@76
|
1221 for (SparseTimeValueModel::PointList::iterator i = points.begin();
|
Chris@76
|
1222 i != points.end(); ++i) {
|
Chris@76
|
1223 if (((i->frame / resolution) * resolution) != frame) {
|
Chris@526
|
1224 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
1225 std::cerr << "ignoring out-of-range frame at " << i->frame << std::endl;
|
Chris@526
|
1226 #endif
|
Chris@76
|
1227 continue;
|
Chris@76
|
1228 }
|
Chris@76
|
1229 m_editingPoint = *i;
|
Chris@76
|
1230 havePoint = true;
|
Chris@76
|
1231 }
|
Chris@76
|
1232 }
|
Chris@76
|
1233
|
Chris@76
|
1234 if (!havePoint) {
|
Chris@76
|
1235 m_editingPoint = SparseTimeValueModel::Point
|
Chris@76
|
1236 (frame, value, tr("New Point"));
|
Chris@76
|
1237 }
|
Chris@76
|
1238
|
Chris@23
|
1239 m_originalPoint = m_editingPoint;
|
Chris@22
|
1240
|
Chris@376
|
1241 if (m_editingCommand) finish(m_editingCommand);
|
Chris@22
|
1242 m_editingCommand = new SparseTimeValueModel::EditCommand(m_model,
|
Chris@22
|
1243 tr("Draw Point"));
|
Chris@76
|
1244 if (!havePoint) {
|
Chris@76
|
1245 m_editingCommand->addPoint(m_editingPoint);
|
Chris@76
|
1246 }
|
Chris@22
|
1247
|
Chris@21
|
1248 m_editing = true;
|
Chris@21
|
1249 }
|
Chris@21
|
1250
|
Chris@21
|
1251 void
|
Chris@44
|
1252 TimeValueLayer::drawDrag(View *v, QMouseEvent *e)
|
Chris@21
|
1253 {
|
Chris@526
|
1254 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
1255 std::cerr << "TimeValueLayer::drawDrag(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@526
|
1256 #endif
|
Chris@21
|
1257
|
Chris@21
|
1258 if (!m_model || !m_editing) return;
|
Chris@21
|
1259
|
Chris@44
|
1260 long frame = v->getFrameForX(e->x());
|
Chris@76
|
1261 long resolution = m_model->getResolution();
|
Chris@21
|
1262 if (frame < 0) frame = 0;
|
Chris@76
|
1263 frame = (frame / resolution) * resolution;
|
Chris@21
|
1264
|
Chris@44
|
1265 float value = getValueForY(v, e->y());
|
Chris@21
|
1266
|
Chris@76
|
1267 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
|
Chris@76
|
1268
|
Chris@526
|
1269 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
1270 std::cerr << points.size() << " points" << std::endl;
|
Chris@526
|
1271 #endif
|
Chris@76
|
1272
|
Chris@76
|
1273 bool havePoint = false;
|
Chris@76
|
1274
|
Chris@76
|
1275 if (!points.empty()) {
|
Chris@76
|
1276 for (SparseTimeValueModel::PointList::iterator i = points.begin();
|
Chris@76
|
1277 i != points.end(); ++i) {
|
Chris@76
|
1278 if (i->frame == m_editingPoint.frame &&
|
Chris@76
|
1279 i->value == m_editingPoint.value) {
|
Chris@526
|
1280 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
1281 std::cerr << "ignoring current editing point at " << i->frame << ", " << i->value << std::endl;
|
Chris@526
|
1282 #endif
|
Chris@76
|
1283 continue;
|
Chris@76
|
1284 }
|
Chris@76
|
1285 if (((i->frame / resolution) * resolution) != frame) {
|
Chris@526
|
1286 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
1287 std::cerr << "ignoring out-of-range frame at " << i->frame << std::endl;
|
Chris@526
|
1288 #endif
|
Chris@76
|
1289 continue;
|
Chris@76
|
1290 }
|
Chris@526
|
1291 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
1292 std::cerr << "adjusting to new point at " << i->frame << ", " << i->value << std::endl;
|
Chris@526
|
1293 #endif
|
Chris@76
|
1294 m_editingPoint = *i;
|
Chris@76
|
1295 m_originalPoint = m_editingPoint;
|
Chris@76
|
1296 m_editingCommand->deletePoint(m_editingPoint);
|
Chris@76
|
1297 havePoint = true;
|
Chris@76
|
1298 }
|
Chris@76
|
1299 }
|
Chris@76
|
1300
|
Chris@76
|
1301 if (!havePoint) {
|
Chris@76
|
1302 if (frame == m_editingPoint.frame) {
|
Chris@76
|
1303 m_editingCommand->deletePoint(m_editingPoint);
|
Chris@76
|
1304 }
|
Chris@76
|
1305 }
|
Chris@76
|
1306
|
Chris@76
|
1307 // m_editingCommand->deletePoint(m_editingPoint);
|
Chris@21
|
1308 m_editingPoint.frame = frame;
|
Chris@21
|
1309 m_editingPoint.value = value;
|
Chris@22
|
1310 m_editingCommand->addPoint(m_editingPoint);
|
Chris@21
|
1311 }
|
Chris@21
|
1312
|
Chris@21
|
1313 void
|
Chris@248
|
1314 TimeValueLayer::drawEnd(View *, QMouseEvent *)
|
Chris@21
|
1315 {
|
Chris@526
|
1316 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
1317 std::cerr << "TimeValueLayer::drawEnd(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@526
|
1318 #endif
|
Chris@21
|
1319 if (!m_model || !m_editing) return;
|
Chris@376
|
1320 finish(m_editingCommand);
|
Chris@22
|
1321 m_editingCommand = 0;
|
Chris@21
|
1322 m_editing = false;
|
Chris@21
|
1323 }
|
Chris@21
|
1324
|
Chris@21
|
1325 void
|
Chris@335
|
1326 TimeValueLayer::eraseStart(View *v, QMouseEvent *e)
|
Chris@335
|
1327 {
|
Chris@335
|
1328 if (!m_model) return;
|
Chris@335
|
1329
|
Chris@335
|
1330 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
|
Chris@335
|
1331 if (points.empty()) return;
|
Chris@335
|
1332
|
Chris@335
|
1333 m_editingPoint = *points.begin();
|
Chris@335
|
1334
|
Chris@335
|
1335 if (m_editingCommand) {
|
Chris@376
|
1336 finish(m_editingCommand);
|
Chris@335
|
1337 m_editingCommand = 0;
|
Chris@335
|
1338 }
|
Chris@335
|
1339
|
Chris@335
|
1340 m_editing = true;
|
Chris@335
|
1341 }
|
Chris@335
|
1342
|
Chris@335
|
1343 void
|
Chris@335
|
1344 TimeValueLayer::eraseDrag(View *v, QMouseEvent *e)
|
Chris@335
|
1345 {
|
Chris@335
|
1346 }
|
Chris@335
|
1347
|
Chris@335
|
1348 void
|
Chris@335
|
1349 TimeValueLayer::eraseEnd(View *v, QMouseEvent *e)
|
Chris@335
|
1350 {
|
Chris@335
|
1351 if (!m_model || !m_editing) return;
|
Chris@335
|
1352
|
Chris@335
|
1353 m_editing = false;
|
Chris@335
|
1354
|
Chris@335
|
1355 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
|
Chris@335
|
1356 if (points.empty()) return;
|
Chris@335
|
1357 if (points.begin()->frame != m_editingPoint.frame ||
|
Chris@335
|
1358 points.begin()->value != m_editingPoint.value) return;
|
Chris@335
|
1359
|
Chris@335
|
1360 m_editingCommand = new SparseTimeValueModel::EditCommand
|
Chris@335
|
1361 (m_model, tr("Erase Point"));
|
Chris@335
|
1362
|
Chris@335
|
1363 m_editingCommand->deletePoint(m_editingPoint);
|
Chris@335
|
1364
|
Chris@376
|
1365 finish(m_editingCommand);
|
Chris@335
|
1366 m_editingCommand = 0;
|
Chris@335
|
1367 m_editing = false;
|
Chris@335
|
1368 }
|
Chris@335
|
1369
|
Chris@335
|
1370 void
|
Chris@44
|
1371 TimeValueLayer::editStart(View *v, QMouseEvent *e)
|
Chris@21
|
1372 {
|
Chris@526
|
1373 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
1374 std::cerr << "TimeValueLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@526
|
1375 #endif
|
Chris@21
|
1376
|
Chris@21
|
1377 if (!m_model) return;
|
Chris@21
|
1378
|
Chris@44
|
1379 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
|
Chris@21
|
1380 if (points.empty()) return;
|
Chris@21
|
1381
|
Chris@21
|
1382 m_editingPoint = *points.begin();
|
Chris@23
|
1383 m_originalPoint = m_editingPoint;
|
Chris@22
|
1384
|
Chris@22
|
1385 if (m_editingCommand) {
|
Chris@376
|
1386 finish(m_editingCommand);
|
Chris@22
|
1387 m_editingCommand = 0;
|
Chris@22
|
1388 }
|
Chris@22
|
1389
|
Chris@21
|
1390 m_editing = true;
|
Chris@21
|
1391 }
|
Chris@21
|
1392
|
Chris@21
|
1393 void
|
Chris@44
|
1394 TimeValueLayer::editDrag(View *v, QMouseEvent *e)
|
Chris@21
|
1395 {
|
Chris@526
|
1396 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
1397 std::cerr << "TimeValueLayer::editDrag(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@526
|
1398 #endif
|
Chris@21
|
1399
|
Chris@21
|
1400 if (!m_model || !m_editing) return;
|
Chris@21
|
1401
|
Chris@44
|
1402 long frame = v->getFrameForX(e->x());
|
Chris@21
|
1403 if (frame < 0) frame = 0;
|
Chris@21
|
1404 frame = frame / m_model->getResolution() * m_model->getResolution();
|
Chris@21
|
1405
|
Chris@44
|
1406 float value = getValueForY(v, e->y());
|
Chris@21
|
1407
|
Chris@22
|
1408 if (!m_editingCommand) {
|
Chris@22
|
1409 m_editingCommand = new SparseTimeValueModel::EditCommand(m_model,
|
Chris@22
|
1410 tr("Drag Point"));
|
Chris@22
|
1411 }
|
Chris@22
|
1412
|
Chris@22
|
1413 m_editingCommand->deletePoint(m_editingPoint);
|
Chris@21
|
1414 m_editingPoint.frame = frame;
|
Chris@21
|
1415 m_editingPoint.value = value;
|
Chris@22
|
1416 m_editingCommand->addPoint(m_editingPoint);
|
Chris@21
|
1417 }
|
Chris@21
|
1418
|
Chris@21
|
1419 void
|
Chris@248
|
1420 TimeValueLayer::editEnd(View *, QMouseEvent *)
|
Chris@21
|
1421 {
|
Chris@526
|
1422 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
1423 std::cerr << "TimeValueLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@526
|
1424 #endif
|
Chris@21
|
1425 if (!m_model || !m_editing) return;
|
Chris@23
|
1426
|
Chris@23
|
1427 if (m_editingCommand) {
|
Chris@23
|
1428
|
Chris@23
|
1429 QString newName = m_editingCommand->getName();
|
Chris@23
|
1430
|
Chris@23
|
1431 if (m_editingPoint.frame != m_originalPoint.frame) {
|
Chris@23
|
1432 if (m_editingPoint.value != m_originalPoint.value) {
|
Chris@23
|
1433 newName = tr("Edit Point");
|
Chris@23
|
1434 } else {
|
Chris@23
|
1435 newName = tr("Relocate Point");
|
Chris@23
|
1436 }
|
Chris@23
|
1437 } else {
|
Chris@23
|
1438 newName = tr("Change Point Value");
|
Chris@23
|
1439 }
|
Chris@23
|
1440
|
Chris@23
|
1441 m_editingCommand->setName(newName);
|
Chris@376
|
1442 finish(m_editingCommand);
|
Chris@23
|
1443 }
|
Chris@23
|
1444
|
Chris@22
|
1445 m_editingCommand = 0;
|
Chris@21
|
1446 m_editing = false;
|
Chris@21
|
1447 }
|
Chris@21
|
1448
|
Chris@255
|
1449 bool
|
Chris@70
|
1450 TimeValueLayer::editOpen(View *v, QMouseEvent *e)
|
Chris@70
|
1451 {
|
Chris@255
|
1452 if (!m_model) return false;
|
Chris@70
|
1453
|
Chris@70
|
1454 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
|
Chris@255
|
1455 if (points.empty()) return false;
|
Chris@70
|
1456
|
Chris@70
|
1457 SparseTimeValueModel::Point point = *points.begin();
|
Chris@70
|
1458
|
Chris@70
|
1459 ItemEditDialog *dialog = new ItemEditDialog
|
Chris@70
|
1460 (m_model->getSampleRate(),
|
Chris@70
|
1461 ItemEditDialog::ShowTime |
|
Chris@70
|
1462 ItemEditDialog::ShowValue |
|
Chris@73
|
1463 ItemEditDialog::ShowText,
|
Chris@73
|
1464 m_model->getScaleUnits());
|
Chris@70
|
1465
|
Chris@70
|
1466 dialog->setFrameTime(point.frame);
|
Chris@70
|
1467 dialog->setValue(point.value);
|
Chris@70
|
1468 dialog->setText(point.label);
|
Chris@70
|
1469
|
Chris@70
|
1470 if (dialog->exec() == QDialog::Accepted) {
|
Chris@70
|
1471
|
Chris@70
|
1472 SparseTimeValueModel::Point newPoint = point;
|
Chris@70
|
1473 newPoint.frame = dialog->getFrameTime();
|
Chris@70
|
1474 newPoint.value = dialog->getValue();
|
Chris@70
|
1475 newPoint.label = dialog->getText();
|
Chris@70
|
1476
|
Chris@70
|
1477 SparseTimeValueModel::EditCommand *command =
|
Chris@70
|
1478 new SparseTimeValueModel::EditCommand(m_model, tr("Edit Point"));
|
Chris@70
|
1479 command->deletePoint(point);
|
Chris@70
|
1480 command->addPoint(newPoint);
|
Chris@376
|
1481 finish(command);
|
Chris@70
|
1482 }
|
Chris@70
|
1483
|
Chris@70
|
1484 delete dialog;
|
Chris@255
|
1485 return true;
|
Chris@70
|
1486 }
|
Chris@70
|
1487
|
Chris@70
|
1488 void
|
Chris@43
|
1489 TimeValueLayer::moveSelection(Selection s, size_t newStartFrame)
|
Chris@43
|
1490 {
|
Chris@99
|
1491 if (!m_model) return;
|
Chris@99
|
1492
|
Chris@43
|
1493 SparseTimeValueModel::EditCommand *command =
|
Chris@43
|
1494 new SparseTimeValueModel::EditCommand(m_model,
|
Chris@43
|
1495 tr("Drag Selection"));
|
Chris@43
|
1496
|
Chris@43
|
1497 SparseTimeValueModel::PointList points =
|
Chris@43
|
1498 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
|
Chris@43
|
1499
|
Chris@43
|
1500 for (SparseTimeValueModel::PointList::iterator i = points.begin();
|
Chris@43
|
1501 i != points.end(); ++i) {
|
Chris@43
|
1502
|
Chris@43
|
1503 if (s.contains(i->frame)) {
|
Chris@43
|
1504 SparseTimeValueModel::Point newPoint(*i);
|
Chris@43
|
1505 newPoint.frame = i->frame + newStartFrame - s.getStartFrame();
|
Chris@43
|
1506 command->deletePoint(*i);
|
Chris@43
|
1507 command->addPoint(newPoint);
|
Chris@43
|
1508 }
|
Chris@43
|
1509 }
|
Chris@43
|
1510
|
Chris@376
|
1511 finish(command);
|
Chris@43
|
1512 }
|
Chris@43
|
1513
|
Chris@43
|
1514 void
|
Chris@43
|
1515 TimeValueLayer::resizeSelection(Selection s, Selection newSize)
|
Chris@43
|
1516 {
|
Chris@99
|
1517 if (!m_model) return;
|
Chris@99
|
1518
|
Chris@43
|
1519 SparseTimeValueModel::EditCommand *command =
|
Chris@43
|
1520 new SparseTimeValueModel::EditCommand(m_model,
|
Chris@43
|
1521 tr("Resize Selection"));
|
Chris@43
|
1522
|
Chris@43
|
1523 SparseTimeValueModel::PointList points =
|
Chris@43
|
1524 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
|
Chris@43
|
1525
|
Chris@43
|
1526 double ratio =
|
Chris@43
|
1527 double(newSize.getEndFrame() - newSize.getStartFrame()) /
|
Chris@43
|
1528 double(s.getEndFrame() - s.getStartFrame());
|
Chris@43
|
1529
|
Chris@43
|
1530 for (SparseTimeValueModel::PointList::iterator i = points.begin();
|
Chris@43
|
1531 i != points.end(); ++i) {
|
Chris@43
|
1532
|
Chris@43
|
1533 if (s.contains(i->frame)) {
|
Chris@43
|
1534
|
Chris@43
|
1535 double target = i->frame;
|
Chris@43
|
1536 target = newSize.getStartFrame() +
|
Chris@43
|
1537 double(target - s.getStartFrame()) * ratio;
|
Chris@43
|
1538
|
Chris@43
|
1539 SparseTimeValueModel::Point newPoint(*i);
|
Chris@43
|
1540 newPoint.frame = lrint(target);
|
Chris@43
|
1541 command->deletePoint(*i);
|
Chris@43
|
1542 command->addPoint(newPoint);
|
Chris@43
|
1543 }
|
Chris@43
|
1544 }
|
Chris@43
|
1545
|
Chris@376
|
1546 finish(command);
|
Chris@43
|
1547 }
|
Chris@43
|
1548
|
Chris@76
|
1549 void
|
Chris@76
|
1550 TimeValueLayer::deleteSelection(Selection s)
|
Chris@76
|
1551 {
|
Chris@99
|
1552 if (!m_model) return;
|
Chris@99
|
1553
|
Chris@76
|
1554 SparseTimeValueModel::EditCommand *command =
|
Chris@76
|
1555 new SparseTimeValueModel::EditCommand(m_model,
|
Chris@76
|
1556 tr("Delete Selected Points"));
|
Chris@76
|
1557
|
Chris@76
|
1558 SparseTimeValueModel::PointList points =
|
Chris@76
|
1559 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
|
Chris@76
|
1560
|
Chris@76
|
1561 for (SparseTimeValueModel::PointList::iterator i = points.begin();
|
Chris@76
|
1562 i != points.end(); ++i) {
|
Chris@76
|
1563
|
Chris@76
|
1564 if (s.contains(i->frame)) {
|
Chris@76
|
1565 command->deletePoint(*i);
|
Chris@76
|
1566 }
|
Chris@76
|
1567 }
|
Chris@76
|
1568
|
Chris@376
|
1569 finish(command);
|
Chris@76
|
1570 }
|
Chris@76
|
1571
|
Chris@76
|
1572 void
|
Chris@359
|
1573 TimeValueLayer::copy(View *v, Selection s, Clipboard &to)
|
Chris@76
|
1574 {
|
Chris@99
|
1575 if (!m_model) return;
|
Chris@99
|
1576
|
Chris@76
|
1577 SparseTimeValueModel::PointList points =
|
Chris@76
|
1578 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
|
Chris@76
|
1579
|
Chris@76
|
1580 for (SparseTimeValueModel::PointList::iterator i = points.begin();
|
Chris@76
|
1581 i != points.end(); ++i) {
|
Chris@76
|
1582 if (s.contains(i->frame)) {
|
Chris@83
|
1583 Clipboard::Point point(i->frame, i->value, i->label);
|
Chris@360
|
1584 point.setReferenceFrame(alignToReference(v, i->frame));
|
Chris@76
|
1585 to.addPoint(point);
|
Chris@76
|
1586 }
|
Chris@76
|
1587 }
|
Chris@76
|
1588 }
|
Chris@76
|
1589
|
Chris@125
|
1590 bool
|
Chris@359
|
1591 TimeValueLayer::paste(View *v, const Clipboard &from, int frameOffset,
|
Chris@125
|
1592 bool interactive)
|
Chris@76
|
1593 {
|
Chris@125
|
1594 if (!m_model) return false;
|
Chris@99
|
1595
|
Chris@76
|
1596 const Clipboard::PointList &points = from.getPoints();
|
Chris@76
|
1597
|
Chris@360
|
1598 bool realign = false;
|
Chris@360
|
1599
|
Chris@360
|
1600 if (clipboardHasDifferentAlignment(v, from)) {
|
Chris@360
|
1601
|
Chris@360
|
1602 QMessageBox::StandardButton button =
|
Chris@360
|
1603 QMessageBox::question(v, tr("Re-align pasted items?"),
|
Chris@360
|
1604 tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"),
|
Chris@360
|
1605 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
|
Chris@360
|
1606 QMessageBox::Yes);
|
Chris@360
|
1607
|
Chris@360
|
1608 if (button == QMessageBox::Cancel) {
|
Chris@360
|
1609 return false;
|
Chris@360
|
1610 }
|
Chris@360
|
1611
|
Chris@360
|
1612 if (button == QMessageBox::Yes) {
|
Chris@360
|
1613 realign = true;
|
Chris@360
|
1614 }
|
Chris@360
|
1615 }
|
Chris@360
|
1616
|
Chris@76
|
1617 SparseTimeValueModel::EditCommand *command =
|
Chris@76
|
1618 new SparseTimeValueModel::EditCommand(m_model, tr("Paste"));
|
Chris@76
|
1619
|
Chris@125
|
1620 enum ValueAvailability {
|
Chris@125
|
1621 UnknownAvailability,
|
Chris@125
|
1622 NoValues,
|
Chris@125
|
1623 SomeValues,
|
Chris@125
|
1624 AllValues
|
Chris@125
|
1625 };
|
Chris@125
|
1626
|
Chris@340
|
1627 Labeller::ValueType generation = Labeller::ValueNone;
|
Chris@125
|
1628
|
Chris@125
|
1629 bool haveUsableLabels = false;
|
Chris@125
|
1630 bool haveExistingItems = !(m_model->isEmpty());
|
Chris@340
|
1631 Labeller labeller;
|
Chris@340
|
1632 labeller.setSampleRate(m_model->getSampleRate());
|
Chris@125
|
1633
|
Chris@125
|
1634 if (interactive) {
|
Chris@125
|
1635
|
Chris@125
|
1636 ValueAvailability availability = UnknownAvailability;
|
Chris@125
|
1637
|
Chris@125
|
1638 for (Clipboard::PointList::const_iterator i = points.begin();
|
Chris@125
|
1639 i != points.end(); ++i) {
|
Chris@125
|
1640
|
Chris@125
|
1641 if (!i->haveFrame()) continue;
|
Chris@125
|
1642
|
Chris@125
|
1643 if (availability == UnknownAvailability) {
|
Chris@125
|
1644 if (i->haveValue()) availability = AllValues;
|
Chris@125
|
1645 else availability = NoValues;
|
Chris@125
|
1646 continue;
|
Chris@125
|
1647 }
|
Chris@125
|
1648
|
Chris@125
|
1649 if (i->haveValue()) {
|
Chris@125
|
1650 if (availability == NoValues) {
|
Chris@125
|
1651 availability = SomeValues;
|
Chris@125
|
1652 }
|
Chris@125
|
1653 } else {
|
Chris@125
|
1654 if (availability == AllValues) {
|
Chris@125
|
1655 availability = SomeValues;
|
Chris@125
|
1656 }
|
Chris@125
|
1657 }
|
Chris@125
|
1658
|
Chris@125
|
1659 if (!haveUsableLabels) {
|
Chris@125
|
1660 if (i->haveLabel()) {
|
Chris@125
|
1661 if (i->getLabel().contains(QRegExp("[0-9]"))) {
|
Chris@125
|
1662 haveUsableLabels = true;
|
Chris@125
|
1663 }
|
Chris@125
|
1664 }
|
Chris@125
|
1665 }
|
Chris@125
|
1666
|
Chris@125
|
1667 if (availability == SomeValues && haveUsableLabels) break;
|
Chris@125
|
1668 }
|
Chris@125
|
1669
|
Chris@125
|
1670 if (availability == NoValues || availability == SomeValues) {
|
Chris@125
|
1671
|
Chris@125
|
1672 QString text;
|
Chris@125
|
1673 if (availability == NoValues) {
|
Chris@125
|
1674 text = tr("The items you are pasting do not have values.\nWhat values do you want to use for these items?");
|
Chris@125
|
1675 } else {
|
Chris@125
|
1676 text = tr("Some of the items you are pasting do not have values.\nWhat values do you want to use for these items?");
|
Chris@125
|
1677 }
|
Chris@125
|
1678
|
Chris@340
|
1679 Labeller::TypeNameMap names = labeller.getTypeNames();
|
Chris@340
|
1680
|
Chris@125
|
1681 QStringList options;
|
Chris@340
|
1682 std::vector<Labeller::ValueType> genopts;
|
Chris@125
|
1683
|
Chris@340
|
1684 for (Labeller::TypeNameMap::const_iterator i = names.begin();
|
Chris@340
|
1685 i != names.end(); ++i) {
|
Chris@340
|
1686 if (i->first == Labeller::ValueNone) options << tr("Zero for all items");
|
Chris@340
|
1687 else options << i->second;
|
Chris@340
|
1688 genopts.push_back(i->first);
|
Chris@125
|
1689 }
|
Chris@125
|
1690
|
Chris@125
|
1691 static int prevSelection = 0;
|
Chris@125
|
1692
|
Chris@125
|
1693 bool ok = false;
|
Chris@125
|
1694 QString selected = ListInputDialog::getItem
|
Chris@125
|
1695 (0, tr("Choose value calculation"),
|
Chris@125
|
1696 text, options, prevSelection, &ok);
|
Chris@125
|
1697
|
Chris@125
|
1698 if (!ok) return false;
|
Chris@125
|
1699 int selection = 0;
|
Chris@340
|
1700 generation = Labeller::ValueNone;
|
Chris@125
|
1701
|
Chris@125
|
1702 for (QStringList::const_iterator i = options.begin();
|
Chris@125
|
1703 i != options.end(); ++i) {
|
Chris@125
|
1704 if (selected == *i) {
|
Chris@340
|
1705 generation = genopts[selection];
|
Chris@125
|
1706 break;
|
Chris@125
|
1707 }
|
Chris@125
|
1708 ++selection;
|
Chris@125
|
1709 }
|
Chris@340
|
1710
|
Chris@340
|
1711 labeller.setType(generation);
|
Chris@340
|
1712
|
Chris@340
|
1713 if (generation == Labeller::ValueFromCyclicalCounter ||
|
Chris@340
|
1714 generation == Labeller::ValueFromTwoLevelCounter) {
|
Chris@340
|
1715 int cycleSize = QInputDialog::getInteger
|
Chris@340
|
1716 (0, tr("Select cycle size"),
|
Chris@340
|
1717 tr("Cycle size:"), 4, 2, 16, 1);
|
Chris@340
|
1718 labeller.setCounterCycleSize(cycleSize);
|
Chris@340
|
1719 }
|
Chris@125
|
1720
|
Chris@125
|
1721 prevSelection = selection;
|
Chris@125
|
1722 }
|
Chris@125
|
1723 }
|
Chris@125
|
1724
|
Chris@372
|
1725 SparseTimeValueModel::Point prevPoint(0);
|
Chris@125
|
1726
|
Chris@76
|
1727 for (Clipboard::PointList::const_iterator i = points.begin();
|
Chris@76
|
1728 i != points.end(); ++i) {
|
Chris@76
|
1729
|
Chris@76
|
1730 if (!i->haveFrame()) continue;
|
Chris@360
|
1731
|
Chris@76
|
1732 size_t frame = 0;
|
Chris@360
|
1733
|
Chris@360
|
1734 if (!realign) {
|
Chris@360
|
1735
|
Chris@360
|
1736 frame = i->getFrame();
|
Chris@360
|
1737
|
Chris@360
|
1738 } else {
|
Chris@360
|
1739
|
Chris@360
|
1740 if (i->haveReferenceFrame()) {
|
Chris@360
|
1741 frame = i->getReferenceFrame();
|
Chris@360
|
1742 frame = alignFromReference(v, frame);
|
Chris@360
|
1743 } else {
|
Chris@360
|
1744 frame = i->getFrame();
|
Chris@360
|
1745 }
|
Chris@76
|
1746 }
|
Chris@360
|
1747
|
Chris@76
|
1748 SparseTimeValueModel::Point newPoint(frame);
|
Chris@76
|
1749
|
Chris@125
|
1750 if (i->haveLabel()) {
|
Chris@125
|
1751 newPoint.label = i->getLabel();
|
Chris@125
|
1752 } else if (i->haveValue()) {
|
Chris@125
|
1753 newPoint.label = QString("%1").arg(i->getValue());
|
Chris@125
|
1754 }
|
Chris@125
|
1755
|
Chris@372
|
1756 bool usePrev = false;
|
Chris@372
|
1757 SparseTimeValueModel::Point formerPrevPoint = prevPoint;
|
Chris@372
|
1758
|
Chris@125
|
1759 if (i->haveValue()) {
|
Chris@125
|
1760 newPoint.value = i->getValue();
|
Chris@125
|
1761 } else {
|
Chris@526
|
1762 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
1763 std::cerr << "Setting value on point at " << newPoint.frame << " from labeller";
|
Chris@526
|
1764 if (i == points.begin()) {
|
Chris@526
|
1765 std::cerr << ", no prev point" << std::endl;
|
Chris@526
|
1766 } else {
|
Chris@526
|
1767 std::cerr << ", prev point is at " << prevPoint.frame << std::endl;
|
Chris@526
|
1768 }
|
Chris@526
|
1769 #endif
|
Chris@340
|
1770 labeller.setValue<SparseTimeValueModel::Point>
|
Chris@371
|
1771 (newPoint, (i == points.begin()) ? 0 : &prevPoint);
|
Chris@526
|
1772 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
1773 std::cerr << "New point value = " << newPoint.value << std::endl;
|
Chris@526
|
1774 #endif
|
Chris@372
|
1775 if (labeller.actingOnPrevPoint() && i != points.begin()) {
|
Chris@372
|
1776 usePrev = true;
|
Chris@372
|
1777 }
|
Chris@372
|
1778 }
|
Chris@372
|
1779
|
Chris@372
|
1780 if (usePrev) {
|
Chris@372
|
1781 command->deletePoint(formerPrevPoint);
|
Chris@372
|
1782 command->addPoint(prevPoint);
|
Chris@340
|
1783 }
|
Chris@125
|
1784
|
Chris@340
|
1785 prevPoint = newPoint;
|
Chris@76
|
1786 command->addPoint(newPoint);
|
Chris@76
|
1787 }
|
Chris@76
|
1788
|
Chris@376
|
1789 finish(command);
|
Chris@125
|
1790 return true;
|
Chris@360
|
1791 }
|
Chris@76
|
1792
|
Chris@316
|
1793 void
|
Chris@316
|
1794 TimeValueLayer::toXml(QTextStream &stream,
|
Chris@316
|
1795 QString indent, QString extraAttributes) const
|
Chris@6
|
1796 {
|
Chris@316
|
1797 SingleColourLayer::toXml(stream, indent,
|
Chris@316
|
1798 extraAttributes +
|
Chris@513
|
1799 QString(" colourMap=\"%1\" plotStyle=\"%2\" verticalScale=\"%3\" scaleMinimum=\"%4\" scaleMaximum=\"%5\" drawDivisions=\"%6\" ")
|
Chris@316
|
1800 .arg(m_colourMap)
|
Chris@316
|
1801 .arg(m_plotStyle)
|
Chris@445
|
1802 .arg(m_verticalScale)
|
Chris@445
|
1803 .arg(m_scaleMinimum)
|
Chris@513
|
1804 .arg(m_scaleMaximum)
|
Chris@513
|
1805 .arg(m_drawSegmentDivisions ? "true" : "false"));
|
Chris@0
|
1806 }
|
Chris@0
|
1807
|
Chris@11
|
1808 void
|
Chris@11
|
1809 TimeValueLayer::setProperties(const QXmlAttributes &attributes)
|
Chris@11
|
1810 {
|
Chris@287
|
1811 SingleColourLayer::setProperties(attributes);
|
Chris@11
|
1812
|
Chris@445
|
1813 bool ok, alsoOk;
|
Chris@287
|
1814
|
Chris@287
|
1815 int cmap = attributes.value("colourMap").toInt(&ok);
|
Chris@287
|
1816 if (ok) setFillColourMap(cmap);
|
Chris@287
|
1817
|
Chris@11
|
1818 PlotStyle style = (PlotStyle)
|
Chris@11
|
1819 attributes.value("plotStyle").toInt(&ok);
|
Chris@11
|
1820 if (ok) setPlotStyle(style);
|
Chris@286
|
1821
|
Chris@286
|
1822 VerticalScale scale = (VerticalScale)
|
Chris@286
|
1823 attributes.value("verticalScale").toInt(&ok);
|
Chris@286
|
1824 if (ok) setVerticalScale(scale);
|
Chris@445
|
1825
|
Chris@513
|
1826 bool draw = (attributes.value("drawDivisions").trimmed() == "true");
|
Chris@513
|
1827 setDrawSegmentDivisions(draw);
|
Chris@513
|
1828
|
Chris@445
|
1829 float min = attributes.value("scaleMinimum").toFloat(&ok);
|
Chris@445
|
1830 float max = attributes.value("scaleMaximum").toFloat(&alsoOk);
|
Chris@526
|
1831 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@526
|
1832 std::cerr << "from properties: min = " << min << ", max = " << max << std::endl;
|
Chris@526
|
1833 #endif
|
Chris@526
|
1834 if (ok && alsoOk && min != max) setDisplayExtents(min, max);
|
Chris@11
|
1835 }
|
Chris@11
|
1836
|