changeset 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 5a72bf7490ae
children 47bff9f88882
files document/Document.cpp
diffstat 1 files changed, 29 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/document/Document.cpp	Wed Oct 04 14:01:28 2006 +0000
+++ b/document/Document.cpp	Thu Oct 05 11:00:59 2006 +0000
@@ -233,7 +233,12 @@
 	Layer *layer = *i;
 	Model *model = layer->getModel();
 
+        std::cerr << "Document::setMainModel: inspecting model "
+                  << (model ? model->objectName().toStdString() : "(null)") << " in layer "
+                  << layer->objectName().toStdString() << std::endl;
+
 	if (model == oldMainModel) {
+            std::cerr << "... it uses the old main model, replacing" << std::endl;
 	    LayerFactory::getInstance()->setModel(layer, m_mainModel);
 	    continue;
 	}
@@ -248,6 +253,8 @@
 	    
 	if (m_models[model].source == oldMainModel) {
 
+            std::cerr << "... it uses a model derived from the old main model, regenerating" << std::endl;
+
 	    // This model was derived from the previous main
 	    // model: regenerate it.
 	    
@@ -270,6 +277,19 @@
                 }
 		obsoleteLayers.push_back(layer);
 	    } else {
+                std::cerr << "Replacing model " << model << " (type "
+                          << typeid(*model).name() << ") with model "
+                          << replacementModel << " (type "
+                          << typeid(*replacementModel).name() << ") in layer "
+                          << layer << " (name " << layer->objectName().toStdString() << ")"
+                          << std::endl;
+                RangeSummarisableTimeValueModel *rm =
+                    dynamic_cast<RangeSummarisableTimeValueModel *>(replacementModel);
+                if (rm) {
+                    std::cerr << "new model has " << rm->getChannelCount() << " channels " << std::endl;
+                } else {
+                    std::cerr << "new model is not a RangeSummarisableTimeValueModel!" << std::endl;
+                }
 		setModel(layer, replacementModel);
 	    }
 	}	    
@@ -469,12 +489,11 @@
 	return;
     }
 
-    if (layer->getModel()) {
-	if (layer->getModel() == model) {
-	    std::cerr << "WARNING: Document::setModel: Layer is already set to this model" << std::endl;
-	    return;
-	}
-	releaseModel(layer->getModel());
+    Model *previousModel = layer->getModel();
+
+    if (previousModel == model) {
+        std::cerr << "WARNING: Document::setModel: Layer is already set to this model" << std::endl;
+        return;
     }
 
     if (model && model != m_mainModel) {
@@ -482,6 +501,10 @@
     }
 
     LayerFactory::getInstance()->setModel(layer, model);
+
+    if (previousModel) {
+        releaseModel(previousModel);
+    }
 }
 
 void