From d88729d2c42630064142b341b636c2ff6afa1391 Mon Sep 17 00:00:00 2001 From: berniev Date: Sat, 6 Aug 2022 03:13:53 +1000 Subject: [PATCH] Gui: use empty --- src/Gui/Application.cpp | 2 +- src/Gui/Command.cpp | 4 +- src/Gui/CommandDoc.cpp | 18 +++---- src/Gui/CommandLink.cpp | 6 +-- src/Gui/CommandView.cpp | 6 +-- src/Gui/CommandWindow.cpp | 2 +- src/Gui/DlgCustomizeSpaceball.cpp | 8 +-- src/Gui/DlgExpressionInput.cpp | 2 +- src/Gui/DlgObjectSelection.cpp | 10 ++-- src/Gui/DlgParameterImp.cpp | 4 +- src/Gui/DlgPropertyLink.cpp | 8 +-- src/Gui/Document.cpp | 8 +-- src/Gui/ExpressionBinding.cpp | 2 +- src/Gui/ExpressionCompleter.cpp | 4 +- src/Gui/GestureNavigationStyle.cpp | 2 +- src/Gui/InputField.cpp | 8 +-- src/Gui/Macro.cpp | 2 +- src/Gui/MainWindow.cpp | 4 +- src/Gui/Placement.cpp | 2 +- src/Gui/PreferencePackManager.cpp | 6 +-- src/Gui/Selection.cpp | 64 +++++++++++------------ src/Gui/SelectionObject.h | 2 +- src/Gui/SoFCSelectionContext.cpp | 2 +- src/Gui/SoFCSelectionContext.h | 2 +- src/Gui/SoFCUnifiedSelection.cpp | 4 +- src/Gui/TaskElementColors.cpp | 10 ++-- src/Gui/Tree.cpp | 54 +++++++++---------- src/Gui/View3DInventorViewer.cpp | 4 +- src/Gui/View3DPy.cpp | 8 +-- src/Gui/ViewProvider.cpp | 2 +- src/Gui/ViewProviderLink.cpp | 36 ++++++------- src/Gui/propertyeditor/PropertyEditor.cpp | 6 +-- src/Gui/propertyeditor/PropertyItem.cpp | 6 +-- 33 files changed, 154 insertions(+), 154 deletions(-) diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 20a7603b55..8f187af58b 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -914,7 +914,7 @@ void Application::onLastWindowClosed(Gui::Document* pcDoc) if (!d->isClosing && pcDoc) { // Call the closing mechanism from Python. This also checks whether pcDoc is the last open document. Command::doCommand(Command::Doc, "App.closeDocument(\"%s\")", pcDoc->getDocument()->getName()); - if (!d->activeDocument && d->documents.size()) { + if (!d->activeDocument && !d->documents.empty()) { Document *gdoc = nullptr; for(auto &v : d->documents) { if (v.second->getDocument()->testStatus(App::Document::TempDoc)) diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index fb4820fc6b..37671d96ca 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -838,7 +838,7 @@ bool Command::isActiveObjectValid(void) /// Updates the (all or listed) documents (propagate changes) void Command::updateAll(std::list cList) { - if (cList.size()>0) { + if (!cList.empty()) { for (std::list::iterator It= cList.begin();It!=cList.end();++It) (*It)->onUpdate(); } @@ -1212,7 +1212,7 @@ void MacroCommand::save() hGrp->Clear(); std::vector macros = Application::Instance->commandManager().getGroupCommands("Macros"); - if ( macros.size() > 0 ) { + if ( !macros.empty() ) { for (std::vector::iterator it = macros.begin(); it!=macros.end(); ++it ) { MacroCommand* macro = (MacroCommand*)(*it); ParameterGrp::handle hMacro = hGrp->GetGroup(macro->getName()); diff --git a/src/Gui/CommandDoc.cpp b/src/Gui/CommandDoc.cpp index dc5770d72f..7bdd660d0e 100644 --- a/src/Gui/CommandDoc.cpp +++ b/src/Gui/CommandDoc.cpp @@ -398,7 +398,7 @@ void StdCmdExport::activated(int iMsg) static QString lastExportFilterUsed = QString(); auto selection = Gui::Selection().getObjectsOfType(App::DocumentObject::getClassTypeId()); - if (selection.size() == 0) { + if (selection.empty()) { QMessageBox::warning(Gui::getMainWindow(), QString::fromUtf8(QT_TR_NOOP("No selection")), QString::fromUtf8(QT_TR_NOOP("Select the objects to export before choosing Export."))); @@ -1175,7 +1175,7 @@ void StdCmdDuplicateSelection::activated(int iMsg) } std::vector unsaved; hasXLink = App::PropertyXLink::hasXLink(sel,&unsaved); - if(unsaved.size()) { + if(!unsaved.empty()) { QMessageBox::critical(getMainWindow(), QObject::tr("Unsaved document"), QObject::tr("The exported object contains external link. Please save the document" "at least once before exporting.")); @@ -1362,7 +1362,7 @@ void StdCmdDelete::activated(int iMsg) } } } - if(docs.size()) { + if(!docs.empty()) { const auto &outList = App::PropertyXLink::getDocumentOutList(); for(auto it=docs.begin();it!=docs.end();++it) { auto itd = outList.find(*it); @@ -1392,7 +1392,7 @@ void StdCmdDelete::activated(int iMsg) bool StdCmdDelete::isActive(void) { - return Selection().getCompleteSelection().size() > 0; + return !Selection().getCompleteSelection().empty(); } //=========================================================================== @@ -1640,7 +1640,7 @@ void StdCmdEdit::activated(int iMsg) if (viewer->isEditingViewProvider()) { doCommand(Command::Gui,"Gui.activeDocument().resetEdit()"); } else { - if (Selection().getCompleteSelection().size() > 0) { + if (!Selection().getCompleteSelection().empty()) { SelectionSingleton::SelObj obj = Selection().getCompleteSelection()[0]; doCommand(Command::Gui,"Gui.activeDocument().setEdit(\"%s\",0)",obj.FeatName); } @@ -1650,7 +1650,7 @@ void StdCmdEdit::activated(int iMsg) bool StdCmdEdit::isActive(void) { - return (Selection().getCompleteSelection().size() > 0) || (Gui::Control().activeDialog() != nullptr); + return (!Selection().getCompleteSelection().empty()) || (Gui::Control().activeDialog() != nullptr); } //====================================================================== @@ -1733,7 +1733,7 @@ protected: << obj->getFullName() << '.' << p->getName() << " (" << obj->Label.getValue() << ')' << std::endl; ss << "##@@"; - if(v.second->comment.size()) { + if(!v.second->comment.empty()) { if(v.second->comment[0] == '&' || v.second->comment.find('\n') != std::string::npos || v.second->comment.find('\r') != std::string::npos) @@ -1802,7 +1802,7 @@ protected: size_t len = (found?m2[0].first:tend) - m[0].second; try { App::ExpressionPtr expr(App::Expression::parse(obj,std::string(m[0].second,len))); - if(expr && comment.size()) { + if(expr && !comment.empty()) { if(comment[0] == '&') { expr->comment = comment.c_str()+1; boost::replace_all(expr->comment,"&","&"); @@ -1836,7 +1836,7 @@ protected: if(iter != old.end() && it->second->isSame(*iter->second)) expressions.erase(it); } - if(expressions.size()) + if(!expressions.empty()) v2.first->setExpressions(std::move(expressions)); } } diff --git a/src/Gui/CommandLink.cpp b/src/Gui/CommandLink.cpp index 824389343e..aff832f92a 100644 --- a/src/Gui/CommandLink.cpp +++ b/src/Gui/CommandLink.cpp @@ -450,7 +450,7 @@ static void linkConvert(bool unlink) { if(obj) recomputes.push_back(obj); } - if(recomputes.size()) + if(!recomputes.empty()) recomputes.front()->getDocument()->recompute(recomputes); Command::commitCommand(); @@ -726,7 +726,7 @@ static App::DocumentObject *getSelectedLink(bool finalLink, std::string *subname if(found) { linked = sels[0].pObject; - *subname = prefix.size()?prefix:prefix2 + *subname; + *subname = !prefix.empty()?prefix:prefix2 + *subname; } } @@ -747,7 +747,7 @@ void StdCmdLinkSelectLinked::activated(int) } Selection().selStackPush(); Selection().clearCompleteSelection(); - if(subname.size()) { + if(!subname.empty()) { Selection().addSelection(linked->getDocument()->getName(),linked->getNameInDocument(),subname.c_str()); auto doc = Application::Instance->getDocument(linked->getDocument()); if(doc) { diff --git a/src/Gui/CommandView.cpp b/src/Gui/CommandView.cpp index ce7c33896c..f0121404ab 100644 --- a/src/Gui/CommandView.cpp +++ b/src/Gui/CommandView.cpp @@ -2721,7 +2721,7 @@ static std::vector getBoxSelection( continue; const auto &sels = getBoxSelection(svp,mode,selectElement,proj,polygon,smat,false,depth+1); - if(sels.size()==1 && sels[0] == "") + if(sels.size()==1 && sels[0].empty()) ++count; for(auto &sel : sels) ret.emplace_back(sub+sel); @@ -3564,8 +3564,8 @@ public: addCommand(); - addCommand(new StdTreeDrag(),cmds.size()); - addCommand(new StdTreeSelection(),cmds.size()); + addCommand(new StdTreeDrag(),!cmds.empty()); + addCommand(new StdTreeSelection(),!cmds.empty()); }; virtual const char* className() const {return "StdCmdTreeViewActions";} }; diff --git a/src/Gui/CommandWindow.cpp b/src/Gui/CommandWindow.cpp index adbe4906f3..a6c70324a8 100644 --- a/src/Gui/CommandWindow.cpp +++ b/src/Gui/CommandWindow.cpp @@ -183,7 +183,7 @@ void StdCmdCloseAllWindows::activated(int iMsg) bool StdCmdCloseAllWindows::isActive(void) { - return !(getMainWindow()->windows().isEmpty()) || App::GetApplication().getDocuments().size(); + return !(getMainWindow()->windows().isEmpty()) || !App::GetApplication().getDocuments().empty(); } //=========================================================================== diff --git a/src/Gui/DlgCustomizeSpaceball.cpp b/src/Gui/DlgCustomizeSpaceball.cpp index dc258e50d4..6e57bc1775 100644 --- a/src/Gui/DlgCustomizeSpaceball.cpp +++ b/src/Gui/DlgCustomizeSpaceball.cpp @@ -316,7 +316,7 @@ void CommandView::goChangeCommandSelection(const QString& commandName) return; QModelIndexList index(this->model()->match(this->model()->index(0,0), Qt::UserRole, QVariant(commandName), 1, Qt::MatchWrap | Qt::MatchRecursive)); - if (index.size() < 1) + if (index.empty()) return; this->expand(index.at(0)); this->setCurrentIndex(index.at(0)); @@ -421,7 +421,7 @@ QVariant CommandModel::data(const QModelIndex &index, int role) const return QVariant(qApp->translate(node->aCommand->className(), node->aCommand->getMenuText())); if (node->nodeType == CommandNode::GroupType) { - if (node->children.size() < 1) + if (node->children.empty()) return QVariant(); CommandNode *childNode = node->children.at(0); return QVariant(childNode->aCommand->translatedGroupName()); @@ -446,7 +446,7 @@ QVariant CommandModel::data(const QModelIndex &index, int role) const return QVariant(QString::fromLatin1(node->aCommand->getName())); if (node->nodeType == CommandNode::GroupType) { - if (node->children.size() < 1) + if (node->children.empty()) return QVariant(); CommandNode *childNode = node->children.at(0); return QVariant(QString::fromLatin1(childNode->aCommand->getGroupName())); @@ -490,7 +490,7 @@ void CommandModel::goAddMacro(const QByteArray ¯oName) QModelIndexList indexList(this->match(this->index(0,0), Qt::UserRole, QVariant(QString::fromLatin1("Macros")), 1, Qt::MatchWrap | Qt::MatchRecursive)); QModelIndex macrosIndex; - if (indexList.size() < 1) + if (indexList.empty()) { //this is the first macro and we have to add the Macros item. //figure out where to insert it. Should be in the command groups now. diff --git a/src/Gui/DlgExpressionInput.cpp b/src/Gui/DlgExpressionInput.cpp index 82d642a3dd..e342ad7022 100644 --- a/src/Gui/DlgExpressionInput.cpp +++ b/src/Gui/DlgExpressionInput.cpp @@ -144,7 +144,7 @@ void DlgExpressionInput::textChanged(const QString &text) if (expr) { std::string error = path.getDocumentObject()->ExpressionEngine.validateExpression(path, expr); - if (error.size() > 0) + if (!error.empty()) throw Base::RuntimeError(error.c_str()); std::unique_ptr result(expr->eval()); diff --git a/src/Gui/DlgObjectSelection.cpp b/src/Gui/DlgObjectSelection.cpp index 17f6b485ef..3aec2b367c 100644 --- a/src/Gui/DlgObjectSelection.cpp +++ b/src/Gui/DlgObjectSelection.cpp @@ -186,7 +186,7 @@ QTreeWidgetItem *DlgObjectSelection::getItem(App::DocumentObject *obj, *pitems = &items; QTreeWidgetItem *item; if (!parent) { - if (items.size()) + if (!items.empty()) return items[0]; item = new QTreeWidgetItem(ui->treeWidget); auto vp = Base::freecad_dynamic_cast( @@ -204,7 +204,7 @@ QTreeWidgetItem *DlgObjectSelection::getItem(App::DocumentObject *obj, item->setData(0, Qt::UserRole, QVariant::fromValue(objT)); item->setChildIndicatorPolicy(obj->getOutList().empty() ? QTreeWidgetItem::DontShowIndicator : QTreeWidgetItem::ShowIndicator); - } else if (items.size()) { + } else if (!items.empty()) { item = new QTreeWidgetItem(parent); item->setIcon(0, items[0]->icon(0)); item->setText(0, items[0]->text(0)); @@ -486,7 +486,7 @@ void DlgObjectSelection::checkItemChanged() { } } - if (unchecked.size()) { + if (!unchecked.empty()) { // When some item is unchecked by the user, we need to re-check the // recursive outlist of the initially selected object, excluding all // currently unchecked object. And then uncheck any item that does not @@ -566,7 +566,7 @@ void DlgObjectSelection::onItemSelectionChanged() { } std::vector _deps; - if (sels.size()) { + if (!sels.empty()) { std::sort(sels.begin(), sels.end()); for (auto dep : App::Document::getDependencyList(sels, App::Document::DepSort)) { if (!std::binary_search(sels.begin(), sels.end(), dep)) @@ -584,7 +584,7 @@ void DlgObjectSelection::onItemSelectionChanged() { { QSignalBlocker blocker(ui->depList); - auto &objs = sels.size() ? _deps : deps; + auto &objs = !sels.empty() ? _deps : deps; for (auto it = objs.rbegin(); it != objs.rend(); ++it) createDepItem(ui->depList, *it); } diff --git a/src/Gui/DlgParameterImp.cpp b/src/Gui/DlgParameterImp.cpp index 147b2915a5..5a03838b7f 100644 --- a/src/Gui/DlgParameterImp.cpp +++ b/src/Gui/DlgParameterImp.cpp @@ -144,7 +144,7 @@ void DlgParameterImp::on_findGroupLE_textChanged(const QString &SearchStr) QTreeWidgetItem* ExpandItem; // at first reset all items to the default font and expand state - if (foundList.size() > 0) { + if (!foundList.empty()) { for (QTreeWidgetItem* item : qAsConst(foundList)) { item->setFont(0, defaultFont); item->setForeground(0, defaultColor); @@ -172,7 +172,7 @@ void DlgParameterImp::on_findGroupLE_textChanged(const QString &SearchStr) // search the tree widget foundList = paramGroup->findItems(SearchStr, Qt::MatchContains | Qt::MatchRecursive); - if (foundList.size() > 0) { + if (!foundList.empty()) { // reset background style sheet if (!ui->findGroupLE->styleSheet().isEmpty()) ui->findGroupLE->setStyleSheet(QString()); diff --git a/src/Gui/DlgPropertyLink.cpp b/src/Gui/DlgPropertyLink.cpp index 4b4c7abddb..0c02f3b3ff 100644 --- a/src/Gui/DlgPropertyLink.cpp +++ b/src/Gui/DlgPropertyLink.cpp @@ -466,7 +466,7 @@ void DlgPropertyLink::detachObserver() { detachSelection(); auto view = qobject_cast(parentView.data()); - if(view && savedSelections.size()) { + if(view && !savedSelections.empty()) { try { Gui::Selection().clearSelection(); } @@ -501,7 +501,7 @@ void DlgPropertyLink::onItemSelectionChanged() selections = newSelections; auto sobjs = getLinkFromItem(newSelections.back()); - App::DocumentObject *obj = sobjs.size()?sobjs.front().getObject():nullptr; + App::DocumentObject *obj = !sobjs.empty()?sobjs.front().getObject():nullptr; if(!obj) { Gui::Selection().clearSelection(); return; @@ -760,7 +760,7 @@ QString DlgPropertyLink::linksToPython(const QList& links) { ss << '(' << links.front().getObjectPython() << ", ["; for(const auto& link : links) { const auto &sub = link.getSubName(); - if(sub.size()) + if(!sub.empty()) ss << "u'" << Base::Tools::escapedUnicodeFromUtf8(sub.c_str()) << "',"; } ss << "])"; @@ -900,7 +900,7 @@ QTreeWidgetItem *DlgPropertyLink::createItem( item->setData(0, Qt::UserRole+1, QByteArray(obj->getDocument()->getName())); if(allowSubObject) { - item->setChildIndicatorPolicy(obj->getLinkedObject(true)->getOutList().size()? + item->setChildIndicatorPolicy(!obj->getLinkedObject(true)->getOutList().empty()? QTreeWidgetItem::ShowIndicator:QTreeWidgetItem::DontShowIndicator); item->setFlags(item->flags() | Qt::ItemIsEditable | Qt::ItemIsUserCheckable); } diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index 316a5a7d4b..4d8db2190e 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -925,7 +925,7 @@ void Document::slotSkipRecompute(const App::Document& doc, const std::vectorgetNameInDocument() || (objs.size() && objs.front()!=obj)) + if(!obj || !obj->getNameInDocument() || (!objs.empty() && objs.front()!=obj)) return; obj->recomputeFeature(true); } @@ -1886,7 +1886,7 @@ void Document::detachView(Gui::BaseView* pcView, bool bPassiv) d->baseViews.remove(pcView); // last view? - if (d->baseViews.size() == 0) { + if (d->baseViews.empty()) { // decouple a passive view std::list::iterator it = d->passiveViews.begin(); while (it != d->passiveViews.end()) { @@ -1974,7 +1974,7 @@ bool Document::canClose (bool checkModify, bool checkLink) // } //} - if (checkLink && App::PropertyXLink::getDocumentInList(getDocument()).size()) + if (checkLink && !App::PropertyXLink::getDocumentInList(getDocument()).empty()) return true; if (getDocument()->testStatus(App::Document::TempDoc)) @@ -2314,7 +2314,7 @@ bool Document::checkTransactionID(bool undo, int iSteps) { currentSteps = steps; } } - if(prompts.size()) { + if(!prompts.empty()) { std::ostringstream str; int i=0; for(auto doc : prompts) { diff --git a/src/Gui/ExpressionBinding.cpp b/src/Gui/ExpressionBinding.cpp index 3878a7041a..f6ad623b4c 100644 --- a/src/Gui/ExpressionBinding.cpp +++ b/src/Gui/ExpressionBinding.cpp @@ -77,7 +77,7 @@ void Gui::ExpressionBinding::setExpression(std::shared_ptr expr) if (expr) { const std::string error = docObj->ExpressionEngine.validateExpression(path, expr); - if (error.size()) + if (!error.empty()) throw Base::RuntimeError(error.c_str()); } diff --git a/src/Gui/ExpressionCompleter.cpp b/src/Gui/ExpressionCompleter.cpp index d09bfb1211..b418c62174 100644 --- a/src/Gui/ExpressionCompleter.cpp +++ b/src/Gui/ExpressionCompleter.cpp @@ -407,9 +407,9 @@ QStringList ExpressionCompleter::splitPath ( const QString & input ) const std::vector sl = p.getStringList(); std::vector::const_iterator sli = sl.begin(); - if(retry && sl.size()) + if(retry && !sl.empty()) sl.pop_back(); - if(trim.size() && boost::ends_with(sl.back(),trim)) + if(!trim.empty() && boost::ends_with(sl.back(),trim)) sl.back().resize(sl.back().size()-trim.size()); while (sli != sl.end()) { l << Base::Tools::fromStdString(*sli); diff --git a/src/Gui/GestureNavigationStyle.cpp b/src/Gui/GestureNavigationStyle.cpp index 251385beb5..4080376b1e 100644 --- a/src/Gui/GestureNavigationStyle.cpp +++ b/src/Gui/GestureNavigationStyle.cpp @@ -994,7 +994,7 @@ void GestureNavigationStyle::onRollGesture(int direction) cmd = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/View")->GetASCII("GestureRollBackCommand"); } - if (cmd.size() == 0) + if (cmd.empty()) return; std::stringstream code; code << "Gui.runCommand(\"" << cmd << "\")"; diff --git a/src/Gui/InputField.cpp b/src/Gui/InputField.cpp index 6839c10ce4..0a5d4cf156 100644 --- a/src/Gui/InputField.cpp +++ b/src/Gui/InputField.cpp @@ -323,7 +323,7 @@ void InputField::pushToHistory(const QString &valueq) snprintf(hist1,20,"Hist%i",i+1); snprintf(hist0,20,"Hist%i",i); std::string tHist = _handle->GetASCII(hist0,""); - if(tHist != "") + if(!tHist.empty()) _handle->SetASCII(hist1,tHist.c_str()); } _handle->SetASCII("Hist0",value.c_str()); @@ -340,7 +340,7 @@ std::vector InputField::getHistory(void) for(int i = 0 ; i< HistorySize ;i++){ snprintf(hist,20,"Hist%i",i); tmp = _handle->GetASCII(hist,""); - if( tmp != "") + if( !tmp.empty()) res.push_back(QString::fromUtf8(tmp.c_str())); else break; // end of history reached @@ -371,7 +371,7 @@ void InputField::pushToSavedValues(const QString &valueq) snprintf(hist1,20,"Save%i",i+1); snprintf(hist0,20,"Save%i",i); std::string tHist = _handle->GetASCII(hist0,""); - if(tHist != "") + if(!tHist.empty()) _handle->SetASCII(hist1,tHist.c_str()); } _handle->SetASCII("Save0",value.c_str()); @@ -388,7 +388,7 @@ std::vector InputField::getSavedValues(void) for(int i = 0 ; i< SaveSize ;i++){ snprintf(hist,20,"Save%i",i); tmp = _handle->GetASCII(hist,""); - if( tmp != "") + if( !tmp.empty()) res.push_back(QString::fromUtf8(tmp.c_str())); else break; // end of history reached diff --git a/src/Gui/Macro.cpp b/src/Gui/Macro.cpp index 35a415701e..e6e86e6836 100644 --- a/src/Gui/Macro.cpp +++ b/src/Gui/Macro.cpp @@ -176,7 +176,7 @@ void MacroManager::addLine(LineType Type, const char* sLine, bool pending) if(!sLine) return; - if(pendingLine.size()) { + if(!pendingLine.empty()) { if(Type == Cmt) { pendingLine.emplace_back(Type,sLine); return; diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index b88073562b..a5a363afb8 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -1239,7 +1239,7 @@ void MainWindow::delayedStartup() // Create new document? ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("Document"); if (hGrp->GetBool("CreateNewDoc", false)) { - if (App::GetApplication().getDocuments().size()==0){ + if (App::GetApplication().getDocuments().empty()){ App::GetApplication().newDocument(); Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeDocument().activeView().viewDefaultOrientation()"); @@ -1623,7 +1623,7 @@ QMimeData * MainWindow::createMimeDataFromSelection () const std::vector unsaved; bool hasXLink = App::PropertyXLink::hasXLink(sel,&unsaved); - if(unsaved.size()) { + if(!unsaved.empty()) { QMessageBox::critical(getMainWindow(), tr("Unsaved document"), tr("The exported object contains external link. Please save the document" "at least once before exporting.")); diff --git a/src/Gui/Placement.cpp b/src/Gui/Placement.cpp index 8b352ced14..11eca6d970 100644 --- a/src/Gui/Placement.cpp +++ b/src/Gui/Placement.cpp @@ -371,7 +371,7 @@ void Placement::on_selectedVertex_clicked() Base::Vector3d firstSelected; //first selected will be central point when 3 points picked for (std::vector::iterator it=selection.begin(); it!=selection.end(); ++it){ std::vector points = it->getPickedPoints(); - if (it==selection.begin() && points.size()>0){ + if (it==selection.begin() && !points.empty()){ firstSelected=points[0]; } picked.insert(picked.begin(),points.begin(),points.end()); diff --git a/src/Gui/PreferencePackManager.cpp b/src/Gui/PreferencePackManager.cpp index 6931d89e49..39a73eedf9 100644 --- a/src/Gui/PreferencePackManager.cpp +++ b/src/Gui/PreferencePackManager.cpp @@ -243,7 +243,7 @@ std::string findUnusedName(const std::string &basename, ParameterGrp::handle par bool PreferencePackManager::isVisible(const std::string& addonName, const std::string& preferencePackName) const { - if (addonName == "" || preferencePackName == "") + if (addonName.empty() || preferencePackName.empty()) return true; auto pref = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General/HiddenPreferencePacks"); @@ -259,7 +259,7 @@ bool PreferencePackManager::isVisible(const std::string& addonName, const std::s void PreferencePackManager::toggleVisibility(const std::string& addonName, const std::string& preferencePackName) { - if (preferencePackName == "") + if (preferencePackName.empty()) return; auto pref = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General/HiddenPreferencePacks"); auto hiddenPacks = pref->GetGroups(); @@ -282,7 +282,7 @@ void PreferencePackManager::toggleVisibility(const std::string& addonName, const void Gui::PreferencePackManager::deleteUserPack(const std::string& name) { - if (name == "") + if (name.empty()) return; auto savedPreferencePacksDirectory = fs::path(App::Application::getUserAppDataDir()) / "SavedPreferencePacks"; auto savedPath = savedPreferencePacksDirectory / name; diff --git a/src/Gui/Selection.cpp b/src/Gui/Selection.cpp index 73ac16802d..d6eaa19095 100644 --- a/src/Gui/Selection.cpp +++ b/src/Gui/Selection.cpp @@ -68,9 +68,9 @@ SelectionGateFilterExternal::SelectionGateFilterExternal(const char *docName, co bool SelectionGateFilterExternal::allow(App::Document *doc ,App::DocumentObject *obj, const char*) { if(!doc || !obj) return true; - if(DocName.size() && doc->getName()!=DocName) + if(!DocName.empty() && doc->getName()!=DocName) notAllowedReason = "Cannot select external object"; - else if(ObjName.size() && ObjName==obj->getNameInDocument()) + else if(!ObjName.empty() && ObjName==obj->getNameInDocument()) notAllowedReason = "Cannot select self"; else return true; @@ -133,7 +133,7 @@ void SelectionObserver::attachSelection() connectSelection = signal.connect(boost::bind (&SelectionObserver::_onSelectionChanged, this, bp::_1)); - if (filterDocName.size()) { + if (!filterDocName.empty()) { Selection().addSelectionGate( new SelectionGateFilterExternal(filterDocName.c_str(),filterObjName.c_str())); } @@ -159,7 +159,7 @@ void SelectionObserver::detachSelection() { if (connectSelection.connected()) { connectSelection.disconnect(); - if (filterDocName.size()) + if (!filterDocName.empty()) Selection().rmvSelectionGate(); } } @@ -397,7 +397,7 @@ std::vector SelectionSingleton::getSelection(const c if (resolve != ResolveMode::NoResolve && !objMap[obj].insert(std::string(subelement ? subelement : "")).second) continue; - if (single && temp.size()) { + if (single && !temp.empty()) { temp.clear(); break; } @@ -541,7 +541,7 @@ std::vector SelectionSingleton::getObjectList(const char* pDocN } } else { - if (single && temp.size()) { + if (single && !temp.empty()) { temp.clear(); break; } @@ -582,7 +582,7 @@ void SelectionSingleton::notify(SelectionChanges &&Chng) } Base::FlagToggler flag(Notifying); NotificationQueue.push_back(std::move(Chng)); - while(NotificationQueue.size()) { + while(!NotificationQueue.empty()) { const auto &msg = NotificationQueue.front(); bool notify; switch(msg.Type) { @@ -618,7 +618,7 @@ void SelectionSingleton::notify(SelectionChanges &&Chng) bool SelectionSingleton::hasPickedList() const { - return _PickedList.size(); + return !_PickedList.empty(); } int SelectionSingleton::getAsPropertyLinkSubList(App::PropertyLinkSubList &prop) const @@ -632,7 +632,7 @@ int SelectionSingleton::getAsPropertyLinkSubList(App::PropertyLinkSubList &prop) const std::vector &subnames = selitem.getSubNames(); //whole object is selected - if (subnames.size() == 0){ + if (subnames.empty()){ objs.push_back(obj); subs.emplace_back(); } @@ -657,7 +657,7 @@ App::DocumentObject *SelectionSingleton::getObjectOfType(_SelObj &sel, Base::Typ const char *subname = sel.SubName.c_str(); if (resolve != ResolveMode::NoResolve) { obj = sel.pResolvedObject; - if (resolve == ResolveMode::NewStyleElement && sel.elementName.first.size()) + if (resolve == ResolveMode::NewStyleElement && !sel.elementName.first.empty()) subname = sel.elementName.first.c_str(); else subname = sel.elementName.second.c_str(); @@ -742,7 +742,7 @@ void SelectionSingleton::slotSelectionChanged(const SelectionChanges& msg) msg.Type == SelectionChanges::HideSelection) return; - if(msg.Object.getSubName().size()) { + if(!msg.Object.getSubName().empty()) { auto pParent = msg.Object.getObject(); if(!pParent) return; @@ -754,7 +754,7 @@ void SelectionSingleton::slotSelectionChanged(const SelectionChanges& msg) return; SelectionChanges msg2(msg.Type,pObject->getDocument()->getName(), pObject->getNameInDocument(), - newElementName.size()?newElementName.c_str():oldElementName.c_str(), + !newElementName.empty()?newElementName.c_str():oldElementName.c_str(), pObject->getTypeId().getName(), msg.x,msg.y,msg.z); try { @@ -814,7 +814,7 @@ int SelectionSingleton::setPreselect(const char* pDocName, const char* pObjectNa if (!pObject) return 0; if (gateResolve > ResolveMode::OldStyleElement) - subelement = newElementName.size() ? newElementName.c_str() : oldElementName.c_str(); + subelement = !newElementName.empty() ? newElementName.c_str() : oldElementName.c_str(); else subelement = oldElementName.c_str(); } @@ -864,7 +864,7 @@ int SelectionSingleton::setPreselect(const char* pDocName, const char* pObjectNa notify(Chng); - if (signal == SelectionChanges::MsgSource::Internal && DocName.size()) { + if (signal == SelectionChanges::MsgSource::Internal && !DocName.empty()) { FC_TRACE("preselect "< tmpStack; _SelStackForward.swap(tmpStack); - while(_SelStackBack.size()) { + while(!_SelStackBack.empty()) { bool found = false; for(auto &sobjT : _SelStackBack.back()) { if(sobjT.getSubObject()) { @@ -1190,7 +1190,7 @@ void SelectionSingleton::selStackGoForward(int count) { count = _SelStackForward.size(); if(count<=0) return; - if(_SelList.size()) { + if(!_SelList.empty()) { selStackPush(false,true); clearCompleteSelection(); } @@ -1253,7 +1253,7 @@ std::vector SelectionSingleton::selStackGet(const char* pDocNam bool SelectionSingleton::addSelections(const char* pDocName, const char* pObjectName, const std::vector& pSubNames) { - if(_PickedList.size()) { + if(!_PickedList.empty()) { _PickedList.clear(); notify(SelectionChanges(SelectionChanges::PickedListChanged)); } @@ -1384,7 +1384,7 @@ void SelectionSingleton::rmvSelection(const char* pDocName, const char* pObjectN if(It->DocName!=temp.DocName || It->FeatName!=temp.FeatName) continue; // if no subname is specified, remove all subobjects of the matching object - if(temp.SubName.size()) { + if(!temp.SubName.empty()) { // otherwise, match subojects with common prefix, separated by '.' if(!boost::starts_with(It->SubName,temp.SubName) || (It->SubName.length()!=temp.SubName.length() && It->SubName[temp.SubName.length()-1]!='.')) @@ -1405,7 +1405,7 @@ void SelectionSingleton::rmvSelection(const char* pDocName, const char* pObjectN // as this can invalidate the iterators and thus leads to undefined // behaviour. // So, the notification is done after the loop, see also #0003469 - if(changes.size()) { + if(!changes.empty()) { for(auto &Chng : changes) { FC_LOG("Rmv Selection "<getNameInDocument(); sel.TypeName = sel.pObject->getTypeId().getName(); const char *element = nullptr; @@ -1684,7 +1684,7 @@ int SelectionSingleton::checkSelection(const char *pDocName, const char *pObject std::string prefix; if(pSubName && element) { prefix = std::string(pSubName, element-pSubName); - if(sel.elementName.first.size()) { + if(!sel.elementName.first.empty()) { // make sure the selected sub name is a new style if available subname = prefix + sel.elementName.first; pSubName = subname.c_str(); @@ -1711,7 +1711,7 @@ int SelectionSingleton::checkSelection(const char *pDocName, const char *pObject continue; if(!pSubName[0]) return 1; - if (s.elementName.first.size()) { + if (!s.elementName.first.empty()) { if (s.elementName.first == sel.elementName.first) return 1; } @@ -1760,7 +1760,7 @@ void SelectionSingleton::slotDeletedObject(const App::DocumentObject& Obj) _SelList.erase(it); } } - if(changes.size()) { + if(!changes.empty()) { for(auto &Chng : changes) { FC_LOG("Rmv Selection "<updateActions(); } - if(_PickedList.size()) { + if(!_PickedList.empty()) { bool changed = false; for(auto it=_PickedList.begin(),itNext=it;it!=_PickedList.end();it=itNext) { ++itNext; diff --git a/src/Gui/SelectionObject.h b/src/Gui/SelectionObject.h index bf5701886d..3ef71a8262 100644 --- a/src/Gui/SelectionObject.h +++ b/src/Gui/SelectionObject.h @@ -59,7 +59,7 @@ public: /// get the SubElement name of this SelectionObject inline const std::vector &getSubNames(void) const { return SubNames; } /// are there any SubNames selected - bool hasSubNames(void)const { return SubNames.size() != 0; } + bool hasSubNames(void)const { return !SubNames.empty(); } /// get the name of the Document of this SelctionObject inline const char* getDocName(void) const { return DocName.c_str(); } /// get the name of the Document Object of this SelectionObject diff --git a/src/Gui/SoFCSelectionContext.cpp b/src/Gui/SoFCSelectionContext.cpp index 84b2253872..bc474d7df8 100644 --- a/src/Gui/SoFCSelectionContext.cpp +++ b/src/Gui/SoFCSelectionContext.cpp @@ -170,7 +170,7 @@ bool SoFCSelectionContextEx::applyColor(int idx, std::vector &packedCo } bool SoFCSelectionContextEx::isSingleColor(uint32_t &color, bool &hasTransparency) { - if(colors.size() && colors.begin()->first<0) { + if(!colors.empty() && colors.begin()->first<0) { color = packColor(colors.begin()->second,hasTransparency); return colors.size()==1; } diff --git a/src/Gui/SoFCSelectionContext.h b/src/Gui/SoFCSelectionContext.h index bc7c4d9bb0..6c86468914 100644 --- a/src/Gui/SoFCSelectionContext.h +++ b/src/Gui/SoFCSelectionContext.h @@ -68,7 +68,7 @@ struct GuiExport SoFCSelectionContext : SoFCSelectionContextBase } bool isSelectAll() const{ - return selectionIndex.size() && *selectionIndex.begin()<0; + return !selectionIndex.empty() && *selectionIndex.begin()<0; } bool isHighlighted() const { diff --git a/src/Gui/SoFCUnifiedSelection.cpp b/src/Gui/SoFCUnifiedSelection.cpp index b5db3b52b1..5055ac3b71 100644 --- a/src/Gui/SoFCUnifiedSelection.cpp +++ b/src/Gui/SoFCUnifiedSelection.cpp @@ -723,7 +723,7 @@ SoFCUnifiedSelection::handleEvent(SoHandleEventAction * action) if (mymode == AUTO || mymode == ON) { // check to see if the mouse is over our geometry... auto infos = this->getPickedList(action,true); - if(infos.size()) + if(!infos.empty()) setHighlight(infos[0]); else { setHighlight(PickedInfo()); @@ -1103,7 +1103,7 @@ void SoFCSelectionRoot::finish() } SoNode *SoFCSelectionRoot::getCurrentRoot(bool front, SoNode *def) { - if(SelStack.size()) + if(!SelStack.empty()) return front?SelStack.front():SelStack.back(); return def; } diff --git a/src/Gui/TaskElementColors.cpp b/src/Gui/TaskElementColors.cpp index dfdd396d26..afb4e148d2 100644 --- a/src/Gui/TaskElementColors.cpp +++ b/src/Gui/TaskElementColors.cpp @@ -206,7 +206,7 @@ public: } void removeAll() { - if(elements.size()) { + if(!elements.empty()) { hiddenSub.clear(); ui->elementList->clear(); elements.clear(); @@ -386,7 +386,7 @@ void ElementColors::on_hideSelection_clicked() { if(d->editObj!=sel.getFeatName()) continue; const auto &subs = sel.getSubNames(); - if(subs.size()) { + if(!subs.empty()) { for(auto &sub : subs) { if(boost::starts_with(sub,d->editSub)) { auto name = Data::ComplexGeoData::noElementName(sub.c_str()+d->editSub.size()); @@ -422,7 +422,7 @@ void ElementColors::on_addSelection_clicked() break; } } - if(d->items.size()) { + if(!d->items.empty()) { auto color = d->items.front()->data(Qt::UserRole).value(); QColorDialog cd(color, this); cd.setOption(QColorDialog::ShowAlphaChannel); @@ -470,7 +470,7 @@ void ElementColors::changeEvent(QEvent *e) void ElementColors::leaveEvent(QEvent *e) { QWidget::leaveEvent(e); Selection().rmvPreselect(); - if(d->hiddenSub.size()) { + if(!d->hiddenSub.empty()) { d->vp->partialRender({d->hiddenSub},false); d->hiddenSub.clear(); } @@ -478,7 +478,7 @@ void ElementColors::leaveEvent(QEvent *e) { void ElementColors::on_elementList_itemEntered(QListWidgetItem *item) { std::string name(qPrintable(item->data(Qt::UserRole+1).value())); - if(d->hiddenSub.size()) { + if(!d->hiddenSub.empty()) { d->vp->partialRender({d->hiddenSub},false); d->hiddenSub.clear(); } diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index cce328ad7a..8589972584 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -629,7 +629,7 @@ static bool _DisableCheckTopParent; void TreeWidget::checkTopParent(App::DocumentObject*& obj, std::string& subname) { if (_DisableCheckTopParent) return; - if (Instances.size() && obj && obj->getNameInDocument()) { + if (!Instances.empty() && obj && obj->getNameInDocument()) { auto tree = *Instances.begin(); auto it = tree->DocumentMap.find(Application::Instance->getDocument(obj->getDocument())); if (it != tree->DocumentMap.end()) { @@ -679,9 +679,9 @@ void TreeWidget::startItemSearch(QLineEdit* edit) { searchDoc = Application::Instance->activeDocument(); App::DocumentObject* obj = nullptr; - if (searchContextDoc && searchContextDoc->getDocument()->getObjects().size()) + if (searchContextDoc && !searchContextDoc->getDocument()->getObjects().empty()) obj = searchContextDoc->getDocument()->getObjects().front(); - else if (searchDoc && searchDoc->getDocument()->getObjects().size()) + else if (searchDoc && !searchDoc->getDocument()->getObjects().empty()) obj = searchDoc->getDocument()->getObjects().front(); if (obj) @@ -810,7 +810,7 @@ void TreeWidget::updateStatus(bool delay) { void TreeWidget::_updateStatus(bool delay) { if (!delay) { - if (ChangedObjects.size() || NewObjects.size()) + if (!ChangedObjects.empty() || !NewObjects.empty()) onUpdateStatus(); return; } @@ -1062,7 +1062,7 @@ bool TreeWidget::CheckForDependents() App::DocumentObject* obj = objitem->object()->getObject(); // get dependents auto subObjectList = obj->getOutList(); - if (subObjectList.size() > 0) + if (!subObjectList.empty()) return true; } } @@ -1855,7 +1855,7 @@ void TreeWidget::dropEvent(QDropEvent* event) } ViewProviderDocumentObject* vpp = nullptr; - if (da != Qt::LinkAction && info.parentDoc.size()) { + if (da != Qt::LinkAction && !info.parentDoc.empty()) { auto parentDoc = App::GetApplication().getDocument(info.parentDoc.c_str()); if (parentDoc) { auto parent = parentDoc->getObject(info.parent.c_str()); @@ -1869,7 +1869,7 @@ void TreeWidget::dropEvent(QDropEvent* event) } App::DocumentObject* owner = nullptr; - if (info.ownerDoc.size()) { + if (!info.ownerDoc.empty()) { auto ownerDoc = App::GetApplication().getDocument(info.ownerDoc.c_str()); if (ownerDoc) owner = ownerDoc->getObject(info.owner.c_str()); @@ -1882,7 +1882,7 @@ void TreeWidget::dropEvent(QDropEvent* event) Base::Matrix4D mat; App::PropertyPlacement* propPlacement = nullptr; if (syncPlacement) { - if (info.topObj.size()) { + if (!info.topObj.empty()) { auto doc = App::GetApplication().getDocument(info.topDoc.c_str()); if (doc) { auto topObj = doc->getObject(info.topObj.c_str()); @@ -1993,7 +1993,7 @@ void TreeWidget::dropEvent(QDropEvent* event) dropName = vp->dropObjectEx(obj, owner, subname.c_str(), info.subs); if (manager->getLines() == lines) manager->addLine(MacroManager::Gui, ss.str().c_str()); - if (dropName.size()) + if (!dropName.empty()) dropName = targetSubname.str() + dropName; } @@ -2035,7 +2035,7 @@ void TreeWidget::dropEvent(QDropEvent* event) droppedObjects.emplace_back(dropParent, dropName); } Base::FlagToggler<> guard(_DisableCheckTopParent); - if (setSelection && droppedObjects.size()) { + if (setSelection && !droppedObjects.empty()) { Selection().selStackPush(); Selection().clearCompleteSelection(); for (auto& v : droppedObjects) @@ -2056,7 +2056,7 @@ void TreeWidget::dropEvent(QDropEvent* event) FC_ERR("Unknown exception"); errMsg = "Unknown exception"; } - if (errMsg.size()) { + if (!errMsg.empty()) { committer.close(true); QMessageBox::critical(getMainWindow(), QObject::tr("Drag & drop failed"), QString::fromUtf8(errMsg.c_str())); @@ -2140,7 +2140,7 @@ void TreeWidget::dropEvent(QDropEvent* event) Base::Matrix4D mat; App::PropertyPlacement* propPlacement = nullptr; if (syncPlacement) { - if (info.topObj.size()) { + if (!info.topObj.empty()) { auto doc = App::GetApplication().getDocument(info.topDoc.c_str()); if (doc) { auto topObj = doc->getObject(info.topObj.c_str()); @@ -2174,7 +2174,7 @@ void TreeWidget::dropEvent(QDropEvent* event) propPlacement->setValueIfChanged(Base::Placement(mat)); droppedObjs.push_back(link); } - else if (info.parent.size()) { + else if (!info.parent.empty()) { auto parentDoc = App::GetApplication().getDocument(info.parentDoc.c_str()); if (!parentDoc) { FC_WARN("Canont find document " << info.parentDoc); @@ -2220,7 +2220,7 @@ void TreeWidget::dropEvent(QDropEvent* event) App::DocumentObject* res = nullptr; if (da == Qt::CopyAction) { auto copied = thisDoc->copyObject({ obj }, true); - if (copied.size()) + if (!copied.empty()) res = copied.back(); } else @@ -2252,7 +2252,7 @@ void TreeWidget::dropEvent(QDropEvent* event) FC_ERR("Unknown exception"); errMsg = "Unknown exception"; } - if (errMsg.size()) { + if (!errMsg.empty()) { committer.close(true); QMessageBox::critical(getMainWindow(), QObject::tr("Drag & drop failed"), QString::fromUtf8(errMsg.c_str())); @@ -2508,7 +2508,7 @@ void TreeWidget::onUpdateStatus(void) if (v.second.test(CS_Error) && obj->isError()) errors.push_back(obj); - if (iter->second.size()) { + if (!iter->second.empty()) { auto data = *iter->second.begin(); bool itemHidden = !data->viewObject->showInTree(); if (data->itemHidden != itemHidden) { @@ -2566,7 +2566,7 @@ void TreeWidget::onUpdateStatus(void) continue; if (iter->second->rootItem) docItem->restoreItemExpansion(entry.second, iter->second->rootItem); - else if (legacy && iter->second->items.size()) { + else if (legacy && !iter->second->items.empty()) { auto item = *iter->second->items.begin(); item->setExpanded(true); } @@ -2606,7 +2606,7 @@ void TreeWidget::onUpdateStatus(void) } if (data) { auto item = data->rootItem; - if (!item && data->items.size()) { + if (!item && !data->items.empty()) { item = *data->items.begin(); data->docItem->showItem(item, false, true); } @@ -2872,7 +2872,7 @@ void TreeWidget::onItemSelectionChanged() auto selItems = selectedItems(); // do not allow document item multi-selection - if (selItems.size()) { + if (!selItems.empty()) { auto firstType = selItems.back()->type(); for (auto it = selItems.begin(); it != selItems.end();) { auto item = *it; @@ -2896,7 +2896,7 @@ void TreeWidget::onItemSelectionChanged() // DocumentObject::redirectSubName() Selection().clearCompleteSelection(); DocumentObjectItem* item = nullptr; - if (selItems.size()) { + if (!selItems.empty()) { if (selItems.front()->type() == ObjectType) item = static_cast(selItems.front()); else if (selItems.front()->type() == DocumentType) { @@ -3096,7 +3096,7 @@ void TreePanel::hideEditor() this->searchBox->hide(); this->treeWidget->resetItemSearch(); auto sels = this->treeWidget->selectedItems(); - if (sels.size()) + if (!sels.empty()) this->treeWidget->scrollToItem(sels.front()); } @@ -3304,7 +3304,7 @@ bool DocumentItem::createNewItem(const Gui::ViewProviderDocumentObject& obj, pdata = std::make_shared( this, const_cast(&obj)); auto& entry = getTree()->ObjectTable[obj.getObject()]; - if (entry.size()) + if (!entry.empty()) pdata->updateChildren(*entry.begin()); else pdata->updateChildren(true); @@ -3330,7 +3330,7 @@ bool DocumentItem::createNewItem(const Gui::ViewProviderDocumentObject& obj, parent->insertChild(index, item); assert(item->parent() == parent); item->setText(0, QString::fromUtf8(data->label.c_str())); - if (data->label2.size()) + if (!data->label2.empty()) item->setText(1, QString::fromUtf8(data->label2.c_str())); if (!obj.showInTree() && !showHidden()) item->setHidden(true); @@ -4022,7 +4022,7 @@ void DocumentItem::slotRecomputed(const App::Document&, const std::vectorisValid()) tree->ChangedObjects[obj].set(TreeWidget::CS_Error); } - if (tree->ChangedObjects.size()) + if (!tree->ChangedObjects.empty()) tree->_updateStatus(); } @@ -4147,7 +4147,7 @@ void DocumentItem::updateItemSelection(DocumentObjectItem* item) { const char* docname = obj->getDocument()->getName(); const auto& subname = str.str(); - if (subname.size()) { + if (!subname.empty()) { auto parentItem = item->getParentItem(); assert(parentItem); if (selected && parentItem->selected) { @@ -4183,7 +4183,7 @@ void DocumentItem::updateItemSelection(DocumentObjectItem* item) { return; } selected = false; - if (item->mySubs.size()) { + if (!item->mySubs.empty()) { for (auto& sub : item->mySubs) { if (Gui::Selection().addSelection(docname, objname, (subname + sub).c_str())) selected = true; @@ -4565,7 +4565,7 @@ DocumentObjectItem::~DocumentObjectItem() if (myOwner && myData->items.empty()) { auto it = myOwner->_ParentMap.find(object()->getObject()); - if (it != myOwner->_ParentMap.end() && it->second.size()) { + if (it != myOwner->_ParentMap.end() && !it->second.empty()) { myOwner->PopulateObjects.push_back(*it->second.begin()); myOwner->getTree()->_updateStatus(); } diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index de23b1d63f..5ca6072358 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -665,7 +665,7 @@ void View3DInventorViewer::initialize() } void View3DInventorViewer::clearGroupOnTop() { - if(objectsOnTop.size() || objectsOnTopPreSel.size()) { + if(!objectsOnTop.empty() || !objectsOnTopPreSel.empty()) { objectsOnTop.clear(); objectsOnTopPreSel.clear(); SoSelectionElementAction action(SoSelectionElementAction::None,true); @@ -2739,7 +2739,7 @@ const SoPickedPoint* View3DInventorViewer::getPickedPoint(SoEventCallback* n) co { if (selectionRoot) { auto ret = selectionRoot->getPickedList(n->getAction(), true); - if(ret.size()) + if(!ret.empty()) return ret[0].pp; return nullptr; } diff --git a/src/Gui/View3DPy.cpp b/src/Gui/View3DPy.cpp index 6593d741ef..d5fe267162 100644 --- a/src/Gui/View3DPy.cpp +++ b/src/Gui/View3DPy.cpp @@ -1483,7 +1483,7 @@ Py::Object View3DInventorPy::getObjectInfo(const Py::Tuple& args) auto obj = vpd->getObject(); if (!obj) return ret; - if (subname.size()) { + if (!subname.empty()) { std::pair elementName; auto sobj = App::GeoFeature::resolveElement(obj,subname.c_str(),elementName); if (!sobj) @@ -1493,7 +1493,7 @@ Py::Object View3DInventorPy::getObjectInfo(const Py::Tuple& args) dict.setItem("SubName",Py::String(subname)); obj = sobj; } - subname = elementName.second.size()?elementName.second:elementName.first; + subname = !elementName.second.empty()?elementName.second:elementName.first; } dict.setItem("Document", Py::String(obj->getDocument()->getName())); @@ -1595,7 +1595,7 @@ Py::Object View3DInventorPy::getObjectsInfo(const Py::Tuple& args) auto obj = vpd->getObject(); if (!obj) continue; - if (subname.size()) { + if (!subname.empty()) { std::pair elementName; auto sobj = App::GeoFeature::resolveElement(obj,subname.c_str(),elementName); if (!sobj) @@ -1605,7 +1605,7 @@ Py::Object View3DInventorPy::getObjectsInfo(const Py::Tuple& args) dict.setItem("SubName",Py::String(subname)); obj = sobj; } - subname = elementName.second.size()?elementName.second:elementName.first; + subname = !elementName.second.empty()?elementName.second:elementName.first; } dict.setItem("Document", Py::String(obj->getDocument()->getName())); diff --git a/src/Gui/ViewProvider.cpp b/src/Gui/ViewProvider.cpp index 2b651d96b4..8be208031e 100644 --- a/src/Gui/ViewProvider.cpp +++ b/src/Gui/ViewProvider.cpp @@ -1009,7 +1009,7 @@ Base::BoundBox3d ViewProvider::getBoundingBox(const char *subname, bool transfor auto doc = Application::Instance->activeDocument(); if(doc) { auto views = doc->getMDIViewsOfType(View3DInventor::getClassTypeId()); - if(views.size()) + if(!views.empty()) iview = dynamic_cast(views.front()); } if(!iview) { diff --git a/src/Gui/ViewProviderLink.cpp b/src/Gui/ViewProviderLink.cpp index 590658bb0e..59e23d392b 100644 --- a/src/Gui/ViewProviderLink.cpp +++ b/src/Gui/ViewProviderLink.cpp @@ -245,7 +245,7 @@ public: FC_LOG("link detach " << getLinkedNameSafe()); auto me = LinkInfoPtr(this); if(unlink) { - while(links.size()) { + while(!links.empty()) { auto link = *links.begin(); links.erase(links.begin()); link->unlink(me); @@ -1101,7 +1101,7 @@ void LinkView::setChildren(const std::vector &children, const boost::dynamic_bitset<> &vis, SnapshotType type) { if(children.empty()) { - if(nodeArray.size()) { + if(!nodeArray.empty()) { nodeArray.clear(); nodeMap.clear(); childType = SnapshotContainer; @@ -1146,7 +1146,7 @@ void LinkView::setChildren(const std::vector &children, for(size_t i=0;ipcLinked->getObject())); if(iter != groups.end()) { @@ -1333,7 +1333,7 @@ void LinkView::updateLink() { linkedRoot->addChild(sub.pcNode); setTransform(sub.pcTransform,mat); - if(sub.subElements.size()) { + if(!sub.subElements.empty()) { path.truncate(1); appendPath(&path,sub.pcNode); SoSelectionElementAction action(SoSelectionElementAction::Append,true); @@ -1356,7 +1356,7 @@ bool LinkView::linkGetElementPicked(const SoPickedPoint *pp, std::string &subnam { std::ostringstream ss; CoinPtr path = pp->getPath(); - if(nodeArray.size()) { + if(!nodeArray.empty()) { auto idx = path->findNode(pcLinkRoot); if(idx<0 || idx+2>=path->getLength()) return false; @@ -1413,7 +1413,7 @@ bool LinkView::linkGetElementPicked(const SoPickedPoint *pp, std::string &subnam if(!sub.linkInfo->getElementPicked(false,SnapshotTransform,pp,ss2)) return false; const std::string &element = ss2.str(); - if(sub.subElements.size()) { + if(!sub.subElements.empty()) { if(sub.subElements.find(element)==sub.subElements.end()) { auto pos = element.find('.'); if(pos==std::string::npos || @@ -1528,7 +1528,7 @@ bool LinkView::linkGetDetailPath(const char *subname, SoFullPath *path, SoDetail continue; ++nextsub; } - if(*nextsub && sub.subElements.size() && + if(*nextsub && !sub.subElements.empty() && sub.subElements.find(nextsub)==sub.subElements.end()) break; appendPath(path,sub.pcNode); @@ -1584,7 +1584,7 @@ QIcon LinkView::getLinkedIcon(QPixmap px) const { } bool LinkView::hasSubs() const { - return isLinked() && subInfo.size(); + return isLinked() && !subInfo.empty(); } /////////////////////////////////////////////////////////////////////////////////// @@ -1856,7 +1856,7 @@ void ViewProviderLink::updateDataPrivate(App::LinkBaseExtension *ext, const App: subs.push_back(sub+s); } - if(subs.empty() && sub.size()) + if(subs.empty() && !sub.empty()) subs.push_back(sub); hasSubName = !subs.empty(); @@ -1891,7 +1891,7 @@ void ViewProviderLink::updateDataPrivate(App::LinkBaseExtension *ext, const App: const auto &elements = ext->_getElementListValue(); // elements is about to be collapsed, preserve the materials - if(elements.size()) { + if(!elements.empty()) { std::vector materials; boost::dynamic_bitset<> overrideMaterials; overrideMaterials.resize(elements.size(),false); @@ -2075,7 +2075,7 @@ bool ViewProviderLink::hasElements(const App::LinkBaseExtension *ext) const { return false; } const auto &elements = ext->getElementListValue(); - return elements.size() && (int)elements.size()==ext->_getElementCountValue(); + return !elements.empty() && (int)elements.size()==ext->_getElementCountValue(); } bool ViewProviderLink::isGroup(const App::LinkBaseExtension *ext, bool plainGroup) const { @@ -2242,11 +2242,11 @@ std::string ViewProviderLink::dropObjectEx(App::DocumentObject* obj, return linked->dropObjectEx(obj,owner,subname,subElements); } if(owner) { - if(ext->getSubElements().size()) + if(!ext->getSubElements().empty()) ext->setLink(-1,owner,subname,subElements); else ext->setLink(-1,owner,subname); - } else if(ext->getSubElements().size()) + } else if(!ext->getSubElements().empty()) ext->setLink(-1,obj,nullptr,subElements); else ext->setLink(-1,obj,nullptr); @@ -3046,7 +3046,7 @@ std::map ViewProviderLink::getElementColors(const char if(wildcard.size()==4) return colors; } - if(wildcard.size()) + if(!wildcard.empty()) wildcard.resize(4); }else if(wildcard == "Edge*") wildcard.resize(4); @@ -3058,7 +3058,7 @@ std::map ViewProviderLink::getElementColors(const char wildcard.clear(); int i=-1; - if(wildcard.size()) { + if(!wildcard.empty()) { for(const auto &sub : subs) { if(++i >= size) break; @@ -3122,7 +3122,7 @@ std::map ViewProviderLink::getElementColors(const char int offset = 0; - if(sub.second.size() && element_count && !std::isdigit(sub.second[0])) { + if(!sub.second.empty() && element_count && !std::isdigit(sub.second[0])) { // For checking and expanding color override of array base if(!subname[0]) { std::ostringstream ss; @@ -3207,7 +3207,7 @@ void ViewProviderLink::setElementColors(const std::map continue; } - if(element_count && v.first.size() && std::isdigit(v.first[0])) { + if(element_count && !v.first.empty() && std::isdigit(v.first[0])) { // In case of array, check if there are override of the same // sub-element for every array element. And collapse those overrides // into one without the index. @@ -3303,7 +3303,7 @@ void ViewProviderLink::applyColors() { for(const auto &sub : hideList) { SoDetail *det=nullptr; path.truncate(0); - if(sub.size() && getDetailPath(sub.c_str(), &path, false, det)) + if(!sub.empty() && getDetailPath(sub.c_str(), &path, false, det)) action.apply(&path); delete det; } diff --git a/src/Gui/propertyeditor/PropertyEditor.cpp b/src/Gui/propertyeditor/PropertyEditor.cpp index c7d9af522b..e256a232d9 100644 --- a/src/Gui/propertyeditor/PropertyEditor.cpp +++ b/src/Gui/propertyeditor/PropertyEditor.cpp @@ -631,7 +631,7 @@ void PropertyEditor::contextMenuEvent(QContextMenuEvent *) { continue; for(auto parent=item;parent;parent=parent->parent()) { const auto &ps = parent->getPropertyData(); - if(ps.size()) { + if(!ps.empty()) { props.insert(ps.begin(),ps.end()); break; } @@ -655,7 +655,7 @@ void PropertyEditor::contextMenuEvent(QContextMenuEvent *) { } if(PropertyView::showAll()) { - if(props.size()) { + if(!props.empty()) { menu.addAction(tr("Add property"))->setData(QVariant(MA_AddProp)); if (std::all_of(props.begin(), props.end(), [](auto prop) { return prop->testStatus(App::Property::PropDynamic) @@ -681,7 +681,7 @@ void PropertyEditor::contextMenuEvent(QContextMenuEvent *) { if(canRemove) menu.addAction(tr("Remove property"))->setData(QVariant(MA_RemoveProp)); - if(props.size()) { + if(!props.empty()) { menu.addSeparator(); QAction *action; diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 2d182fcdfb..ecef0408b3 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -4339,7 +4339,7 @@ void LinkLabel::updatePropertyLink() linkcolor, DlgPropertyLink::formatObject( owner->getDocument(), sobj.getObject(), sobj.getSubName().c_str())); - } else if (links.size()) { + } else if (!links.empty()) { text = DlgPropertyLink::formatLinks(owner->getDocument(), links); } } @@ -4396,7 +4396,7 @@ PropertyLinkItem::PropertyLinkItem() QVariant PropertyLinkItem::toString(const QVariant& prop) const { QString res; - if(propertyItems.size()) { + if(!propertyItems.empty()) { App::DocumentObjectT owner(propertyItems[0]); res = DlgPropertyLink::formatLinks(owner.getDocument(), qvariant_cast >(prop)); @@ -4405,7 +4405,7 @@ QVariant PropertyLinkItem::toString(const QVariant& prop) const } QVariant PropertyLinkItem::data(int column, int role) const { - if(propertyItems.size() && column == 1 + if(!propertyItems.empty() && column == 1 && (role == Qt::ForegroundRole || role == Qt::ToolTipRole)) { auto propLink = Base::freecad_dynamic_cast(propertyItems[0]);