From cb5caf676557a81e55ddf57d65c2e3c47ae4e78a Mon Sep 17 00:00:00 2001 From: bofdahof <172177156+bofdahof@users.noreply.github.com> Date: Wed, 12 Mar 2025 17:47:04 +1000 Subject: [PATCH] Gui: apply std::ranges --- src/Gui/ApplicationPy.cpp | 2 +- src/Gui/CommandDoc.cpp | 5 ++--- src/Gui/CommandView.cpp | 2 +- .../Dialogs/DlgCreateNewPreferencePackImp.cpp | 6 +++--- src/Gui/Document.cpp | 6 +++--- src/Gui/DocumentRecovery.cpp | 4 ++-- src/Gui/Language/Translator.cpp | 2 +- src/Gui/PrefWidgets.cpp | 13 +++++++------ src/Gui/PreferencePages/DlgSettingsGeneral.cpp | 4 ++-- .../DlgSettingsWorkbenchesImp.cpp | 10 +++++----- src/Gui/Tree.cpp | 17 +++++++++-------- src/Gui/ViewProviderGroupExtension.cpp | 2 +- src/Gui/ViewProviderVRMLObject.cpp | 4 ++-- src/Gui/propertyeditor/PropertyEditor.cpp | 2 +- src/Gui/propertyeditor/PropertyItem.cpp | 4 ++-- 15 files changed, 42 insertions(+), 41 deletions(-) diff --git a/src/Gui/ApplicationPy.cpp b/src/Gui/ApplicationPy.cpp index 16dc543900..7a7185d432 100644 --- a/src/Gui/ApplicationPy.cpp +++ b/src/Gui/ApplicationPy.cpp @@ -1626,7 +1626,7 @@ PyObject* ApplicationPy::sGetMarkerIndex(PyObject * /*self*/, PyObject *args) //get the marker size auto sizeList = Gui::Inventor::MarkerBitmaps::getSupportedSizes(marker_arg); - if (std::find(std::begin(sizeList), std::end(sizeList), defSize) == std::end(sizeList)) { + if (std::ranges::find(sizeList, defSize) == std::end(sizeList)) { defSize = defaultSize; } diff --git a/src/Gui/CommandDoc.cpp b/src/Gui/CommandDoc.cpp index 8ed8880d7e..548bd3b662 100644 --- a/src/Gui/CommandDoc.cpp +++ b/src/Gui/CommandDoc.cpp @@ -106,9 +106,8 @@ void StdCmdOpen::activated(int iMsg) formatList += QLatin1String(" ("); std::vector filetypes = App::GetApplication().getImportTypes(); - std::vector::iterator it; // Make sure FCStd is the very first fileformat - it = std::find(filetypes.begin(), filetypes.end(), "FCStd"); + auto it = std::ranges::find(filetypes, "FCStd"); if (it != filetypes.end()) { filetypes.erase(it); filetypes.insert(filetypes.begin(), "FCStd"); @@ -498,7 +497,7 @@ void StdCmdExport::activated(int iMsg) lastExportUsedGeneratedFilename = true; else lastExportUsedGeneratedFilename = false; - + lastExportFullPath = fileName; lastActiveDocument = getActiveGuiDocument(); lastExportedObject = selection.front(); diff --git a/src/Gui/CommandView.cpp b/src/Gui/CommandView.cpp index 04fe6742ae..b2c6ef13e0 100644 --- a/src/Gui/CommandView.cpp +++ b/src/Gui/CommandView.cpp @@ -948,7 +948,7 @@ void StdCmdToggleTransparency::activated(int iMsg) } } - if (std::find(views.begin(), views.end(), view) == views.end()) { + if (std::ranges::find(views, view) == views.end()) { views.push_back(view); } } diff --git a/src/Gui/Dialogs/DlgCreateNewPreferencePackImp.cpp b/src/Gui/Dialogs/DlgCreateNewPreferencePackImp.cpp index a811b78e49..565723900e 100644 --- a/src/Gui/Dialogs/DlgCreateNewPreferencePackImp.cpp +++ b/src/Gui/Dialogs/DlgCreateNewPreferencePackImp.cpp @@ -166,9 +166,9 @@ void DlgCreateNewPreferencePackImp::onBrowseButtonClicked() void Gui::Dialog::DlgCreateNewPreferencePackImp::accept() { // Ensure that the chosen name is either unique, or that the user actually wants to overwrite the old one - if (auto chosenName = ui->lineEdit->text().toStdString(); - std::find(_existingPackNames.begin(), _existingPackNames.end(), chosenName) != _existingPackNames.end()) { - auto result = QMessageBox::warning(this, tr("Pack already exists"), + if (const auto chosenName = ui->lineEdit->text().toStdString(); + std::ranges::find(_existingPackNames, chosenName) != _existingPackNames.end()) { + const auto result = QMessageBox::warning(this, tr("Pack already exists"), tr("A preference pack with that name already exists. Do you want to overwrite it?"), QMessageBox::Yes | QMessageBox::Cancel); if (result == QMessageBox::Cancel) diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index 18b71de9c9..f1207b0cbf 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -118,7 +118,7 @@ struct DocumentP std::map _CoinMap; std::map _ViewProviderMapAnnotation; std::list _redoViewProviders; - + using Connection = boost::signals2::connection; Connection connectNewObject; Connection connectDelObject; @@ -2483,11 +2483,11 @@ void Document::setActiveWindow(Gui::MDIView* view) std::list mdis = getMDIViews(); // this document is not active - if (std::find(mdis.begin(), mdis.end(), active) == mdis.end()) + if (std::ranges::find(mdis, active) == mdis.end()) return; // the view is not part of the document - if (std::find(mdis.begin(), mdis.end(), view) == mdis.end()) + if (std::ranges::find(mdis, view) == mdis.end()) return; getMainWindow()->setActiveWindow(view); diff --git a/src/Gui/DocumentRecovery.cpp b/src/Gui/DocumentRecovery.cpp index e4ae5a94b0..be3f7d7685 100644 --- a/src/Gui/DocumentRecovery.cpp +++ b/src/Gui/DocumentRecovery.cpp @@ -483,8 +483,8 @@ DocumentRecoveryPrivate::XmlConfig DocumentRecoveryPrivate::readXmlFile(const QS child = root.firstChildElement(); while (!child.isNull()) { QString name = child.localName(); - QString value = child.text(); - if (std::find(filter.begin(), filter.end(), name) != filter.end()) + const QString value = child.text(); + if (std::ranges::find(filter, name) != filter.end()) cfg[name] = value; child = child.nextSiblingElement(); } diff --git a/src/Gui/Language/Translator.cpp b/src/Gui/Language/Translator.cpp index cdfd257a4c..3955a2a887 100644 --- a/src/Gui/Language/Translator.cpp +++ b/src/Gui/Language/Translator.cpp @@ -240,7 +240,7 @@ void Translator::activateLanguage (const char* lang) removeTranslators(); // remove the currently installed translators d->activatedLanguage = lang; TStringList languages = supportedLanguages(); - if (std::find(languages.begin(), languages.end(), lang) != languages.end()) { + if (std::ranges::find(languages, lang) != languages.end()) { refresh(); } } diff --git a/src/Gui/PrefWidgets.cpp b/src/Gui/PrefWidgets.cpp index c3e69656bd..f43a7650da 100644 --- a/src/Gui/PrefWidgets.cpp +++ b/src/Gui/PrefWidgets.cpp @@ -218,7 +218,7 @@ void PrefDoubleSpinBox::wheelEvent(QWheelEvent *event) if (hasFocus()) QDoubleSpinBox::wheelEvent(event); else - event->ignore(); + event->ignore(); } PrefDoubleSpinBox::~PrefDoubleSpinBox() = default; @@ -358,7 +358,7 @@ void PrefComboBox::wheelEvent(QWheelEvent *event) if (hasFocus()) QComboBox::wheelEvent(event); else - event->ignore(); + event->ignore(); } PrefComboBox::~PrefComboBox() = default; @@ -601,7 +601,7 @@ void PrefUnitSpinBox::wheelEvent(QWheelEvent *event) if (hasFocus()) QuantitySpinBox::wheelEvent(event); else - event->ignore(); + event->ignore(); } PrefUnitSpinBox::~PrefUnitSpinBox() = default; @@ -650,9 +650,10 @@ public: list.clear(); } void append(const QString& value) { - if (!list.isEmpty() && list.back() == value) + if (!list.isEmpty() && list.back() == value) { return; - auto it = std::find(list.begin(), list.end(), value); + } + const auto it = std::ranges::find(list, value); if (it != list.end()) list.erase(it); else if (list.size() == max_size) @@ -750,7 +751,7 @@ void PrefQuantitySpinBox::wheelEvent(QWheelEvent *event) if (hasFocus()) QuantitySpinBox::wheelEvent(event); else - event->ignore(); + event->ignore(); } void PrefQuantitySpinBox::restorePreferences() diff --git a/src/Gui/PreferencePages/DlgSettingsGeneral.cpp b/src/Gui/PreferencePages/DlgSettingsGeneral.cpp index 48a0a25855..1ad45f53d6 100644 --- a/src/Gui/PreferencePages/DlgSettingsGeneral.cpp +++ b/src/Gui/PreferencePages/DlgSettingsGeneral.cpp @@ -745,7 +745,7 @@ void DlgSettingsGeneral::onImportConfigClicked() auto packName = path.filename().stem().string(); std::replace(packName.begin(), packName.end(), '_', ' '); auto existingPacks = Application::Instance->prefPackManager()->preferencePackNames(); - if (std::find(existingPacks.begin(), existingPacks.end(), packName) + if (std::ranges::find(existingPacks, packName) != existingPacks.end()) { auto result = QMessageBox::question( this, tr("File exists"), @@ -803,7 +803,7 @@ void DlgSettingsGeneral::onLinkActivated(const QString& link) // This is a quick and dirty way to open Addon Manager with only themes. auto pref = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Addons"); pref->SetInt("PackageTypeSelection", 3); // 3 stands for Preference Packs - pref->SetInt("StatusSelection", 0); // 0 stands for any installation status + pref->SetInt("StatusSelection", 0); // 0 stands for any installation status Gui::Application::Instance->commandManager().runCommandByName("Std_AddonMgr"); } diff --git a/src/Gui/PreferencePages/DlgSettingsWorkbenchesImp.cpp b/src/Gui/PreferencePages/DlgSettingsWorkbenchesImp.cpp index 99b15a0659..e030f3c51a 100644 --- a/src/Gui/PreferencePages/DlgSettingsWorkbenchesImp.cpp +++ b/src/Gui/PreferencePages/DlgSettingsWorkbenchesImp.cpp @@ -400,12 +400,12 @@ void DlgSettingsWorkbenchesImp::buildWorkbenchList() void DlgSettingsWorkbenchesImp::addWorkbench(const QString& wbName, bool enabled) { - bool isStartupWb = wbName.toStdString() == _startupModule; - bool autoLoad = std::find(_backgroundAutoloadedModules.begin(), _backgroundAutoloadedModules.end(), - wbName.toStdString()) != _backgroundAutoloadedModules.end(); - wbListItem* widget = new wbListItem(wbName, enabled, isStartupWb, autoLoad, ui->wbList->count(), this); + const bool isStartupWb = wbName.toStdString() == _startupModule; + const bool autoLoad = std::ranges::find(_backgroundAutoloadedModules, wbName.toStdString()) + != _backgroundAutoloadedModules.end(); + const auto widget = new wbListItem(wbName, enabled, isStartupWb, autoLoad, ui->wbList->count(), this); connect(widget, &wbListItem::wbToggled, this, &DlgSettingsWorkbenchesImp::wbToggled); - auto wItem = new QListWidgetItem(); + const auto wItem = new QListWidgetItem(); wItem->setSizeHint(widget->sizeHint()); ui->wbList->addItem(wItem); ui->wbList->setItemWidget(wItem, widget); diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index d66c28e00b..77adeb35ee 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -101,7 +101,7 @@ static bool isVisibilityIconEnabled() { } static bool isOnlyNameColumnDisplayed() { - return TreeParams::getHideInternalNames() + return TreeParams::getHideInternalNames() && TreeParams::getHideColumn(); } @@ -488,7 +488,7 @@ void TreeWidgetItemDelegate::paint(QPainter *painter, // If only the first column is shown, we'll trim the color background when // rendering as transparent overlay. - bool trimColumnSize = isOnlyNameColumnDisplayed(); + bool trimColumnSize = isOnlyNameColumnDisplayed(); if (index.column() == 0) { if (tree->testAttribute(Qt::WA_NoSystemBackground) @@ -550,7 +550,7 @@ public: QSize sizeHint() const override { - QSize size = QLineEdit::sizeHint(); + QSize size = QLineEdit::sizeHint(); QFontMetrics fm(font()); int availableWidth = parentWidget()->width() - geometry().x(); // Calculate available width int margin = 2 * (style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1) @@ -2779,7 +2779,7 @@ void TreeWidget::sortDroppedObjects(TargetItemInfo& targetInfo, std::vectorselected += 2; - if (std::find(item->mySubs.begin(), item->mySubs.end(), subname) == item->mySubs.end()) + if (std::ranges::find(item->mySubs, subname) == item->mySubs.end()) { item->mySubs.emplace_back(subname); + } } return item; } @@ -5006,7 +5007,7 @@ DocumentObjectItem* DocumentItem::findItem( TREE_LOG("sub object not found " << item->getName() << '.' << name.c_str()); if (select) { item->selected += 2; - if (std::find(item->mySubs.begin(), item->mySubs.end(), subname) == item->mySubs.end()) + if (std::ranges::find(item->mySubs, subname) == item->mySubs.end()) item->mySubs.emplace_back(subname); } return item; @@ -5051,7 +5052,7 @@ DocumentObjectItem* DocumentItem::findItem( // Select the current object instead. TREE_TRACE("element " << subname << " not found"); item->selected += 2; - if (std::find(item->mySubs.begin(), item->mySubs.end(), subname) == item->mySubs.end()) + if (std::ranges::find(item->mySubs, subname) == item->mySubs.end()) item->mySubs.emplace_back(subname); } return res; diff --git a/src/Gui/ViewProviderGroupExtension.cpp b/src/Gui/ViewProviderGroupExtension.cpp index e42bdacd4e..9fdc5f7c90 100644 --- a/src/Gui/ViewProviderGroupExtension.cpp +++ b/src/Gui/ViewProviderGroupExtension.cpp @@ -88,7 +88,7 @@ bool ViewProviderGroupExtension::extensionCanDropObject(App::DocumentObject* obj // Check for possible cyclic dependencies if we allowed to drop the object const auto& list = obj->getOutList(); - if (std::find(list.begin(), list.end(), extobj) != list.end()) { + if (std::ranges::find(list, extobj) != list.end()) { Base::Console().Warning("Do not add cyclic dependency to %s\n", extobj->Label.getValue()); return false; } diff --git a/src/Gui/ViewProviderVRMLObject.cpp b/src/Gui/ViewProviderVRMLObject.cpp index 0f106c69f1..0bf4f262d6 100644 --- a/src/Gui/ViewProviderVRMLObject.cpp +++ b/src/Gui/ViewProviderVRMLObject.cpp @@ -164,7 +164,7 @@ void ViewProviderVRMLObject::addResource(const SbString& url, std::listgetFullURLName(); if (url.getLength() > 0) { // add the resource file if not yet listed - if (std::find(resources.begin(), resources.end(), url.getString()) == resources.end()) { + if (std::ranges::find(resources, url.getString()) == resources.end()) { resources.emplace_back(url.getString()); } diff --git a/src/Gui/propertyeditor/PropertyEditor.cpp b/src/Gui/propertyeditor/PropertyEditor.cpp index 6dfa5db131..f36d561ce7 100644 --- a/src/Gui/propertyeditor/PropertyEditor.cpp +++ b/src/Gui/propertyeditor/PropertyEditor.cpp @@ -680,7 +680,7 @@ void PropertyEditor::removeProperty(const App::Property& prop) for (PropertyModel::PropertyList::iterator it = propList.begin(); it != propList.end(); ++it) { // find the given property in the list and remove it if it's there std::vector::iterator pos = - std::find(it->second.begin(), it->second.end(), &prop); + std::ranges::find(it->second, &prop); if (pos != it->second.end()) { it->second.erase(pos); // if the last property of this name is removed then also remove the whole group diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index d4aa272aae..c189c51a4e 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -199,7 +199,7 @@ const std::vector& PropertyItem::getPropertyData() const bool PropertyItem::hasProperty(const App::Property* prop) const { - auto it = std::find(propertyItems.begin(), propertyItems.end(), prop); + auto it = std::ranges::find(propertyItems, prop); return (it != propertyItems.end()); } @@ -210,7 +210,7 @@ void PropertyItem::assignProperty(const App::Property* prop) bool PropertyItem::removeProperty(const App::Property* prop) { - auto it = std::find(propertyItems.begin(), propertyItems.end(), prop); + auto it = std::ranges::find(propertyItems, prop); if (it != propertyItems.end()) { propertyItems.erase(it); }