From 916c81421936056cf81fb4bdda73cfed8419482c Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 24 Jul 2022 20:07:04 +0200 Subject: [PATCH] Fix several clazy issue: * Use multi-arg instead [-Wclazy-qstring-arg] * Use an empty QLatin1String instead of an empty QStringLiteral [-Wclazy-empty-qstringliteral] * getter Gui::ProgressBar::canAbort possibly mismarked as a slot [-Wclazy-const-signal-or-slot] * Missing emit keyword on signal call [-Wclazy-incorrect-emit] --- src/Gui/Action.cpp | 4 +-- src/Gui/DlgPreferencePackManagementImp.cpp | 6 ++-- src/Gui/Document.cpp | 24 +++++++-------- src/Gui/ProgressBar.h | 1 + src/Gui/QuantitySpinBox.cpp | 2 +- src/Gui/SelectionView.cpp | 21 +++++++------ src/Gui/Splashscreen.cpp | 6 ++-- src/Gui/VectorListEditor.cpp | 4 +-- src/Gui/propertyeditor/PropertyItem.cpp | 36 +++++++++++----------- 9 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/Gui/Action.cpp b/src/Gui/Action.cpp index a6d1ba7e22..e0a4c259b3 100644 --- a/src/Gui/Action.cpp +++ b/src/Gui/Action.cpp @@ -914,7 +914,7 @@ void RecentMacrosAction::setFiles(const QStringList& files) if (check) { recentFiles[index]->setShortcut(QKeySequence()); auto msg = QStringLiteral("Recent macros : keyboard shortcut %1 disabled because conflicting with %2") - .arg(accel_tmp).arg(QLatin1String(check->getName())); + .arg(accel_tmp, QLatin1String(check->getName())); Base::Console().Warning("%s\n", qPrintable(msg)); } else { @@ -922,7 +922,7 @@ void RecentMacrosAction::setFiles(const QStringList& files) recentFiles[index]->setShortcut(accel); } } - recentFiles[index]->setStatusTip(tr("Run macro %1 (Shift+click to edit) keyboard shortcut: %2").arg(files[index]).arg(accel)); + recentFiles[index]->setStatusTip(tr("Run macro %1 (Shift+click to edit) keyboard shortcut: %2").arg(files[index], accel)); recentFiles[index]->setVisible(true); } diff --git a/src/Gui/DlgPreferencePackManagementImp.cpp b/src/Gui/DlgPreferencePackManagementImp.cpp index 6134266424..dde897ca7d 100644 --- a/src/Gui/DlgPreferencePackManagementImp.cpp +++ b/src/Gui/DlgPreferencePackManagementImp.cpp @@ -182,7 +182,7 @@ void DlgPreferencePackManagementImp::deleteUserPack(const std::string& name) if (result == QMessageBox::Yes) { Application::Instance->prefPackManager()->deleteUserPack(name); showEvent(nullptr); - packVisibilityChanged(); + Q_EMIT packVisibilityChanged(); } } @@ -190,14 +190,14 @@ void DlgPreferencePackManagementImp::hideBuiltInPack(const std::string& prefPack { Application::Instance->prefPackManager()->toggleVisibility("##BUILT_IN##", prefPackName); showEvent(nullptr); - packVisibilityChanged(); + Q_EMIT packVisibilityChanged(); } void DlgPreferencePackManagementImp::hideInstalledPack(const std::string& addonName, const std::string& prefPackName) { Application::Instance->prefPackManager()->toggleVisibility(addonName, prefPackName); showEvent(nullptr); - packVisibilityChanged(); + Q_EMIT packVisibilityChanged(); } void DlgPreferencePackManagementImp::showAddonManager() diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index 9d197f1b36..316a5a7d4b 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -1206,7 +1206,7 @@ bool Document::saveAs(void) QString exe = qApp->applicationName(); QString fn = FileDialog::getSaveFileName(getMainWindow(), QObject::tr("Save %1 Document").arg(exe), QString::fromUtf8(getDocument()->FileName.getValue()), - QString::fromLatin1("%1 %2 (*.FCStd)").arg(exe).arg(QObject::tr("Document"))); + QString::fromLatin1("%1 %2 (*.FCStd)").arg(exe, QObject::tr("Document"))); if (!fn.isEmpty()) { QFileInfo fi; @@ -2324,20 +2324,18 @@ bool Document::checkTransactionID(bool undo, int iSteps) { } str << " " << doc->getName() << "\n"; } - int ret = QMessageBox::warning(getMainWindow(), - undo?QObject::tr("Undo"):QObject::tr("Redo"), - QString::fromLatin1("%1,\n%2%3") - .arg(QObject::tr( - "There are grouped transactions in the following documents with " - "other preceding transactions")) - .arg(QString::fromUtf8(str.str().c_str())) - .arg(QObject::tr("Choose 'Yes' to roll back all preceding transactions.\n" - "Choose 'No' to roll back in the active document only.\n" - "Choose 'Abort' to abort")), + int ret = QMessageBox::warning(getMainWindow(), undo ? QObject::tr("Undo") : QObject::tr("Redo"), + QString::fromLatin1("%1,\n%2%3").arg( + QObject::tr("There are grouped transactions in the following documents with " + "other preceding transactions"), + QString::fromStdString(str.str()), + QObject::tr("Choose 'Yes' to roll back all preceding transactions.\n" + "Choose 'No' to roll back in the active document only.\n" + "Choose 'Abort' to abort")), QMessageBox::Yes|QMessageBox::No|QMessageBox::Abort, QMessageBox::Yes); - if(ret == QMessageBox::Abort) + if (ret == QMessageBox::Abort) return false; - if(ret == QMessageBox::No) + if (ret == QMessageBox::No) return true; } for(auto &v : dmap) { diff --git a/src/Gui/ProgressBar.h b/src/Gui/ProgressBar.h index f27d09233e..b780d5a4c3 100644 --- a/src/Gui/ProgressBar.h +++ b/src/Gui/ProgressBar.h @@ -168,6 +168,7 @@ public Q_SLOTS: */ void setMinimumDuration (int ms); +public: bool canAbort() const; protected: diff --git a/src/Gui/QuantitySpinBox.cpp b/src/Gui/QuantitySpinBox.cpp index 5e6cc9b20c..a229ca7646 100644 --- a/src/Gui/QuantitySpinBox.cpp +++ b/src/Gui/QuantitySpinBox.cpp @@ -601,7 +601,7 @@ void QuantitySpinBox::updateFromCache(bool notify, bool updateUnit /* = true */) d->pendingEmit = false; Q_EMIT valueChanged(res); Q_EMIT valueChanged(res.getValue()); - textChanged(text); + Q_EMIT textChanged(text); } } } diff --git a/src/Gui/SelectionView.cpp b/src/Gui/SelectionView.cpp index 9b62ff34a5..d16b84b770 100644 --- a/src/Gui/SelectionView.cpp +++ b/src/Gui/SelectionView.cpp @@ -177,7 +177,8 @@ void SelectionView::onSelectionChanged(const SelectionChanges &Reason) str << Reason.pDocName; str << "#"; // remove all items - for(auto item : selectionView->findItems(selObject,Qt::MatchStartsWith)) + const auto items = selectionView->findItems(selObject,Qt::MatchStartsWith); + for(auto item : items) delete item; } } @@ -381,15 +382,15 @@ void SelectionView::toggleSelect(QListWidgetItem* item) if(Gui::Selection().isSelected(docname,objname,subname)) cmd = QString::fromLatin1("Gui.Selection.removeSelection(" "App.getDocument('%1').getObject('%2'),'%3')") - .arg(QString::fromLatin1(docname)) - .arg(QString::fromLatin1(objname)) - .arg(QString::fromLatin1(subname)); + .arg(QString::fromLatin1(docname), + QString::fromLatin1(objname), + QString::fromLatin1(subname)); else cmd = QString::fromLatin1("Gui.Selection.addSelection(" "App.getDocument('%1').getObject('%2'),'%3',%4,%5,%6)") - .arg(QString::fromLatin1(docname)) - .arg(QString::fromLatin1(objname)) - .arg(QString::fromLatin1(subname)) + .arg(QString::fromLatin1(docname), + QString::fromLatin1(objname), + QString::fromLatin1(subname)) .arg(x).arg(y).arg(z); try { Gui::Command::runCommand(Gui::Command::Gui,cmd.toLatin1()); @@ -419,9 +420,9 @@ void SelectionView::preselect(QListWidgetItem* item) } QString cmd = QString::fromLatin1("Gui.Selection.setPreselection(" "App.getDocument('%1').getObject('%2'),'%3',tp=2)") - .arg(QString::fromLatin1(docname)) - .arg(QString::fromLatin1(objname)) - .arg(QString::fromLatin1(subname)); + .arg(QString::fromLatin1(docname), + QString::fromLatin1(objname), + QString::fromLatin1(subname)); try { Gui::Command::runCommand(Gui::Command::Gui,cmd.toLatin1()); }catch(Base::Exception &e) { diff --git a/src/Gui/Splashscreen.cpp b/src/Gui/Splashscreen.cpp index 3965665159..1a454da40b 100644 --- a/src/Gui/Splashscreen.cpp +++ b/src/Gui/Splashscreen.cpp @@ -686,9 +686,9 @@ void AboutDialog::on_copyButton_clicked() QString minor = QString::fromLatin1(config["BuildVersionMinor"].c_str()); QString build = QString::fromLatin1(config["BuildRevision"].c_str()); - QString deskEnv = QProcessEnvironment::systemEnvironment().value(QStringLiteral("XDG_CURRENT_DESKTOP"),QStringLiteral("")); - QString deskSess = QProcessEnvironment::systemEnvironment().value(QStringLiteral("DESKTOP_SESSION"),QStringLiteral("")); - QString deskInfo = QStringLiteral(""); + QString deskEnv = QProcessEnvironment::systemEnvironment().value(QStringLiteral("XDG_CURRENT_DESKTOP"), QString()); + QString deskSess = QProcessEnvironment::systemEnvironment().value(QStringLiteral("DESKTOP_SESSION"), QString()); + QString deskInfo; if ( !(deskEnv.isEmpty() && deskSess.isEmpty()) ) { if ( deskEnv.isEmpty() || deskSess.isEmpty() ) diff --git a/src/Gui/VectorListEditor.cpp b/src/Gui/VectorListEditor.cpp index b12d203308..6a27bcaf99 100644 --- a/src/Gui/VectorListEditor.cpp +++ b/src/Gui/VectorListEditor.cpp @@ -76,7 +76,7 @@ bool VectorTableModel::setData(const QModelIndex &index, const QVariant &value, if (role == Qt::EditRole && r < vectors.size()) { if (value.canConvert()) { vectors[r] = value.value(); - dataChanged(index, index.sibling(index.row(), 2)); + Q_EMIT dataChanged(index, index.sibling(index.row(), 2)); return true; } else if (c < 3) { @@ -87,7 +87,7 @@ bool VectorTableModel::setData(const QModelIndex &index, const QVariant &value, vectors[r].y = d; else if (c == 2) vectors[r].z = d; - dataChanged(index, index); + Q_EMIT dataChanged(index, index); return true; } } diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 86c6ce9ccb..e397a81131 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -123,7 +123,7 @@ void PropertyItem::reset() void PropertyItem::onChange() { if(hasExpression()) { - for(auto child : childItems) { + for(auto child : qAsConst(childItems)) { if(child && child->hasExpression()) child->setExpression(std::shared_ptr()); } @@ -1356,7 +1356,7 @@ public: } bool apply(const std::string &propName) { - if (!ExpressionBinding::apply(propName)) { + if (!ExpressionBinding::apply(propName)) { // clazy:exclude=skipped-base-method QVariant data = property("coords"); if (data.canConvert()) { const Base::Vector3d& value = data.value(); @@ -1554,7 +1554,7 @@ void PropertyEditorWidget::setValue(const QVariant& val) { variant = val; showValue(variant); - valueChanged(variant); + Q_EMIT valueChanged(variant); } // --------------------------------------------------------------- @@ -1724,9 +1724,9 @@ void PropertyVectorDistanceItem::setValue(const QVariant& variant) Base::QuantityFormat format(Base::QuantityFormat::Fixed, decimals()); QString data = QString::fromLatin1("(%1, %2, %3)") - .arg(Base::UnitsApi::toNumber(x, format)) - .arg(Base::UnitsApi::toNumber(y, format)) - .arg(Base::UnitsApi::toNumber(z, format)); + .arg(Base::UnitsApi::toNumber(x, format), + Base::UnitsApi::toNumber(y, format), + Base::UnitsApi::toNumber(z, format)); setPropertyValue(data); } @@ -2412,10 +2412,10 @@ void PropertyRotationItem::setValue(const QVariant& value) h.getValue(axis, angle); Base::QuantityFormat format(Base::QuantityFormat::Fixed, decimals()); QString data = QString::fromLatin1("App.Rotation(App.Vector(%1,%2,%3),%4)") - .arg(Base::UnitsApi::toNumber(axis.x, format)) - .arg(Base::UnitsApi::toNumber(axis.y, format)) - .arg(Base::UnitsApi::toNumber(axis.z, format)) - .arg(Base::UnitsApi::toNumber(angle, format)); + .arg(Base::UnitsApi::toNumber(axis.x, format), + Base::UnitsApi::toNumber(axis.y, format), + Base::UnitsApi::toNumber(axis.z, format), + Base::UnitsApi::toNumber(angle, format)); setPropertyValue(data); } @@ -2724,13 +2724,13 @@ void PropertyPlacementItem::setValue(const QVariant& value) QString data = QString::fromLatin1("App.Placement(" "App.Vector(%1,%2,%3)," "App.Rotation(App.Vector(%4,%5,%6),%7))") - .arg(Base::UnitsApi::toNumber(pos.x, format)) - .arg(Base::UnitsApi::toNumber(pos.y, format)) - .arg(Base::UnitsApi::toNumber(pos.z, format)) - .arg(Base::UnitsApi::toNumber(axis.x, format)) - .arg(Base::UnitsApi::toNumber(axis.y, format)) - .arg(Base::UnitsApi::toNumber(axis.z, format)) - .arg(Base::UnitsApi::toNumber(angle, format)); + .arg(Base::UnitsApi::toNumber(pos.x, format), + Base::UnitsApi::toNumber(pos.y, format), + Base::UnitsApi::toNumber(pos.z, format), + Base::UnitsApi::toNumber(axis.x, format), + Base::UnitsApi::toNumber(axis.y, format), + Base::UnitsApi::toNumber(axis.z, format), + Base::UnitsApi::toNumber(angle, format)); setPropertyValue(data); } @@ -2971,7 +2971,7 @@ QWidget* PropertyEnumItem::createEditor(QWidget* parent, const QObject* receiver }); QObject::connect(menu, &QMenu::triggered, this, [=](QAction *action) { button->setText(action->data().toString()); - button->picked(); + Q_EMIT button->picked(); }); QObject::connect(button, SIGNAL(picked()), receiver, method); return button;