Mercurial > hg > svgui
comparison layer/TimeValueLayer.cpp @ 629:355fa700ce70
Allow a bit more space at top and bottom of scale range; make it easier to see point in case where model has only a single point
author | Chris Cannam |
---|---|
date | Mon, 15 Apr 2013 10:54:02 +0100 |
parents | 156a120345ae |
children | c3593bb2de6b |
comparison
equal
deleted
inserted
replaced
615:156a120345ae | 629:355fa700ce70 |
---|---|
40 #include <QInputDialog> | 40 #include <QInputDialog> |
41 | 41 |
42 #include <iostream> | 42 #include <iostream> |
43 #include <cmath> | 43 #include <cmath> |
44 | 44 |
45 //#define DEBUG_TIME_VALUE_LAYER 1 | 45 #define DEBUG_TIME_VALUE_LAYER 1 |
46 | 46 |
47 TimeValueLayer::TimeValueLayer() : | 47 TimeValueLayer::TimeValueLayer() : |
48 SingleColourLayer(), | 48 SingleColourLayer(), |
49 m_model(0), | 49 m_model(0), |
50 m_editing(false), | 50 m_editing(false), |
79 if (m_model && m_model->getRDFTypeURI().endsWith("Change")) { | 79 if (m_model && m_model->getRDFTypeURI().endsWith("Change")) { |
80 setPlotStyle(PlotSegmentation); | 80 setPlotStyle(PlotSegmentation); |
81 } | 81 } |
82 | 82 |
83 #ifdef DEBUG_TIME_VALUE_LAYER | 83 #ifdef DEBUG_TIME_VALUE_LAYER |
84 SVDEBUG << "TimeValueLayer::setModel(" << model << ")" << endl; | 84 std::cerr << "TimeValueLayer::setModel(" << model << ")" << std::endl; |
85 #endif | 85 #endif |
86 | 86 |
87 emit modelReplaced(); | 87 emit modelReplaced(); |
88 } | 88 } |
89 | 89 |
326 unit = m_model->getScaleUnits(); | 326 unit = m_model->getScaleUnits(); |
327 if (m_derivative) { | 327 if (m_derivative) { |
328 max = std::max(fabsf(min), fabsf(max)); | 328 max = std::max(fabsf(min), fabsf(max)); |
329 min = -max; | 329 min = -max; |
330 } | 330 } |
331 | |
332 #ifdef DEBUG_TIME_VALUE_LAYER | |
333 std::cerr << "TimeValueLayer::getValueExtents: min = " << min << ", max = " << max << std::endl; | |
334 #endif | |
335 | |
331 return true; | 336 return true; |
332 } | 337 } |
333 | 338 |
334 bool | 339 bool |
335 TimeValueLayer::getDisplayExtents(float &min, float &max) const | 340 TimeValueLayer::getDisplayExtents(float &min, float &max) const |
348 max = std::max(fabsf(min), fabsf(max)); | 353 max = std::max(fabsf(min), fabsf(max)); |
349 min = -max; | 354 min = -max; |
350 } | 355 } |
351 | 356 |
352 #ifdef DEBUG_TIME_VALUE_LAYER | 357 #ifdef DEBUG_TIME_VALUE_LAYER |
353 SVDEBUG << "TimeValueLayer::getDisplayExtents: min = " << min << ", max = " << max << endl; | 358 std::cerr << "TimeValueLayer::getDisplayExtents: min = " << min << ", max = " << max << std::endl; |
354 #endif | 359 #endif |
355 | 360 |
356 return true; | 361 return true; |
357 } | 362 } |
358 | 363 |
371 | 376 |
372 m_scaleMinimum = min; | 377 m_scaleMinimum = min; |
373 m_scaleMaximum = max; | 378 m_scaleMaximum = max; |
374 | 379 |
375 #ifdef DEBUG_TIME_VALUE_LAYER | 380 #ifdef DEBUG_TIME_VALUE_LAYER |
376 SVDEBUG << "TimeValueLayer::setDisplayExtents: min = " << min << ", max = " << max << endl; | 381 std::cerr << "TimeValueLayer::setDisplayExtents: min = " << min << ", max = " << max << std::endl; |
377 #endif | 382 #endif |
378 | 383 |
379 emit layerParametersChanged(); | 384 emit layerParametersChanged(); |
380 return true; | 385 return true; |
381 } | 386 } |
403 getDisplayExtents(dmin, dmax); | 408 getDisplayExtents(dmin, dmax); |
404 | 409 |
405 int nr = mapper->getPositionForValue(dmax - dmin); | 410 int nr = mapper->getPositionForValue(dmax - dmin); |
406 | 411 |
407 #ifdef DEBUG_TIME_VALUE_LAYER | 412 #ifdef DEBUG_TIME_VALUE_LAYER |
408 SVDEBUG << "TimeValueLayer::getCurrentVerticalZoomStep: dmin = " << dmin << ", dmax = " << dmax << ", nr = " << nr << endl; | 413 std::cerr << "TimeValueLayer::getCurrentVerticalZoomStep: dmin = " << dmin << ", dmax = " << dmax << ", nr = " << nr << std::endl; |
409 #endif | 414 #endif |
410 | 415 |
411 delete mapper; | 416 delete mapper; |
412 | 417 |
413 return 100 - nr; | 418 return 100 - nr; |
458 if (newmax > max) { | 463 if (newmax > max) { |
459 newmax = max; | 464 newmax = max; |
460 } | 465 } |
461 | 466 |
462 #ifdef DEBUG_TIME_VALUE_LAYER | 467 #ifdef DEBUG_TIME_VALUE_LAYER |
463 SVDEBUG << "TimeValueLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << newdist << ")" << endl; | 468 std::cerr << "TimeValueLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << newdist << ")" << std::endl; |
464 #endif | 469 #endif |
465 | 470 |
466 setDisplayExtents(newmin, newmax); | 471 setDisplayExtents(newmin, newmax); |
467 } | 472 } |
468 | 473 |
761 LogRange::mapRange(min, max); | 766 LogRange::mapRange(min, max); |
762 log = true; | 767 log = true; |
763 } | 768 } |
764 } | 769 } |
765 | 770 |
766 if (max == min) max = min + 1.0; | 771 #ifdef DEBUG_TIME_VALUE_LAYER |
772 std::cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << std::endl; | |
773 #endif | |
774 | |
775 if (max == min) { | |
776 max = max + 0.5; | |
777 min = min - 0.5; | |
778 } else { | |
779 float margin = (max - min) / 10.0; | |
780 max = max + margin; | |
781 min = min - margin; | |
782 } | |
783 | |
784 #ifdef DEBUG_TIME_VALUE_LAYER | |
785 std::cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << " (after adjustment)" << std::endl; | |
786 #endif | |
767 } | 787 } |
768 | 788 |
769 int | 789 int |
770 TimeValueLayer::getYForValue(View *v, float val) const | 790 TimeValueLayer::getYForValue(View *v, float val) const |
771 { | 791 { |
826 if (log) { | 846 if (log) { |
827 val = LogRange::map(val); | 847 val = LogRange::map(val); |
828 } | 848 } |
829 | 849 |
830 #ifdef DEBUG_TIME_VALUE_LAYER | 850 #ifdef DEBUG_TIME_VALUE_LAYER |
831 SVDEBUG << "TimeValueLayer::getColourForValue: min " << min << ", max " | 851 std::cerr << "TimeValueLayer::getColourForValue: min " << min << ", max " |
832 << max << ", log " << log << ", value " << val << endl; | 852 << max << ", log " << log << ", value " << val << std::endl; |
833 #endif | 853 #endif |
834 | 854 |
835 QColor solid = ColourMapper(m_colourMap, min, max).map(val); | 855 QColor solid = ColourMapper(m_colourMap, min, max).map(val); |
836 return QColor(solid.red(), solid.green(), solid.blue(), 120); | 856 return QColor(solid.red(), solid.green(), solid.blue(), 120); |
837 } | 857 } |
870 QColor brushColour(getBaseQColor()); | 890 QColor brushColour(getBaseQColor()); |
871 brushColour.setAlpha(80); | 891 brushColour.setAlpha(80); |
872 paint.setBrush(brushColour); | 892 paint.setBrush(brushColour); |
873 | 893 |
874 #ifdef DEBUG_TIME_VALUE_LAYER | 894 #ifdef DEBUG_TIME_VALUE_LAYER |
875 SVDEBUG << "TimeValueLayer::paint: resolution is " | 895 std::cerr << "TimeValueLayer::paint: resolution is " |
876 << m_model->getResolution() << " frames" << endl; | 896 << m_model->getResolution() << " frames" << std::endl; |
877 #endif | 897 #endif |
878 | 898 |
879 float min = m_model->getValueMinimum(); | 899 float min = m_model->getValueMinimum(); |
880 float max = m_model->getValueMaximum(); | 900 float max = m_model->getValueMaximum(); |
881 if (max == min) max = min + 1.0; | 901 if (max == min) max = min + 1.0; |
896 } | 916 } |
897 | 917 |
898 int w = | 918 int w = |
899 v->getXForFrame(frame0 + m_model->getResolution()) - | 919 v->getXForFrame(frame0 + m_model->getResolution()) - |
900 v->getXForFrame(frame0); | 920 v->getXForFrame(frame0); |
921 | |
922 if (m_plotStyle == PlotStems) { | |
923 if (w < 2) w = 2; | |
924 } else { | |
925 if (w < 1) w = 1; | |
926 } | |
901 | 927 |
902 paint.save(); | 928 paint.save(); |
903 | 929 |
904 QPainterPath path; | 930 QPainterPath path; |
905 int pointCount = 0; | 931 int pointCount = 0; |
968 haveNext = true; | 994 haveNext = true; |
969 } | 995 } |
970 | 996 |
971 // std::cout << "frame = " << p.frame << ", x = " << x << ", haveNext = " << haveNext | 997 // std::cout << "frame = " << p.frame << ", x = " << x << ", haveNext = " << haveNext |
972 // << ", nx = " << nx << std::endl; | 998 // << ", nx = " << nx << std::endl; |
973 | |
974 if (w < 1) w = 1; | |
975 | 999 |
976 if (m_plotStyle == PlotDiscreteCurves) { | 1000 if (m_plotStyle == PlotDiscreteCurves) { |
977 paint.setPen(QPen(getBaseQColor(), 3)); | 1001 paint.setPen(QPen(getBaseQColor(), 3)); |
978 paint.setBrush(Qt::NoBrush); | 1002 paint.setBrush(Qt::NoBrush); |
979 } else if (m_plotStyle == PlotSegmentation) { | 1003 } else if (m_plotStyle == PlotSegmentation) { |
1092 } | 1116 } |
1093 | 1117 |
1094 if (m_plotStyle == PlotSegmentation) { | 1118 if (m_plotStyle == PlotSegmentation) { |
1095 | 1119 |
1096 #ifdef DEBUG_TIME_VALUE_LAYER | 1120 #ifdef DEBUG_TIME_VALUE_LAYER |
1097 SVDEBUG << "drawing rect" << endl; | 1121 std::cerr << "drawing rect" << std::endl; |
1098 #endif | 1122 #endif |
1099 | 1123 |
1100 if (nx <= x) continue; | 1124 if (nx <= x) continue; |
1101 | 1125 |
1102 paint.setPen(QPen(getForegroundQColor(v), 2)); | 1126 paint.setPen(QPen(getForegroundQColor(v), 2)); |
1110 } | 1134 } |
1111 | 1135 |
1112 paint.drawRect(x, -1, nx - x, v->height() + 1); | 1136 paint.drawRect(x, -1, nx - x, v->height() + 1); |
1113 } | 1137 } |
1114 | 1138 |
1115 if (p.label != "") { | 1139 QString label = p.label; |
1140 | |
1141 if (label == "" && | |
1142 (m_plotStyle == PlotPoints || | |
1143 m_plotStyle == PlotSegmentation)) { | |
1144 label = QString("%1").arg(p.value); //??? but use italic? | |
1145 } | |
1146 | |
1147 if (label != "") { | |
1116 if (!haveNext || nx > x + 6 + paint.fontMetrics().width(p.label)) { | 1148 if (!haveNext || nx > x + 6 + paint.fontMetrics().width(p.label)) { |
1117 v->drawVisibleText(paint, x + 5, textY, p.label, View::OutlinedText); | 1149 v->drawVisibleText(paint, x + 5, textY, label, View::OutlinedText); |
1118 // paint.drawText(x + 5, textY, p.label); | |
1119 } | 1150 } |
1120 } | 1151 } |
1121 | 1152 |
1122 prevFrame = p.frame; | 1153 prevFrame = p.frame; |
1123 } | 1154 } |
1279 | 1310 |
1280 void | 1311 void |
1281 TimeValueLayer::drawStart(View *v, QMouseEvent *e) | 1312 TimeValueLayer::drawStart(View *v, QMouseEvent *e) |
1282 { | 1313 { |
1283 #ifdef DEBUG_TIME_VALUE_LAYER | 1314 #ifdef DEBUG_TIME_VALUE_LAYER |
1284 SVDEBUG << "TimeValueLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; | 1315 std::cerr << "TimeValueLayer::drawStart(" << e->x() << "," << e->y() << ")" << std::endl; |
1285 #endif | 1316 #endif |
1286 | 1317 |
1287 if (!m_model) return; | 1318 if (!m_model) return; |
1288 | 1319 |
1289 long frame = v->getFrameForX(e->x()); | 1320 long frame = v->getFrameForX(e->x()); |
1299 if (!points.empty()) { | 1330 if (!points.empty()) { |
1300 for (SparseTimeValueModel::PointList::iterator i = points.begin(); | 1331 for (SparseTimeValueModel::PointList::iterator i = points.begin(); |
1301 i != points.end(); ++i) { | 1332 i != points.end(); ++i) { |
1302 if (((i->frame / resolution) * resolution) != frame) { | 1333 if (((i->frame / resolution) * resolution) != frame) { |
1303 #ifdef DEBUG_TIME_VALUE_LAYER | 1334 #ifdef DEBUG_TIME_VALUE_LAYER |
1304 SVDEBUG << "ignoring out-of-range frame at " << i->frame << endl; | 1335 std::cerr << "ignoring out-of-range frame at " << i->frame << std::endl; |
1305 #endif | 1336 #endif |
1306 continue; | 1337 continue; |
1307 } | 1338 } |
1308 m_editingPoint = *i; | 1339 m_editingPoint = *i; |
1309 havePoint = true; | 1340 havePoint = true; |
1329 | 1360 |
1330 void | 1361 void |
1331 TimeValueLayer::drawDrag(View *v, QMouseEvent *e) | 1362 TimeValueLayer::drawDrag(View *v, QMouseEvent *e) |
1332 { | 1363 { |
1333 #ifdef DEBUG_TIME_VALUE_LAYER | 1364 #ifdef DEBUG_TIME_VALUE_LAYER |
1334 SVDEBUG << "TimeValueLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; | 1365 std::cerr << "TimeValueLayer::drawDrag(" << e->x() << "," << e->y() << ")" << std::endl; |
1335 #endif | 1366 #endif |
1336 | 1367 |
1337 if (!m_model || !m_editing) return; | 1368 if (!m_model || !m_editing) return; |
1338 | 1369 |
1339 long frame = v->getFrameForX(e->x()); | 1370 long frame = v->getFrameForX(e->x()); |
1355 for (SparseTimeValueModel::PointList::iterator i = points.begin(); | 1386 for (SparseTimeValueModel::PointList::iterator i = points.begin(); |
1356 i != points.end(); ++i) { | 1387 i != points.end(); ++i) { |
1357 if (i->frame == m_editingPoint.frame && | 1388 if (i->frame == m_editingPoint.frame && |
1358 i->value == m_editingPoint.value) { | 1389 i->value == m_editingPoint.value) { |
1359 #ifdef DEBUG_TIME_VALUE_LAYER | 1390 #ifdef DEBUG_TIME_VALUE_LAYER |
1360 SVDEBUG << "ignoring current editing point at " << i->frame << ", " << i->value << endl; | 1391 std::cerr << "ignoring current editing point at " << i->frame << ", " << i->value << std::endl; |
1361 #endif | 1392 #endif |
1362 continue; | 1393 continue; |
1363 } | 1394 } |
1364 if (((i->frame / resolution) * resolution) != frame) { | 1395 if (((i->frame / resolution) * resolution) != frame) { |
1365 #ifdef DEBUG_TIME_VALUE_LAYER | 1396 #ifdef DEBUG_TIME_VALUE_LAYER |
1366 SVDEBUG << "ignoring out-of-range frame at " << i->frame << endl; | 1397 std::cerr << "ignoring out-of-range frame at " << i->frame << std::endl; |
1367 #endif | 1398 #endif |
1368 continue; | 1399 continue; |
1369 } | 1400 } |
1370 #ifdef DEBUG_TIME_VALUE_LAYER | 1401 #ifdef DEBUG_TIME_VALUE_LAYER |
1371 SVDEBUG << "adjusting to new point at " << i->frame << ", " << i->value << endl; | 1402 std::cerr << "adjusting to new point at " << i->frame << ", " << i->value << std::endl; |
1372 #endif | 1403 #endif |
1373 m_editingPoint = *i; | 1404 m_editingPoint = *i; |
1374 m_originalPoint = m_editingPoint; | 1405 m_originalPoint = m_editingPoint; |
1375 m_editingCommand->deletePoint(m_editingPoint); | 1406 m_editingCommand->deletePoint(m_editingPoint); |
1376 havePoint = true; | 1407 havePoint = true; |
1391 | 1422 |
1392 void | 1423 void |
1393 TimeValueLayer::drawEnd(View *, QMouseEvent *) | 1424 TimeValueLayer::drawEnd(View *, QMouseEvent *) |
1394 { | 1425 { |
1395 #ifdef DEBUG_TIME_VALUE_LAYER | 1426 #ifdef DEBUG_TIME_VALUE_LAYER |
1396 SVDEBUG << "TimeValueLayer::drawEnd" << endl; | 1427 std::cerr << "TimeValueLayer::drawEnd" << std::endl; |
1397 #endif | 1428 #endif |
1398 if (!m_model || !m_editing) return; | 1429 if (!m_model || !m_editing) return; |
1399 finish(m_editingCommand); | 1430 finish(m_editingCommand); |
1400 m_editingCommand = 0; | 1431 m_editingCommand = 0; |
1401 m_editing = false; | 1432 m_editing = false; |
1448 | 1479 |
1449 void | 1480 void |
1450 TimeValueLayer::editStart(View *v, QMouseEvent *e) | 1481 TimeValueLayer::editStart(View *v, QMouseEvent *e) |
1451 { | 1482 { |
1452 #ifdef DEBUG_TIME_VALUE_LAYER | 1483 #ifdef DEBUG_TIME_VALUE_LAYER |
1453 SVDEBUG << "TimeValueLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; | 1484 std::cerr << "TimeValueLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl; |
1454 #endif | 1485 #endif |
1455 | 1486 |
1456 if (!m_model) return; | 1487 if (!m_model) return; |
1457 | 1488 |
1458 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x()); | 1489 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x()); |
1471 | 1502 |
1472 void | 1503 void |
1473 TimeValueLayer::editDrag(View *v, QMouseEvent *e) | 1504 TimeValueLayer::editDrag(View *v, QMouseEvent *e) |
1474 { | 1505 { |
1475 #ifdef DEBUG_TIME_VALUE_LAYER | 1506 #ifdef DEBUG_TIME_VALUE_LAYER |
1476 SVDEBUG << "TimeValueLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl; | 1507 std::cerr << "TimeValueLayer::editDrag(" << e->x() << "," << e->y() << ")" << std::endl; |
1477 #endif | 1508 #endif |
1478 | 1509 |
1479 if (!m_model || !m_editing) return; | 1510 if (!m_model || !m_editing) return; |
1480 | 1511 |
1481 long frame = v->getFrameForX(e->x()); | 1512 long frame = v->getFrameForX(e->x()); |
1497 | 1528 |
1498 void | 1529 void |
1499 TimeValueLayer::editEnd(View *, QMouseEvent *) | 1530 TimeValueLayer::editEnd(View *, QMouseEvent *) |
1500 { | 1531 { |
1501 #ifdef DEBUG_TIME_VALUE_LAYER | 1532 #ifdef DEBUG_TIME_VALUE_LAYER |
1502 SVDEBUG << "TimeValueLayer::editEnd" << endl; | 1533 std::cerr << "TimeValueLayer::editEnd" << std::endl; |
1503 #endif | 1534 #endif |
1504 if (!m_model || !m_editing) return; | 1535 if (!m_model || !m_editing) return; |
1505 | 1536 |
1506 if (m_editingCommand) { | 1537 if (m_editingCommand) { |
1507 | 1538 |
1837 | 1868 |
1838 if (i->haveValue()) { | 1869 if (i->haveValue()) { |
1839 newPoint.value = i->getValue(); | 1870 newPoint.value = i->getValue(); |
1840 } else { | 1871 } else { |
1841 #ifdef DEBUG_TIME_VALUE_LAYER | 1872 #ifdef DEBUG_TIME_VALUE_LAYER |
1842 SVDEBUG << "Setting value on point at " << newPoint.frame << " from labeller"; | 1873 std::cerr << "Setting value on point at " << newPoint.frame << " from labeller"; |
1843 if (i == points.begin()) { | 1874 if (i == points.begin()) { |
1844 SVDEBUG << ", no prev point" << endl; | 1875 std::cerr << ", no prev point" << std::endl; |
1845 } else { | 1876 } else { |
1846 std::cerr << ", prev point is at " << prevPoint.frame << std::endl; | 1877 std::cerr << ", prev point is at " << prevPoint.frame << std::endl; |
1847 } | 1878 } |
1848 #endif | 1879 #endif |
1849 labeller.setValue<SparseTimeValueModel::Point> | 1880 labeller.setValue<SparseTimeValueModel::Point> |