# HG changeset patch # User Chris Cannam # Date 1201103007 0 # Node ID 369a197737c701f95fb553012e27abb8afb9f616 # Parent 0093f351641cf9696eef684541f97c41d7bd5d4d * Various fixes to object lifetime management, particularly in the spectrum layer and for notification of main model deletion. The main purpose of this is to improve the behaviour of the spectrum, but I think it may also help with #1840922 Various crashes in Layer Summary window. diff -r 0093f351641c -r 369a197737c7 layer/LayerFactory.cpp --- a/layer/LayerFactory.cpp Wed Jan 23 11:38:34 2008 +0000 +++ b/layer/LayerFactory.cpp Wed Jan 23 15:43:27 2008 +0000 @@ -350,6 +350,10 @@ dynamic_cast(layer)->setChannel(channel); return; } + if (dynamic_cast(layer)) { + dynamic_cast(layer)->setChannel(channel); + return; + } } Layer * diff -r 0093f351641c -r 369a197737c7 layer/SpectrumLayer.cpp --- a/layer/SpectrumLayer.cpp Wed Jan 23 11:38:34 2008 +0000 +++ b/layer/SpectrumLayer.cpp Wed Jan 23 15:43:27 2008 +0000 @@ -47,8 +47,11 @@ SpectrumLayer::~SpectrumLayer() { - //!!! delete parent's model -// for (size_t i = 0; i < m_fft.size(); ++i) delete m_fft[i]; + Model *m = const_cast + (static_cast(m_sliceableModel)); + m->aboutToDelete(); + m_sliceableModel = 0; + delete m; } void @@ -57,27 +60,43 @@ 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; - setSliceableModel(0); - // surprised I'm allowed to delete a const pointer -- may be a - // source of future compiler rejection? - delete oldModel; - } -//!!! 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 - (const_cast(m_sliceableModel)); - - if (oldFFT) { + if (m_sliceableModel) { + Model *m = const_cast + (static_cast(m_sliceableModel)); + m->aboutToDelete(); setSliceableModel(0); - delete oldFFT; + delete m; + } + + if (!m_originModel) { + return; } FFTModel *newFFT = new FFTModel(m_originModel, @@ -99,24 +118,8 @@ } newFFT->resume(); -} -void -SpectrumLayer::setChannel(int channel) -{ - m_channelSet = true; - - FFTModel *fft = dynamic_cast - (const_cast(m_sliceableModel)); - - if (m_channel == channel) { - if (fft) fft->resume(); - return; - } - - m_channel = channel; - - emit layerParametersChanged(); + m_newFFTNeeded = false; } Layer::PropertyList @@ -642,11 +645,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" << std::endl; + return; + } if (m_newFFTNeeded) { + std::cerr << "SpectrumLayer::paint: new FFT needed, calling setupFFT" << std::endl; const_cast(this)->setupFFT(); //ugh - m_newFFTNeeded = false; } FFTModel *fft = dynamic_cast diff -r 0093f351641c -r 369a197737c7 layer/SpectrumLayer.h --- a/layer/SpectrumLayer.h Wed Jan 23 11:38:34 2008 +0000 +++ b/layer/SpectrumLayer.h Wed Jan 23 15:43:27 2008 +0000 @@ -24,6 +24,7 @@ #include "data/model/DenseTimeValueModel.h" #include +#include class FFTModel; @@ -113,6 +114,8 @@ bool m_showPeaks; mutable bool m_newFFTNeeded; + mutable QMutex m_fftMutex; + void setupFFT(); virtual void getBiasCurve(BiasCurve &) const;