Mercurial > hg > svgui
comparison layer/SliceLayer.cpp @ 1389:1eb560b363e7 spectrogramparam
Make "zoom to region" work sensibly for slice/spectrum layers; ensure that min/max bin are remapped properly when changing fft size
author | Chris Cannam |
---|---|
date | Tue, 13 Nov 2018 14:06:48 +0000 |
parents | bca9870301b7 |
children | 4a36f6130056 |
comparison
equal
deleted
inserted
replaced
1388:81dda64a7edc | 1389:1eb560b363e7 |
---|---|
72 | 72 |
73 if (!m_sliceableModel) return; | 73 if (!m_sliceableModel) return; |
74 | 74 |
75 connectSignals(m_sliceableModel); | 75 connectSignals(m_sliceableModel); |
76 | 76 |
77 m_minbin = 0; | 77 if (m_minbin == 0 && m_maxbin == 0) { |
78 m_maxbin = m_sliceableModel->getHeight(); | 78 m_minbin = 0; |
79 m_maxbin = m_sliceableModel->getHeight(); | |
80 } | |
79 | 81 |
80 emit modelReplaced(); | 82 emit modelReplaced(); |
81 emit layerParametersChanged(); | 83 emit layerParametersChanged(); |
82 } | 84 } |
83 | 85 |
401 } | 403 } |
402 } | 404 } |
403 } | 405 } |
404 | 406 |
405 int mh = m_sliceableModel->getHeight(); | 407 int mh = m_sliceableModel->getHeight(); |
408 int bin0 = 0; | |
409 if (m_maxbin > m_minbin) { | |
410 mh = m_maxbin - m_minbin; | |
411 bin0 = m_minbin; | |
412 } | |
406 | 413 |
407 if (m_plotStyle == PlotBlocks) { | 414 if (m_plotStyle == PlotBlocks) { |
408 // Must use actual zero-width pen, too slow otherwise | 415 // Must use actual zero-width pen, too slow otherwise |
409 paint.setPen(QPen(getBaseQColor(), 0)); | 416 paint.setPen(QPen(getBaseQColor(), 0)); |
410 } else { | 417 } else { |
411 // Similarly, if there are very many bins here, let's drop to | 418 // Similarly, if there are very many bins here, we use a |
412 // a precise 1-pixel-width pen | 419 // thinner pen |
413 if (mh > 10000) { | 420 QPen pen(getBaseQColor(), 1); |
414 paint.setPen(QPen(getBaseQColor(), 1)); | 421 if (mh < 10000) { |
415 } else { | 422 pen = PaintAssistant::scalePen(pen); |
416 paint.setPen(PaintAssistant::scalePen(getBaseQColor())); | 423 } |
417 } | 424 paint.setPen(pen); |
418 } | 425 } |
419 | 426 |
420 int xorigin = getVerticalScaleWidth(v, true, paint) + 1; | 427 int xorigin = getVerticalScaleWidth(v, true, paint) + 1; |
421 m_xorigins[v->getId()] = xorigin; // for use in getFeatureDescription | 428 m_xorigins[v->getId()] = xorigin; // for use in getFeatureDescription |
422 | 429 |
428 m_heights[v->getId()] = h; | 435 m_heights[v->getId()] = h; |
429 | 436 |
430 if (h <= 0) return; | 437 if (h <= 0) return; |
431 | 438 |
432 QPainterPath path; | 439 QPainterPath path; |
433 | |
434 int bin0 = 0; | |
435 | |
436 if (m_maxbin > m_minbin) { | |
437 mh = m_maxbin - m_minbin; | |
438 bin0 = m_minbin; | |
439 } | |
440 | 440 |
441 int divisor = 0; | 441 int divisor = 0; |
442 | 442 |
443 m_values.clear(); | 443 m_values.clear(); |
444 for (int bin = 0; bin < mh; ++bin) { | 444 for (int bin = 0; bin < mh; ++bin) { |
1208 if (!m_sliceableModel) return 0; | 1208 if (!m_sliceableModel) return 0; |
1209 | 1209 |
1210 return new LinearRangeMapper(0, m_sliceableModel->getHeight(), | 1210 return new LinearRangeMapper(0, m_sliceableModel->getHeight(), |
1211 0, m_sliceableModel->getHeight(), ""); | 1211 0, m_sliceableModel->getHeight(), ""); |
1212 } | 1212 } |
1213 | |
1214 void | |
1215 SliceLayer::zoomToRegion(const LayerGeometryProvider *v, QRect rect) | |
1216 { | |
1217 double bin0 = getBinForX(v, rect.x()); | |
1218 double bin1 = getBinForX(v, rect.x() + rect.width()); | |
1219 | |
1220 // ignore y for now... | |
1221 | |
1222 SVDEBUG << "SliceLayer::zoomToRegion: zooming to bin range " | |
1223 << bin0 << " -> " << bin1 << endl; | |
1224 | |
1225 setDisplayExtents(floor(bin0), ceil(bin1)); | |
1226 } | |
1227 |