Gui: use contains() and isEmpty() instead of count() where possible

This commit is contained in:
Benjamin Nauck
2025-03-10 21:39:54 +01:00
parent 02d095f6e2
commit df3c324b7d
16 changed files with 39 additions and 39 deletions

View File

@@ -2602,7 +2602,7 @@ App::Document* Application::reopen(App::Document* doc)
if (name == v.first->FileName.getValue()) {
doc = const_cast<App::Document*>(v.first);
}
if (untouchedDocs.count(v.second)) {
if (untouchedDocs.contains(v.second)) {
if (!v.second->isModified()) {
continue;
}

View File

@@ -1977,7 +1977,7 @@ const Command* Gui::CommandManager::checkAcceleratorForConflicts(const char* acc
if (newCombo.isEmpty())
return nullptr;
auto newSequence = QKeySequence::fromString(newCombo);
if (newSequence.count() == 0)
if (newSequence.isEmpty())
return nullptr;
// Does this command shortcut conflict with other commands already defined?
@@ -1998,7 +1998,7 @@ const Command* Gui::CommandManager::checkAcceleratorForConflicts(const char* acc
if (existingCombo.isEmpty())
continue;
auto existingSequence = QKeySequence::fromString(existingCombo);
if (existingSequence.count() == 0)
if (existingSequence.isEmpty())
continue;
// Exact match

View File

@@ -403,7 +403,7 @@ static void linkConvert(bool unlink) {
auto obj = info.obj.getObject();
if(!parent || !obj || !parentVp)
continue;
if(!recomputeSet.count(parent))
if(!recomputeSet.contains(parent))
recomputeSet.emplace(parent,parent);
auto doc = parent->getDocument();
App::DocumentObject *replaceObj;

View File

@@ -1096,7 +1096,7 @@ void Model::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
contextMenu.addAction(editingFinishedAction);
}
if (contextMenu.actions().count() > 0)
if (!contextMenu.actions().isEmpty())
contextMenu.exec(event->screenPos());
}

View File

@@ -280,7 +280,7 @@ void DlgObjectSelection::setItemState(App::DocumentObject *obj,
if (ui->checkBoxAutoDeps->isChecked() && state == Qt::Checked) {
// If an object is newly checked, check all its dependencies
for (auto o : obj->getOutListRecursive()) {
if (!depSet.count(o) || itemChanged.count(o))
if (!depSet.contains(o) || itemChanged.contains(o))
continue;
auto itItem = itemMap.find(o);
if (itItem == itemMap.end() || itItem->second[0]->checkState(0) == state)
@@ -304,7 +304,7 @@ void DlgObjectSelection::setItemState(App::DocumentObject *obj,
// If an object toggles state, we need to revisit all its in-list
// object to update the partial/full checked state.
for (auto o : obj->getInList()) {
if (!depSet.count(o) ||itemChanged.count(o))
if (!depSet.contains(o) || itemChanged.contains(o))
continue;
auto it = itemMap.find(o);
if (it == itemMap.end() || it->second[0]->checkState(0) == state)
@@ -312,7 +312,7 @@ void DlgObjectSelection::setItemState(App::DocumentObject *obj,
int count = 0;
int selcount = 0;
for (auto sibling : o->getOutList()) {
if (!depSet.count(sibling))
if (!depSet.contains(sibling))
continue;
++count;
auto it = itemMap.find(sibling);
@@ -511,7 +511,7 @@ void DlgObjectSelection::checkItemChanged() {
std::sort(outlist.begin(), outlist.end());
for (const auto &v : itemMap) {
if (itemChanged.count(v.first) == 0 && v.second[0]->checkState(0) == Qt::Unchecked)
if (!itemChanged.contains(v.first) && v.second[0]->checkState(0) == Qt::Unchecked)
continue;
if (auto obj = v.first.getObject()) {
if (!std::binary_search(outlist.begin(), outlist.end(), obj))
@@ -598,7 +598,7 @@ void DlgObjectSelection::onItemSelectionChanged() {
for (auto obj : sels)
obj->getInListEx(inlist, true);
for (auto it = inlist.begin(); it != inlist.end();) {
if (!depSet.count(*it) || std::binary_search(sels.begin(), sels.end(), *it))
if (!depSet.contains(*it) || std::binary_search(sels.begin(), sels.end(), *it))
it = inlist.erase(it);
else
++it;

View File

@@ -98,7 +98,7 @@ void DlgOnlineHelpImp::changeEvent(QEvent *e)
void DlgOnlineHelpImp::onLineEditDownloadFileNameSelected( const QString& url )
{
QDir dir(url);
if (dir.exists() && dir.count() == 0) {
if (dir.exists() && dir.isEmpty()) {
QMessageBox::critical(this, tr("Access denied"), tr("Access denied to '%1'\n\n"
"Specify another directory, please.").arg(url));
}

View File

@@ -1047,7 +1047,7 @@ void Document::slotChangedObject(const App::DocumentObject& Obj, const App::Prop
&& (Prop.isDerivedFrom<App::PropertyPlacement>()
// Issue ID 0004230 : getName() can return null in which case strstr() crashes
|| (Prop.getName() && strstr(Prop.getName(),"Scale")))
&& d->_editObjs.count(&Obj))
&& d->_editObjs.contains(&Obj))
{
Base::Matrix4D mat;
auto sobj = d->_editViewProviderParent->getObject()->getSubObject(
@@ -1294,7 +1294,7 @@ static bool checkCanonicalPath(const std::map<App::Document*, bool> &docs)
auto &d = paths[info.canonicalFilePath()];
d.push_back(doc);
if (!warn && d.size() > 1) {
if (docs.count(d.front()) || docs.count(d.back()))
if (docs.contains(d.front()) || docs.contains(d.back()))
warn = true;
}
}
@@ -1315,7 +1315,7 @@ static bool checkCanonicalPath(const std::map<App::Document*, bool> &docs)
for (auto &v : paths) {
if (v.second.size() <= 1) continue;
for (auto doc : v.second) {
if (docs.count(doc)) {
if (docs.contains(doc)) {
FC_WARN("Physical path: " << v.first.toUtf8().constData());
for (auto d : v.second)
FC_WARN(" Document: " << docName(d).toUtf8().constData()

View File

@@ -341,7 +341,7 @@ public:
if (idx >= 0 && idx < objSize) {
obj = objs[idx / 2];
// if they are in the ignore list skip
if (inList.count(obj)) {
if (inList.contains(obj)) {
return;
}
}
@@ -430,7 +430,7 @@ public:
const auto& objs = doc->getObjects();
objSize = (int)objs.size() * 2;
// if invalid index, or in the ignore list bail out
if (idx < 0 || idx >= objSize || inList.count(obj)) {
if (idx < 0 || idx >= objSize || inList.contains(obj)) {
return;
}
obj = objs[idx / 2];

View File

@@ -66,7 +66,7 @@ public:
Base::PyGILStateLocker lock;
PythonWrapper wrap;
wrap.loadWidgetsModule();
if (func.count("widget") == 0) {
if (!func.contains("widget")) {
throw Py::AttributeError("Object has no attribute 'widget'");
}
Py::Callable target(func.at("widget"));

View File

@@ -62,7 +62,7 @@ std::string MenuItem::command() const
bool MenuItem::hasItems() const
{
return _items.count() > 0;
return !_items.isEmpty();
}
MenuItem* MenuItem::findItem(const std::string& name)

View File

@@ -1179,7 +1179,7 @@ public:
if (dockWidget == dock
|| !dockWidget->isVisible()
|| dockWidget->isFloating()
|| _overlayMap.count(dockWidget))
|| _overlayMap.contains(dockWidget))
continue;
if (dockWidget->rect().contains(dockWidget->mapFromGlobal(pos))) {
dstDock = dockWidget;

View File

@@ -214,7 +214,7 @@ void PropertyView::slotRollback() {
void PropertyView::slotChangePropertyData(const App::Property& prop)
{
if (propertyEditorData->propOwners.count(prop.getContainer())) {
if (propertyEditorData->propOwners.contains(prop.getContainer())) {
propertyEditorData->updateProperty(prop);
timer->start(ViewParams::instance()->getPropertyViewTimer());
}
@@ -222,7 +222,7 @@ void PropertyView::slotChangePropertyData(const App::Property& prop)
void PropertyView::slotChangePropertyView(const Gui::ViewProvider&, const App::Property& prop)
{
if (propertyEditorView->propOwners.count(prop.getContainer())) {
if (propertyEditorView->propOwners.contains(prop.getContainer())) {
propertyEditorView->updateProperty(prop);
timer->start(ViewParams::instance()->getPropertyViewTimer());
}
@@ -239,8 +239,8 @@ void PropertyView::slotAppendDynamicProperty(const App::Property& prop)
return;
App::PropertyContainer* parent = prop.getContainer();
if (propertyEditorData->propOwners.count(parent)
|| propertyEditorView->propOwners.count(parent))
if (propertyEditorData->propOwners.contains(parent)
|| propertyEditorView->propOwners.contains(parent))
{
timer->start(ViewParams::instance()->getPropertyViewTimer());
}
@@ -249,9 +249,9 @@ void PropertyView::slotAppendDynamicProperty(const App::Property& prop)
void PropertyView::slotRemoveDynamicProperty(const App::Property& prop)
{
App::PropertyContainer* parent = prop.getContainer();
if(propertyEditorData->propOwners.count(parent))
if(propertyEditorData->propOwners.contains(parent))
propertyEditorData->removeProperty(prop);
else if(propertyEditorView->propOwners.count(parent))
else if(propertyEditorView->propOwners.contains(parent))
propertyEditorView->removeProperty(prop);
else
return;
@@ -261,13 +261,13 @@ void PropertyView::slotRemoveDynamicProperty(const App::Property& prop)
void PropertyView::slotChangePropertyEditor(const App::Document &, const App::Property& prop)
{
App::PropertyContainer* parent = prop.getContainer();
if (propertyEditorData->propOwners.count(parent)
|| propertyEditorView->propOwners.count(parent))
if (propertyEditorData->propOwners.contains(parent)
|| propertyEditorView->propOwners.contains(parent))
timer->start(ViewParams::instance()->getPropertyViewTimer());
}
void PropertyView::slotDeleteDocument(const Gui::Document &doc) {
if(propertyEditorData->propOwners.count(doc.getDocument())) {
if(propertyEditorData->propOwners.contains(doc.getDocument())) {
propertyEditorView->buildUp();
propertyEditorData->buildUp();
clearPropertyItemSelection();
@@ -276,7 +276,7 @@ void PropertyView::slotDeleteDocument(const Gui::Document &doc) {
}
void PropertyView::slotDeletedViewObject(const Gui::ViewProvider &vp) {
if(propertyEditorView->propOwners.count(&vp)) {
if(propertyEditorView->propOwners.contains(&vp)) {
propertyEditorView->buildUp();
propertyEditorData->buildUp();
clearPropertyItemSelection();
@@ -285,7 +285,7 @@ void PropertyView::slotDeletedViewObject(const Gui::ViewProvider &vp) {
}
void PropertyView::slotDeletedObject(const App::DocumentObject &obj) {
if(propertyEditorData->propOwners.count(&obj)) {
if(propertyEditorData->propOwners.contains(&obj)) {
propertyEditorView->buildUp();
propertyEditorData->buildUp();
clearPropertyItemSelection();

View File

@@ -104,7 +104,7 @@ int SoFCSelectionContext::merge(int status, SoFCSelectionContextBasePtr &output,
std::vector<int> remove;
for(auto idx : ret->selectionIndex) {
if(!ctx->selectionIndex.count(idx))
if(!ctx->selectionIndex.contains(idx))
remove.push_back(idx);
}
@@ -216,7 +216,7 @@ int SoFCSelectionContextEx::merge(int status, SoFCSelectionContextBasePtr &outpu
auto ret = std::dynamic_pointer_cast<SoFCSelectionContextEx>(output);
assert(ret);
for(auto &v : ctx->colors) {
if(ret->colors.count(v.first))
if(ret->colors.contains(v.first))
continue;
if(!status) {
status = 1;

View File

@@ -78,7 +78,7 @@ const std::string & ToolBarItem::command() const
bool ToolBarItem::hasItems() const
{
return _items.count() > 0;
return !_items.isEmpty();
}
ToolBarItem* ToolBarItem::findItem(const std::string& name)

View File

@@ -1177,7 +1177,7 @@ void TreeWidget::contextMenuEvent(QContextMenuEvent* e)
header()->setVisible(action->isChecked()||internalNameAction->isChecked());
});
if (contextMenu.actions().count() > 0) {
if (!contextMenu.actions().isEmpty()) {
try {
contextMenu.exec(QCursor::pos());
}
@@ -2573,7 +2573,7 @@ bool TreeWidget::dropInObject(QDropEvent* event, TargetItemInfo& targetInfo,
}
}
if (inList.count(obj)) {
if (inList.contains(obj)) {
FC_THROWM(Base::RuntimeError, "Dependency loop detected for " << obj->getFullName());
}
@@ -3059,7 +3059,7 @@ void TreeWidget::onUpdateStatus()
continue;
if (obj->isError())
errors.push_back(obj);
if (docItem->ObjectMap.count(obj))
if (docItem->ObjectMap.contains(obj))
continue;
auto vpd = freecad_cast<ViewProviderDocumentObject*>(gdoc->getViewProvider(obj));
if (vpd)
@@ -4447,7 +4447,7 @@ void TreeWidget::updateChildren(App::DocumentObject* obj,
// and thus, its property change will not be propagated through
// recomputation. So we have to manually check for each links here.
for (auto link : App::GetApplication().getLinksTo(obj, App::GetLinkRecursive)) {
if (ChangedObjects.count(link))
if (ChangedObjects.contains(link))
continue;
std::vector<App::DocumentObject*> linkedChildren;
DocumentObjectDataPtr found;
@@ -4475,7 +4475,7 @@ void TreeWidget::updateChildren(App::DocumentObject* obj,
//if the item is in a GeoFeatureGroup we may need to update that too, as the claim children
//of the geofeaturegroup depends on what the childs claim
auto grp = App::GeoFeatureGroupExtension::getGroupOfObject(obj);
if (grp && !ChangedObjects.count(grp)) {
if (grp && !ChangedObjects.contains(grp)) {
auto iter = ObjectTable.find(grp);
if (iter != ObjectTable.end())
updateChildren(grp, iter->second, true, false);

View File

@@ -104,7 +104,7 @@ std::vector<App::DocumentObject*> ViewProviderGeoFeatureGroupExtension::extensio
for(auto obj : model) {
if(!obj || !obj->isAttachedToDocument())
continue;
if(outSet.count(obj))
if(outSet.contains(obj))
obj->setStatus(App::ObjectStatus::GeoExcluded,true);
else {
obj->setStatus(App::ObjectStatus::GeoExcluded,false);