Mercurial > hg > svgui
comparison layer/SpectrumLayer.cpp @ 349:369a197737c7
* 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.
author | Chris Cannam |
---|---|
date | Wed, 23 Jan 2008 15:43:27 +0000 |
parents | 8c3fb13ef11c |
children | 3a55cd576334 |
comparison
equal
deleted
inserted
replaced
348:0093f351641c | 349:369a197737c7 |
---|---|
45 setBinScale(LogBins); | 45 setBinScale(LogBins); |
46 } | 46 } |
47 | 47 |
48 SpectrumLayer::~SpectrumLayer() | 48 SpectrumLayer::~SpectrumLayer() |
49 { | 49 { |
50 //!!! delete parent's model | 50 Model *m = const_cast<Model *> |
51 // for (size_t i = 0; i < m_fft.size(); ++i) delete m_fft[i]; | 51 (static_cast<const Model *>(m_sliceableModel)); |
52 m->aboutToDelete(); | |
53 m_sliceableModel = 0; | |
54 delete m; | |
52 } | 55 } |
53 | 56 |
54 void | 57 void |
55 SpectrumLayer::setModel(DenseTimeValueModel *model) | 58 SpectrumLayer::setModel(DenseTimeValueModel *model) |
56 { | 59 { |
57 std::cerr << "SpectrumLayer::setModel(" << model << ") from " << m_originModel << std::endl; | 60 std::cerr << "SpectrumLayer::setModel(" << model << ") from " << m_originModel << std::endl; |
58 | 61 |
59 if (m_originModel == model) return; | 62 if (m_originModel == model) return; |
63 | |
60 m_originModel = model; | 64 m_originModel = model; |
61 | 65 |
66 m_newFFTNeeded = true; | |
67 | |
68 emit layerParametersChanged(); | |
69 } | |
70 | |
71 void | |
72 SpectrumLayer::setChannel(int channel) | |
73 { | |
74 std::cerr << "SpectrumLayer::setChannel(" << channel << ") from " << m_channel << std::endl; | |
75 | |
76 m_channelSet = true; | |
77 | |
78 if (m_channel == channel) return; | |
79 | |
80 m_channel = channel; | |
81 | |
82 m_newFFTNeeded = true; | |
83 | |
84 emit layerParametersChanged(); | |
85 } | |
86 | |
87 void | |
88 SpectrumLayer::setupFFT() | |
89 { | |
62 if (m_sliceableModel) { | 90 if (m_sliceableModel) { |
63 const Model *oldModel = m_sliceableModel; | 91 Model *m = const_cast<Model *> |
92 (static_cast<const Model *>(m_sliceableModel)); | |
93 m->aboutToDelete(); | |
64 setSliceableModel(0); | 94 setSliceableModel(0); |
65 // surprised I'm allowed to delete a const pointer -- may be a | 95 delete m; |
66 // source of future compiler rejection? | 96 } |
67 delete oldModel; | 97 |
68 } | 98 if (!m_originModel) { |
69 //!!! setupFFT(); | 99 return; |
70 } | |
71 | |
72 void | |
73 SpectrumLayer::setupFFT() | |
74 { | |
75 FFTModel *oldFFT = dynamic_cast<FFTModel *> | |
76 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel)); | |
77 | |
78 if (oldFFT) { | |
79 setSliceableModel(0); | |
80 delete oldFFT; | |
81 } | 100 } |
82 | 101 |
83 FFTModel *newFFT = new FFTModel(m_originModel, | 102 FFTModel *newFFT = new FFTModel(m_originModel, |
84 m_channel, | 103 m_channel, |
85 m_windowType, | 104 m_windowType, |
97 for (size_t i = 0; i < m_windowSize; ++i) { | 116 for (size_t i = 0; i < m_windowSize; ++i) { |
98 m_biasCurve.push_back(1.f / (float(m_windowSize)/2.f)); | 117 m_biasCurve.push_back(1.f / (float(m_windowSize)/2.f)); |
99 } | 118 } |
100 | 119 |
101 newFFT->resume(); | 120 newFFT->resume(); |
102 } | 121 |
103 | 122 m_newFFTNeeded = false; |
104 void | |
105 SpectrumLayer::setChannel(int channel) | |
106 { | |
107 m_channelSet = true; | |
108 | |
109 FFTModel *fft = dynamic_cast<FFTModel *> | |
110 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel)); | |
111 | |
112 if (m_channel == channel) { | |
113 if (fft) fft->resume(); | |
114 return; | |
115 } | |
116 | |
117 m_channel = channel; | |
118 | |
119 emit layerParametersChanged(); | |
120 } | 123 } |
121 | 124 |
122 Layer::PropertyList | 125 Layer::PropertyList |
123 SpectrumLayer::getProperties() const | 126 SpectrumLayer::getProperties() const |
124 { | 127 { |
640 | 643 |
641 void | 644 void |
642 SpectrumLayer::paint(View *v, QPainter &paint, QRect rect) const | 645 SpectrumLayer::paint(View *v, QPainter &paint, QRect rect) const |
643 { | 646 { |
644 if (!m_originModel || !m_originModel->isOK() || | 647 if (!m_originModel || !m_originModel->isOK() || |
645 !m_originModel->isReady()) return; | 648 !m_originModel->isReady()) { |
649 std::cerr << "SpectrumLayer::paint: no origin model" << std::endl; | |
650 return; | |
651 } | |
646 | 652 |
647 if (m_newFFTNeeded) { | 653 if (m_newFFTNeeded) { |
654 std::cerr << "SpectrumLayer::paint: new FFT needed, calling setupFFT" << std::endl; | |
648 const_cast<SpectrumLayer *>(this)->setupFFT(); //ugh | 655 const_cast<SpectrumLayer *>(this)->setupFFT(); //ugh |
649 m_newFFTNeeded = false; | |
650 } | 656 } |
651 | 657 |
652 FFTModel *fft = dynamic_cast<FFTModel *> | 658 FFTModel *fft = dynamic_cast<FFTModel *> |
653 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel)); | 659 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel)); |
654 | 660 |