Mercurial > hg > svgui
comparison view/Pane.cpp @ 1486:ac0a8addabcf
Merge from branch by-id
author | Chris Cannam |
---|---|
date | Wed, 17 Jul 2019 14:25:16 +0100 |
parents | e540aa5d89cd |
children | c83504eb2649 |
comparison
equal
deleted
inserted
replaced
1468:de41a11cabc2 | 1486:ac0a8addabcf |
---|---|
365 // Locate some relevant layers and models | 365 // Locate some relevant layers and models |
366 | 366 |
367 Layer *topLayer = getTopLayer(); | 367 Layer *topLayer = getTopLayer(); |
368 bool haveSomeTimeXAxis = false; | 368 bool haveSomeTimeXAxis = false; |
369 | 369 |
370 const Model *waveformModel = nullptr; // just for reporting purposes | 370 ModelId waveformModelId; // just for reporting purposes |
371 const Model *workModel = nullptr; | 371 ModelId workModelId; |
372 | 372 |
373 for (LayerList::iterator vi = m_layerStack.end(); vi != m_layerStack.begin(); ) { | 373 for (LayerList::iterator vi = m_layerStack.end(); |
374 vi != m_layerStack.begin(); ) { | |
375 | |
374 --vi; | 376 --vi; |
377 | |
375 if (!haveSomeTimeXAxis && (*vi)->hasTimeXAxis()) { | 378 if (!haveSomeTimeXAxis && (*vi)->hasTimeXAxis()) { |
376 haveSomeTimeXAxis = true; | 379 haveSomeTimeXAxis = true; |
377 } | 380 } |
378 if (dynamic_cast<WaveformLayer *>(*vi)) { | 381 |
379 waveformModel = (*vi)->getModel(); | 382 ModelId modelId = (*vi)->getModel(); |
380 workModel = waveformModel; | 383 if (!modelId.isNone()) { |
381 } else { | 384 if (dynamic_cast<WaveformLayer *>(*vi)) { |
382 Model *m = (*vi)->getModel(); | 385 waveformModelId = modelId; |
383 if (dynamic_cast<WaveFileModel *>(m)) { | 386 workModelId = modelId; |
384 workModel = m; | 387 } else { |
385 } else if (m && dynamic_cast<WaveFileModel *>(m->getSourceModel())) { | 388 if (ModelById::isa<WaveFileModel>(modelId)) { |
386 workModel = m->getSourceModel(); | 389 workModelId = modelId; |
390 } else { | |
391 auto model = ModelById::get(modelId); | |
392 if (model) { | |
393 ModelId sourceId = model->getSourceModel(); | |
394 if (ModelById::isa<WaveFileModel>(sourceId)) { | |
395 workModelId = sourceId; | |
396 } | |
397 } | |
398 } | |
387 } | 399 } |
388 } | 400 } |
389 | 401 |
390 if (waveformModel && workModel && haveSomeTimeXAxis) break; | 402 if (!waveformModelId.isNone() && |
403 !workModelId.isNone() && | |
404 haveSomeTimeXAxis) { | |
405 break; | |
406 } | |
391 } | 407 } |
392 | 408 |
393 // Block off left and right extents so we can see where the main model ends | 409 // Block off left and right extents so we can see where the main model ends |
394 | 410 |
395 if (workModel && hasTopLayerTimeXAxis()) { | 411 if (!workModelId.isNone() && hasTopLayerTimeXAxis()) { |
396 drawModelTimeExtents(r, paint, workModel); | 412 drawModelTimeExtents(r, paint, workModelId); |
397 } | 413 } |
398 | 414 |
399 // Crosshairs for mouse movement in measure mode | 415 // Crosshairs for mouse movement in measure mode |
400 | 416 |
401 if (m_manager && | 417 if (m_manager && |
442 drawCentreLine(sampleRate, paint, !haveSomeTimeXAxis); | 458 drawCentreLine(sampleRate, paint, !haveSomeTimeXAxis); |
443 } | 459 } |
444 | 460 |
445 paint.setPen(QColor(50, 50, 50)); | 461 paint.setPen(QColor(50, 50, 50)); |
446 | 462 |
447 if (waveformModel && | 463 if (!waveformModelId.isNone() && |
448 sampleRate && | 464 sampleRate && |
449 m_manager && | 465 m_manager && |
450 m_manager->shouldShowDuration()) { | 466 m_manager->shouldShowDuration()) { |
451 drawDurationAndRate(r, waveformModel, sampleRate, paint); | 467 drawDurationAndRate(r, waveformModelId, sampleRate, paint); |
452 } | 468 } |
453 | 469 |
454 bool haveWorkTitle = false; | 470 bool haveWorkTitle = false; |
455 | 471 |
456 if (workModel && | 472 if (!workModelId.isNone() && |
457 m_manager && | 473 m_manager && |
458 m_manager->shouldShowWorkTitle()) { | 474 m_manager->shouldShowWorkTitle()) { |
459 drawWorkTitle(r, paint, workModel); | 475 drawWorkTitle(r, paint, workModelId); |
460 haveWorkTitle = true; | 476 haveWorkTitle = true; |
461 } | 477 } |
462 | 478 |
463 if (workModel && | 479 if (!workModelId.isNone() && |
464 m_manager && | 480 m_manager && |
465 m_manager->getAlignMode()) { | 481 m_manager->getAlignMode()) { |
466 drawAlignmentStatus(r, paint, workModel, haveWorkTitle); | 482 drawAlignmentStatus(r, paint, workModelId, haveWorkTitle); |
467 } | 483 } |
468 | 484 |
469 if (m_manager && | 485 if (m_manager && |
470 m_manager->shouldShowLayerNames()) { | 486 m_manager->shouldShowLayerNames()) { |
471 drawLayerNames(r, paint); | 487 drawLayerNames(r, paint); |
630 | 646 |
631 if (desc != "") { | 647 if (desc != "") { |
632 | 648 |
633 paint.save(); | 649 paint.save(); |
634 | 650 |
651 // Qt 5.13 deprecates QFontMetrics::width(), but its suggested | |
652 // replacement (horizontalAdvance) was only added in Qt 5.11 | |
653 // which is too new for us | |
654 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
655 | |
635 int tabStop = | 656 int tabStop = |
636 paint.fontMetrics().width(tr("Some lengthy prefix:")); | 657 paint.fontMetrics().width(tr("Some lengthy prefix:")); |
637 | 658 |
638 QRect boundingRect = | 659 QRect boundingRect = |
639 paint.fontMetrics().boundingRect | 660 paint.fontMetrics().boundingRect |
748 PaintAssistant::drawVisibleText(this, paint, x, y, text, PaintAssistant::OutlinedText); | 769 PaintAssistant::drawVisibleText(this, paint, x, y, text, PaintAssistant::OutlinedText); |
749 } | 770 } |
750 } | 771 } |
751 | 772 |
752 void | 773 void |
753 Pane::drawModelTimeExtents(QRect r, QPainter &paint, const Model *model) | 774 Pane::drawModelTimeExtents(QRect r, QPainter &paint, ModelId modelId) |
754 { | 775 { |
776 auto model = ModelById::get(modelId); | |
777 if (!model) return; | |
778 | |
755 paint.save(); | 779 paint.save(); |
756 | 780 |
757 QBrush brush; | 781 QBrush brush; |
758 | 782 |
759 if (hasLightBackground()) { | 783 if (hasLightBackground()) { |
786 | 810 |
787 paint.restore(); | 811 paint.restore(); |
788 } | 812 } |
789 | 813 |
790 void | 814 void |
791 Pane::drawAlignmentStatus(QRect r, QPainter &paint, const Model *model, | 815 Pane::drawAlignmentStatus(QRect r, QPainter &paint, ModelId modelId, |
792 bool down) | 816 bool down) |
793 { | 817 { |
794 const Model *reference = model->getAlignmentReference(); | 818 auto model = ModelById::get(modelId); |
819 if (!model) return; | |
820 | |
821 ModelId reference = model->getAlignmentReference(); | |
795 /* | 822 /* |
796 if (!reference) { | 823 if (!reference) { |
797 cerr << "Pane[" << this << "]::drawAlignmentStatus: No reference" << endl; | 824 cerr << "Pane[" << this << "]::drawAlignmentStatus: No reference" << endl; |
798 } else if (reference == model) { | 825 } else if (reference == model->getId()) { |
799 cerr << "Pane[" << this << "]::drawAlignmentStatus: This is the reference model" << endl; | 826 cerr << "Pane[" << this << "]::drawAlignmentStatus: This is the reference model" << endl; |
800 } else { | 827 } else { |
801 cerr << "Pane[" << this << "]::drawAlignmentStatus: This is not the reference" << endl; | 828 cerr << "Pane[" << this << "]::drawAlignmentStatus: This is not the reference" << endl; |
802 } | 829 } |
803 */ | 830 */ |
804 QString text; | 831 QString text; |
805 int completion = 100; | 832 int completion = 100; |
806 | 833 |
807 if (reference == model) { | 834 if (reference == modelId) { |
808 text = tr("Reference"); | 835 text = tr("Reference"); |
809 } else if (!reference) { | 836 } else if (reference.isNone()) { |
810 text = tr("Unaligned"); | 837 text = tr("Unaligned"); |
811 } else { | 838 } else { |
812 completion = model->getAlignmentCompletion(); | 839 completion = model->getAlignmentCompletion(); |
813 if (completion == 0) { | 840 if (completion == 0) { |
814 text = tr("Unaligned"); | 841 text = tr("Unaligned"); |
839 | 866 |
840 paint.restore(); | 867 paint.restore(); |
841 } | 868 } |
842 | 869 |
843 void | 870 void |
844 Pane::modelAlignmentCompletionChanged() | 871 Pane::modelAlignmentCompletionChanged(ModelId modelId) |
845 { | 872 { |
846 View::modelAlignmentCompletionChanged(); | 873 View::modelAlignmentCompletionChanged(modelId); |
847 update(QRect(0, 0, 300, 100)); | 874 update(QRect(0, 0, 300, 100)); |
848 } | 875 } |
849 | 876 |
850 void | 877 void |
851 Pane::drawWorkTitle(QRect r, QPainter &paint, const Model *model) | 878 Pane::drawWorkTitle(QRect r, QPainter &paint, ModelId modelId) |
852 { | 879 { |
880 auto model = ModelById::get(modelId); | |
881 if (!model) return; | |
882 | |
853 QString title = model->getTitle(); | 883 QString title = model->getTitle(); |
854 QString maker = model->getMaker(); | 884 QString maker = model->getMaker(); |
855 //SVDEBUG << "Pane::drawWorkTitle: title=\"" << title//<< "\", maker=\"" << maker << "\"" << endl; | 885 //SVDEBUG << "Pane::drawWorkTitle: title=\"" << title//<< "\", maker=\"" << maker << "\"" << endl; |
856 if (title == "") return; | 886 if (title == "") return; |
857 | 887 |
1023 } | 1053 } |
1024 paint.restore(); | 1054 paint.restore(); |
1025 } | 1055 } |
1026 | 1056 |
1027 void | 1057 void |
1028 Pane::drawDurationAndRate(QRect r, const Model *waveformModel, | 1058 Pane::drawDurationAndRate(QRect r, ModelId waveformModelId, |
1029 sv_samplerate_t sampleRate, QPainter &paint) | 1059 sv_samplerate_t sampleRate, QPainter &paint) |
1030 { | 1060 { |
1061 auto waveformModel = ModelById::get(waveformModelId); | |
1062 if (!waveformModel) return; | |
1063 | |
1031 int fontHeight = paint.fontMetrics().height(); | 1064 int fontHeight = paint.fontMetrics().height(); |
1032 int fontAscent = paint.fontMetrics().ascent(); | 1065 int fontAscent = paint.fontMetrics().ascent(); |
1033 | 1066 |
1034 if (r.y() + r.height() < height() - fontHeight - 6) return; | 1067 if (r.y() + r.height() < height() - fontHeight - 6) return; |
1035 | 1068 |