diff layer/SpectrumLayer.cpp @ 373:0895517bb2d1 1.2-stable

* merge from trunk (1.2 ended up being tracked from trunk, but we may want this branch for fixes later)
author Chris Cannam
date Wed, 27 Feb 2008 10:32:45 +0000
parents 2f83b6e3b8ca
children
line wrap: on
line diff
--- a/layer/SpectrumLayer.cpp	Thu Nov 29 10:43:54 2007 +0000
+++ b/layer/SpectrumLayer.cpp	Wed Feb 27 10:32:45 2008 +0000
@@ -47,35 +47,64 @@
 
 SpectrumLayer::~SpectrumLayer()
 {
-    //!!! delete parent's model
-//    for (size_t i = 0; i < m_fft.size(); ++i) delete m_fft[i];
+    Model *m = const_cast<Model *>
+        (static_cast<const Model *>(m_sliceableModel));
+    m->aboutToDelete();
+    m_sliceableModel = 0;
+    delete m;
 }
 
 void
 SpectrumLayer::setModel(DenseTimeValueModel *model)
 {
+    std::cerr << "SpectrumLayer::setModel(" << model << ") from " << m_originModel << std::endl;
+    
     if (m_originModel == model) return;
+
     m_originModel = model;
 
     if (m_sliceableModel) {
-        const Model *oldModel = m_sliceableModel;
+        Model *m = const_cast<Model *>
+            (static_cast<const Model *>(m_sliceableModel));
+        m->aboutToDelete();
         setSliceableModel(0);
-        // surprised I'm allowed to delete a const pointer -- may be a
-        // source of future compiler rejection?
-        delete oldModel;
+        delete m;
     }
-//!!!    setupFFT();
+
+    m_newFFTNeeded = true;
+
+    emit layerParametersChanged();
+}
+
+void
+SpectrumLayer::setChannel(int channel)
+{
+    std::cerr << "SpectrumLayer::setChannel(" << channel << ") from " << m_channel << std::endl;
+    
+    m_channelSet = true;
+    
+    if (m_channel == channel) return;
+
+    m_channel = channel;
+
+    m_newFFTNeeded = true;
+
+    emit layerParametersChanged();
 }
 
 void
 SpectrumLayer::setupFFT()
 {
-    FFTModel *oldFFT = dynamic_cast<FFTModel *>
-        (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel));
-    
-    if (oldFFT) {
+    if (m_sliceableModel) {
+        Model *m = const_cast<Model *>
+            (static_cast<const Model *>(m_sliceableModel));
+        m->aboutToDelete();
         setSliceableModel(0);
-        delete oldFFT;
+        delete m;
+    }
+
+    if (!m_originModel) {
+        return;
     }
 
     FFTModel *newFFT = new FFTModel(m_originModel,
@@ -97,24 +126,8 @@
     }
 
     newFFT->resume();
-}
 
-void
-SpectrumLayer::setChannel(int channel)
-{
-    m_channelSet = true;
-
-    FFTModel *fft = dynamic_cast<FFTModel *>
-        (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel));
-
-    if (m_channel == channel) {
-        if (fft) fft->resume();
-        return;
-    }
-
-    m_channel = channel;
-
-    emit layerParametersChanged();
+    m_newFFTNeeded = false;
 }
 
 Layer::PropertyList
@@ -640,11 +653,14 @@
 SpectrumLayer::paint(View *v, QPainter &paint, QRect rect) const
 {
     if (!m_originModel || !m_originModel->isOK() ||
-        !m_originModel->isReady()) return;
+        !m_originModel->isReady()) {
+        std::cerr << "SpectrumLayer::paint: no origin model, or origin model not OK or not ready" << std::endl;
+        return;
+    }
 
     if (m_newFFTNeeded) {
+        std::cerr << "SpectrumLayer::paint: new FFT needed, calling setupFFT" << std::endl;
         const_cast<SpectrumLayer *>(this)->setupFFT(); //ugh
-        m_newFFTNeeded = false;
     }
 
     FFTModel *fft = dynamic_cast<FFTModel *>
@@ -660,6 +676,8 @@
         pkh = 10;
 //!!!    }
 
+    paint.save();
+
     if (fft && m_showPeaks) {
 
         // draw peak lines
@@ -799,6 +817,8 @@
 	    px = x;
 	}
 //    }
+
+    paint.restore();
 }
 
 void