diff main/MainWindow.cpp @ 232:99e0dfd3ea75

* 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 e8a7a935128e
children 5544593dd850
line wrap: on
line diff
--- a/main/MainWindow.cpp	Wed Jan 23 11:38:34 2008 +0000
+++ b/main/MainWindow.cpp	Wed Jan 23 15:43:27 2008 +0000
@@ -859,7 +859,7 @@
     action->setStatusTip(tr("Add a new pane containing only a time ruler"));
     connect(action, SIGNAL(triggered()), this, SLOT(addPane()));
     connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool)));
-    m_paneActions[action] = PaneConfiguration(LayerFactory::TimeRuler);
+    m_paneActions[action] = LayerConfiguration(LayerFactory::TimeRuler);
     m_keyReference->registerShortcut(action);
     menu->addAction(action);
 
@@ -895,7 +895,7 @@
 
 	connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
 	connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
-	m_layerActions[action] = type;
+	m_layerActions[action] = LayerConfiguration(type);
 	menu->addAction(action);
         m_rightButtonLayerMenu->addAction(action);
     }
@@ -1046,13 +1046,13 @@
                                     this, SLOT(addPane()));
                             connect(this, SIGNAL(canAddPane(bool)),
                                     action, SLOT(setEnabled(bool)));
-                            m_paneActions[action] = PaneConfiguration(type);
+                            m_paneActions[action] = LayerConfiguration(type);
                         } else {
                             connect(action, SIGNAL(triggered()),
                                     this, SLOT(addLayer()));
                             connect(this, SIGNAL(canAddLayer(bool)),
                                     action, SLOT(setEnabled(bool)));
-                            m_layerActions[action] = type;
+                            m_layerActions[action] = LayerConfiguration(type);
                         }
                         if (shortcutText != "") {
                             m_keyReference->registerShortcut(action);
@@ -1102,13 +1102,14 @@
                             connect(this, SIGNAL(canAddPane(bool)),
                                     action, SLOT(setEnabled(bool)));
                             m_paneActions[action] =
-                                PaneConfiguration(type, model, c - 1);
+                                LayerConfiguration(type, model, c - 1);
                         } else {
                             connect(action, SIGNAL(triggered()),
                                     this, SLOT(addLayer()));
                             connect(this, SIGNAL(canAddLayer(bool)),
                                     action, SLOT(setEnabled(bool)));
-                            m_layerActions[action] = type;
+                            m_layerActions[action] =
+                                LayerConfiguration(type, model, c - 1);
                         }
 
                         submenu->addAction(action);
@@ -1153,7 +1154,7 @@
     action->setStatusTip(tr("Add a new layer showing a time ruler"));
     connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
     connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
-    m_layerActions[action] = LayerFactory::TimeRuler;
+    m_layerActions[action] = LayerConfiguration(LayerFactory::TimeRuler);
     menu->addAction(action);
 
     menu->addSeparator();
@@ -2586,11 +2587,6 @@
         m_preferencesDialog->applicationClosing(false);
     }
 
-    if (m_layerTreeDialog &&
-        m_layerTreeDialog->isVisible()) {
-        delete m_layerTreeDialog;
-    }
-
     closeSession();
 
     e->accept();
@@ -2760,7 +2756,7 @@
 }
 
 void
-MainWindow::addPane(const PaneConfiguration &configuration, QString text)
+MainWindow::addPane(const LayerConfiguration &configuration, QString text)
 {
     CommandHistory::getInstance()->startCompoundOperation(text, true);
 
@@ -2891,7 +2887,7 @@
 	    return;
 	}
 
-	LayerFactory::LayerType type = i->second;
+	LayerFactory::LayerType type = i->second.layer;
 	
 	LayerFactory::LayerTypeSet emptyTypes =
 	    LayerFactory::getInstance()->getValidEmptyLayerTypes();
@@ -2907,7 +2903,19 @@
 
 	} else {
 
-	    newLayer = m_document->createMainModelLayer(type);
+//	    newLayer = m_document->createMainModelLayer(type);
+            newLayer = m_document->createLayer(type);
+            if (m_document->isKnownModel(i->second.sourceModel)) {
+                m_document->setChannel(newLayer, i->second.channel);
+                m_document->setModel(newLayer, i->second.sourceModel);
+            } else {
+                std::cerr << "WARNING: MainWindow::addLayer: unknown model "
+                          << i->second.sourceModel
+                          << " (\""
+                          << i->second.sourceModel->objectName().toStdString()
+                          << "\") in layer action map"
+                          << std::endl;
+            }
 	}
 
         if (newLayer) {
@@ -3361,6 +3369,7 @@
     }
 
     m_layerTreeDialog = new LayerTreeDialog(m_paneStack);
+    m_layerTreeDialog->setAttribute(Qt::WA_DeleteOnClose); // see below
     m_layerTreeDialog->show();
 }