Mercurial > hg > sonic-visualiser
comparison main/MainWindow.cpp @ 2093:6e3ef3aa341e spectrogramparam
Ensure that operations that need to iterate through action maps in order (most pointedly MainWindow::updateLayerShortcutsFor) get to do it in order of construction and not arbitrary pointer order. Fixes incorrect shortcut associations for add-layer/pane shortcuts in some cases
author | Chris Cannam |
---|---|
date | Tue, 13 Nov 2018 14:09:30 +0000 |
parents | 63da6a82c12d |
children | 0b15f3b16776 c476db6cf3eb |
comparison
equal
deleted
inserted
replaced
2092:16d2c946171c | 2093:6e3ef3aa341e |
---|---|
843 menu->addSeparator(); | 843 menu->addSeparator(); |
844 | 844 |
845 QMenu *numberingMenu = menu->addMenu(tr("Number New Instants with")); | 845 QMenu *numberingMenu = menu->addMenu(tr("Number New Instants with")); |
846 numberingMenu->setTearOffEnabled(true); | 846 numberingMenu->setTearOffEnabled(true); |
847 QActionGroup *numberingGroup = new QActionGroup(this); | 847 QActionGroup *numberingGroup = new QActionGroup(this); |
848 m_numberingActions.clear(); | |
848 | 849 |
849 Labeller::TypeNameMap types = m_labeller->getTypeNames(); | 850 Labeller::TypeNameMap types = m_labeller->getTypeNames(); |
850 for (Labeller::TypeNameMap::iterator i = types.begin(); i != types.end(); ++i) { | 851 for (Labeller::TypeNameMap::iterator i = types.begin(); i != types.end(); ++i) { |
851 | 852 |
852 if (i->first == Labeller::ValueFromLabel || | 853 if (i->first == Labeller::ValueFromLabel || |
856 connect(action, SIGNAL(triggered()), this, SLOT(setInstantsNumbering())); | 857 connect(action, SIGNAL(triggered()), this, SLOT(setInstantsNumbering())); |
857 action->setCheckable(true); | 858 action->setCheckable(true); |
858 action->setChecked(m_labeller->getType() == i->first); | 859 action->setChecked(m_labeller->getType() == i->first); |
859 numberingGroup->addAction(action); | 860 numberingGroup->addAction(action); |
860 numberingMenu->addAction(action); | 861 numberingMenu->addAction(action); |
861 m_numberingActions[action] = (int)i->first; | 862 m_numberingActions.push_back({ action, (int)i->first }); |
862 | 863 |
863 if (i->first == Labeller::ValueFromTwoLevelCounter) { | 864 if (i->first == Labeller::ValueFromTwoLevelCounter) { |
864 | 865 |
865 QMenu *cycleMenu = numberingMenu->addMenu(tr("Cycle size")); | 866 QMenu *cycleMenu = numberingMenu->addMenu(tr("Cycle size")); |
866 QActionGroup *cycleGroup = new QActionGroup(this); | 867 QActionGroup *cycleGroup = new QActionGroup(this); |
1227 | 1228 |
1228 IconLoader il; | 1229 IconLoader il; |
1229 | 1230 |
1230 m_keyReference->setCategory(tr("Managing Panes and Layers")); | 1231 m_keyReference->setCategory(tr("Managing Panes and Layers")); |
1231 | 1232 |
1233 m_paneActions.clear(); | |
1234 m_layerActions.clear(); | |
1235 | |
1232 QAction *action = new QAction(il.load("pane"), tr("Add &New Pane"), this); | 1236 QAction *action = new QAction(il.load("pane"), tr("Add &New Pane"), this); |
1233 action->setShortcut(tr("N")); | 1237 action->setShortcut(tr("N")); |
1234 action->setStatusTip(tr("Add a new pane containing only a time ruler")); | 1238 action->setStatusTip(tr("Add a new pane containing only a time ruler")); |
1235 connect(action, SIGNAL(triggered()), this, SLOT(addPane())); | 1239 connect(action, SIGNAL(triggered()), this, SLOT(addPane())); |
1236 connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool))); | 1240 connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool))); |
1237 m_paneActions[action] = LayerConfiguration(LayerFactory::TimeRuler); | 1241 m_paneActions.push_back({ action, LayerConfiguration(LayerFactory::TimeRuler) }); |
1238 m_keyReference->registerShortcut(action); | 1242 m_keyReference->registerShortcut(action); |
1239 menu->addAction(action); | 1243 menu->addAction(action); |
1240 | 1244 |
1241 menu->addSeparator(); | 1245 menu->addSeparator(); |
1242 | 1246 |
1266 m_keyReference->registerShortcut(action); | 1270 m_keyReference->registerShortcut(action); |
1267 } | 1271 } |
1268 | 1272 |
1269 connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); | 1273 connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); |
1270 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); | 1274 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); |
1271 m_layerActions[action] = LayerConfiguration(type); | 1275 m_layerActions.push_back({ action, LayerConfiguration(type) }); |
1272 menu->addAction(action); | 1276 menu->addAction(action); |
1273 m_rightButtonLayerMenu->addAction(action); | 1277 m_rightButtonLayerMenu->addAction(action); |
1274 } | 1278 } |
1275 | 1279 |
1276 m_rightButtonLayerMenu->addSeparator(); | 1280 m_rightButtonLayerMenu->addSeparator(); |
1408 if (menuType == paneMenuType) { | 1412 if (menuType == paneMenuType) { |
1409 connect(action, SIGNAL(triggered()), | 1413 connect(action, SIGNAL(triggered()), |
1410 this, SLOT(addPane())); | 1414 this, SLOT(addPane())); |
1411 connect(this, SIGNAL(canAddPane(bool)), | 1415 connect(this, SIGNAL(canAddPane(bool)), |
1412 action, SLOT(setEnabled(bool))); | 1416 action, SLOT(setEnabled(bool))); |
1413 m_paneActions[action] = | 1417 m_paneActions.push_back |
1414 LayerConfiguration(type, model); | 1418 ({ action, LayerConfiguration(type, model) }); |
1415 } else { | 1419 } else { |
1416 connect(action, SIGNAL(triggered()), | 1420 connect(action, SIGNAL(triggered()), |
1417 this, SLOT(addLayer())); | 1421 this, SLOT(addLayer())); |
1418 connect(this, SIGNAL(canAddLayer(bool)), | 1422 connect(this, SIGNAL(canAddLayer(bool)), |
1419 action, SLOT(setEnabled(bool))); | 1423 action, SLOT(setEnabled(bool))); |
1420 m_layerActions[action] = | 1424 m_layerActions.push_back |
1421 LayerConfiguration(type, model); | 1425 ({ action, LayerConfiguration(type, model) }); |
1422 } | 1426 } |
1423 if (shortcutText != "") { | 1427 if (shortcutText != "") { |
1424 m_keyReference->registerShortcut(action); | 1428 m_keyReference->registerShortcut(action); |
1425 } | 1429 } |
1426 menu->addAction(action); | 1430 menu->addAction(action); |
1452 } | 1456 } |
1453 | 1457 |
1454 if (isDefault) { | 1458 if (isDefault) { |
1455 action = new QAction(icon, actionText, this); | 1459 action = new QAction(icon, actionText, this); |
1456 if (!model || model == getMainModel()) { | 1460 if (!model || model == getMainModel()) { |
1461 // Default for the shortcut is to | |
1462 // attach to an action that uses the | |
1463 // main model as input. But this may | |
1464 // change when the user selects a | |
1465 // different pane - see | |
1466 // updateLayerShortcutsFor() below. | |
1457 action->setShortcut(shortcutText); | 1467 action->setShortcut(shortcutText); |
1458 } | 1468 } |
1459 } else { | 1469 } else { |
1460 action = new QAction(actionText, this); | 1470 action = new QAction(actionText, this); |
1461 } | 1471 } |
1465 if (menuType == paneMenuType) { | 1475 if (menuType == paneMenuType) { |
1466 connect(action, SIGNAL(triggered()), | 1476 connect(action, SIGNAL(triggered()), |
1467 this, SLOT(addPane())); | 1477 this, SLOT(addPane())); |
1468 connect(this, SIGNAL(canAddPane(bool)), | 1478 connect(this, SIGNAL(canAddPane(bool)), |
1469 action, SLOT(setEnabled(bool))); | 1479 action, SLOT(setEnabled(bool))); |
1470 m_paneActions[action] = | 1480 m_paneActions.push_back |
1471 LayerConfiguration(type, model, c - 1); | 1481 ({ action, LayerConfiguration(type, model, c - 1) }); |
1472 } else { | 1482 } else { |
1473 connect(action, SIGNAL(triggered()), | 1483 connect(action, SIGNAL(triggered()), |
1474 this, SLOT(addLayer())); | 1484 this, SLOT(addLayer())); |
1475 connect(this, SIGNAL(canAddLayer(bool)), | 1485 connect(this, SIGNAL(canAddLayer(bool)), |
1476 action, SLOT(setEnabled(bool))); | 1486 action, SLOT(setEnabled(bool))); |
1477 m_layerActions[action] = | 1487 m_layerActions.push_back |
1478 LayerConfiguration(type, model, c - 1); | 1488 ({ action, LayerConfiguration(type, model, c - 1) }); |
1479 } | 1489 } |
1480 | 1490 |
1481 submenu->addAction(action); | 1491 submenu->addAction(action); |
1482 } | 1492 } |
1483 | 1493 |
1490 action->setStatusTip(tipText); | 1500 action->setStatusTip(tipText); |
1491 connect(action, SIGNAL(triggered()), | 1501 connect(action, SIGNAL(triggered()), |
1492 this, SLOT(addLayer())); | 1502 this, SLOT(addLayer())); |
1493 connect(this, SIGNAL(canAddLayer(bool)), | 1503 connect(this, SIGNAL(canAddLayer(bool)), |
1494 action, SLOT(setEnabled(bool))); | 1504 action, SLOT(setEnabled(bool))); |
1495 m_layerActions[action] = LayerConfiguration(type, 0, 0); | 1505 m_layerActions.push_back |
1506 ({ action, LayerConfiguration(type, 0, 0) }); | |
1496 m_rightButtonLayerMenu->addAction(action); | 1507 m_rightButtonLayerMenu->addAction(action); |
1497 } | 1508 } |
1498 } | 1509 } |
1499 } | 1510 } |
1500 } | 1511 } |
1535 | 1546 |
1536 action = new QAction(il.load("timeruler"), tr("Add &Time Ruler"), this); | 1547 action = new QAction(il.load("timeruler"), tr("Add &Time Ruler"), this); |
1537 action->setStatusTip(tr("Add a new layer showing a time ruler")); | 1548 action->setStatusTip(tr("Add a new layer showing a time ruler")); |
1538 connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); | 1549 connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); |
1539 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); | 1550 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); |
1540 m_layerActions[action] = LayerConfiguration(LayerFactory::TimeRuler); | 1551 m_layerActions.push_back({ action, LayerConfiguration(LayerFactory::TimeRuler) }); |
1541 menu->addAction(action); | 1552 menu->addAction(action); |
1542 | 1553 |
1543 menu->addSeparator(); | 1554 menu->addSeparator(); |
1544 | 1555 |
1545 m_existingLayersMenu = menu->addMenu(tr("Add &Existing Layer")); | 1556 m_existingLayersMenu = menu->addMenu(tr("Add &Existing Layer")); |
1605 } | 1616 } |
1606 | 1617 |
1607 void | 1618 void |
1608 MainWindow::updateLayerShortcutsFor(Model *model) | 1619 MainWindow::updateLayerShortcutsFor(Model *model) |
1609 { | 1620 { |
1621 // Called when e.g. the current pane has changed, to ensure the | |
1622 // various layer shortcuts select an action whose input model is | |
1623 // the active one in this pane | |
1624 | |
1610 set<LayerFactory::LayerType> seen; | 1625 set<LayerFactory::LayerType> seen; |
1611 | 1626 |
1612 for (auto &a : m_paneActions) { | 1627 for (auto &a : m_paneActions) { |
1613 if (!a.second.sourceModel) continue; // empty pane/layer shortcut | 1628 if (!a.second.sourceModel) continue; // empty pane/layer shortcut |
1614 auto type = a.second.layer; | 1629 auto type = a.second.layer; |
1772 } else { | 1787 } else { |
1773 seenNames.insert(name); | 1788 seenNames.insert(name); |
1774 } | 1789 } |
1775 } | 1790 } |
1776 | 1791 |
1792 m_transformActions.clear(); | |
1793 m_transformActionsReverse.clear(); | |
1794 | |
1777 for (int i = 0; in_range_for(transforms, i); ++i) { | 1795 for (int i = 0; in_range_for(transforms, i); ++i) { |
1778 | 1796 |
1779 QString name = transforms[i].name; | 1797 QString name = transforms[i].name; |
1780 if (name == "") name = transforms[i].identifier; | 1798 if (name == "") name = transforms[i].identifier; |
1781 | 1799 |
1804 .arg(output); | 1822 .arg(output); |
1805 } | 1823 } |
1806 | 1824 |
1807 QAction *action = new QAction(tr("%1...").arg(name), this); | 1825 QAction *action = new QAction(tr("%1...").arg(name), this); |
1808 connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); | 1826 connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); |
1809 m_transformActions[action] = transforms[i].identifier; | 1827 m_transformActions.push_back({ action, transforms[i].identifier }); |
1810 m_transformActionsReverse[transforms[i].identifier] = action; | 1828 m_transformActionsReverse[transforms[i].identifier] = action; |
1811 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); | 1829 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); |
1812 | 1830 |
1813 action->setStatusTip(transforms[i].longDescription); | 1831 action->setStatusTip(transforms[i].longDescription); |
1814 | 1832 |
1830 makerMenus[type][maker]->addAction(action); | 1848 makerMenus[type][maker]->addAction(action); |
1831 } | 1849 } |
1832 | 1850 |
1833 action = new QAction(tr("%1...").arg(output == "" ? pluginName : output), this); | 1851 action = new QAction(tr("%1...").arg(output == "" ? pluginName : output), this); |
1834 connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); | 1852 connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); |
1835 m_transformActions[action] = transforms[i].identifier; | 1853 m_transformActions.push_back({ action, transforms[i].identifier }); |
1836 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); | 1854 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); |
1837 action->setStatusTip(transforms[i].longDescription); | 1855 action->setStatusTip(transforms[i].longDescription); |
1838 | 1856 |
1839 // cerr << "Transform: \"" << name << "\": plugin name \"" << pluginName << "\"" << endl; | 1857 // cerr << "Transform: \"" << name << "\": plugin name \"" << pluginName << "\"" << endl; |
1840 | 1858 |
2080 (factory->getLayerType(layer))); | 2098 (factory->getLayerType(layer))); |
2081 | 2099 |
2082 QAction *action = new QAction(icon, name, this); | 2100 QAction *action = new QAction(icon, name, this); |
2083 connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); | 2101 connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); |
2084 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); | 2102 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); |
2085 m_existingLayerActions[action] = layer; | 2103 m_existingLayerActions.push_back({ action, layer }); |
2086 | 2104 |
2087 m_existingLayersMenu->addAction(action); | 2105 m_existingLayersMenu->addAction(action); |
2088 | 2106 |
2089 if (sliceableLayers.find(layer) != sliceableLayers.end()) { | 2107 if (sliceableLayers.find(layer) != sliceableLayers.end()) { |
2090 action = new QAction(icon, name, this); | 2108 action = new QAction(icon, name, this); |
2091 connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); | 2109 connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); |
2092 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); | 2110 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); |
2093 m_sliceActions[action] = layer; | 2111 m_sliceActions.push_back({ action, layer }); |
2094 m_sliceMenu->addAction(action); | 2112 m_sliceMenu->addAction(action); |
2095 } | 2113 } |
2096 } | 2114 } |
2097 | 2115 |
2098 m_sliceMenu->setEnabled(!m_sliceActions.empty()); | 2116 m_sliceMenu->setEnabled(!m_sliceActions.empty()); |
2306 toolbar = addToolBar(tr("Edit Toolbar")); | 2324 toolbar = addToolBar(tr("Edit Toolbar")); |
2307 CommandHistory::getInstance()->registerToolbar(toolbar); | 2325 CommandHistory::getInstance()->registerToolbar(toolbar); |
2308 | 2326 |
2309 toolbar = addToolBar(tr("Tools Toolbar")); | 2327 toolbar = addToolBar(tr("Tools Toolbar")); |
2310 QActionGroup *group = new QActionGroup(this); | 2328 QActionGroup *group = new QActionGroup(this); |
2311 | 2329 m_toolActions.clear(); |
2330 | |
2312 m_keyReference->setCategory(tr("Tool Selection")); | 2331 m_keyReference->setCategory(tr("Tool Selection")); |
2313 QAction *action = toolbar->addAction(il.load("navigate"), | 2332 QAction *action = toolbar->addAction(il.load("navigate"), tr("Navigate")); |
2314 tr("Navigate")); | |
2315 action->setCheckable(true); | 2333 action->setCheckable(true); |
2316 action->setChecked(true); | 2334 action->setChecked(true); |
2317 action->setShortcut(tr("1")); | 2335 action->setShortcut(tr("1")); |
2318 action->setStatusTip(tr("Navigate")); | 2336 action->setStatusTip(tr("Navigate")); |
2319 connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected())); | 2337 connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected())); |
2320 connect(this, SIGNAL(replacedDocument()), action, SLOT(trigger())); | 2338 connect(this, SIGNAL(replacedDocument()), action, SLOT(trigger())); |
2321 group->addAction(action); | 2339 group->addAction(action); |
2322 m_keyReference->registerShortcut(action); | 2340 m_keyReference->registerShortcut(action); |
2323 m_toolActions[ViewManager::NavigateMode] = action; | 2341 m_toolActions.push_back({ ViewManager::NavigateMode, action }); |
2324 | 2342 |
2325 m_keyReference->setCategory | 2343 m_keyReference->setCategory |
2326 (tr("Navigate Tool Mouse Actions")); | 2344 (tr("Navigate Tool Mouse Actions")); |
2327 m_keyReference->registerShortcut | 2345 m_keyReference->registerShortcut |
2328 (tr("Navigate"), tr("Left"), | 2346 (tr("Navigate"), tr("Left"), |
2336 m_keyReference->registerShortcut | 2354 m_keyReference->registerShortcut |
2337 (tr("Edit"), tr("Double-Click Left"), | 2355 (tr("Edit"), tr("Double-Click Left"), |
2338 tr("Double-click left button on an item to edit it")); | 2356 tr("Double-click left button on an item to edit it")); |
2339 | 2357 |
2340 m_keyReference->setCategory(tr("Tool Selection")); | 2358 m_keyReference->setCategory(tr("Tool Selection")); |
2341 action = toolbar->addAction(il.load("select"), | 2359 action = toolbar->addAction(il.load("select"), tr("Select")); |
2342 tr("Select")); | |
2343 action->setCheckable(true); | 2360 action->setCheckable(true); |
2344 action->setShortcut(tr("2")); | 2361 action->setShortcut(tr("2")); |
2345 action->setStatusTip(tr("Select ranges")); | 2362 action->setStatusTip(tr("Select ranges")); |
2346 connect(action, SIGNAL(triggered()), this, SLOT(toolSelectSelected())); | 2363 connect(action, SIGNAL(triggered()), this, SLOT(toolSelectSelected())); |
2347 group->addAction(action); | 2364 group->addAction(action); |
2348 m_keyReference->registerShortcut(action); | 2365 m_keyReference->registerShortcut(action); |
2349 m_toolActions[ViewManager::SelectMode] = action; | 2366 m_toolActions.push_back({ ViewManager::SelectMode, action }); |
2350 | 2367 |
2351 m_keyReference->setCategory | 2368 m_keyReference->setCategory |
2352 (tr("Select Tool Mouse Actions")); | 2369 (tr("Select Tool Mouse Actions")); |
2353 m_keyReference->registerShortcut | 2370 m_keyReference->registerShortcut |
2354 (tr("Select"), tr("Left"), | 2371 (tr("Select"), tr("Left"), |
2365 m_keyReference->registerShortcut | 2382 m_keyReference->registerShortcut |
2366 (tr("Fine Select"), tr("Shift+Left"), | 2383 (tr("Fine Select"), tr("Shift+Left"), |
2367 tr("Shift-click left button and drag to select without snapping to items or grid")); | 2384 tr("Shift-click left button and drag to select without snapping to items or grid")); |
2368 | 2385 |
2369 m_keyReference->setCategory(tr("Tool Selection")); | 2386 m_keyReference->setCategory(tr("Tool Selection")); |
2370 action = toolbar->addAction(il.load("move"), | 2387 action = toolbar->addAction(il.load("move"), tr("Edit")); |
2371 tr("Edit")); | |
2372 action->setCheckable(true); | 2388 action->setCheckable(true); |
2373 action->setShortcut(tr("3")); | 2389 action->setShortcut(tr("3")); |
2374 action->setStatusTip(tr("Edit items in layer")); | 2390 action->setStatusTip(tr("Edit items in layer")); |
2375 connect(action, SIGNAL(triggered()), this, SLOT(toolEditSelected())); | 2391 connect(action, SIGNAL(triggered()), this, SLOT(toolEditSelected())); |
2376 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool))); | 2392 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool))); |
2377 group->addAction(action); | 2393 group->addAction(action); |
2378 m_keyReference->registerShortcut(action); | 2394 m_keyReference->registerShortcut(action); |
2379 m_toolActions[ViewManager::EditMode] = action; | 2395 m_toolActions.push_back({ ViewManager::EditMode, action }); |
2380 | 2396 |
2381 m_keyReference->setCategory | 2397 m_keyReference->setCategory |
2382 (tr("Edit Tool Mouse Actions")); | 2398 (tr("Edit Tool Mouse Actions")); |
2383 m_keyReference->registerShortcut | 2399 m_keyReference->registerShortcut |
2384 (tr("Move"), tr("Left"), | 2400 (tr("Move"), tr("Left"), |
2386 m_keyReference->registerShortcut | 2402 m_keyReference->registerShortcut |
2387 (tr("Edit"), tr("Double-Click Left"), | 2403 (tr("Edit"), tr("Double-Click Left"), |
2388 tr("Double-click left button on an item to edit it")); | 2404 tr("Double-click left button on an item to edit it")); |
2389 | 2405 |
2390 m_keyReference->setCategory(tr("Tool Selection")); | 2406 m_keyReference->setCategory(tr("Tool Selection")); |
2391 action = toolbar->addAction(il.load("draw"), | 2407 action = toolbar->addAction(il.load("draw"), tr("Draw")); |
2392 tr("Draw")); | |
2393 action->setCheckable(true); | 2408 action->setCheckable(true); |
2394 action->setShortcut(tr("4")); | 2409 action->setShortcut(tr("4")); |
2395 action->setStatusTip(tr("Draw new items in layer")); | 2410 action->setStatusTip(tr("Draw new items in layer")); |
2396 connect(action, SIGNAL(triggered()), this, SLOT(toolDrawSelected())); | 2411 connect(action, SIGNAL(triggered()), this, SLOT(toolDrawSelected())); |
2397 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool))); | 2412 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool))); |
2398 group->addAction(action); | 2413 group->addAction(action); |
2399 m_keyReference->registerShortcut(action); | 2414 m_keyReference->registerShortcut(action); |
2400 m_toolActions[ViewManager::DrawMode] = action; | 2415 m_toolActions.push_back({ ViewManager::DrawMode, action }); |
2401 | 2416 |
2402 m_keyReference->setCategory | 2417 m_keyReference->setCategory |
2403 (tr("Draw Tool Mouse Actions")); | 2418 (tr("Draw Tool Mouse Actions")); |
2404 m_keyReference->registerShortcut | 2419 m_keyReference->registerShortcut |
2405 (tr("Draw"), tr("Left"), | 2420 (tr("Draw"), tr("Left"), |
2406 tr("Click left button and drag to create new item")); | 2421 tr("Click left button and drag to create new item")); |
2407 | 2422 |
2408 m_keyReference->setCategory(tr("Tool Selection")); | 2423 m_keyReference->setCategory(tr("Tool Selection")); |
2409 action = toolbar->addAction(il.load("erase"), | 2424 action = toolbar->addAction(il.load("erase"), tr("Erase")); |
2410 tr("Erase")); | |
2411 action->setCheckable(true); | 2425 action->setCheckable(true); |
2412 action->setShortcut(tr("5")); | 2426 action->setShortcut(tr("5")); |
2413 action->setStatusTip(tr("Erase items from layer")); | 2427 action->setStatusTip(tr("Erase items from layer")); |
2414 connect(action, SIGNAL(triggered()), this, SLOT(toolEraseSelected())); | 2428 connect(action, SIGNAL(triggered()), this, SLOT(toolEraseSelected())); |
2415 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool))); | 2429 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool))); |
2416 group->addAction(action); | 2430 group->addAction(action); |
2417 m_keyReference->registerShortcut(action); | 2431 m_keyReference->registerShortcut(action); |
2418 m_toolActions[ViewManager::EraseMode] = action; | 2432 m_toolActions.push_back({ ViewManager::EraseMode, action }); |
2419 | 2433 |
2420 m_keyReference->setCategory | 2434 m_keyReference->setCategory |
2421 (tr("Erase Tool Mouse Actions")); | 2435 (tr("Erase Tool Mouse Actions")); |
2422 m_keyReference->registerShortcut | 2436 m_keyReference->registerShortcut |
2423 (tr("Erase"), tr("Left"), | 2437 (tr("Erase"), tr("Left"), |
2430 action->setStatusTip(tr("Make measurements in layer")); | 2444 action->setStatusTip(tr("Make measurements in layer")); |
2431 connect(action, SIGNAL(triggered()), this, SLOT(toolMeasureSelected())); | 2445 connect(action, SIGNAL(triggered()), this, SLOT(toolMeasureSelected())); |
2432 connect(this, SIGNAL(canMeasureLayer(bool)), action, SLOT(setEnabled(bool))); | 2446 connect(this, SIGNAL(canMeasureLayer(bool)), action, SLOT(setEnabled(bool))); |
2433 group->addAction(action); | 2447 group->addAction(action); |
2434 m_keyReference->registerShortcut(action); | 2448 m_keyReference->registerShortcut(action); |
2435 m_toolActions[ViewManager::MeasureMode] = action; | 2449 m_toolActions.push_back({ ViewManager::MeasureMode, action }); |
2436 | 2450 |
2437 m_keyReference->setCategory | 2451 m_keyReference->setCategory |
2438 (tr("Measure Tool Mouse Actions")); | 2452 (tr("Measure Tool Mouse Actions")); |
2439 m_keyReference->registerShortcut | 2453 m_keyReference->registerShortcut |
2440 (tr("Measure Area"), tr("Left"), | 2454 (tr("Measure Area"), tr("Left"), |
3832 cerr << "WARNING: MainWindow::addPane: sender is not an action" | 3846 cerr << "WARNING: MainWindow::addPane: sender is not an action" |
3833 << endl; | 3847 << endl; |
3834 return; | 3848 return; |
3835 } | 3849 } |
3836 | 3850 |
3837 PaneActionMap::iterator i = m_paneActions.find(action); | 3851 PaneActions::iterator i = m_paneActions.begin(); |
3852 while (i != m_paneActions.end()) { | |
3853 if (i->first == action) break; | |
3854 ++i; | |
3855 } | |
3838 | 3856 |
3839 if (i == m_paneActions.end()) { | 3857 if (i == m_paneActions.end()) { |
3840 cerr << "WARNING: MainWindow::addPane: unknown action " | 3858 cerr << "WARNING: MainWindow::addPane: unknown action " |
3841 << action->objectName() << endl; | 3859 << action->objectName() << endl; |
3842 cerr << "known actions are:" << endl; | 3860 cerr << "known actions are:" << endl; |
3843 for (PaneActionMap::const_iterator i = m_paneActions.begin(); | 3861 for (PaneActions::const_iterator i = m_paneActions.begin(); |
3844 i != m_paneActions.end(); ++i) { | 3862 i != m_paneActions.end(); ++i) { |
3845 cerr << i->first << ", name " << i->first->text() << endl; | 3863 cerr << i->first << ", name " << i->first->text() << endl; |
3846 } | 3864 } |
3847 return; | 3865 return; |
3848 } | 3866 } |
3941 if (!pane) { | 3959 if (!pane) { |
3942 cerr << "WARNING: MainWindow::addLayer: no current pane" << endl; | 3960 cerr << "WARNING: MainWindow::addLayer: no current pane" << endl; |
3943 return; | 3961 return; |
3944 } | 3962 } |
3945 | 3963 |
3946 ExistingLayerActionMap::iterator ei = m_existingLayerActions.find(action); | 3964 ExistingLayerActions::iterator ei = m_existingLayerActions.begin(); |
3965 while (ei != m_existingLayerActions.end()) { | |
3966 if (ei->first == action) break; | |
3967 ++ei; | |
3968 } | |
3947 | 3969 |
3948 if (ei != m_existingLayerActions.end()) { | 3970 if (ei != m_existingLayerActions.end()) { |
3949 Layer *newLayer = ei->second; | 3971 Layer *newLayer = ei->second; |
3950 m_document->addLayerToView(pane, newLayer); | 3972 m_document->addLayerToView(pane, newLayer); |
3951 m_paneStack->setCurrentLayer(pane, newLayer); | 3973 m_paneStack->setCurrentLayer(pane, newLayer); |
3952 return; | 3974 return; |
3953 } | 3975 } |
3954 | 3976 |
3955 ei = m_sliceActions.find(action); | 3977 ei = m_sliceActions.begin(); |
3978 while (ei != m_sliceActions.end()) { | |
3979 if (ei->first == action) break; | |
3980 ++ei; | |
3981 } | |
3956 | 3982 |
3957 if (ei != m_sliceActions.end()) { | 3983 if (ei != m_sliceActions.end()) { |
3958 Layer *newLayer = m_document->createLayer(LayerFactory::Slice); | 3984 Layer *newLayer = m_document->createLayer(LayerFactory::Slice); |
3959 // document->setModel(newLayer, ei->second->getModel()); | 3985 // document->setModel(newLayer, ei->second->getModel()); |
3960 SliceableLayer *source = dynamic_cast<SliceableLayer *>(ei->second); | 3986 SliceableLayer *source = dynamic_cast<SliceableLayer *>(ei->second); |
3970 m_document->addLayerToView(pane, newLayer); | 3996 m_document->addLayerToView(pane, newLayer); |
3971 m_paneStack->setCurrentLayer(pane, newLayer); | 3997 m_paneStack->setCurrentLayer(pane, newLayer); |
3972 return; | 3998 return; |
3973 } | 3999 } |
3974 | 4000 |
3975 TransformActionMap::iterator i = m_transformActions.find(action); | 4001 TransformActions::iterator i = m_transformActions.begin(); |
4002 while (i != m_transformActions.end()) { | |
4003 if (i->first == action) break; | |
4004 ++i; | |
4005 } | |
3976 | 4006 |
3977 if (i == m_transformActions.end()) { | 4007 if (i == m_transformActions.end()) { |
3978 | 4008 |
3979 LayerActionMap::iterator i = m_layerActions.find(action); | 4009 LayerActions::iterator i = m_layerActions.begin(); |
4010 while (i != m_layerActions.end()) { | |
4011 if (i->first == action) break; | |
4012 ++i; | |
4013 } | |
3980 | 4014 |
3981 if (i == m_layerActions.end()) { | 4015 if (i == m_layerActions.end()) { |
3982 cerr << "WARNING: MainWindow::addLayer: unknown action " | 4016 cerr << "WARNING: MainWindow::addLayer: unknown action " |
3983 << action->objectName() << endl; | 4017 << action->objectName() << endl; |
3984 return; | 4018 return; |
3993 | 4027 |
3994 if (emptyTypes.find(type) != emptyTypes.end()) { | 4028 if (emptyTypes.find(type) != emptyTypes.end()) { |
3995 | 4029 |
3996 newLayer = m_document->createEmptyLayer(type); | 4030 newLayer = m_document->createEmptyLayer(type); |
3997 if (newLayer) { | 4031 if (newLayer) { |
3998 m_toolActions[ViewManager::DrawMode]->trigger(); | 4032 for (auto &a : m_toolActions) { |
4033 if (a.first == ViewManager::DrawMode) { | |
4034 a.second->trigger(); | |
4035 break; | |
4036 } | |
4037 } | |
3999 } | 4038 } |
4000 | 4039 |
4001 } else { | 4040 } else { |
4002 | 4041 |
4003 Model *model = i->second.sourceModel; | 4042 Model *model = i->second.sourceModel; |
4727 MainWindow::setInstantsNumbering() | 4766 MainWindow::setInstantsNumbering() |
4728 { | 4767 { |
4729 QAction *a = dynamic_cast<QAction *>(sender()); | 4768 QAction *a = dynamic_cast<QAction *>(sender()); |
4730 if (!a) return; | 4769 if (!a) return; |
4731 | 4770 |
4732 int type = m_numberingActions[a]; | 4771 int type = 0; |
4772 for (auto &ai : m_numberingActions) { | |
4773 if (ai.first == a) type = ai.second; | |
4774 } | |
4733 | 4775 |
4734 if (m_labeller) m_labeller->setType(Labeller::ValueType(type)); | 4776 if (m_labeller) m_labeller->setType(Labeller::ValueType(type)); |
4735 | 4777 |
4736 QSettings settings; | 4778 QSettings settings; |
4737 settings.beginGroup("MainWindow"); | 4779 settings.beginGroup("MainWindow"); |