changeset 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
files main/MainWindow.cpp main/MainWindow.h main/OSCHandler.cpp
diffstat 3 files changed, 36 insertions(+), 27 deletions(-) [+]
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();
 }
 
--- a/main/MainWindow.h	Wed Jan 23 11:38:34 2008 +0000
+++ b/main/MainWindow.h	Wed Jan 23 15:43:27 2008 +0000
@@ -202,29 +202,29 @@
 
     KeyReference            *m_keyReference;
 
-    struct PaneConfiguration {
-	PaneConfiguration(LayerFactory::LayerType _layer
+    struct LayerConfiguration {
+	LayerConfiguration(LayerFactory::LayerType _layer
 			                       = LayerFactory::TimeRuler,
-                          Model *_source = 0,
-			  int _channel = -1) :
+                           Model *_source = 0,
+                           int _channel = -1) :
 	    layer(_layer), sourceModel(_source), channel(_channel) { }
 	LayerFactory::LayerType layer;
         Model *sourceModel;
 	int channel;
     };
 
-    typedef std::map<QAction *, PaneConfiguration> PaneActionMap;
+    typedef std::map<QAction *, LayerConfiguration> PaneActionMap;
     PaneActionMap m_paneActions;
 
+    typedef std::map<QAction *, LayerConfiguration> LayerActionMap;
+    LayerActionMap m_layerActions;
+
     typedef std::map<QAction *, TransformId> TransformActionMap;
     TransformActionMap m_transformActions;
 
     typedef std::map<TransformId, QAction *> TransformActionReverseMap;
     TransformActionReverseMap m_transformActionsReverse;
 
-    typedef std::map<QAction *, LayerFactory::LayerType> LayerActionMap;
-    LayerActionMap m_layerActions;
-
     typedef std::map<QAction *, Layer *> ExistingLayerActionMap;
     ExistingLayerActionMap m_existingLayerActions;
     ExistingLayerActionMap m_sliceActions;
@@ -245,7 +245,7 @@
     virtual void setupExistingLayersMenus();
     virtual void setupToolbars();
 
-    virtual void addPane(const PaneConfiguration &configuration, QString text);
+    virtual void addPane(const LayerConfiguration &configuration, QString text);
 
     virtual void closeEvent(QCloseEvent *e);
     virtual bool checkSaveModified();
--- a/main/OSCHandler.cpp	Wed Jan 23 11:38:34 2008 +0000
+++ b/main/OSCHandler.cpp	Wed Jan 23 15:43:27 2008 +0000
@@ -281,9 +281,9 @@
                               << "type " << str.toStdString() << std::endl;
                 } else {
 
-                    PaneConfiguration configuration(type,
-                                                    getMainModel(),
-                                                    channel);
+                    LayerConfiguration configuration(type,
+                                                     getMainModel(),
+                                                     channel);
                     
                     addPane(configuration,
                             tr("Add %1 Pane")