Mercurial > hg > sonic-visualiser
comparison main/MainWindow.cpp @ 2538:9910ba30a572
Update subrepos with various performance tweaks; when rebuilding menus, delete old actions (turns out addAction(QAction*) doesn't take ownership - I did know this once, but...)
author | Chris Cannam |
---|---|
date | Thu, 14 May 2020 16:40:20 +0100 |
parents | 11a552b3ad88 |
children | 56503c58178f |
comparison
equal
deleted
inserted
replaced
2537:11a552b3ad88 | 2538:9910ba30a572 |
---|---|
344 Surveyer::Config config; | 344 Surveyer::Config config; |
345 config.hostname = "sonicvisualiser.org"; | 345 config.hostname = "sonicvisualiser.org"; |
346 config.testPath = "feedback41-present.txt"; | 346 config.testPath = "feedback41-present.txt"; |
347 config.surveyPath = "feedback41.php"; | 347 config.surveyPath = "feedback41.php"; |
348 config.countdownKey = "countdown41"; | 348 config.countdownKey = "countdown41"; |
349 config.countdownFrom = 1; | 349 config.countdownFrom = 5; |
350 config.title = "Sonic Visualiser - Can you help?"; | 350 config.title = "Sonic Visualiser - Can you help?"; |
351 config.text = "<h3>Sonic Visualiser: Can you help?</h3><p>" | 351 config.text = "<h3>Sonic Visualiser: Can you help?</h3><p>" |
352 "<p>Are you using Sonic Visualiser in academic research or for commercial purposes? Or do you intend to do so?</p>" | 352 "<p>Are you using Sonic Visualiser in academic research or for commercial purposes? Or do you intend to do so?</p>" |
353 "<p>If so, would you be interested in telling us something about your work? We are gathering case studies to gauge the impact of our work and to guide our future actions.</p><p>Anything you tell us will be used only to guide research and development at the Centre for Digital Music, Queen Mary University of London.</p>"; | 353 "<p>If so, would you be interested in telling us something about your work? We are gathering case studies to gauge the impact of our work and to guide our future actions.</p><p>Anything you tell us will be used only to guide research and development at the Centre for Digital Music, Queen Mary University of London.</p>"; |
354 config.acceptLabel = tr("Yes, I'd be happy to"); | 354 config.acceptLabel = tr("Yes, I'd be happy to"); |
1219 } | 1219 } |
1220 | 1220 |
1221 void | 1221 void |
1222 MainWindow::setupPaneAndLayerMenus() | 1222 MainWindow::setupPaneAndLayerMenus() |
1223 { | 1223 { |
1224 Profiler profiler("MainWindow::setupPaneAndLayerMenus"); | |
1225 | |
1224 if (m_paneMenu) { | 1226 if (m_paneMenu) { |
1227 m_paneMenu->clear(); | |
1228 for (auto a: m_paneActions) { | |
1229 delete a.first; | |
1230 } | |
1225 m_paneActions.clear(); | 1231 m_paneActions.clear(); |
1226 m_paneMenu->clear(); | |
1227 } else { | 1232 } else { |
1228 m_paneMenu = menuBar()->addMenu(tr("&Pane")); | 1233 m_paneMenu = menuBar()->addMenu(tr("&Pane")); |
1229 m_paneMenu->setTearOffEnabled(true); | 1234 m_paneMenu->setTearOffEnabled(true); |
1230 } | |
1231 | |
1232 if (m_layerMenu) { | |
1233 m_layerActions.clear(); | |
1234 m_layerMenu->clear(); | |
1235 } else { | |
1236 m_layerMenu = menuBar()->addMenu(tr("&Layer")); | |
1237 m_layerMenu->setTearOffEnabled(true); | |
1238 } | 1235 } |
1239 | 1236 |
1240 if (m_rightButtonLayerMenu) { | 1237 if (m_rightButtonLayerMenu) { |
1241 m_rightButtonLayerMenu->clear(); | 1238 m_rightButtonLayerMenu->clear(); |
1242 } else { | 1239 } else { |
1243 m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer")); | 1240 m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer")); |
1244 m_rightButtonLayerMenu->setTearOffEnabled(true); | 1241 m_rightButtonLayerMenu->setTearOffEnabled(true); |
1245 m_rightButtonMenu->addSeparator(); | 1242 m_rightButtonMenu->addSeparator(); |
1243 } | |
1244 | |
1245 if (m_layerMenu) { | |
1246 m_layerMenu->clear(); | |
1247 for (auto a: m_layerActions) { | |
1248 delete a.first; | |
1249 } | |
1250 m_layerActions.clear(); | |
1251 } else { | |
1252 m_layerMenu = menuBar()->addMenu(tr("&Layer")); | |
1253 m_layerMenu->setTearOffEnabled(true); | |
1246 } | 1254 } |
1247 | 1255 |
1248 QMenu *menu = m_paneMenu; | 1256 QMenu *menu = m_paneMenu; |
1249 | 1257 |
1250 IconLoader il; | 1258 IconLoader il; |
1678 | 1686 |
1679 void | 1687 void |
1680 MainWindow::setupTransformsMenu() | 1688 MainWindow::setupTransformsMenu() |
1681 { | 1689 { |
1682 if (m_transformsMenu) { | 1690 if (m_transformsMenu) { |
1691 m_transformsMenu->clear(); | |
1692 m_recentTransformsMenu->clear(); | |
1693 m_transformActionsReverse.clear(); | |
1683 m_transformActions.clear(); | 1694 m_transformActions.clear(); |
1684 m_transformActionsReverse.clear(); | 1695 for (auto a: m_transformActions) { |
1685 m_transformsMenu->clear(); | 1696 delete a.first; |
1697 } | |
1686 } else { | 1698 } else { |
1687 m_transformsMenu = menuBar()->addMenu(tr("&Transform")); | 1699 m_transformsMenu = menuBar()->addMenu(tr("&Transform")); |
1688 m_transformsMenu->setTearOffEnabled(true); | 1700 m_transformsMenu->setTearOffEnabled(true); |
1689 m_transformsMenu->setSeparatorsCollapsible(true); | 1701 m_transformsMenu->setSeparatorsCollapsible(true); |
1690 } | 1702 } |
1969 { | 1981 { |
1970 m_recentFilesMenu->clear(); | 1982 m_recentFilesMenu->clear(); |
1971 vector<QString> files = m_recentFiles.getRecent(); | 1983 vector<QString> files = m_recentFiles.getRecent(); |
1972 for (size_t i = 0; i < files.size(); ++i) { | 1984 for (size_t i = 0; i < files.size(); ++i) { |
1973 QString path = files[i]; | 1985 QString path = files[i]; |
1974 QAction *action = new QAction(path, this); | 1986 QAction *action = m_recentFilesMenu->addAction(path); |
1975 action->setObjectName(path); | 1987 action->setObjectName(path); |
1976 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile())); | 1988 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile())); |
1977 if (i == 0) { | 1989 if (i == 0) { |
1978 action->setShortcut(tr("Ctrl+R")); | 1990 action->setShortcut(tr("Ctrl+R")); |
1979 m_keyReference->registerShortcut | 1991 m_keyReference->registerShortcut |
1980 (tr("Re-open"), | 1992 (tr("Re-open"), |
1981 action->shortcut().toString(), | 1993 action->shortcut().toString(), |
1982 tr("Re-open the current or most recently opened file")); | 1994 tr("Re-open the current or most recently opened file")); |
1983 } | 1995 } |
1984 m_recentFilesMenu->addAction(action); | |
1985 } | 1996 } |
1986 } | 1997 } |
1987 | 1998 |
1988 void | 1999 void |
1989 MainWindow::setupTemplatesMenu() | 2000 MainWindow::setupTemplatesMenu() |
1990 { | 2001 { |
1991 m_templatesMenu->clear(); | 2002 m_templatesMenu->clear(); |
1992 | 2003 |
1993 QAction *defaultAction = new QAction(tr("Standard Waveform"), this); | 2004 QAction *defaultAction = m_templatesMenu->addAction(tr("Standard Waveform")); |
1994 defaultAction->setObjectName("default"); | 2005 defaultAction->setObjectName("default"); |
1995 connect(defaultAction, SIGNAL(triggered()), this, SLOT(applyTemplate())); | 2006 connect(defaultAction, SIGNAL(triggered()), this, SLOT(applyTemplate())); |
1996 m_templatesMenu->addAction(defaultAction); | |
1997 | 2007 |
1998 m_templatesMenu->addSeparator(); | 2008 m_templatesMenu->addSeparator(); |
1999 | 2009 |
2000 QAction *action = nullptr; | 2010 QAction *action = nullptr; |
2001 | 2011 |
2010 byName.insert(QFileInfo(t).baseName()); | 2020 byName.insert(QFileInfo(t).baseName()); |
2011 } | 2021 } |
2012 | 2022 |
2013 foreach (QString t, byName) { | 2023 foreach (QString t, byName) { |
2014 if (t.toLower() == "default") continue; | 2024 if (t.toLower() == "default") continue; |
2015 action = new QAction(t, this); | 2025 action = m_templatesMenu->addAction(t); |
2016 connect(action, SIGNAL(triggered()), this, SLOT(applyTemplate())); | 2026 connect(action, SIGNAL(triggered()), this, SLOT(applyTemplate())); |
2017 m_templatesMenu->addAction(action); | |
2018 } | 2027 } |
2019 | 2028 |
2020 if (!templates.empty()) m_templatesMenu->addSeparator(); | 2029 if (!templates.empty()) m_templatesMenu->addSeparator(); |
2021 | 2030 |
2022 if (!m_templateWatcher) { | 2031 if (!m_templateWatcher) { |
2024 m_templateWatcher->addPath(ResourceFinder().getResourceSaveDir("templates")); | 2033 m_templateWatcher->addPath(ResourceFinder().getResourceSaveDir("templates")); |
2025 connect(m_templateWatcher, SIGNAL(directoryChanged(const QString &)), | 2034 connect(m_templateWatcher, SIGNAL(directoryChanged(const QString &)), |
2026 this, SLOT(setupTemplatesMenu())); | 2035 this, SLOT(setupTemplatesMenu())); |
2027 } | 2036 } |
2028 | 2037 |
2029 QAction *setDefaultAction = new QAction(tr("Choose Default Template..."), this); | 2038 m_templatesMenu->addSeparator(); |
2039 | |
2040 QAction *setDefaultAction = m_templatesMenu->addAction(tr("Choose Default Template...")); | |
2030 setDefaultAction->setObjectName("set_default_template"); | 2041 setDefaultAction->setObjectName("set_default_template"); |
2031 connect(setDefaultAction, SIGNAL(triggered()), this, SLOT(preferences())); | 2042 connect(setDefaultAction, SIGNAL(triggered()), this, SLOT(preferences())); |
2032 m_templatesMenu->addSeparator(); | |
2033 m_templatesMenu->addAction(setDefaultAction); | |
2034 | 2043 |
2035 m_manageTemplatesAction->setEnabled(havePersonal); | 2044 m_manageTemplatesAction->setEnabled(havePersonal); |
2036 } | 2045 } |
2037 | 2046 |
2038 | 2047 |
2068 { | 2077 { |
2069 if (!m_existingLayersMenu) return; // should have been created by setupMenus | 2078 if (!m_existingLayersMenu) return; // should have been created by setupMenus |
2070 | 2079 |
2071 // SVDEBUG << "MainWindow::setupExistingLayersMenu" << endl; | 2080 // SVDEBUG << "MainWindow::setupExistingLayersMenu" << endl; |
2072 | 2081 |
2082 Profiler profiler1("MainWindow::setupExistingLayersMenu"); | |
2083 | |
2073 m_existingLayersMenu->clear(); | 2084 m_existingLayersMenu->clear(); |
2085 for (auto a: m_existingLayerActions) { | |
2086 delete a.first; | |
2087 } | |
2074 m_existingLayerActions.clear(); | 2088 m_existingLayerActions.clear(); |
2075 | 2089 |
2076 m_sliceMenu->clear(); | 2090 m_sliceMenu->clear(); |
2091 for (auto a: m_sliceActions) { | |
2092 delete a.first; | |
2093 } | |
2077 m_sliceActions.clear(); | 2094 m_sliceActions.clear(); |
2078 | 2095 |
2079 IconLoader il; | 2096 IconLoader il; |
2080 | 2097 |
2081 vector<Layer *> orderedLayers; | 2098 vector<Layer *> orderedLayers; |
2108 sliceableLayers.insert(layer); | 2125 sliceableLayers.insert(layer); |
2109 } | 2126 } |
2110 } | 2127 } |
2111 } | 2128 } |
2112 | 2129 |
2130 Profiler profiler3("MainWindow::setupExistingLayersMenu: after sorting"); | |
2131 | |
2113 map<QString, int> observedNames; | 2132 map<QString, int> observedNames; |
2114 | 2133 |
2115 for (size_t i = 0; i < orderedLayers.size(); ++i) { | 2134 for (size_t i = 0; i < orderedLayers.size(); ++i) { |
2116 | 2135 |
2117 Layer *layer = orderedLayers[i]; | 2136 Layer *layer = orderedLayers[i]; |
4834 } | 4853 } |
4835 | 4854 |
4836 void | 4855 void |
4837 MainWindow::layerRemoved(Layer *layer) | 4856 MainWindow::layerRemoved(Layer *layer) |
4838 { | 4857 { |
4858 Profiler profiler("MainWindow::layerRemoved"); | |
4839 setupExistingLayersMenus(); | 4859 setupExistingLayersMenus(); |
4840 MainWindowBase::layerRemoved(layer); | 4860 MainWindowBase::layerRemoved(layer); |
4841 } | 4861 } |
4842 | 4862 |
4843 void | 4863 void |