comparison base/View.cpp @ 36:935a2419a77c

* Refactor Layer classes so as no longer to store a single View pointer; instead they need to be able to draw themselves on any View on demand. Layers with caches (e.g. spectrogram) will need to be further refactored so as to maintain a per-View cache * Begin refactoring MainWindow by pulling out the document stuff (set of layers, models etc) into a Document class. Not yet in use. This revision is fairly unstable.
author Chris Cannam
date Thu, 02 Mar 2006 16:58:49 +0000
parents aaf73f7309f2
children 838652cc31e6
comparison
equal deleted inserted replaced
35:0164c8d3023b 36:935a2419a77c
50 // QWidget::setAttribute(Qt::WA_PaintOnScreen); 50 // QWidget::setAttribute(Qt::WA_PaintOnScreen);
51 } 51 }
52 52
53 View::~View() 53 View::~View()
54 { 54 {
55 //!!! will want to _not_ delete layers
56
55 m_deleting = true; 57 m_deleting = true;
56 58
57 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 59 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
58 delete *i; 60 delete *i;
59 } 61 }
409 } else { 411 } else {
410 return 0; 412 return 0;
411 } 413 }
412 } 414 }
413 415
416 const Layer *
417 View::getSelectedLayer() const
418 {
419 return const_cast<const Layer *>(const_cast<View *>(this)->getSelectedLayer());
420 }
421
414 void 422 void
415 View::setViewManager(ViewManager *manager) 423 View::setViewManager(ViewManager *manager)
416 { 424 {
417 if (m_manager) { 425 if (m_manager) {
418 m_manager->disconnect(this, SLOT(viewManagerCentreFrameChanged(void *, unsigned long, bool))); 426 m_manager->disconnect(this, SLOT(viewManagerCentreFrameChanged(void *, unsigned long, bool)));
787 bool 795 bool
788 View::areLayersScrollable() const 796 View::areLayersScrollable() const
789 { 797 {
790 // True iff all views are scrollable 798 // True iff all views are scrollable
791 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 799 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
792 if (!(*i)->isLayerScrollable()) return false; 800 if (!(*i)->isLayerScrollable(this)) return false;
793 } 801 }
794 return true; 802 return true;
795 } 803 }
796 804
797 View::LayerList 805 View::LayerList
799 { 807 {
800 changed = false; 808 changed = false;
801 809
802 LayerList scrollables; 810 LayerList scrollables;
803 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 811 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
804 if ((*i)->isLayerDormant()) continue; 812 if ((*i)->isLayerDormant(this)) continue;
805 if ((*i)->isLayerScrollable()) scrollables.push_back(*i); 813 if ((*i)->isLayerScrollable(this)) scrollables.push_back(*i);
806 else { 814 else {
807 if (testChanged && scrollables != m_lastScrollableBackLayers) { 815 if (testChanged && scrollables != m_lastScrollableBackLayers) {
808 m_lastScrollableBackLayers = scrollables; 816 m_lastScrollableBackLayers = scrollables;
809 changed = true; 817 changed = true;
810 } 818 }
838 // Everything in front of the first non-scrollable from the back 846 // Everything in front of the first non-scrollable from the back
839 // should also be considered non-scrollable 847 // should also be considered non-scrollable
840 848
841 size_t count = 0; 849 size_t count = 0;
842 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 850 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
843 if ((*i)->isLayerDormant()) continue; 851 if ((*i)->isLayerDormant(this)) continue;
844 if (count < scrollables.size()) { 852 if (count < scrollables.size()) {
845 ++count; 853 ++count;
846 continue; 854 continue;
847 } 855 }
848 nonScrollables.push_back(*i); 856 nonScrollables.push_back(*i);
1146 paint.setBrush(Qt::NoBrush); 1154 paint.setBrush(Qt::NoBrush);
1147 1155
1148 for (LayerList::iterator i = scrollables.begin(); i != scrollables.end(); ++i) { 1156 for (LayerList::iterator i = scrollables.begin(); i != scrollables.end(); ++i) {
1149 paint.setRenderHint(QPainter::Antialiasing, false); 1157 paint.setRenderHint(QPainter::Antialiasing, false);
1150 paint.save(); 1158 paint.save();
1151 (*i)->paint(paint, cacheRect); 1159 (*i)->paint(this, paint, cacheRect);
1152 paint.restore(); 1160 paint.restore();
1153 } 1161 }
1154 1162
1155 if (haveSelections && selectionCacheable) { 1163 if (haveSelections && selectionCacheable) {
1156 drawSelections(paint); 1164 drawSelections(paint);
1190 1198
1191 paint.setPen(Qt::black); 1199 paint.setPen(Qt::black);
1192 paint.setBrush(Qt::NoBrush); 1200 paint.setBrush(Qt::NoBrush);
1193 1201
1194 for (LayerList::iterator i = nonScrollables.begin(); i != nonScrollables.end(); ++i) { 1202 for (LayerList::iterator i = nonScrollables.begin(); i != nonScrollables.end(); ++i) {
1195 (*i)->paint(paint, nonCacheRect); 1203 (*i)->paint(this, paint, nonCacheRect);
1196 } 1204 }
1197 1205
1198 paint.end(); 1206 paint.end();
1199 1207
1200 paint.begin(this); 1208 paint.begin(this);