Mercurial > hg > svgui
comparison layer/Colour3DPlotLayer.cpp @ 445:4a14499fb184
* Save & reload vertical scale extents from note, time/value & colour 3d
plot layers
* Fix display of vertical scale in zoomed colour 3d plot layer
author | Chris Cannam |
---|---|
date | Wed, 12 Nov 2008 15:51:41 +0000 |
parents | e5800f4490c4 |
children | ae51d4b73860 |
comparison
equal
deleted
inserted
replaced
444:e5800f4490c4 | 445:4a14499fb184 |
---|---|
360 void | 360 void |
361 Colour3DPlotLayer::setVerticalZoomStep(int step) | 361 Colour3DPlotLayer::setVerticalZoomStep(int step) |
362 { | 362 { |
363 if (!m_model) return; | 363 if (!m_model) return; |
364 | 364 |
365 std::cerr << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): before: miny = " << m_miny << ", maxy = " << m_maxy << std::endl; | 365 // std::cerr << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): before: miny = " << m_miny << ", maxy = " << m_maxy << std::endl; |
366 | 366 |
367 int dist = m_model->getHeight() - step; | 367 int dist = m_model->getHeight() - step; |
368 if (dist < 1) dist = 1; | 368 if (dist < 1) dist = 1; |
369 float centre = m_miny + (float(m_maxy) - float(m_miny)) / 2.f; | 369 float centre = m_miny + (float(m_maxy) - float(m_miny)) / 2.f; |
370 m_miny = lrintf(centre - float(dist)/2); | 370 m_miny = lrintf(centre - float(dist)/2); |
371 if (m_miny < 0) m_miny = 0; | 371 if (m_miny < 0) m_miny = 0; |
372 m_maxy = m_miny + dist; | 372 m_maxy = m_miny + dist; |
373 if (m_maxy > m_model->getHeight()) m_maxy = m_model->getHeight(); | 373 if (m_maxy > m_model->getHeight()) m_maxy = m_model->getHeight(); |
374 | 374 |
375 std::cerr << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): after: miny = " << m_miny << ", maxy = " << m_maxy << std::endl; | 375 // std::cerr << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): after: miny = " << m_miny << ", maxy = " << m_maxy << std::endl; |
376 | 376 |
377 emit layerParametersChanged(); | 377 emit layerParametersChanged(); |
378 } | 378 } |
379 | 379 |
380 RangeMapper * | 380 RangeMapper * |
464 Colour3DPlotLayer::paintVerticalScale(View *v, QPainter &paint, QRect rect) const | 464 Colour3DPlotLayer::paintVerticalScale(View *v, QPainter &paint, QRect rect) const |
465 { | 465 { |
466 if (!m_model) return; | 466 if (!m_model) return; |
467 | 467 |
468 int h = rect.height(), w = rect.width(); | 468 int h = rect.height(), w = rect.width(); |
469 float binHeight = float(v->height()) / m_model->getHeight(); | |
470 | 469 |
471 int cw = getColourScaleWidth(paint); | 470 int cw = getColourScaleWidth(paint); |
472 | 471 |
473 int ch = h - 20; | 472 int ch = h - 20; |
474 if (ch > 20 && m_cache) { | 473 if (ch > 20 && m_cache) { |
484 } | 483 } |
485 } | 484 } |
486 | 485 |
487 paint.setPen(v->getForeground()); | 486 paint.setPen(v->getForeground()); |
488 | 487 |
488 int sh = m_model->getHeight(); | |
489 | |
490 int symin = m_miny; | |
491 int symax = m_maxy; | |
492 if (symax <= symin) { | |
493 symin = 0; | |
494 symax = sh; | |
495 } | |
496 if (symin < 0) symin = 0; | |
497 if (symax > sh) symax = sh; | |
498 | |
489 int count = v->height() / paint.fontMetrics().height(); | 499 int count = v->height() / paint.fontMetrics().height(); |
490 int step = m_model->getHeight() / count; | 500 int step = (symax - symin) / count; |
491 if (step == 0) step = 1; | 501 if (step == 0) step = 1; |
492 | 502 |
493 for (size_t i = 0; i < m_model->getHeight(); ++i) { | 503 float binHeight = float(v->height()) / (symax - symin); |
504 | |
505 for (size_t i = symin; i < symax; ++i) { | |
494 | 506 |
495 size_t idx = i; | 507 size_t idx = i; |
496 if (m_invertVertical) idx = m_model->getHeight() - idx - 1; | 508 if (m_invertVertical) idx = m_model->getHeight() - idx - 1; |
497 | 509 |
498 if ((idx % step) != 0) continue; | 510 if ((idx % step) != 0) continue; |
499 | 511 |
500 int y0 = int(v->height() - (i * binHeight) - 1); | 512 int y0 = int(v->height() - ((i - symin) * binHeight) - 1); |
501 | 513 |
502 QString text = m_model->getBinName(idx); | 514 QString text = m_model->getBinName(idx); |
503 if (text == "") text = QString("[%1]").arg(idx + 1); | 515 if (text == "") text = QString("[%1]").arg(idx + 1); |
504 | 516 |
505 paint.drawLine(cw, y0, w, y0); | 517 paint.drawLine(cw, y0, w, y0); |
955 QString indent, QString extraAttributes) const | 967 QString indent, QString extraAttributes) const |
956 { | 968 { |
957 QString s = QString("scale=\"%1\" " | 969 QString s = QString("scale=\"%1\" " |
958 "colourScheme=\"%2\" " | 970 "colourScheme=\"%2\" " |
959 "normalizeColumns=\"%3\" " | 971 "normalizeColumns=\"%3\" " |
960 "normalizeVisibleArea=\"%4\"") | 972 "normalizeVisibleArea=\"%4\" " |
973 "minY=\"%5\" " | |
974 "maxY=\"%6\" ") | |
961 .arg((int)m_colourScale) | 975 .arg((int)m_colourScale) |
962 .arg(m_colourMap) | 976 .arg(m_colourMap) |
963 .arg(m_normalizeColumns ? "true" : "false") | 977 .arg(m_normalizeColumns ? "true" : "false") |
964 .arg(m_normalizeVisibleArea ? "true" : "false"); | 978 .arg(m_normalizeVisibleArea ? "true" : "false") |
979 .arg(m_miny) | |
980 .arg(m_maxy); | |
965 | 981 |
966 Layer::toXml(stream, indent, extraAttributes + " " + s); | 982 Layer::toXml(stream, indent, extraAttributes + " " + s); |
967 } | 983 } |
968 | 984 |
969 void | 985 void |
970 Colour3DPlotLayer::setProperties(const QXmlAttributes &attributes) | 986 Colour3DPlotLayer::setProperties(const QXmlAttributes &attributes) |
971 { | 987 { |
972 bool ok = false; | 988 bool ok = false, alsoOk = false; |
973 | 989 |
974 ColourScale scale = (ColourScale)attributes.value("scale").toInt(&ok); | 990 ColourScale scale = (ColourScale)attributes.value("scale").toInt(&ok); |
975 if (ok) setColourScale(scale); | 991 if (ok) setColourScale(scale); |
976 | 992 |
977 int colourMap = attributes.value("colourScheme").toInt(&ok); | 993 int colourMap = attributes.value("colourScheme").toInt(&ok); |
982 setNormalizeColumns(normalizeColumns); | 998 setNormalizeColumns(normalizeColumns); |
983 | 999 |
984 bool normalizeVisibleArea = | 1000 bool normalizeVisibleArea = |
985 (attributes.value("normalizeVisibleArea").trimmed() == "true"); | 1001 (attributes.value("normalizeVisibleArea").trimmed() == "true"); |
986 setNormalizeVisibleArea(normalizeVisibleArea); | 1002 setNormalizeVisibleArea(normalizeVisibleArea); |
987 } | 1003 |
988 | 1004 float min = attributes.value("minY").toFloat(&ok); |
1005 float max = attributes.value("maxY").toFloat(&alsoOk); | |
1006 if (ok && alsoOk) setDisplayExtents(min, max); | |
1007 } | |
1008 |