Mercurial > hg > svgui
comparison view/Pane.cpp @ 1539:bfacecf7ea7e
Overhaul choice of layer to show scale, in Pane::drawVerticalScale, making it call out to the same logic used by View::getVisibleExtentsForUnit when appropriate. Also refuse to accept scale from dormant top layer.
author | Chris Cannam |
---|---|
date | Tue, 15 Oct 2019 14:53:25 +0100 |
parents | 1819978526f9 |
children | 35c7b7a592f0 |
comparison
equal
deleted
inserted
replaced
1538:0ca4ca37809e | 1539:bfacecf7ea7e |
---|---|
59 #include "widgets/RangeInputDialog.h" | 59 #include "widgets/RangeInputDialog.h" |
60 #include "widgets/NotifyingPushButton.h" | 60 #include "widgets/NotifyingPushButton.h" |
61 | 61 |
62 #include "widgets/KeyReference.h" //!!! should probably split KeyReference into a data class in base and another that shows the widget | 62 #include "widgets/KeyReference.h" //!!! should probably split KeyReference into a data class in base and another that shows the widget |
63 | 63 |
64 //#define DEBUG_PANE | 64 //#define DEBUG_PANE 1 |
65 //#define DEBUG_PANE_SCALE_CHOICE 1 | |
65 | 66 |
66 QCursor *Pane::m_measureCursor1 = nullptr; | 67 QCursor *Pane::m_measureCursor1 = nullptr; |
67 QCursor *Pane::m_measureCursor2 = nullptr; | 68 QCursor *Pane::m_measureCursor2 = nullptr; |
68 | 69 |
69 Pane::Pane(QWidget *w) : | 70 Pane::Pane(QWidget *w) : |
523 } | 524 } |
524 | 525 |
525 void | 526 void |
526 Pane::drawVerticalScale(QRect r, Layer *topLayer, QPainter &paint) | 527 Pane::drawVerticalScale(QRect r, Layer *topLayer, QPainter &paint) |
527 { | 528 { |
528 Layer *scaleLayer = nullptr; | |
529 | |
530 // cerr << "Pane::drawVerticalScale[" << this << "]" << endl; | |
531 | |
532 double min, max; | 529 double min, max; |
533 bool log; | 530 bool log; |
534 QString unit; | 531 QString unit; |
535 | 532 |
536 // If the top layer has no scale and reports no display extents, | 533 bool includeColourScale = m_manager->shouldShowVerticalColourScale(); |
537 // but does report a unit, then the scale should be drawn from any | 534 |
538 // (visible) underlying layer with a scale and that unit. If the | 535 Layer *scaleLayer = nullptr; |
539 // top layer has no scale and no value extents at all, then the | 536 int scaleWidth = 0; |
540 // scale should be drawn from any (visible) underlying layer with | 537 |
541 // a scale regardless of unit. | 538 // If the topmost layer is prepared to draw a scale, then use it. |
542 | 539 // |
543 int sw = topLayer->getVerticalScaleWidth | 540 // Otherwise: find the topmost layer that has value extents, |
544 (this, m_manager->shouldShowVerticalColourScale(), paint); | 541 // i.e. for which a scale is relevant at all. |
545 | 542 // |
546 if (sw > 0) { | 543 // If that layer is prepared to draw a scale directly, then use |
544 // it. This could be the case even if the layer has no unit and so | |
545 // does not participate in scale-providing / auto-align layers. | |
546 // | |
547 // Otherwise, request the scale-providing layer for that layer | |
548 // from the view, and if there is one and it can draw a scale, use | |
549 // that. | |
550 // | |
551 // In all cases ignore dormant layers, and if we hit an opaque | |
552 // layer before finding any with value extents, give up. | |
553 | |
554 if (topLayer && !topLayer->isLayerDormant(this)) { | |
555 scaleWidth = topLayer->getVerticalScaleWidth | |
556 (this, includeColourScale, paint); | |
557 | |
558 #ifdef DEBUG_PANE_SCALE_CHOICE | |
559 SVCERR << "Pane[" << getId() << "]::drawVerticalScale: Top layer (" | |
560 << topLayer << ") offers vertical scale width of " << scaleWidth | |
561 << endl; | |
562 #endif | |
563 } | |
564 | |
565 if (scaleWidth > 0) { | |
547 scaleLayer = topLayer; | 566 scaleLayer = topLayer; |
548 m_scaleWidth = sw; | |
549 | |
550 } else { | 567 } else { |
551 | 568 |
552 bool hasDisplayExtents = topLayer->getDisplayExtents(min, max); | 569 for (auto i = m_layerStack.rbegin(); i != m_layerStack.rend(); ++i) { |
553 bool hasValueExtents = topLayer->getValueExtents(min, max, log, unit); | 570 Layer *layer = *i; |
571 | |
572 if (layer->isLayerDormant(this)) { | |
573 #ifdef DEBUG_PANE_SCALE_CHOICE | |
574 SVCERR << "Pane[" << getId() << "]::drawVerticalScale: " | |
575 << "Layer " << layer << " is dormant, skipping" << endl; | |
576 #endif | |
577 continue; | |
578 } | |
579 | |
580 if (layer->getValueExtents(min, max, log, unit)) { | |
581 scaleLayer = layer; | |
582 | |
583 #ifdef DEBUG_PANE_SCALE_CHOICE | |
584 SVCERR << "Pane[" << getId() << "]::drawVerticalScale: " | |
585 << "Layer " << layer << " has value extents (unit = " | |
586 << unit << "), using this layer or unit" << endl; | |
587 #endif | |
588 break; | |
589 } | |
590 | |
591 if (layer->isLayerOpaque()) { | |
592 #ifdef DEBUG_PANE | |
593 SVCERR << "Pane[" << getId() << "]::drawVerticalScale: " | |
594 << "Layer " << layer | |
595 << " is opaque, searching no further" << endl; | |
596 #endif | |
597 break; | |
598 } | |
599 } | |
600 | |
601 if (scaleLayer) { | |
602 scaleWidth = scaleLayer->getVerticalScaleWidth | |
603 (this, includeColourScale, paint); | |
604 | |
605 #ifdef DEBUG_PANE_SCALE_CHOICE | |
606 SVCERR << "Pane[" << getId() << "]::drawVerticalScale: Layer " | |
607 << topLayer << " offers vertical scale width of " | |
608 << scaleWidth << endl; | |
609 #endif | |
610 } | |
611 | |
612 if (scaleWidth == 0 && unit != "") { | |
613 #ifdef DEBUG_PANE_SCALE_CHOICE | |
614 SVDEBUG << "Pane[" << getId() | |
615 << "]::drawVerticalScale: No good scale layer, then, " | |
616 << "but we have a unit of " << unit | |
617 << " - seeking scale-providing layer for that" << endl; | |
618 #endif | |
554 | 619 |
555 if (!hasDisplayExtents) { | 620 scaleLayer = getScaleProvidingLayerForUnit(unit); |
556 | 621 |
557 if (!hasValueExtents) { | 622 #ifdef DEBUG_PANE_SCALE_CHOICE |
558 | 623 SVDEBUG << "Pane[" << getId() |
559 for (LayerList::iterator vi = m_layerStack.end(); | 624 << "]::drawVerticalScale: That returned " |
560 vi != m_layerStack.begin(); ) { | 625 << scaleLayer << endl; |
561 | 626 #endif |
562 --vi; | 627 } |
563 | 628 } |
564 if ((*vi) == topLayer) continue; | 629 |
565 if ((*vi)->isLayerDormant(this)) continue; | 630 if (scaleWidth > 0) { |
566 | 631 m_scaleWidth = scaleWidth; |
567 sw = (*vi)->getVerticalScaleWidth | 632 } else if (scaleLayer) { |
568 (this, m_manager->shouldShowVerticalColourScale(), paint); | 633 m_scaleWidth = scaleLayer->getVerticalScaleWidth |
569 | 634 (this, includeColourScale, paint); |
570 if (sw > 0) { | 635 } else { |
571 scaleLayer = *vi; | 636 m_scaleWidth = 0; |
572 m_scaleWidth = sw; | 637 } |
573 break; | 638 |
574 } | |
575 } | |
576 } else if (unit != "") { // && hasValueExtents && !hasDisplayExtents | |
577 | |
578 QString requireUnit = unit; | |
579 | |
580 for (LayerList::iterator vi = m_layerStack.end(); | |
581 vi != m_layerStack.begin(); ) { | |
582 | |
583 --vi; | |
584 | |
585 if ((*vi) == topLayer) continue; | |
586 if ((*vi)->isLayerDormant(this)) continue; | |
587 | |
588 if ((*vi)->getDisplayExtents(min, max)) { | |
589 | |
590 // search no further than this: if the | |
591 // scale from this layer isn't suitable, | |
592 // we'll have to draw no scale (else we'd | |
593 // risk ending up with the wrong scale) | |
594 | |
595 if ((*vi)->getValueExtents(min, max, log, unit) && | |
596 unit == requireUnit) { | |
597 | |
598 sw = (*vi)->getVerticalScaleWidth | |
599 (this, m_manager->shouldShowVerticalColourScale(), paint); | |
600 if (sw > 0) { | |
601 scaleLayer = *vi; | |
602 m_scaleWidth = sw; | |
603 } | |
604 } | |
605 break; | |
606 } | |
607 } | |
608 } | |
609 } | |
610 } | |
611 | |
612 if (!scaleLayer) m_scaleWidth = 0; | |
613 | |
614 // cerr << "m_scaleWidth = " << m_scaleWidth << ", r.left = " << r.left() << endl; | |
615 | |
616 if (m_scaleWidth > 0 && r.left() < m_scaleWidth) { | 639 if (m_scaleWidth > 0 && r.left() < m_scaleWidth) { |
617 | 640 |
618 // Profiler profiler("Pane::paintEvent - painting vertical scale", true); | 641 // Profiler profiler("Pane::paintEvent - painting vertical scale", true); |
619 | 642 |
620 // SVDEBUG << "Pane::paintEvent: calling paint.save() in vertical scale block" << endl; | |
621 paint.save(); | 643 paint.save(); |
622 | 644 |
623 paint.setPen(Qt::NoPen); | 645 paint.setPen(Qt::NoPen); |
624 paint.setBrush(getBackground()); | 646 paint.setBrush(getBackground()); |
625 paint.drawRect(0, 0, m_scaleWidth, height()); | 647 paint.drawRect(0, 0, m_scaleWidth, height()); |
627 paint.setPen(getForeground()); | 649 paint.setPen(getForeground()); |
628 paint.drawLine(m_scaleWidth, 0, m_scaleWidth, height()); | 650 paint.drawLine(m_scaleWidth, 0, m_scaleWidth, height()); |
629 | 651 |
630 paint.setBrush(Qt::NoBrush); | 652 paint.setBrush(Qt::NoBrush); |
631 scaleLayer->paintVerticalScale | 653 scaleLayer->paintVerticalScale |
632 (this, m_manager->shouldShowVerticalColourScale(), | 654 (this, includeColourScale, paint, |
633 paint, QRect(0, 0, m_scaleWidth, height())); | 655 QRect(0, 0, m_scaleWidth, height())); |
634 | 656 |
635 paint.restore(); | 657 paint.restore(); |
636 } | 658 } |
637 } | 659 } |
638 | 660 |