diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index 0a400c6690..fb4820fc6b 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -498,7 +498,8 @@ void Command::testActive(void) Gui::ActionGroup* pcAction = qobject_cast(_pcAction); if(pcAction) { Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); - for(auto action : pcAction->actions()) { + const auto actions = pcAction->actions(); + for(auto action : actions) { auto name = action->property("CommandName").toByteArray(); if(!name.size()) continue; diff --git a/src/Gui/CommandLink.cpp b/src/Gui/CommandLink.cpp index 56f597e0b3..824389343e 100644 --- a/src/Gui/CommandLink.cpp +++ b/src/Gui/CommandLink.cpp @@ -755,7 +755,8 @@ void StdCmdLinkSelectLinked::activated(int) doc->setActiveView(vp); } } else { - for(auto tree : getMainWindow()->findChildren()) + const auto trees = getMainWindow()->findChildren(); + for(auto tree : trees) tree->selectLinkedObject(linked); } Selection().selStackPush(); @@ -790,7 +791,8 @@ void StdCmdLinkSelectLinkedFinal::activated(int) { } Selection().selStackPush(); Selection().clearCompleteSelection(); - for(auto tree : getMainWindow()->findChildren()) + const auto trees = getMainWindow()->findChildren(); + for(auto tree : trees) tree->selectLinkedObject(linked); Selection().selStackPush(); } @@ -825,7 +827,8 @@ void StdCmdLinkSelectAllLinks::activated(int) return; Selection().selStackPush(); Selection().clearCompleteSelection(); - for(auto tree : getMainWindow()->findChildren()) + const auto trees = getMainWindow()->findChildren(); + for(auto tree : trees) tree->selectAllLinks(sels[0].pObject); Selection().selStackPush(); } diff --git a/src/Gui/CommandPyImp.cpp b/src/Gui/CommandPyImp.cpp index 99064c72b0..6982168317 100644 --- a/src/Gui/CommandPyImp.cpp +++ b/src/Gui/CommandPyImp.cpp @@ -309,7 +309,8 @@ PyObject* CommandPy::getAction(PyObject *args) Py::List list; if (group) { - for (auto a : group->actions()) + const auto actions = group->actions(); + for (auto a : actions) list.append(wrap.fromQObject(a)); } else if (action) { diff --git a/src/Gui/CommandView.cpp b/src/Gui/CommandView.cpp index a86e805432..554f76add6 100644 --- a/src/Gui/CommandView.cpp +++ b/src/Gui/CommandView.cpp @@ -3013,7 +3013,8 @@ void StdCmdTreeSelectAllInstances::activated(int iMsg) return; Selection().selStackPush(); Selection().clearCompleteSelection(); - for(auto tree : getMainWindow()->findChildren()) + const auto trees = getMainWindow()->findChildren(); + for(auto tree : trees) tree->selectAllInstances(*vpd); Selection().selStackPush(); } @@ -3521,7 +3522,8 @@ StdTreeDrag::StdTreeDrag() void StdTreeDrag::activated(int) { if(Gui::Selection().hasSelection()) { - for(auto tree : getMainWindow()->findChildren()) { + const auto trees = getMainWindow()->findChildren(); + for(auto tree : trees) { if(tree->isVisible()) { tree->startDragging(); break; diff --git a/src/Gui/DlgObjectSelection.cpp b/src/Gui/DlgObjectSelection.cpp index efe75080c1..17f6b485ef 100644 --- a/src/Gui/DlgObjectSelection.cpp +++ b/src/Gui/DlgObjectSelection.cpp @@ -365,7 +365,8 @@ void DlgObjectSelection::onDepItemChanged(QTreeWidgetItem * depItem, int column) QSignalBlocker blocker3(ui->treeWidget); auto state = depItem->checkState(0); if (depItem->isSelected()) { - for (auto item : depItem->treeWidget()->selectedItems()) { + const auto items = depItem->treeWidget()->selectedItems(); + for (auto item : items) { auto objT = qvariant_cast(item->data(0, Qt::UserRole)); auto it = itemMap.find(objT); if (it == itemMap.end()) @@ -437,7 +438,8 @@ void DlgObjectSelection::onObjItemChanged(QTreeWidgetItem * objItem, int column) onItemSelectionChanged(); } else { - for (auto item : ui->treeWidget->selectedItems()) { + const auto items = ui->treeWidget->selectedItems(); + for (auto item : items) { setCheckState(item, state); itemChanged[qvariant_cast(item->data(0, Qt::UserRole))] = state; } @@ -552,7 +554,8 @@ void DlgObjectSelection::onItemSelectionChanged() { inMap.clear(); std::vector sels; - for (auto item : ui->treeWidget->selectedItems()) { + const auto items = ui->treeWidget->selectedItems(); + for (auto item : items) { if (item == allItem) { sels.clear(); break; diff --git a/src/Gui/DlgParameterImp.cpp b/src/Gui/DlgParameterImp.cpp index 543ad7376a..147b2915a5 100644 --- a/src/Gui/DlgParameterImp.cpp +++ b/src/Gui/DlgParameterImp.cpp @@ -145,7 +145,7 @@ void DlgParameterImp::on_findGroupLE_textChanged(const QString &SearchStr) // at first reset all items to the default font and expand state if (foundList.size() > 0) { - for (QTreeWidgetItem* item : foundList) { + for (QTreeWidgetItem* item : qAsConst(foundList)) { item->setFont(0, defaultFont); item->setForeground(0, defaultColor); ExpandItem = item; @@ -176,7 +176,7 @@ void DlgParameterImp::on_findGroupLE_textChanged(const QString &SearchStr) // reset background style sheet if (!ui->findGroupLE->styleSheet().isEmpty()) ui->findGroupLE->setStyleSheet(QString()); - for (QTreeWidgetItem* item : foundList) { + for (QTreeWidgetItem* item : qAsConst(foundList)) { item->setFont(0, boldFont); item->setForeground(0, Qt::red); // expand its parent to see the item diff --git a/src/Gui/DlgPropertyLink.cpp b/src/Gui/DlgPropertyLink.cpp index 5ee99da6b2..ded629e71b 100644 --- a/src/Gui/DlgPropertyLink.cpp +++ b/src/Gui/DlgPropertyLink.cpp @@ -161,9 +161,9 @@ QString DlgPropertyLink::formatObject(App::Document *ownerDoc, App::DocumentObje QString::fromUtf8(sobj->Label.getValue())); } -static inline bool isLinkSub(QList links) +static inline bool isLinkSub(const QList& links) { - for(auto &link : links) { + for(const auto &link : links) { if(&link == &links.front()) continue; if(link.getDocumentName() != links.front().getDocumentName() @@ -353,7 +353,7 @@ void DlgPropertyLink::init(const App::DocumentObjectT &prop, bool tryFilter) { // For link list type property, try to auto filter type if(tryFilter && isLinkList) { Base::Type objType; - for(const auto& link : oldLinks) { + for(const auto& link : qAsConst(oldLinks)) { auto obj = link.getSubObject(); if(!obj) continue; @@ -534,7 +534,8 @@ void DlgPropertyLink::onItemSelectionChanged() // Enforce single parent if(singleParent && currentObj && currentObj!=obj) { ui->treeWidget->blockSignals(true); - for(auto item : ui->treeWidget->selectedItems()) { + const auto items = ui->treeWidget->selectedItems(); + for(auto item : items) { if(item != selections.back()) item->setSelected(false); } @@ -707,7 +708,8 @@ DlgPropertyLink::getLinkFromItem(QTreeWidgetItem *item, bool needSubName) const return res; } - for(const QString &element : elements.split(QLatin1Char(','))) { + const auto split = elements.split(QLatin1Char(',')); + for(const QString &element : split) { res.append(App::SubObjectT()); res.last() = App::SubObjectT(sobj.getDocumentName().c_str(), sobj.getObjectName().c_str(), @@ -1052,7 +1054,8 @@ void DlgPropertyLink::on_checkObjectType_toggled(bool on) void DlgPropertyLink::on_typeTree_itemSelectionChanged() { selectedTypes.clear(); - for(auto item : ui->typeTree->selectedItems()) + const auto items = ui->typeTree->selectedItems(); + for(auto item : items) selectedTypes.insert(item->data(0, Qt::UserRole).toByteArray()); if(ui->checkObjectType->isChecked()) diff --git a/src/Gui/DlgSettingsCacheDirectory.cpp b/src/Gui/DlgSettingsCacheDirectory.cpp index 295d5f7ba6..eda5e9f2cb 100644 --- a/src/Gui/DlgSettingsCacheDirectory.cpp +++ b/src/Gui/DlgSettingsCacheDirectory.cpp @@ -301,14 +301,16 @@ qint64 ApplicationCache::dirSize(QString dirPath) const QDir dir(dirPath); QDir::Filters fileFilters = QDir::Files; - for (QString filePath : dir.entryList(fileFilters)) { + const auto& files = dir.entryList(fileFilters); + for (const QString& filePath : files) { QFileInfo fi(dir, filePath); total += fi.size(); } // traverse sub-directories recursively QDir::Filters dirFilters = QDir::Dirs | QDir::NoDotAndDotDot; - for (QString subDirPath : dir.entryList(dirFilters)) + const auto& dirs = dir.entryList(dirFilters); + for (const QString& subDirPath : dirs) total += dirSize(dirPath + QDir::separator() + subDirPath); return total; } diff --git a/src/Gui/DocumentRecovery.cpp b/src/Gui/DocumentRecovery.cpp index 0305ddea48..978b62abdd 100644 --- a/src/Gui/DocumentRecovery.cpp +++ b/src/Gui/DocumentRecovery.cpp @@ -723,7 +723,7 @@ void DocumentRecoveryCleaner::subtractFiles(QStringList& files) void DocumentRecoveryCleaner::subtractDirs(QFileInfoList& dirs) { if (!ignoreDirs.isEmpty() && !dirs.isEmpty()) { - for (const auto& it : ignoreDirs) { + for (const auto& it : qAsConst(ignoreDirs)) { dirs.removeOne(it); } } diff --git a/src/Gui/Language/Translator.cpp b/src/Gui/Language/Translator.cpp index 935532511f..c30fb56661 100644 --- a/src/Gui/Language/Translator.cpp +++ b/src/Gui/Language/Translator.cpp @@ -213,7 +213,7 @@ TStringMap Translator::supportedLocales() const // List all .qm files for (const auto& domainMap : d->mapLanguageTopLevelDomain) { - for (const auto& directoryName : d->paths) { + for (const auto& directoryName : qAsConst(d->paths)) { QDir dir(directoryName); QString filter = QString::fromLatin1("*_%1.qm").arg(QString::fromStdString(domainMap.second)); QStringList fileNames = dir.entryList(QStringList(filter), QDir::Files, QDir::Name); diff --git a/src/Gui/PropertyView.cpp b/src/Gui/PropertyView.cpp index 5426716f58..0106505e4a 100644 --- a/src/Gui/PropertyView.cpp +++ b/src/Gui/PropertyView.cpp @@ -161,7 +161,8 @@ bool PropertyView::showAll() { void PropertyView::setShowAll(bool enable) { if(_ShowAll != enable) { _ShowAll = enable; - for(auto view : getMainWindow()->findChildren()) { + const auto views = getMainWindow()->findChildren(); + for(auto view : views) { if(view->isVisible()) { view->propertyEditorData->buildUp(); view->propertyEditorView->buildUp(); diff --git a/src/Gui/TaskElementColors.cpp b/src/Gui/TaskElementColors.cpp index 40a9007556..dfdd396d26 100644 --- a/src/Gui/TaskElementColors.cpp +++ b/src/Gui/TaskElementColors.cpp @@ -215,7 +215,8 @@ public: } void removeItems() { - for(auto item : ui->elementList->selectedItems()) { + const auto items = ui->elementList->selectedItems(); + for(auto item : items) { std::string sub = qPrintable(item->data(Qt::UserRole+1).value()); if(sub == hiddenSub) hiddenSub.clear(); @@ -259,8 +260,8 @@ public: editObj == msg.pObjectName && boost::starts_with(msg.pSubName,editSub)) { - for(auto item : ui->elementList->findItems( - QString::fromLatin1(msg.pSubName-editSub.size()), Qt::MatchExactly)) + const auto items = ui->elementList->findItems(QString::fromLatin1(msg.pSubName-editSub.size()), Qt::MatchExactly); + for(auto item : items) item->setSelected(msg.Type==SelectionChanges::AddSelection); } } @@ -285,7 +286,8 @@ public: } break; } - for(auto item : ui->elementList->selectedItems()) { + const auto items = ui->elementList->selectedItems(); + for(auto item : items) { std::string name(qPrintable(item->data(Qt::UserRole+1).value())); if(ViewProvider::hasHiddenMarker(name.c_str())) continue; diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 1b97a19291..16a9fc1398 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -1158,7 +1158,8 @@ void TreeWidget::onMarkRecompute() void TreeWidget::onRecomputeObject() { std::vector objs; - for (auto ti : selectedItems()) { + const auto items = selectedItems(); + for (auto ti : items) { if (ti->type() == ObjectType) { DocumentObjectItem* objitem = static_cast(ti); objs.push_back(objitem->object()->getObject()); @@ -1224,8 +1225,10 @@ std::vector TreeWidget::getSelection(App::Document* doc) else tree->_updateStatus(false); - for (auto ti : tree->selectedItems()) { - if (ti->type() != ObjectType) continue; + const auto items = tree->selectedItems(); + for (auto ti : items) { + if (ti->type() != ObjectType) + continue; auto item = static_cast(ti); auto vp = item->object(); auto obj = vp->getObject(); @@ -2736,7 +2739,8 @@ void TreeWidget::expandSelectedItems(TreeItemMode mode) if (!isSelectionAttached()) return; - for (auto item : selectedItems()) { + const auto items = selectedItems(); + for (auto item : items) { switch (mode) { case TreeItemMode::ExpandPath: { QTreeWidgetItem* parentItem = item->parent(); diff --git a/src/Gui/ViewProviderLink.cpp b/src/Gui/ViewProviderLink.cpp index 9950a04c96..f007503608 100644 --- a/src/Gui/ViewProviderLink.cpp +++ b/src/Gui/ViewProviderLink.cpp @@ -2582,7 +2582,8 @@ void ViewProviderLink::_setupContextMenu( || (ext->getLinkPlacementProperty() && !ext->getLinkPlacementProperty()->isReadOnly())) { bool found = false; - for(auto action : menu->actions()) { + const auto actions = menu->actions(); + for(auto action : actions) { if(action->data().toInt() == ViewProvider::Transform) { found = true; break; @@ -2598,7 +2599,8 @@ void ViewProviderLink::_setupContextMenu( if(ext->getColoredElementsProperty()) { bool found = false; - for(auto action : menu->actions()) { + const auto actions = menu->actions(); + for(auto action : actions) { if(action->data().toInt() == ViewProvider::Color) { action->setText(QObject::tr("Override colors...")); found = true; diff --git a/src/Gui/Widgets.cpp b/src/Gui/Widgets.cpp index 7534ee1156..57ef33d64c 100644 --- a/src/Gui/Widgets.cpp +++ b/src/Gui/Widgets.cpp @@ -1671,7 +1671,8 @@ ButtonGroup::ButtonGroup(QObject *parent) connect(this, qOverload(&QButtonGroup::buttonClicked), [=](QAbstractButton *button) { if (exclusive()) { - for (auto btn : buttons()) { + const auto btns = buttons(); + for (auto btn : btns) { if (btn && btn != button && btn->isCheckable()) btn->setChecked(false); } diff --git a/src/Gui/propertyeditor/PropertyEditor.cpp b/src/Gui/propertyeditor/PropertyEditor.cpp index fb12f727dd..c7d9af522b 100644 --- a/src/Gui/propertyeditor/PropertyEditor.cpp +++ b/src/Gui/propertyeditor/PropertyEditor.cpp @@ -624,7 +624,8 @@ void PropertyEditor::contextMenuEvent(QContextMenuEvent *) { auto contextIndex = currentIndex(); std::unordered_set props; - for(auto index : selectedIndexes()) { + const auto indexes = selectedIndexes(); + for(const auto& index : indexes) { auto item = static_cast(index.internalPointer()); if(item->isSeparator()) continue; diff --git a/src/Gui/propertyeditor/PropertyItemDelegate.cpp b/src/Gui/propertyeditor/PropertyItemDelegate.cpp index 616c428e65..41539dbae2 100644 --- a/src/Gui/propertyeditor/PropertyItemDelegate.cpp +++ b/src/Gui/propertyeditor/PropertyItemDelegate.cpp @@ -193,7 +193,8 @@ QWidget * PropertyItemDelegate::createEditor (QWidget * parent, const QStyleOpti this->pressed = false; if (editor) { - for (auto w : editor->findChildren()) { + const auto widgets = editor->findChildren(); + for (auto w : widgets) { if (qobject_cast(w) || qobject_cast(w)) {