Skip to content

Commit

Permalink
fixed some modernize-use-auto clean-tidy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Dec 20, 2022
1 parent b380fd2 commit e30bee1
Show file tree
Hide file tree
Showing 25 changed files with 102 additions and 102 deletions.
2 changes: 1 addition & 1 deletion cli/cppcheckexecutorsig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
pid_t killid;
// TODO: separate these two defines
#if defined(__linux__) && defined(REG_ERR)
const ucontext_t* const uc = reinterpret_cast<const ucontext_t*>(context);
const auto* const uc = reinterpret_cast<const ucontext_t*>(context);
killid = (pid_t) syscall(SYS_gettid);
if (uc) {
type = (int)uc->uc_mcontext.gregs[REG_ERR] & 2;
Expand Down
2 changes: 1 addition & 1 deletion cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class PipeWriter : public ErrorLogger {

void writeToPipe(PipeSignal type, const std::string &data) const
{
unsigned int len = static_cast<unsigned int>(data.length() + 1);
auto len = static_cast<unsigned int>(data.length() + 1);
char *out = new char[len + 1 + sizeof(len)];
out[0] = static_cast<char>(type);
std::memcpy(&(out[1]), &len, sizeof(len));
Expand Down
8 changes: 4 additions & 4 deletions gui/codeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,11 @@ CodeEditor::CodeEditor(QWidget *parent) :
setStyleSheet(generateStyleString());

#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QShortcut *copyText = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_C),this);
QShortcut *allText = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_A),this);
auto *copyText = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_C),this);
auto *allText = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_A),this);
#else
QShortcut *copyText = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_C),this);
QShortcut *allText = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_A),this);
auto *copyText = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_C),this);
auto *allText = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_A),this);
#endif

connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
Expand Down
10 changes: 5 additions & 5 deletions gui/codeeditstyledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ StyleEditDialog::StyleEditDialog(const CodeEditorStyle& newStyle,
mStyleIncoming(newStyle),
mStyleOutgoing(newStyle)
{
QVBoxLayout *vboxMain = new QVBoxLayout(this);
QHBoxLayout *hboxEdit = new QHBoxLayout();
auto *vboxMain = new QVBoxLayout(this);
auto *hboxEdit = new QHBoxLayout();
// Color/Weight controls
QFormLayout *flEditControls = new QFormLayout();
auto *flEditControls = new QFormLayout();
mBtnWidgetColorFG = new SelectColorButton(this);
flEditControls->addRow(QObject::tr("Editor Foreground Color"),
mBtnWidgetColorFG);
Expand Down Expand Up @@ -134,7 +134,7 @@ StyleEditDialog::StyleEditDialog(const CodeEditorStyle& newStyle,
vboxMain->addLayout(hboxEdit);

// Default Controls
QHBoxLayout *hboxDefaultControls = new QHBoxLayout();
auto *hboxDefaultControls = new QHBoxLayout();
mBtnDefaultLight = new QPushButton(QObject::tr("Set to Default Light"),
this);
mBtnDefaultDark = new QPushButton(QObject::tr("Set to Default Dark"),
Expand All @@ -146,7 +146,7 @@ StyleEditDialog::StyleEditDialog(const CodeEditorStyle& newStyle,
vboxMain->addLayout(hboxDefaultControls);
vboxMain->addStretch(2);
// dialog controls
QDialogButtonBox *dBtnBox = new QDialogButtonBox(
auto *dBtnBox = new QDialogButtonBox(
QDialogButtonBox::Cancel |
QDialogButtonBox::Ok |
QDialogButtonBox::Reset);
Expand Down
2 changes: 1 addition & 1 deletion gui/librarydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void LibraryDialog::saveCfgAs()

void LibraryDialog::addFunction()
{
LibraryAddFunctionDialog *d = new LibraryAddFunctionDialog;
auto *d = new LibraryAddFunctionDialog;
if (d->exec() == QDialog::Accepted && !d->functionName().isEmpty()) {

CppcheckLibraryData::Function f;
Expand Down
4 changes: 2 additions & 2 deletions gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int main(int argc, char *argv[])
QCoreApplication::setOrganizationName("Cppcheck");
QCoreApplication::setApplicationName("Cppcheck-GUI");

QSettings* settings = new QSettings("Cppcheck", "Cppcheck-GUI", &app);
auto* settings = new QSettings("Cppcheck", "Cppcheck-GUI", &app);

// Set data dir..
const QStringList args = QApplication::arguments();
Expand All @@ -66,7 +66,7 @@ int main(int argc, char *argv[])
return 0;
}

TranslationHandler* th = new TranslationHandler(&app);
auto* th = new TranslationHandler(&app);
th->setLanguage(settings->value(SETTINGS_LANGUAGE, th->suggestLanguage()).toString());

if (!CheckArgs(QApplication::arguments()))
Expand Down
16 changes: 8 additions & 8 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :

for (int i = 0; i < mPlatforms.getCount(); i++) {
Platform platform = mPlatforms.mPlatforms[i];
QAction *action = new QAction(this);
auto *action = new QAction(this);
platform.mActMainWindow = action;
mPlatforms.mPlatforms[i] = platform;
action->setText(platform.mTitle);
Expand Down Expand Up @@ -939,7 +939,7 @@ Settings MainWindow::getCppcheckSettings()
result.loadPlatformFile(applicationFilePath.toStdString().c_str(), platform.toStdString());
} else {
for (int i = cppcheck::Platform::Native; i <= cppcheck::Platform::Unix64; i++) {
const cppcheck::Platform::PlatformType p = (cppcheck::Platform::PlatformType)i;
const auto p = (cppcheck::Platform::PlatformType)i;
if (platform == cppcheck::Platform::platformString(p)) {
result.platform(p);
break;
Expand Down Expand Up @@ -1388,21 +1388,21 @@ void MainWindow::about()
msg.exec();
}
else {
AboutDialog *dlg = new AboutDialog(CppCheck::version(), CppCheck::extraVersion(), this);
auto *dlg = new AboutDialog(CppCheck::version(), CppCheck::extraVersion(), this);
dlg->exec();
}
}

void MainWindow::showLicense()
{
FileViewDialog *dlg = new FileViewDialog(":COPYING", tr("License"), this);
auto *dlg = new FileViewDialog(":COPYING", tr("License"), this);
dlg->resize(570, 400);
dlg->exec();
}

void MainWindow::showAuthors()
{
FileViewDialog *dlg = new FileViewDialog(":AUTHORS", tr("Authors"), this);
auto *dlg = new FileViewDialog(":AUTHORS", tr("Authors"), this);
dlg->resize(350, 400);
dlg->exec();
}
Expand Down Expand Up @@ -1531,7 +1531,7 @@ void MainWindow::openHelpContents()

void MainWindow::openOnlineHelp()
{
HelpDialog *helpDialog = new HelpDialog;
auto *helpDialog = new HelpDialog;
helpDialog->showMaximized();
}

Expand Down Expand Up @@ -1785,7 +1785,7 @@ void MainWindow::enableProjectOpenActions(bool enable)

void MainWindow::openRecentProject()
{
QAction *action = qobject_cast<QAction *>(sender());
auto *action = qobject_cast<QAction *>(sender());
if (!action)
return;
const QString project = action->data().toString();
Expand Down Expand Up @@ -1874,7 +1874,7 @@ void MainWindow::removeProjectMRU(const QString &project)

void MainWindow::selectPlatform()
{
QAction *action = qobject_cast<QAction *>(sender());
auto *action = qobject_cast<QAction *>(sender());
if (action) {
const Settings::PlatformType platform = (Settings::PlatformType) action->data().toInt();
mSettings->setValue(SETTINGS_CHECKED_PLATFORM, platform);
Expand Down
10 changes: 5 additions & 5 deletions gui/projectfiledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, bool premium, QWi
libs.sort();
mUI->mLibraries->clear();
for (const QString &lib : libs) {
QListWidgetItem* item = new QListWidgetItem(lib, mUI->mLibraries);
auto* item = new QListWidgetItem(lib, mUI->mLibraries);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable); // set checkable flag
item->setCheckState(Qt::Unchecked); // AND initialize check state
}
Expand Down Expand Up @@ -566,7 +566,7 @@ void ProjectFileDialog::setProjectConfigurations(const QStringList &configs)
mUI->mListVsConfigs->clear();
mUI->mListVsConfigs->setEnabled(!configs.isEmpty() && !mUI->mChkAllVsConfigs->isChecked());
for (const QString &cfg : configs) {
QListWidgetItem* item = new QListWidgetItem(cfg, mUI->mListVsConfigs);
auto* item = new QListWidgetItem(cfg, mUI->mListVsConfigs);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable); // set checkable flag
item->setCheckState(Qt::Unchecked);
}
Expand All @@ -583,7 +583,7 @@ void ProjectFileDialog::addIncludeDir(const QString &dir)
return;

const QString newdir = QDir::toNativeSeparators(dir);
QListWidgetItem *item = new QListWidgetItem(newdir);
auto *item = new QListWidgetItem(newdir);
item->setFlags(item->flags() | Qt::ItemIsEditable);
mUI->mListIncludeDirs->addItem(item);
}
Expand All @@ -594,7 +594,7 @@ void ProjectFileDialog::addCheckPath(const QString &path)
return;

const QString newpath = QDir::toNativeSeparators(path);
QListWidgetItem *item = new QListWidgetItem(newpath);
auto *item = new QListWidgetItem(newpath);
item->setFlags(item->flags() | Qt::ItemIsEditable);
mUI->mListCheckPaths->addItem(item);
}
Expand All @@ -605,7 +605,7 @@ void ProjectFileDialog::addExcludePath(const QString &path)
return;

const QString newpath = QDir::toNativeSeparators(path);
QListWidgetItem *item = new QListWidgetItem(newpath);
auto *item = new QListWidgetItem(newpath);
item->setFlags(item->flags() | Qt::ItemIsEditable);
mUI->mListExcludedPaths->addItem(item);
}
Expand Down
26 changes: 13 additions & 13 deletions gui/resultstree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ void ResultsTree::initialize(QSettings *settings, ApplicationList *list, ThreadH

QStandardItem *ResultsTree::createNormalItem(const QString &name)
{
QStandardItem *item = new QStandardItem(name);
auto *item = new QStandardItem(name);
item->setData(name, Qt::ToolTipRole);
item->setEditable(false);
return item;
}

QStandardItem *ResultsTree::createCheckboxItem(bool checked)
{
QStandardItem *item = new QStandardItem;
auto *item = new QStandardItem;
item->setCheckable(true);
item->setCheckState(checked ? Qt::Checked : Qt::Unchecked);
item->setEnabled(false);
Expand All @@ -135,7 +135,7 @@ QStandardItem *ResultsTree::createCheckboxItem(bool checked)

QStandardItem *ResultsTree::createLineNumberItem(const QString &linenumber)
{
QStandardItem *item = new QStandardItem();
auto *item = new QStandardItem();
item->setData(QVariant(linenumber.toInt()), Qt::DisplayRole);
item->setToolTip(linenumber);
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
Expand Down Expand Up @@ -617,15 +617,15 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)

//Create a signal mapper so we don't have to store data to class
//member variables
QSignalMapper *signalMapper = new QSignalMapper(this);
auto *signalMapper = new QSignalMapper(this);

if (mContextItem && mApplications->getApplicationCount() > 0 && mContextItem->parent()) {
//Create an action for the application
int defaultApplicationIndex = mApplications->getDefaultApplication();
if (defaultApplicationIndex < 0)
defaultApplicationIndex = 0;
const Application& app = mApplications->getApplication(defaultApplicationIndex);
QAction *start = new QAction(app.getName(), &menu);
auto *start = new QAction(app.getName(), &menu);
if (multipleSelection)
start->setDisabled(true);

Expand All @@ -652,11 +652,11 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
}

//Create an action for the application
QAction *recheckSelectedFiles = new QAction(tr("Recheck"), &menu);
QAction *copy = new QAction(tr("Copy"), &menu);
QAction *hide = new QAction(tr("Hide"), &menu);
QAction *hideallid = new QAction(tr("Hide all with id"), &menu);
QAction *opencontainingfolder = new QAction(tr("Open containing folder"), &menu);
auto *recheckSelectedFiles = new QAction(tr("Recheck"), &menu);
auto *copy = new QAction(tr("Copy"), &menu);
auto *hide = new QAction(tr("Hide"), &menu);
auto *hideallid = new QAction(tr("Hide all with id"), &menu);
auto *opencontainingfolder = new QAction(tr("Open containing folder"), &menu);

if (multipleSelection) {
hideallid->setDisabled(true);
Expand All @@ -674,7 +674,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
menu.addAction(hide);
menu.addAction(hideallid);

QAction *suppress = new QAction(tr("Suppress selected id(s)"), &menu);
auto *suppress = new QAction(tr("Suppress selected id(s)"), &menu);
menu.addAction(suppress);
connect(suppress, &QAction::triggered, this, &ResultsTree::suppressSelectedIds);

Expand All @@ -692,15 +692,15 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
menu.addSeparator();
QMenu *tagMenu = menu.addMenu(tr("Tag"));
{
QAction *action = new QAction(tr("No tag"), tagMenu);
auto *action = new QAction(tr("No tag"), tagMenu);
tagMenu->addAction(action);
connect(action, &QAction::triggered, [=]() {
tagSelectedItems(QString());
});
}

for (const QString& tagstr : currentProject->getTags()) {
QAction *action = new QAction(tagstr, tagMenu);
auto *action = new QAction(tagstr, tagMenu);
tagMenu->addAction(action);
connect(action, &QAction::triggered, [=]() {
tagSelectedItems(tagstr);
Expand Down
2 changes: 1 addition & 1 deletion gui/resultsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ void ResultsView::readErrorsXml(const QString &filename)

void ResultsView::updateDetails(const QModelIndex &index)
{
const QStandardItemModel *model = qobject_cast<const QStandardItemModel*>(mUI->mTree->model());
const auto *model = qobject_cast<const QStandardItemModel*>(mUI->mTree->model());
QStandardItem *item = model->itemFromIndex(index);

if (!item) {
Expand Down
2 changes: 1 addition & 1 deletion gui/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void SettingsDialog::initTranslationsList()
{
const QString current = mTranslator->getCurrentLanguage();
for (const TranslationInfo& translation : mTranslator->getTranslations()) {
QListWidgetItem *item = new QListWidgetItem;
auto *item = new QListWidgetItem;
item->setText(translation.mName);
item->setData(mLangCodeRole, QVariant(translation.mCode));
mUI->mListLanguages->addItem(item);
Expand Down
14 changes: 7 additions & 7 deletions gui/statsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ void StatsDialog::copyToClipboard()

const QString htmlSummary = htmlSettings + htmlPrevious + htmlStatistics;

QMimeData *mimeData = new QMimeData();
auto *mimeData = new QMimeData();
mimeData->setText(textSummary);
mimeData->setHtml(htmlSummary);
clipboard->setMimeData(mimeData);
Expand All @@ -359,30 +359,30 @@ void StatsDialog::setStatistics(const CheckStatistics *stats)
#ifdef HAVE_QCHART
QChartView *StatsDialog::createChart(const QString &statsFile, const QString &tool)
{
QChart *chart = new QChart;
auto *chart = new QChart;
chart->addSeries(numberOfReports(statsFile, tool + "-error"));
chart->addSeries(numberOfReports(statsFile, tool + "-warning"));
chart->addSeries(numberOfReports(statsFile, tool + "-style"));
chart->addSeries(numberOfReports(statsFile, tool + "-performance"));
chart->addSeries(numberOfReports(statsFile, tool + "-portability"));

QDateTimeAxis *axisX = new QDateTimeAxis;
auto *axisX = new QDateTimeAxis;
axisX->setTitleText("Date");
chart->addAxis(axisX, Qt::AlignBottom);

for (QAbstractSeries *s : chart->series()) {
s->attachAxis(axisX);
}

QValueAxis *axisY = new QValueAxis;
auto *axisY = new QValueAxis;
axisY->setLabelFormat("%i");
axisY->setTitleText("Count");
chart->addAxis(axisY, Qt::AlignLeft);

qreal maxY = 0;
for (QAbstractSeries *s : chart->series()) {
s->attachAxis(axisY);
if (const QLineSeries *ls = dynamic_cast<const QLineSeries*>(s)) {
if (const auto *ls = dynamic_cast<const QLineSeries*>(s)) {
for (QPointF p : ls->points()) {
if (p.y() > maxY)
maxY = p.y();
Expand All @@ -394,14 +394,14 @@ QChartView *StatsDialog::createChart(const QString &statsFile, const QString &to
//chart->createDefaultAxes();
chart->setTitle(tool);

QChartView *chartView = new QChartView(chart);
auto *chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);
return chartView;
}

QLineSeries *StatsDialog::numberOfReports(const QString &fileName, const QString &severity) const
{
QLineSeries *series = new QLineSeries();
auto *series = new QLineSeries();
series->setName(severity);
QFile f(fileName);
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
Expand Down
Loading

0 comments on commit e30bee1

Please sign in to comment.