Fix two types of Clazy warnings (#5807)

Chained QString::arg, replace inclusion of QtCore
This commit is contained in:
Christoph Grüninger 2023-12-27 10:36:18 +01:00 committed by GitHub
parent 403e7f1f7d
commit 4a9b921ccf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 68 additions and 71 deletions

View File

@ -22,6 +22,7 @@
#include <QChar> #include <QChar>
#include <QColor> #include <QColor>
#include <QCryptographicHash>
#include <QFont> #include <QFont>
#include <QFontMetrics> #include <QFontMetrics>
#include <QKeySequence> #include <QKeySequence>
@ -37,7 +38,6 @@
#include <QTextCursor> #include <QTextCursor>
#include <QTextEdit> #include <QTextEdit>
#include <QTextFormat> #include <QTextFormat>
#include <QtCore>
class QTextDocument; class QTextDocument;
@ -448,15 +448,14 @@ void CodeEditor::lineNumberAreaPaintEvent(const QPaintEvent *event)
QString CodeEditor::generateStyleString() QString CodeEditor::generateStyleString()
{ {
QString bgcolor = QString("background:rgb(%1,%2,%3);") QString bgcolor = QString("background:rgb(%1,%2,%3);")
.arg(mWidgetStyle->widgetBGColor.red()) .arg(mWidgetStyle->widgetBGColor.red(),
.arg(mWidgetStyle->widgetBGColor.green()) mWidgetStyle->widgetBGColor.green(),
.arg(mWidgetStyle->widgetBGColor.blue()); mWidgetStyle->widgetBGColor.blue());
QString fgcolor = QString("color:rgb(%1,%2,%3);") QString fgcolor = QString("color:rgb(%1,%2,%3);")
.arg(mWidgetStyle->widgetFGColor.red()) .arg(mWidgetStyle->widgetFGColor.red(),
.arg(mWidgetStyle->widgetFGColor.green()) mWidgetStyle->widgetFGColor.green(),
.arg(mWidgetStyle->widgetFGColor.blue()); mWidgetStyle->widgetFGColor.blue());
QString style = QString("%1 %2") QString style = QString("%1 %2")
.arg(bgcolor) .arg(bgcolor, fgcolor);
.arg(fgcolor);
return style; return style;
} }

View File

@ -66,7 +66,7 @@ QString toFilterString(const QMap<QString,QString>& filters, bool addAllSupporte
// name patterns are our values. The generated filter string list will // name patterns are our values. The generated filter string list will
// thus be sorted alphabetically over the descriptions. // thus be sorted alphabetically over the descriptions.
for (const auto& k: filters.keys()) { for (const auto& k: filters.keys()) {
entries << QString("%1 (%2)").arg(k).arg(filters.value(k)); entries << QString("%1 (%2)").arg(k, filters.value(k));
} }
return entries.join(";;"); return entries.join(";;");

View File

@ -37,6 +37,7 @@
#include <QCheckBox> #include <QCheckBox>
#include <QComboBox> #include <QComboBox>
#include <QCoreApplication> #include <QCoreApplication>
#include <QCryptographicHash>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
@ -52,7 +53,6 @@
#include <QStringList> #include <QStringList>
#include <QTemporaryFile> #include <QTemporaryFile>
#include <QTextStream> #include <QTextStream>
#include <QtCore>
static void addHeaders(const QString& file1, QSet<QString> &allFiles) { static void addHeaders(const QString& file1, QSet<QString> &allFiles) {
if (allFiles.contains(file1)) if (allFiles.contains(file1))
@ -170,7 +170,7 @@ void ComplianceReportDialog::save()
} catch (InternalError &e) { } catch (InternalError &e) {
QMessageBox msg(QMessageBox::Critical, QMessageBox msg(QMessageBox::Critical,
tr("Save compliance report"), tr("Save compliance report"),
tr("Failed to import '%1' (%2), can not show files in compliance report").arg(prjfile).arg(QString::fromStdString(e.errorMessage)), tr("Failed to import '%1' (%2), can not show files in compliance report").arg(prjfile, QString::fromStdString(e.errorMessage)),
QMessageBox::Ok, QMessageBox::Ok,
this); this);
msg.exec(); msg.exec();

View File

@ -46,8 +46,8 @@ static std::string mandatoryAttibuteMissing(const QXmlStreamReader &xmlReader, c
{ {
throw std::runtime_error(QObject::tr("line %1: Mandatory attribute '%2' missing in '%3'") throw std::runtime_error(QObject::tr("line %1: Mandatory attribute '%2' missing in '%3'")
.arg(xmlReader.lineNumber()) .arg(xmlReader.lineNumber())
.arg(attributeName) .arg(attributeName, xmlReader.name().toString())
.arg(xmlReader.name().toString()).toStdString()); .toStdString());
} }
static CppcheckLibraryData::Container loadContainer(QXmlStreamReader &xmlReader) static CppcheckLibraryData::Container loadContainer(QXmlStreamReader &xmlReader)

View File

@ -62,8 +62,8 @@ void CsvReport::writeError(const ErrorItem &error)
*/ */
const QString file = QDir::toNativeSeparators(error.errorPath.back().file); const QString file = QDir::toNativeSeparators(error.errorPath.back().file);
QString line = QString("%1,%2,").arg(file).arg(error.errorPath.back().line); QString line = QString("%1,%2,").arg(file, error.errorPath.back().line);
line += QString("%1,%2,%3").arg(GuiSeverity::toString(error.severity)).arg(error.errorId).arg(error.summary); line += QString("%1,%2,%3").arg(GuiSeverity::toString(error.severity), error.errorId, error.summary);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
mTxtWriter << line << Qt::endl; mTxtWriter << line << Qt::endl;
#else #else

View File

@ -121,7 +121,7 @@ void LibraryDialog::openCfg()
if (!errmsg.isNull()) { if (!errmsg.isNull()) {
QMessageBox msg(QMessageBox::Critical, QMessageBox msg(QMessageBox::Critical,
tr("Cppcheck"), tr("Cppcheck"),
tr("Failed to load %1. %2.").arg(selectedFile).arg(errmsg), tr("Failed to load %1. %2.").arg(selectedFile, errmsg),
QMessageBox::Ok, QMessageBox::Ok,
this); this);
msg.exec(); msg.exec();

View File

@ -39,7 +39,6 @@
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QVariant> #include <QVariant>
#include <QtCore>
static void ShowUsage(); static void ShowUsage();

View File

@ -861,7 +861,7 @@ bool MainWindow::tryLoadLibrary(Library *library, const QString& filename)
const Library::Error error = loadLibrary(library, filename); const Library::Error error = loadLibrary(library, filename);
if (error.errorcode != Library::ErrorCode::OK) { if (error.errorcode != Library::ErrorCode::OK) {
if (error.errorcode == Library::ErrorCode::UNKNOWN_ELEMENT) { if (error.errorcode == Library::ErrorCode::UNKNOWN_ELEMENT) {
QMessageBox::information(this, tr("Information"), tr("The library '%1' contains unknown elements:\n%2").arg(filename).arg(error.reason.c_str())); QMessageBox::information(this, tr("Information"), tr("The library '%1' contains unknown elements:\n%2").arg(filename, error.reason.c_str()));
return true; return true;
} }
@ -899,7 +899,7 @@ bool MainWindow::tryLoadLibrary(Library *library, const QString& filename)
} }
if (!error.reason.empty()) if (!error.reason.empty())
errmsg += " '" + QString::fromStdString(error.reason) + "'"; errmsg += " '" + QString::fromStdString(error.reason) + "'";
QMessageBox::information(this, tr("Information"), tr("Failed to load the selected library '%1'.\n%2").arg(filename).arg(errmsg)); QMessageBox::information(this, tr("Information"), tr("Failed to load the selected library '%1'.\n%2").arg(filename, errmsg));
return false; return false;
} }
return true; return true;
@ -958,7 +958,7 @@ Settings MainWindow::getCppcheckSettings()
{ {
const QString cfgErr = QString::fromStdString(result.loadCppcheckCfg()); const QString cfgErr = QString::fromStdString(result.loadCppcheckCfg());
if (!cfgErr.isEmpty()) if (!cfgErr.isEmpty())
QMessageBox::critical(this, tr("Error"), tr("Failed to load %1 - %2").arg("cppcheck.cfg").arg(cfgErr)); QMessageBox::critical(this, tr("Error"), tr("Failed to load %1 - %2").arg("cppcheck.cfg", cfgErr));
const auto cfgAddons = result.addons; const auto cfgAddons = result.addons;
result.addons.clear(); result.addons.clear();
@ -1787,7 +1787,7 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile, const bool check
if (!errorMessage.isEmpty()) { if (!errorMessage.isEmpty()) {
QMessageBox msg(QMessageBox::Critical, QMessageBox msg(QMessageBox::Critical,
tr("Cppcheck"), tr("Cppcheck"),
tr("Failed to import '%1': %2\n\nAnalysis is stopped.").arg(prjfile).arg(errorMessage), tr("Failed to import '%1': %2\n\nAnalysis is stopped.").arg(prjfile, errorMessage),
QMessageBox::Ok, QMessageBox::Ok,
this); this);
msg.exec(); msg.exec();
@ -1796,7 +1796,7 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile, const bool check
} catch (InternalError &e) { } catch (InternalError &e) {
QMessageBox msg(QMessageBox::Critical, QMessageBox msg(QMessageBox::Critical,
tr("Cppcheck"), tr("Cppcheck"),
tr("Failed to import '%1' (%2), analysis is stopped").arg(prjfile).arg(QString::fromStdString(e.errorMessage)), tr("Failed to import '%1' (%2), analysis is stopped").arg(prjfile, QString::fromStdString(e.errorMessage)),
QMessageBox::Ok, QMessageBox::Ok,
this); this);
msg.exec(); msg.exec();
@ -2100,7 +2100,7 @@ void MainWindow::replyFinished(QNetworkReply *reply) {
} }
mUI->mButtonHideInformation->setVisible(true); mUI->mButtonHideInformation->setVisible(true);
mUI->mLabelInformation->setVisible(true); mUI->mLabelInformation->setVisible(true);
mUI->mLabelInformation->setText(tr("New version available: %1. %2").arg(str.trimmed()).arg(install)); mUI->mLabelInformation->setText(tr("New version available: %1. %2").arg(str.trimmed(), install));
} }
} }
} }

View File

@ -46,7 +46,7 @@ void PrintableReport::writeError(const ErrorItem &error)
{ {
const QString file = QDir::toNativeSeparators(error.errorPath.back().file); const QString file = QDir::toNativeSeparators(error.errorPath.back().file);
QString line = QString("%1,%2,").arg(file).arg(error.errorPath.back().line); QString line = QString("%1,%2,").arg(file).arg(error.errorPath.back().line);
line += QString("%1,%2").arg(GuiSeverity::toString(error.severity)).arg(error.summary); line += QString("%1,%2").arg(GuiSeverity::toString(error.severity), error.summary);
mFormattedReport += line; mFormattedReport += line;
mFormattedReport += "\n"; mFormattedReport += "\n";

View File

@ -55,7 +55,6 @@
#include <QSize> #include <QSize>
#include <QSpinBox> #include <QSpinBox>
#include <QVariant> #include <QVariant>
#include <QtCore>
static constexpr char ADDON_MISRA[] = "misra"; static constexpr char ADDON_MISRA[] = "misra";
static constexpr char CODING_STANDARD_MISRA_C_2023[] = "misra-c-2023"; static constexpr char CODING_STANDARD_MISRA_C_2023[] = "misra-c-2023";

View File

@ -816,7 +816,7 @@ void ResultsTree::startApplication(const QStandardItem *target, int application)
} }
#endif // Q_OS_WIN #endif // Q_OS_WIN
const QString cmdLine = QString("%1 %2").arg(program).arg(params); const QString cmdLine = QString("%1 %2").arg(program, params);
// this is reported as deprecated in Qt 5.15.2 but no longer in Qt 6 // this is reported as deprecated in Qt 5.15.2 but no longer in Qt 6
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))

View File

@ -463,7 +463,7 @@ void ResultsView::updateDetails(const QModelIndex &index)
const QString file0 = data["file0"].toString(); const QString file0 = data["file0"].toString();
if (!file0.isEmpty() && Path::isHeader(data["file"].toString().toStdString())) if (!file0.isEmpty() && Path::isHeader(data["file"].toString().toStdString()))
formattedMsg += QString("\n\n%1: %2").arg(tr("First included by")).arg(QDir::toNativeSeparators(file0)); formattedMsg += QString("\n\n%1: %2").arg(tr("First included by"), QDir::toNativeSeparators(file0));
if (data["cwe"].toInt() > 0) if (data["cwe"].toInt() > 0)
formattedMsg.prepend("CWE: " + QString::number(data["cwe"].toInt()) + "\n"); formattedMsg.prepend("CWE: " + QString::number(data["cwe"].toInt()) + "\n");

View File

@ -182,9 +182,9 @@ void StatsDialog::pdfExport()
"<font color=\"blue\"><h3>%9 : %10</h3></font>\n" "<font color=\"blue\"><h3>%9 : %10</h3></font>\n"
"<font color=\"blue\"><h3>%11 : %12</h3></font>\n" "<font color=\"blue\"><h3>%11 : %12</h3></font>\n"
"<font color=\"purple\"><h3>%13 : %14</h3></font>\n") "<font color=\"purple\"><h3>%13 : %14</h3></font>\n")
.arg(tr("Statistics")) .arg(tr("Statistics"),
.arg(QDate::currentDate().toString("dd.MM.yyyy")) QDate::currentDate().toString("dd.MM.yyyy"),
.arg(tr("Errors")) tr("Errors"))
.arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowErrors)) .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowErrors))
.arg(tr("Warnings")) .arg(tr("Warnings"))
.arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowWarnings)) .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowWarnings))
@ -246,17 +246,17 @@ void StatsDialog::copyToClipboard()
"\t%8:\t%9\n" "\t%8:\t%9\n"
"\t%10:\t%11\n" "\t%10:\t%11\n"
) )
.arg(projSettings) .arg(projSettings,
.arg(project) project,
.arg(mUI->mProject->text()) mUI->mProject->text(),
.arg(paths) paths,
.arg(mUI->mPaths->text()) mUI->mPaths->text(),
.arg(incPaths) incPaths,
.arg(mUI->mIncludePaths->text()) mUI->mIncludePaths->text(),
.arg(defines) defines)
.arg(mUI->mDefines->text()) .arg(mUI->mDefines->text(),
.arg(undefines) undefines,
.arg(mUI->mUndefines->text()); mUI->mUndefines->text());
const QString previous = QString( const QString previous = QString(
"%1\n" "%1\n"
@ -264,13 +264,13 @@ void StatsDialog::copyToClipboard()
"\t%4:\t%5\n" "\t%4:\t%5\n"
"\t%6:\t%7\n" "\t%6:\t%7\n"
) )
.arg(prevScan) .arg(prevScan,
.arg(selPath) selPath,
.arg(mUI->mPath->text()) mUI->mPath->text(),
.arg(numFiles) numFiles,
.arg(mUI->mNumberOfFilesScanned->text()) mUI->mNumberOfFilesScanned->text(),
.arg(duration) duration,
.arg(mUI->mScanDuration->text()); mUI->mScanDuration->text());
const QString statistics = QString( const QString statistics = QString(
"%1\n" "%1\n"
@ -281,8 +281,8 @@ void StatsDialog::copyToClipboard()
"\t%10:\t%11\n" "\t%10:\t%11\n"
"\t%12:\t%13\n" "\t%12:\t%13\n"
) )
.arg(stats) .arg(stats,
.arg(errors) errors)
.arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowErrors)) .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowErrors))
.arg(warnings) .arg(warnings)
.arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowWarnings)) .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowWarnings))
@ -308,17 +308,17 @@ void StatsDialog::copyToClipboard()
" <tr><th>%10:</th><td>%11</td></tr>\n" " <tr><th>%10:</th><td>%11</td></tr>\n"
"</table>\n" "</table>\n"
) )
.arg(projSettings) .arg(projSettings,
.arg(project) project,
.arg(mUI->mProject->text()) mUI->mProject->text(),
.arg(paths) paths,
.arg(mUI->mPaths->text()) mUI->mPaths->text(),
.arg(incPaths) incPaths,
.arg(mUI->mIncludePaths->text()) mUI->mIncludePaths->text(),
.arg(defines) defines)
.arg(mUI->mDefines->text()) .arg(mUI->mDefines->text(),
.arg(undefines) undefines,
.arg(mUI->mUndefines->text()); mUI->mUndefines->text());
const QString htmlPrevious = QString( const QString htmlPrevious = QString(
"<h3>%1</h3>\n" "<h3>%1</h3>\n"
@ -328,13 +328,13 @@ void StatsDialog::copyToClipboard()
" <tr><th>%6:</th><td>%7</td></tr>\n" " <tr><th>%6:</th><td>%7</td></tr>\n"
"</table>\n" "</table>\n"
) )
.arg(prevScan) .arg(prevScan,
.arg(selPath) selPath,
.arg(mUI->mPath->text()) mUI->mPath->text(),
.arg(numFiles) numFiles,
.arg(mUI->mNumberOfFilesScanned->text()) mUI->mNumberOfFilesScanned->text(),
.arg(duration) duration,
.arg(mUI->mScanDuration->text()); mUI->mScanDuration->text());
const QString htmlStatistics = QString( const QString htmlStatistics = QString(
"<h3>%1</h3>\n" "<h3>%1</h3>\n"
@ -346,8 +346,8 @@ void StatsDialog::copyToClipboard()
" <tr><th>%12:</th><td>%13</td></tr>\n" " <tr><th>%12:</th><td>%13</td></tr>\n"
"</table>\n" "</table>\n"
) )
.arg(stats) .arg(stats,
.arg(errors) errors)
.arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowErrors)) .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowErrors))
.arg(warnings) .arg(warnings)
.arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowWarnings)) .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowWarnings))