History

fix crash in Menu.removeSeparator() if the menu item doesn't exist or isn't a separator

ZappoMan committed 12 years ago

Commit 13985f81 parent 7a8d2621 file · +13 −5Browse files

Showing the changes to interface/src/Menu.cpp (1 of 1 file). Show all

Unified · Split

interface/src/Menu.cpp+13−5
@@ -1320,17 +1320,25 @@ void Menu::addSeparator(const QString& menuName, const QString& separatorName) { · 1319 unmodified lines
1320 1320
1321void Menu::removeSeparator(const QString& menuName, const QString& separatorName) {1321void Menu::removeSeparator(const QString& menuName, const QString& separatorName) {
1322 QMenu* menu = getMenu(menuName);1322 QMenu* menu = getMenu(menuName);
1323 bool separatorRemoved = false;
1323 if (menu) {1324 if (menu) {
1324 int textAt = findPositionOfMenuItem(menu, separatorName);1325 int textAt = findPositionOfMenuItem(menu, separatorName);
1325 QList<QAction*> menuActions = menu->actions();1326 QList<QAction*> menuActions = menu->actions();
1326 QAction* separatorText = menuActions[textAt];1327 QAction* separatorText = menuActions[textAt];
1327 QAction* separatorLine = menuActions[textAt - 1];1328 if (textAt > 0 && textAt < menuActions.size()) {
1328 if (separatorLine->isSeparator()) {1329 QAction* separatorLine = menuActions[textAt - 1];
1329 menu->removeAction(separatorText);1330 if (separatorLine) {
1330 menu->removeAction(separatorLine);1331 if (separatorLine->isSeparator()) {
1332 menu->removeAction(separatorText);
1333 menu->removeAction(separatorLine);
1334 separatorRemoved = true;
1335 }
1336 }
1331 }1337 }
1332 }1338 }
1333 QMenuBar::repaint();1339 if (separatorRemoved) {
1340 QMenuBar::repaint();
1341 }
1334}1342}
1335 1343
1336void Menu::addMenuItem(const MenuItemProperties& properties) {1344void Menu::addMenuItem(const MenuItemProperties& properties) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t