Mercurial > hg > sonic-visualiser
comparison document/Document.cpp @ 45:6b6bca31ad53
* When setting a new model on a layer, don't delete the old one until after
the new one has been set (a layer's setModel may want to compare against the
old one, as WaveformLayer does)
author | Chris Cannam |
---|---|
date | Thu, 05 Oct 2006 11:00:59 +0000 |
parents | 56e1d4242bb4 |
children | ec77936c268e |
comparison
equal
deleted
inserted
replaced
44:5a72bf7490ae | 45:6b6bca31ad53 |
---|---|
231 for (LayerSet::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { | 231 for (LayerSet::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { |
232 | 232 |
233 Layer *layer = *i; | 233 Layer *layer = *i; |
234 Model *model = layer->getModel(); | 234 Model *model = layer->getModel(); |
235 | 235 |
236 std::cerr << "Document::setMainModel: inspecting model " | |
237 << (model ? model->objectName().toStdString() : "(null)") << " in layer " | |
238 << layer->objectName().toStdString() << std::endl; | |
239 | |
236 if (model == oldMainModel) { | 240 if (model == oldMainModel) { |
241 std::cerr << "... it uses the old main model, replacing" << std::endl; | |
237 LayerFactory::getInstance()->setModel(layer, m_mainModel); | 242 LayerFactory::getInstance()->setModel(layer, m_mainModel); |
238 continue; | 243 continue; |
239 } | 244 } |
240 | 245 |
241 if (m_models.find(model) == m_models.end()) { | 246 if (m_models.find(model) == m_models.end()) { |
245 obsoleteLayers.push_back(layer); | 250 obsoleteLayers.push_back(layer); |
246 continue; | 251 continue; |
247 } | 252 } |
248 | 253 |
249 if (m_models[model].source == oldMainModel) { | 254 if (m_models[model].source == oldMainModel) { |
255 | |
256 std::cerr << "... it uses a model derived from the old main model, regenerating" << std::endl; | |
250 | 257 |
251 // This model was derived from the previous main | 258 // This model was derived from the previous main |
252 // model: regenerate it. | 259 // model: regenerate it. |
253 | 260 |
254 TransformName transform = m_models[model].transform; | 261 TransformName transform = m_models[model].transform; |
268 transform); | 275 transform); |
269 failedTransforms.insert(transform); | 276 failedTransforms.insert(transform); |
270 } | 277 } |
271 obsoleteLayers.push_back(layer); | 278 obsoleteLayers.push_back(layer); |
272 } else { | 279 } else { |
280 std::cerr << "Replacing model " << model << " (type " | |
281 << typeid(*model).name() << ") with model " | |
282 << replacementModel << " (type " | |
283 << typeid(*replacementModel).name() << ") in layer " | |
284 << layer << " (name " << layer->objectName().toStdString() << ")" | |
285 << std::endl; | |
286 RangeSummarisableTimeValueModel *rm = | |
287 dynamic_cast<RangeSummarisableTimeValueModel *>(replacementModel); | |
288 if (rm) { | |
289 std::cerr << "new model has " << rm->getChannelCount() << " channels " << std::endl; | |
290 } else { | |
291 std::cerr << "new model is not a RangeSummarisableTimeValueModel!" << std::endl; | |
292 } | |
273 setModel(layer, replacementModel); | 293 setModel(layer, replacementModel); |
274 } | 294 } |
275 } | 295 } |
276 } | 296 } |
277 | 297 |
467 << ": register the layer's model before setting it!" | 487 << ": register the layer's model before setting it!" |
468 << std::endl; | 488 << std::endl; |
469 return; | 489 return; |
470 } | 490 } |
471 | 491 |
472 if (layer->getModel()) { | 492 Model *previousModel = layer->getModel(); |
473 if (layer->getModel() == model) { | 493 |
474 std::cerr << "WARNING: Document::setModel: Layer is already set to this model" << std::endl; | 494 if (previousModel == model) { |
475 return; | 495 std::cerr << "WARNING: Document::setModel: Layer is already set to this model" << std::endl; |
476 } | 496 return; |
477 releaseModel(layer->getModel()); | |
478 } | 497 } |
479 | 498 |
480 if (model && model != m_mainModel) { | 499 if (model && model != m_mainModel) { |
481 m_models[model].refcount ++; | 500 m_models[model].refcount ++; |
482 } | 501 } |
483 | 502 |
484 LayerFactory::getInstance()->setModel(layer, model); | 503 LayerFactory::getInstance()->setModel(layer, model); |
504 | |
505 if (previousModel) { | |
506 releaseModel(previousModel); | |
507 } | |
485 } | 508 } |
486 | 509 |
487 void | 510 void |
488 Document::setChannel(Layer *layer, int channel) | 511 Document::setChannel(Layer *layer, int channel) |
489 { | 512 { |