comparison base/View.cpp @ 31:4afaf0df4d51

* Add TextModel and TextLayer types * Make View refresh work better when editing a model (previously edits might not be refreshed if their visible changed area extended beyond the strict frame range that was being modified in the model) * Add phase-adjusted instantaneous frequency display to spectrogram layer (still a work in progress) * Pull maths aliases out into a separate header in dsp/maths so MathUtilities can be included without introducing them
author Chris Cannam
date Mon, 20 Feb 2006 13:33:36 +0000
parents 8460b3bf8f04
children 51e158b505da
comparison
equal deleted inserted replaced
30:a6ef94ecbe74 31:4afaf0df4d51
412 QObject *obj = sender(); 412 QObject *obj = sender();
413 413
414 #ifdef DEBUG_VIEW_WIDGET_PAINT 414 #ifdef DEBUG_VIEW_WIDGET_PAINT
415 std::cerr << "View(" << this << ")::modelChanged()" << std::endl; 415 std::cerr << "View(" << this << ")::modelChanged()" << std::endl;
416 #endif 416 #endif
417 delete m_cache; 417
418 m_cache = 0; 418 // If the model that has changed is not used by any of the cached
419 // layers, we won't need to recreate the cache
420
421 bool recreate = false;
422
423 bool discard;
424 LayerList scrollables = getScrollableBackLayers(false, discard);
425 for (LayerList::const_iterator i = scrollables.begin();
426 i != scrollables.end(); ++i) {
427 if (*i == obj || (*i)->getModel() == obj) {
428 recreate = true;
429 break;
430 }
431 }
432
433 if (recreate) {
434 delete m_cache;
435 m_cache = 0;
436 }
419 437
420 checkProgress(obj); 438 checkProgress(obj);
421 439
422 update(); 440 update();
423 } 441 }
441 if (startFrame > myEndFrame) { 459 if (startFrame > myEndFrame) {
442 checkProgress(obj); 460 checkProgress(obj);
443 return; 461 return;
444 } 462 }
445 463
446 delete m_cache; 464 // If the model that has changed is not used by any of the cached
447 m_cache = 0; 465 // layers, we won't need to recreate the cache
466
467 bool recreate = false;
468
469 bool discard;
470 LayerList scrollables = getScrollableBackLayers(false, discard);
471 for (LayerList::const_iterator i = scrollables.begin();
472 i != scrollables.end(); ++i) {
473 if (*i == obj || (*i)->getModel() == obj) {
474 recreate = true;
475 break;
476 }
477 }
478
479 if (recreate) {
480 delete m_cache;
481 m_cache = 0;
482 }
448 483
449 if (long(startFrame) < myStartFrame) startFrame = myStartFrame; 484 if (long(startFrame) < myStartFrame) startFrame = myStartFrame;
450 if (endFrame > myEndFrame) endFrame = myEndFrame; 485 if (endFrame > myEndFrame) endFrame = myEndFrame;
451 486
452 int x0 = getXForFrame(startFrame); 487 int x0 = getXForFrame(startFrame);
453 int x1 = getXForFrame(endFrame + 1); 488 int x1 = getXForFrame(endFrame + 1);
454 if (x1 < x0) x1 = x0; 489 if (x1 < x0) x1 = x0;
455 490
456 checkProgress(obj); 491 checkProgress(obj);
457 492
458 update(x0, 0, x1 - x0 + 1, height()); 493 update();
494 //!! update(x0, 0, x1 - x0 + 1, height());
459 } 495 }
460 496
461 void 497 void
462 View::modelCompletionChanged() 498 View::modelCompletionChanged()
463 { 499 {
693 } 729 }
694 return true; 730 return true;
695 } 731 }
696 732
697 View::LayerList 733 View::LayerList
698 View::getScrollableBackLayers(bool &changed) const 734 View::getScrollableBackLayers(bool testChanged, bool &changed) const
699 { 735 {
700 changed = false; 736 changed = false;
701 737
702 LayerList scrollables; 738 LayerList scrollables;
703 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 739 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
704 if ((*i)->isLayerDormant()) continue; 740 if ((*i)->isLayerDormant()) continue;
705 if ((*i)->isLayerScrollable()) scrollables.push_back(*i); 741 if ((*i)->isLayerScrollable()) scrollables.push_back(*i);
706 else { 742 else {
707 if (scrollables != m_lastScrollableBackLayers) { 743 if (testChanged && scrollables != m_lastScrollableBackLayers) {
708 m_lastScrollableBackLayers = scrollables; 744 m_lastScrollableBackLayers = scrollables;
709 changed = true; 745 changed = true;
710 } 746 }
711 return scrollables; 747 return scrollables;
712 } 748 }
719 // -- it probably redraws as quickly as it refreshes from 755 // -- it probably redraws as quickly as it refreshes from
720 // cache 756 // cache
721 scrollables.clear(); 757 scrollables.clear();
722 } 758 }
723 759
724 if (scrollables != m_lastScrollableBackLayers) { 760 if (testChanged && scrollables != m_lastScrollableBackLayers) {
725 m_lastScrollableBackLayers = scrollables; 761 m_lastScrollableBackLayers = scrollables;
726 changed = true; 762 changed = true;
727 } 763 }
728 return scrollables; 764 return scrollables;
729 } 765 }
730 766
731 View::LayerList 767 View::LayerList
732 View::getNonScrollableFrontLayers(bool &changed) const 768 View::getNonScrollableFrontLayers(bool testChanged, bool &changed) const
733 { 769 {
734 changed = false; 770 changed = false;
735 LayerList scrollables = getScrollableBackLayers(changed); 771 LayerList scrollables = getScrollableBackLayers(testChanged, changed);
736 LayerList nonScrollables; 772 LayerList nonScrollables;
737 773
738 // Everything in front of the first non-scrollable from the back 774 // Everything in front of the first non-scrollable from the back
739 // should also be considered non-scrollable 775 // should also be considered non-scrollable
740 776
746 continue; 782 continue;
747 } 783 }
748 nonScrollables.push_back(*i); 784 nonScrollables.push_back(*i);
749 } 785 }
750 786
751 if (nonScrollables != m_lastNonScrollableBackLayers) { 787 if (testChanged && nonScrollables != m_lastNonScrollableBackLayers) {
752 m_lastNonScrollableBackLayers = nonScrollables; 788 m_lastNonScrollableBackLayers = nonScrollables;
753 changed = true; 789 changed = true;
754 } 790 }
755 791
756 return nonScrollables; 792 return nonScrollables;
895 931
896 // If not all layers are scrollable, but some of the back layers 932 // If not all layers are scrollable, but some of the back layers
897 // are, we should store only those in the cache 933 // are, we should store only those in the cache
898 934
899 bool layersChanged = false; 935 bool layersChanged = false;
900 LayerList scrollables = getScrollableBackLayers(layersChanged); 936 LayerList scrollables = getScrollableBackLayers(true, layersChanged);
901 LayerList nonScrollables = getNonScrollableFrontLayers(layersChanged); 937 LayerList nonScrollables = getNonScrollableFrontLayers(true, layersChanged);
902 bool selectionCacheable = nonScrollables.empty(); 938 bool selectionCacheable = nonScrollables.empty();
903 bool haveSelections = m_manager && !m_manager->getSelections().empty(); 939 bool haveSelections = m_manager && !m_manager->getSelections().empty();
904 bool selectionDrawn = false; 940 bool selectionDrawn = false;
905 941
906 if (!selectionCacheable) { 942 if (!selectionCacheable) {