# HG changeset patch # User Chris Cannam # Date 1201103007 0 # Node ID 99e0dfd3ea754dcc41cd6a05946e288367a780ad # Parent e8a7a935128e36a50bb09df40a9f681a21c608f9 * 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. diff -r e8a7a935128e -r 99e0dfd3ea75 main/MainWindow.cpp --- 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(); } diff -r e8a7a935128e -r 99e0dfd3ea75 main/MainWindow.h --- 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 PaneActionMap; + typedef std::map PaneActionMap; PaneActionMap m_paneActions; + typedef std::map LayerActionMap; + LayerActionMap m_layerActions; + typedef std::map TransformActionMap; TransformActionMap m_transformActions; typedef std::map TransformActionReverseMap; TransformActionReverseMap m_transformActionsReverse; - typedef std::map LayerActionMap; - LayerActionMap m_layerActions; - typedef std::map 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(); diff -r e8a7a935128e -r 99e0dfd3ea75 main/OSCHandler.cpp --- 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")