diff --git a/src/Gui/Action.cpp b/src/Gui/Action.cpp index e79bf0c03a..331234850b 100644 --- a/src/Gui/Action.cpp +++ b/src/Gui/Action.cpp @@ -121,9 +121,12 @@ void Action::onToggled(bool toggle) void Action::setCheckable(bool check) { - if (check == _action->isCheckable()) + if (check == _action->isCheckable()) { return; + } + _action->setCheckable(check); + if (check) { disconnect(_connection); _connection = connect(_action, &QAction::toggled, this, &Action::onToggled); @@ -137,11 +140,13 @@ void Action::setCheckable(bool check) void Action::setChecked(bool check, bool no_signal) { bool blocked = false; - if (no_signal) + if (no_signal) { blocked = _action->blockSignals(true); + } _action->setChecked(check); - if (no_signal) + if (no_signal) { _action->blockSignals(blocked); + } } bool Action::isChecked() const @@ -201,8 +206,9 @@ QString Action::statusTip() const void Action::setText(const QString & text) { _action->setText(text); - if (_title.isEmpty()) + if (_title.isEmpty()) { setToolTip(_tooltip); + } } QString Action::text() const @@ -239,51 +245,64 @@ QString Action::cleanTitle(const QString & title) QString Action::commandToolTip(const Command *cmd, bool richFormat) { - if (!cmd) + if (!cmd) { return QString(); + } if (richFormat) { - if (auto action = cmd->getAction()) + if (auto action = cmd->getAction()) { return action->_action->toolTip(); + } } QString title, tooltip; if (dynamic_cast(cmd)) { - if (auto txt = cmd->getMenuText()) + if (auto txt = cmd->getMenuText()) { title = QString::fromUtf8(txt); - if (auto txt = cmd->getToolTipText()) + } + if (auto txt = cmd->getToolTipText()) { tooltip = QString::fromUtf8(txt); + } } else { - if (auto txt = cmd->getMenuText()) + if (auto txt = cmd->getMenuText()) { title = qApp->translate(cmd->className(), txt); - if (auto txt = cmd->getToolTipText()) + } + if (auto txt = cmd->getToolTipText()) { tooltip = qApp->translate(cmd->className(), txt); + } } - if (!richFormat) + if (!richFormat) { return tooltip; + } return createToolTip(tooltip, title, QFont(), cmd->getShortcut(), cmd); } QString Action::commandMenuText(const Command *cmd) { - if (!cmd) + if (!cmd) { return QString(); - - QString title; - if (auto action = cmd->getAction()) - title = action->text(); - else if (dynamic_cast(cmd)) { - if (auto txt = cmd->getMenuText()) - title = QString::fromUtf8(txt); - } else { - if (auto txt = cmd->getMenuText()) - title = qApp->translate(cmd->className(), txt); } - if (title.isEmpty()) + + QString title; + if (auto action = cmd->getAction()) { + title = action->text(); + } + else if (dynamic_cast(cmd)) { + if (auto txt = cmd->getMenuText()) { + title = QString::fromUtf8(txt); + } + } else { + if (auto txt = cmd->getMenuText()) { + title = qApp->translate(cmd->className(), txt); + } + } + if (title.isEmpty()) { title = QString::fromUtf8(cmd->getName()); - else + } + else { title = cleanTitle(title); + } return title; } @@ -295,8 +314,9 @@ QString Action::createToolTip(QString helpText, { QString text = cleanTitle(title); - if (text.isEmpty()) + if (text.isEmpty()) { return helpText; + } // The following code tries to make a more useful tooltip by inserting at // the beginning of the tooltip the action title in bold followed by the @@ -307,10 +327,12 @@ QString Action::createToolTip(QString helpText, // wrappin using

. QString shortcut = shortCut; - if (shortcut.size() && helpText.endsWith(shortcut)) + if (shortcut.size() && helpText.endsWith(shortcut)) { helpText.resize(helpText.size() - shortcut.size()); - if (shortcut.size()) + } + if (shortcut.size()) { shortcut = QString::fromLatin1(" (%1)").arg(shortcut); + } QString tooltip = QString::fromLatin1( "

%1%2

").arg( @@ -334,8 +356,9 @@ QString Action::createToolTip(QString helpText, .arg(cmdName.toHtmlEscaped()); } - if (shortcut.size() && helpText.endsWith(shortcut)) + if (shortcut.size() && helpText.endsWith(shortcut)) { helpText.resize(helpText.size() - shortcut.size()); + } if (helpText.isEmpty() || helpText == text @@ -368,8 +391,9 @@ QString Action::createToolTip(QString helpText, int index = tipWidth / width * helpText.size(); // Try to only break at white space for(int i=0; i<50 && index") @@ -519,8 +543,9 @@ void ActionGroup::setCheckedAction(int index) act->setChecked(true); this->setIcon(act->icon()); - if (!this->_isMode) + if (!this->_isMode) { this->setToolTip(act->toolTip()); + } this->setProperty("defaultAction", QVariant(index)); } @@ -545,7 +570,9 @@ void ActionGroup::onActivated (QAction* act) int index = groupAction()->actions().indexOf(act); this->setIcon(act->icon()); - if (!this->_isMode) this->setToolTip(act->toolTip()); + if (!this->_isMode) { + this->setToolTip(act->toolTip()); + } this->setProperty("defaultAction", QVariant(index)); command()->invoke(index, Command::TriggerChildAction); } @@ -614,12 +641,15 @@ void WorkbenchComboBox::actionEvent ( QActionEvent* qae ) { if (action->isVisible()) { QIcon icon = action->icon(); - if (icon.isNull()) + if (icon.isNull()) { this->addItem(action->text(), action->data()); - else + } + else { this->addItem(icon, action->text(), action->data()); - if (action->isChecked()) + } + if (action->isChecked()) { this->setCurrentIndex(action->data().toInt()); + } } break; } @@ -682,8 +712,9 @@ void WorkbenchComboBox::onWorkbenchActivated(const QString& name) QList act = actions(); for (QList::Iterator it = act.begin(); it != act.end(); ++it) { if ((*it)->objectName() == name) { - if (/*(*it)->data() != item*/!(*it)->isChecked()) + if (/*(*it)->data() != item*/!(*it)->isChecked()) { (*it)->trigger(); + } break; } } @@ -755,8 +786,9 @@ void WorkbenchGroup::setWorkbenchData(int index, const QString& wb) workbenches[index]->setToolTip(tip); workbenches[index]->setStatusTip(tr("Select the '%1' workbench").arg(name)); workbenches[index]->setVisible(true); - if (index < 9) + if (index < 9) { workbenches[index]->setShortcut(QKeySequence(QString::fromUtf8("W,%1").arg(index+1))); + } } void WorkbenchGroup::refreshWorkbenchList() @@ -974,8 +1006,9 @@ QStringList RecentFilesAction::files() const QList recentFiles = groupAction()->actions(); for (int index = 0; index < recentFiles.count(); index++) { QString file = recentFiles[index]->toolTip(); - if (file.isEmpty()) + if (file.isEmpty()) { break; + } files.append(file); } @@ -986,8 +1019,9 @@ void RecentFilesAction::activateFile(int id) { // restore the list of recent files QStringList files = this->files(); - if (id < 0 || id >= files.count()) + if (id < 0 || id >= files.count()) { return; // no valid item + } QString filename = files[id]; QFileInfo fi(filename); @@ -1031,8 +1065,9 @@ void RecentFilesAction::restore() } std::vector MRU = hGrp->GetASCIIs("MRU"); QStringList files; - for(const auto& it : MRU) + for(const auto& it : MRU) { files.append(QString::fromUtf8(it.c_str())); + } setFiles(files); } @@ -1049,8 +1084,9 @@ void RecentFilesAction::save() for (int index = 0; index < num; index++) { QString key = QString::fromLatin1("MRU%1").arg(index); QString value = recentFiles[index]->toolTip(); - if (value.isEmpty()) + if (value.isEmpty()) { break; + } hGrp->SetASCII(key.toLatin1(), value.toUtf8()); } @@ -1152,8 +1188,9 @@ QStringList RecentMacrosAction::files() const QList recentFiles = groupAction()->actions(); for (int index = 0; index < recentFiles.count(); index++) { QString file = recentFiles[index]->toolTip(); - if (file.isEmpty()) + if (file.isEmpty()) { break; + } files.append(file); } @@ -1164,8 +1201,9 @@ void RecentMacrosAction::activateFile(int id) { // restore the list of recent files QStringList files = this->files(); - if (id < 0 || id >= files.count()) + if (id < 0 || id >= files.count()) { return; // no valid item + } QString filename = files[id]; QFileInfo fi(filename); @@ -1190,8 +1228,9 @@ void RecentMacrosAction::activateFile(int id) getMainWindow()->appendRecentMacro(fi.filePath()); Application::Instance->macroManager()->run(Gui::MacroManager::File, fi.filePath().toUtf8()); // after macro run recalculate the document - if (Application::Instance->activeDocument()) + if (Application::Instance->activeDocument()) { Application::Instance->activeDocument()->getDocument()->recompute(); + } } catch (const Base::SystemExitException&) { // handle SystemExit exceptions @@ -1227,8 +1266,9 @@ void RecentMacrosAction::restore() std::vector MRU = hGrp->GetASCIIs("MRU"); QStringList files; - for (auto& filename : MRU) + for (auto& filename : MRU) { files.append(QString::fromUtf8(filename.c_str())); + } setFiles(files); } @@ -1246,8 +1286,9 @@ void RecentMacrosAction::save() for (int index = 0; index < num; index++) { QString key = QString::fromLatin1("MRU%1").arg(index); QString value = recentFiles[index]->toolTip(); - if (value.isEmpty()) + if (value.isEmpty()) { break; + } hGrp->SetASCII(key.toLatin1(), value.toUtf8()); } diff --git a/src/Gui/MenuManager.cpp b/src/Gui/MenuManager.cpp index cf446366d1..164c36deb2 100644 --- a/src/Gui/MenuManager.cpp +++ b/src/Gui/MenuManager.cpp @@ -43,8 +43,9 @@ MenuItem::MenuItem() MenuItem::MenuItem(MenuItem* item) { - if (item) + if (item) { item->appendItem(this); + } } MenuItem::~MenuItem() @@ -69,16 +70,14 @@ bool MenuItem::hasItems() const MenuItem* MenuItem::findItem(const std::string& name) { - if (_name == name) - { + if (_name == name) { return this; } - else - { - for (QList::Iterator it = _items.begin(); it != _items.end(); ++it) - { - if ((*it)->_name == name) + else { + for (QList::Iterator it = _items.begin(); it != _items.end(); ++it) { + if ((*it)->_name == name) { return *it; + } } } @@ -87,16 +86,16 @@ MenuItem* MenuItem::findItem(const std::string& name) MenuItem* MenuItem::findParentOf(const std::string& name) { - for (QList::Iterator it = _items.begin(); it != _items.end(); ++it) - { - if ((*it)->_name == name) + for (QList::Iterator it = _items.begin(); it != _items.end(); ++it) { + if ((*it)->_name == name) { return this; + } } - for (QList::Iterator it = _items.begin(); it != _items.end(); ++it) - { - if ((*it)->findParentOf(name)) + for (QList::Iterator it = _items.begin(); it != _items.end(); ++it) { + if ((*it)->findParentOf(name)) { return *it; + } } return nullptr; @@ -129,34 +128,36 @@ void MenuItem::appendItem(MenuItem* item) bool MenuItem::insertItem(MenuItem* before, MenuItem* item) { int pos = _items.indexOf(before); - if (pos != -1) - { + if (pos != -1) { _items.insert(pos, item); return true; } - else - return false; + + return false; } MenuItem* MenuItem::afterItem(MenuItem* item) const { int pos = _items.indexOf(item); - if (pos < 0 || pos+1 == _items.size()) + if (pos < 0 || pos+1 == _items.size()) { return nullptr; + } return _items.at(pos+1); } void MenuItem::removeItem(MenuItem* item) { int pos = _items.indexOf(item); - if (pos != -1) + if (pos != -1) { _items.removeAt(pos); + } } void MenuItem::clear() { - for (QList::Iterator it = _items.begin(); it != _items.end(); ++it) + for (QList::Iterator it = _items.begin(); it != _items.end(); ++it) { delete *it; + } _items.clear(); } @@ -184,8 +185,9 @@ MenuManager* MenuManager::_instance=nullptr; MenuManager* MenuManager::getInstance() { - if ( !_instance ) + if ( !_instance ) { _instance = new MenuManager; + } return _instance; } @@ -205,8 +207,9 @@ MenuManager::~MenuManager() void MenuManager::setup(MenuItem* menuItems) const { - if (!menuItems) + if (!menuItems) { return; // empty menu bar + } QMenuBar* menuBar = getMainWindow()->menuBar(); @@ -286,8 +289,9 @@ void MenuManager::setup(MenuItem* menuItems) const } // flll up the menu - if (!action->isSeparator()) + if (!action->isSeparator()) { setup(*it, action->menu()); + } } setupMenuBarCornerWidgets(); @@ -357,8 +361,9 @@ void MenuManager::setup(MenuItem* item, QMenu* menu) const } // fill up the submenu - if ((*it)->hasItems()) + if ((*it)->hasItems()) { setup(*it, used_actions.front()->menu()); + } } // remove all menu items which we don't need for the moment @@ -407,8 +412,9 @@ void MenuManager::retranslate() const QMenuBar* menuBar = getMainWindow()->menuBar(); QList actions = menuBar->actions(); for (QList::Iterator it = actions.begin(); it != actions.end(); ++it) { - if ((*it)->menu()) + if ((*it)->menu()) { retranslate((*it)->menu()); + } } } @@ -444,8 +450,9 @@ void MenuManager::retranslate(QMenu* menu) const QAction* MenuManager::findAction(const QList& acts, const QString& item) const { for (QList::ConstIterator it = acts.begin(); it != acts.end(); ++it) { - if ((*it)->data().toString() == item) + if ((*it)->data().toString() == item) { return *it; + } } return nullptr; // no item with the user data found @@ -464,11 +471,13 @@ QList MenuManager::findActions(const QList& acts, const QStr used.append(*it); first_match = true; // get only one separator per request - if (item == QLatin1String("Separator")) + if (item == QLatin1String("Separator")) { break; + } } - else if (first_match) + else if (first_match) { break; + } } return used; diff --git a/src/Gui/Workbench.cpp b/src/Gui/Workbench.cpp index 2d2c17a5e7..a370ba44e4 100644 --- a/src/Gui/Workbench.cpp +++ b/src/Gui/Workbench.cpp @@ -238,8 +238,9 @@ void Workbench::setupCustomToolbars(ToolBarItem* root, const char* toolbar) cons } // for this workbench global toolbars are not allowed - if (getTypeId() == NoneWorkbench::getClassTypeId()) + if (getTypeId() == NoneWorkbench::getClassTypeId()) { return; + } // application-wide custom toolbars hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp") @@ -260,8 +261,11 @@ void Workbench::setupCustomToolbars(ToolBarItem* root, const Base::ReferenceGetBool("Active", true); - if (!active) // ignore this toolbar + if (!active) { + // ignore this toolbar continue; + } + auto bar = new ToolBarItem(root); bar->setCommand("Custom"); @@ -325,8 +329,10 @@ void Workbench::createMainWindowPopupMenu(MenuItem*) const } void Workbench::createLinkMenu(MenuItem *item) { - if(!item || !App::GetApplication().getActiveDocument()) + if(!item || !App::GetApplication().getActiveDocument()) { return; + } + auto linkMenu = new MenuItem; linkMenu->setCommand("Link actions"); *linkMenu << "Std_LinkMakeGroup" << "Std_LinkMake"; @@ -366,8 +372,9 @@ void Workbench::removePermanentMenuItem(const std::string& cmd) return (pmi.first == cmd); }); - if (it != staticMenuItems.end()) + if (it != staticMenuItems.end()) { staticMenuItems.erase(it); + } } void Workbench::addPermanentMenuItems(MenuItem* mb) const @@ -435,15 +442,17 @@ PyObject* Workbench::getPyObject() void Workbench::addTaskWatcher(const std::vector &Watcher) { Gui::TaskView::TaskView* taskView = Control().taskPanel(); - if (taskView) + if (taskView) { taskView->addTaskWatcher(Watcher); + } } void Workbench::removeTaskWatcher() { Gui::TaskView::TaskView* taskView = Control().taskPanel(); - if (taskView) + if (taskView) { taskView->clearTaskWatcher(); + } } std::list Workbench::listToolbars() const @@ -451,8 +460,9 @@ std::list Workbench::listToolbars() const std::unique_ptr tb(setupToolBars()); std::list bars; QList items = tb->getItems(); - for (const auto & item : items) + for (const auto & item : items) { bars.push_back(item->command()); + } return bars; } @@ -479,8 +489,9 @@ std::list Workbench::listMenus() const std::unique_ptr mb(setupMenuBar()); std::list menus; QList items = mb->getItems(); - for (const auto & item : items) + for (const auto & item : items) { menus.push_back(item->command()); + } return menus; } @@ -489,8 +500,9 @@ std::list Workbench::listCommandbars() const std::unique_ptr cb(setupCommandBars()); std::list bars; QList items = cb->getItems(); - for (const auto & item : items) + for (const auto & item : items) { bars.push_back(item->command()); + } return bars; } @@ -817,8 +829,9 @@ DockWindowItems* StdWorkbench::setupDockWindows() const GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("DockWindows")->GetGroup("DAGView"); bool enabled = group->GetBool("Enabled", false); - if (enabled) + if (enabled) { root->addDockWidget("Std_DAGView", Qt::RightDockWidgetArea, false, false); + } return root; } @@ -839,8 +852,9 @@ BlankWorkbench::~BlankWorkbench() void BlankWorkbench::activated() { QList dw = getMainWindow()->findChildren(); - for (auto & it : dw) + for (auto & it : dw) { it->toggleViewAction()->setVisible(false); + } getMainWindow()->statusBar()->hide(); } @@ -1057,20 +1071,22 @@ void PythonBaseWorkbench::setupContextMenu(const char* recipient, MenuItem* item void PythonBaseWorkbench::appendMenu(const std::list& menu, const std::list& items) const { - if ( menu.empty() || items.empty() ) + if ( menu.empty() || items.empty() ) { return; + } auto jt=menu.begin(); MenuItem* item = _menuBar->findItem( *jt ); - if (!item) - { + if (!item) { item = new MenuItem; item->setCommand( *jt ); Gui::MenuItem* wnd = _menuBar->findItem( "&Windows" ); - if (wnd) + if (wnd) { _menuBar->insertItem(wnd, item); - else + } + else { _menuBar->appendItem(item); + } } // create sub menus @@ -1085,8 +1101,9 @@ void PythonBaseWorkbench::appendMenu(const std::list& menu, const s item = subitem; } - for (const auto & it : items) + for (const auto & it : items) { *item << it; + } } void PythonBaseWorkbench::removeMenu(const std::string& menu) const @@ -1110,8 +1127,9 @@ void PythonBaseWorkbench::appendContextMenu(const std::list& menu, item = subitem; } - for (const auto & it : items) + for (const auto & it : items) { *item << it; + } } void PythonBaseWorkbench::removeContextMenu(const std::string& menu) const @@ -1131,14 +1149,14 @@ void PythonBaseWorkbench::clearContextMenu() void PythonBaseWorkbench::appendToolbar(const std::string& bar, const std::list& items) const { ToolBarItem* item = _toolBar->findItem(bar); - if (!item) - { + if (!item) { item = new ToolBarItem(_toolBar); item->setCommand(bar); } - for (const auto & it : items) + for (const auto & it : items) { *item << it; + } } void PythonBaseWorkbench::removeToolbar(const std::string& bar) const @@ -1153,20 +1171,20 @@ void PythonBaseWorkbench::removeToolbar(const std::string& bar) const void PythonBaseWorkbench::appendCommandbar(const std::string& bar, const std::list& items) const { ToolBarItem* item = _commandBar->findItem( bar ); - if ( !item ) - { + if (!item) { item = new ToolBarItem(_commandBar); item->setCommand(bar); } - for (const auto & it : items) + for (const auto & it : items) { *item << it; + } } void PythonBaseWorkbench::removeCommandbar(const std::string& bar) const { ToolBarItem* item = _commandBar->findItem(bar); - if ( item ) { + if (item) { _commandBar->removeItem(item); delete item; }