From 90c296af6b705d61ee357e83eddae05b74488e63 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 2 Apr 2023 12:06:08 +0200 Subject: [PATCH] Sketcher: fix some lint warnings --- src/Gui/ToolBarManager.cpp | 57 ++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/src/Gui/ToolBarManager.cpp b/src/Gui/ToolBarManager.cpp index 02dbd12648..185aa45d92 100644 --- a/src/Gui/ToolBarManager.cpp +++ b/src/Gui/ToolBarManager.cpp @@ -43,8 +43,9 @@ ToolBarItem::ToolBarItem() : visibility(HideStyle::VISIBLE) ToolBarItem::ToolBarItem(ToolBarItem* item, HideStyle visibility) : visibility(visibility) { - if ( item ) + if (item) { item->appendItem(this); + } } ToolBarItem::~ToolBarItem() @@ -71,11 +72,11 @@ ToolBarItem* ToolBarItem::findItem(const std::string& name) { if ( _name == name ) { return this; - } else { - for ( QList::Iterator it = _items.begin(); it != _items.end(); ++it ) { - if ( (*it)->_name == name ) { - return *it; - } + } + + for (auto it : qAsConst(_items)) { + if (it->_name == name) { + return it; } } @@ -88,8 +89,8 @@ ToolBarItem* ToolBarItem::copy() const root->setCommand( command() ); QList items = getItems(); - for ( QList::Iterator it = items.begin(); it != items.end(); ++it ) { - root->appendItem( (*it)->copy() ); + for (auto it : items) { + root->appendItem(it->copy()); } return root; @@ -111,21 +112,23 @@ bool ToolBarItem::insertItem( ToolBarItem* before, ToolBarItem* item) if (pos != -1) { _items.insert(pos, item); return true; - } else - return false; + } + + return false; } void ToolBarItem::removeItem(ToolBarItem* item) { int pos = _items.indexOf(item); - if (pos != -1) + if (pos != -1) { _items.removeAt(pos); + } } void ToolBarItem::clear() { - for ( QList::Iterator it = _items.begin(); it != _items.end(); ++it ) { - delete *it; + for (auto it : qAsConst(_items)) { + delete it; } _items.clear(); @@ -174,11 +177,9 @@ ToolBarManager::~ToolBarManager() { } -void ToolBarManager::setup(ToolBarItem* toolBarItems) +namespace { +QPointer createActionWidget() { - if (!toolBarItems) - return; // empty menu bar - static QPointer _ActionWidget; if (!_ActionWidget) { _ActionWidget = new QWidget(getMainWindow()); @@ -192,10 +193,23 @@ void ToolBarManager::setup(ToolBarItem* toolBarItems) _ActionWidget->move(QPoint(-100,-100)); } else { - for (auto action : _ActionWidget->actions()) + auto actions = _ActionWidget->actions(); + for (auto action : actions) { _ActionWidget->removeAction(action); + } } + return _ActionWidget; +} +} + +void ToolBarManager::setup(ToolBarItem* toolBarItems) +{ + if (!toolBarItems) + return; // empty menu bar + + QPointer _ActionWidget = createActionWidget(); + saveState(); this->toolbarNames.clear(); @@ -242,7 +256,8 @@ void ToolBarManager::setup(ToolBarItem* toolBarItems) // setup the toolbar setup(*it, toolbar); - for (auto action : toolbar->actions()) { + auto actions = toolbar->actions(); + for (auto action : actions) { _ActionWidget->addAction(action); } @@ -274,7 +289,7 @@ void ToolBarManager::setup(ToolBarItem* toolBarItems) fw = fw->parentWidget(); } // ignore toolbars which do not belong to the previously active workbench - QByteArray toolbarName = (*it)->objectName().toUtf8(); + //QByteArray toolbarName = (*it)->objectName().toUtf8(); if (!(*it)->toggleViewAction()->isVisible()) continue; //hPref->SetBool(toolbarName.constData(), (*it)->isVisible()); @@ -341,7 +356,7 @@ void ToolBarManager::saveState() const } // If hide style is FORCE_HIDE then never save the state because it's - // alwas controlled by the application. + // always controlled by the application. auto value = static_cast(property.toInt()); return value == ToolBarItem::HideStyle::FORCE_HIDE; };