comparison 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
comparison
equal deleted inserted replaced
231:e8a7a935128e 232:99e0dfd3ea75
857 QAction *action = new QAction(il.load("pane"), tr("Add &New Pane"), this); 857 QAction *action = new QAction(il.load("pane"), tr("Add &New Pane"), this);
858 action->setShortcut(tr("N")); 858 action->setShortcut(tr("N"));
859 action->setStatusTip(tr("Add a new pane containing only a time ruler")); 859 action->setStatusTip(tr("Add a new pane containing only a time ruler"));
860 connect(action, SIGNAL(triggered()), this, SLOT(addPane())); 860 connect(action, SIGNAL(triggered()), this, SLOT(addPane()));
861 connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool))); 861 connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool)));
862 m_paneActions[action] = PaneConfiguration(LayerFactory::TimeRuler); 862 m_paneActions[action] = LayerConfiguration(LayerFactory::TimeRuler);
863 m_keyReference->registerShortcut(action); 863 m_keyReference->registerShortcut(action);
864 menu->addAction(action); 864 menu->addAction(action);
865 865
866 menu->addSeparator(); 866 menu->addSeparator();
867 867
893 m_keyReference->registerShortcut(action); 893 m_keyReference->registerShortcut(action);
894 } 894 }
895 895
896 connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); 896 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
897 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); 897 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
898 m_layerActions[action] = type; 898 m_layerActions[action] = LayerConfiguration(type);
899 menu->addAction(action); 899 menu->addAction(action);
900 m_rightButtonLayerMenu->addAction(action); 900 m_rightButtonLayerMenu->addAction(action);
901 } 901 }
902 902
903 m_rightButtonLayerMenu->addSeparator(); 903 m_rightButtonLayerMenu->addSeparator();
1044 if (menuType == paneMenuType) { 1044 if (menuType == paneMenuType) {
1045 connect(action, SIGNAL(triggered()), 1045 connect(action, SIGNAL(triggered()),
1046 this, SLOT(addPane())); 1046 this, SLOT(addPane()));
1047 connect(this, SIGNAL(canAddPane(bool)), 1047 connect(this, SIGNAL(canAddPane(bool)),
1048 action, SLOT(setEnabled(bool))); 1048 action, SLOT(setEnabled(bool)));
1049 m_paneActions[action] = PaneConfiguration(type); 1049 m_paneActions[action] = LayerConfiguration(type);
1050 } else { 1050 } else {
1051 connect(action, SIGNAL(triggered()), 1051 connect(action, SIGNAL(triggered()),
1052 this, SLOT(addLayer())); 1052 this, SLOT(addLayer()));
1053 connect(this, SIGNAL(canAddLayer(bool)), 1053 connect(this, SIGNAL(canAddLayer(bool)),
1054 action, SLOT(setEnabled(bool))); 1054 action, SLOT(setEnabled(bool)));
1055 m_layerActions[action] = type; 1055 m_layerActions[action] = LayerConfiguration(type);
1056 } 1056 }
1057 if (shortcutText != "") { 1057 if (shortcutText != "") {
1058 m_keyReference->registerShortcut(action); 1058 m_keyReference->registerShortcut(action);
1059 } 1059 }
1060 menu->addAction(action); 1060 menu->addAction(action);
1100 connect(action, SIGNAL(triggered()), 1100 connect(action, SIGNAL(triggered()),
1101 this, SLOT(addPane())); 1101 this, SLOT(addPane()));
1102 connect(this, SIGNAL(canAddPane(bool)), 1102 connect(this, SIGNAL(canAddPane(bool)),
1103 action, SLOT(setEnabled(bool))); 1103 action, SLOT(setEnabled(bool)));
1104 m_paneActions[action] = 1104 m_paneActions[action] =
1105 PaneConfiguration(type, model, c - 1); 1105 LayerConfiguration(type, model, c - 1);
1106 } else { 1106 } else {
1107 connect(action, SIGNAL(triggered()), 1107 connect(action, SIGNAL(triggered()),
1108 this, SLOT(addLayer())); 1108 this, SLOT(addLayer()));
1109 connect(this, SIGNAL(canAddLayer(bool)), 1109 connect(this, SIGNAL(canAddLayer(bool)),
1110 action, SLOT(setEnabled(bool))); 1110 action, SLOT(setEnabled(bool)));
1111 m_layerActions[action] = type; 1111 m_layerActions[action] =
1112 LayerConfiguration(type, model, c - 1);
1112 } 1113 }
1113 1114
1114 submenu->addAction(action); 1115 submenu->addAction(action);
1115 } 1116 }
1116 } 1117 }
1151 1152
1152 action = new QAction(il.load("timeruler"), tr("Add &Time Ruler"), this); 1153 action = new QAction(il.load("timeruler"), tr("Add &Time Ruler"), this);
1153 action->setStatusTip(tr("Add a new layer showing a time ruler")); 1154 action->setStatusTip(tr("Add a new layer showing a time ruler"));
1154 connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); 1155 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
1155 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); 1156 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
1156 m_layerActions[action] = LayerFactory::TimeRuler; 1157 m_layerActions[action] = LayerConfiguration(LayerFactory::TimeRuler);
1157 menu->addAction(action); 1158 menu->addAction(action);
1158 1159
1159 menu->addSeparator(); 1160 menu->addSeparator();
1160 1161
1161 m_existingLayersMenu = menu->addMenu(tr("Add &Existing Layer")); 1162 m_existingLayersMenu = menu->addMenu(tr("Add &Existing Layer"));
2584 m_preferencesDialog->isVisible()) { 2585 m_preferencesDialog->isVisible()) {
2585 closeSession(); // otherwise we'll have to wait for prefs changes 2586 closeSession(); // otherwise we'll have to wait for prefs changes
2586 m_preferencesDialog->applicationClosing(false); 2587 m_preferencesDialog->applicationClosing(false);
2587 } 2588 }
2588 2589
2589 if (m_layerTreeDialog &&
2590 m_layerTreeDialog->isVisible()) {
2591 delete m_layerTreeDialog;
2592 }
2593
2594 closeSession(); 2590 closeSession();
2595 2591
2596 e->accept(); 2592 e->accept();
2597 return; 2593 return;
2598 } 2594 }
2758 2754
2759 addPane(i->second, action->text()); 2755 addPane(i->second, action->text());
2760 } 2756 }
2761 2757
2762 void 2758 void
2763 MainWindow::addPane(const PaneConfiguration &configuration, QString text) 2759 MainWindow::addPane(const LayerConfiguration &configuration, QString text)
2764 { 2760 {
2765 CommandHistory::getInstance()->startCompoundOperation(text, true); 2761 CommandHistory::getInstance()->startCompoundOperation(text, true);
2766 2762
2767 AddPaneCommand *command = new AddPaneCommand(this); 2763 AddPaneCommand *command = new AddPaneCommand(this);
2768 CommandHistory::getInstance()->addCommand(command); 2764 CommandHistory::getInstance()->addCommand(command);
2889 std::cerr << "WARNING: MainWindow::addLayer: unknown action " 2885 std::cerr << "WARNING: MainWindow::addLayer: unknown action "
2890 << action->objectName().toStdString() << std::endl; 2886 << action->objectName().toStdString() << std::endl;
2891 return; 2887 return;
2892 } 2888 }
2893 2889
2894 LayerFactory::LayerType type = i->second; 2890 LayerFactory::LayerType type = i->second.layer;
2895 2891
2896 LayerFactory::LayerTypeSet emptyTypes = 2892 LayerFactory::LayerTypeSet emptyTypes =
2897 LayerFactory::getInstance()->getValidEmptyLayerTypes(); 2893 LayerFactory::getInstance()->getValidEmptyLayerTypes();
2898 2894
2899 Layer *newLayer; 2895 Layer *newLayer;
2905 m_toolActions[ViewManager::DrawMode]->trigger(); 2901 m_toolActions[ViewManager::DrawMode]->trigger();
2906 } 2902 }
2907 2903
2908 } else { 2904 } else {
2909 2905
2910 newLayer = m_document->createMainModelLayer(type); 2906 // newLayer = m_document->createMainModelLayer(type);
2907 newLayer = m_document->createLayer(type);
2908 if (m_document->isKnownModel(i->second.sourceModel)) {
2909 m_document->setChannel(newLayer, i->second.channel);
2910 m_document->setModel(newLayer, i->second.sourceModel);
2911 } else {
2912 std::cerr << "WARNING: MainWindow::addLayer: unknown model "
2913 << i->second.sourceModel
2914 << " (\""
2915 << i->second.sourceModel->objectName().toStdString()
2916 << "\") in layer action map"
2917 << std::endl;
2918 }
2911 } 2919 }
2912 2920
2913 if (newLayer) { 2921 if (newLayer) {
2914 m_document->addLayerToView(pane, newLayer); 2922 m_document->addLayerToView(pane, newLayer);
2915 m_paneStack->setCurrentLayer(pane, newLayer); 2923 m_paneStack->setCurrentLayer(pane, newLayer);
3359 m_layerTreeDialog->raise(); 3367 m_layerTreeDialog->raise();
3360 return; 3368 return;
3361 } 3369 }
3362 3370
3363 m_layerTreeDialog = new LayerTreeDialog(m_paneStack); 3371 m_layerTreeDialog = new LayerTreeDialog(m_paneStack);
3372 m_layerTreeDialog->setAttribute(Qt::WA_DeleteOnClose); // see below
3364 m_layerTreeDialog->show(); 3373 m_layerTreeDialog->show();
3365 } 3374 }
3366 3375
3367 void 3376 void
3368 MainWindow::preferences() 3377 MainWindow::preferences()