Gui: apply std::ranges

This commit is contained in:
bofdahof
2025-03-12 17:47:04 +10:00
committed by Chris Hennes
parent 8ba49db74e
commit cb5caf6765
15 changed files with 42 additions and 41 deletions

View File

@@ -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;
}

View File

@@ -106,9 +106,8 @@ void StdCmdOpen::activated(int iMsg)
formatList += QLatin1String(" (");
std::vector<std::string> filetypes = App::GetApplication().getImportTypes();
std::vector<std::string>::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();

View File

@@ -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);
}
}

View File

@@ -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)

View File

@@ -118,7 +118,7 @@ struct DocumentP
std::map<SoSeparator *,ViewProviderDocumentObject*> _CoinMap;
std::map<std::string,ViewProvider*> _ViewProviderMapAnnotation;
std::list<ViewProviderDocumentObject*> _redoViewProviders;
using Connection = boost::signals2::connection;
Connection connectNewObject;
Connection connectDelObject;
@@ -2483,11 +2483,11 @@ void Document::setActiveWindow(Gui::MDIView* view)
std::list<MDIView*> 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);

View File

@@ -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();
}

View File

@@ -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();
}
}

View File

@@ -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()

View File

@@ -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");
}

View File

@@ -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);

View File

@@ -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::vector<App:
}
}
else {
if (std::find(draggedObjects.begin(), draggedObjects.end(), obj) == draggedObjects.end()) {
if (std::ranges::find(draggedObjects, obj) == draggedObjects.end()) {
sortedObjList.push_back(obj);
}
}
@@ -2908,7 +2908,7 @@ void TreeWidget::onOpenFileLocation()
}
param += QDir::toNativeSeparators(filePath);
success = QProcess::startDetached(QStringLiteral("explorer.exe"), param);
#else
#else
success = QProcess::startDetached(QStringLiteral("xdg-open"), {filePath});
#endif
@@ -4992,8 +4992,9 @@ DocumentObjectItem* DocumentItem::findItem(
else {
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;
}
@@ -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;

View File

@@ -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;
}

View File

@@ -164,7 +164,7 @@ void ViewProviderVRMLObject::addResource(const SbString& url, std::list<std::str
Base::FileInfo fi(found.getString());
if (fi.exists()) {
// add the resource file if not yet listed
if (std::find(resources.begin(), resources.end(), found.getString()) == resources.end()) {
if (std::ranges::find(resources, found.getString()) == resources.end()) {
resources.emplace_back(found.getString());
}
}
@@ -186,7 +186,7 @@ void ViewProviderVRMLObject::getLocalResources(SoNode* node, std::list<std::stri
const SbString& url = vrml->getFullURLName();
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());
}

View File

@@ -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<App::Property*>::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

View File

@@ -199,7 +199,7 @@ const std::vector<App::Property*>& 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);
}