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 <QColor>
#include <QCryptographicHash>
#include <QFont>
#include <QFontMetrics>
#include <QKeySequence>
@ -37,7 +38,6 @@
#include <QTextCursor>
#include <QTextEdit>
#include <QTextFormat>
#include <QtCore>
class QTextDocument;
@ -448,15 +448,14 @@ void CodeEditor::lineNumberAreaPaintEvent(const QPaintEvent *event)
QString CodeEditor::generateStyleString()
{
QString bgcolor = QString("background:rgb(%1,%2,%3);")
.arg(mWidgetStyle->widgetBGColor.red())
.arg(mWidgetStyle->widgetBGColor.green())
.arg(mWidgetStyle->widgetBGColor.blue());
.arg(mWidgetStyle->widgetBGColor.red(),
mWidgetStyle->widgetBGColor.green(),
mWidgetStyle->widgetBGColor.blue());
QString fgcolor = QString("color:rgb(%1,%2,%3);")
.arg(mWidgetStyle->widgetFGColor.red())
.arg(mWidgetStyle->widgetFGColor.green())
.arg(mWidgetStyle->widgetFGColor.blue());
.arg(mWidgetStyle->widgetFGColor.red(),
mWidgetStyle->widgetFGColor.green(),
mWidgetStyle->widgetFGColor.blue());
QString style = QString("%1 %2")
.arg(bgcolor)
.arg(fgcolor);
.arg(bgcolor, fgcolor);
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
// thus be sorted alphabetically over the descriptions.
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(";;");

View File

@ -37,6 +37,7 @@
#include <QCheckBox>
#include <QComboBox>
#include <QCoreApplication>
#include <QCryptographicHash>
#include <QDialogButtonBox>
#include <QDir>
#include <QFile>
@ -52,7 +53,6 @@
#include <QStringList>
#include <QTemporaryFile>
#include <QTextStream>
#include <QtCore>
static void addHeaders(const QString& file1, QSet<QString> &allFiles) {
if (allFiles.contains(file1))
@ -170,7 +170,7 @@ void ComplianceReportDialog::save()
} catch (InternalError &e) {
QMessageBox msg(QMessageBox::Critical,
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,
this);
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'")
.arg(xmlReader.lineNumber())
.arg(attributeName)
.arg(xmlReader.name().toString()).toStdString());
.arg(attributeName, xmlReader.name().toString())
.toStdString());
}
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);
QString line = QString("%1,%2,").arg(file).arg(error.errorPath.back().line);
line += QString("%1,%2,%3").arg(GuiSeverity::toString(error.severity)).arg(error.errorId).arg(error.summary);
QString line = QString("%1,%2,").arg(file, error.errorPath.back().line);
line += QString("%1,%2,%3").arg(GuiSeverity::toString(error.severity), error.errorId, error.summary);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
mTxtWriter << line << Qt::endl;
#else

View File

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

View File

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

View File

@ -861,7 +861,7 @@ bool MainWindow::tryLoadLibrary(Library *library, const QString& filename)
const Library::Error error = loadLibrary(library, filename);
if (error.errorcode != Library::ErrorCode::OK) {
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;
}
@ -899,7 +899,7 @@ bool MainWindow::tryLoadLibrary(Library *library, const QString& filename)
}
if (!error.reason.empty())
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 true;
@ -958,7 +958,7 @@ Settings MainWindow::getCppcheckSettings()
{
const QString cfgErr = QString::fromStdString(result.loadCppcheckCfg());
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;
result.addons.clear();
@ -1787,7 +1787,7 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile, const bool check
if (!errorMessage.isEmpty()) {
QMessageBox msg(QMessageBox::Critical,
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,
this);
msg.exec();
@ -1796,7 +1796,7 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile, const bool check
} catch (InternalError &e) {
QMessageBox msg(QMessageBox::Critical,
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,
this);
msg.exec();
@ -2100,7 +2100,7 @@ void MainWindow::replyFinished(QNetworkReply *reply) {
}
mUI->mButtonHideInformation->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);
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 += "\n";

View File

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