From cefe76919c76bff3d6a52786fd6a12297e5bb8cf Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 4 Jul 2024 11:12:40 -0400 Subject: [PATCH] make more use of auto and thus avoid having to specify the same type twice --- tools/lammps-gui/chartviewer.cpp | 2 +- tools/lammps-gui/codeeditor.cpp | 20 ++++++++++---------- tools/lammps-gui/helpers.cpp | 2 +- tools/lammps-gui/imageviewer.cpp | 22 +++++++++++----------- tools/lammps-gui/lammpsgui.cpp | 12 ++++++------ tools/lammps-gui/logwindow.cpp | 6 +++--- tools/lammps-gui/preferences.cpp | 26 +++++++++++++------------- tools/lammps-gui/slideshow.cpp | 4 ++-- 8 files changed, 47 insertions(+), 47 deletions(-) diff --git a/tools/lammps-gui/chartviewer.cpp b/tools/lammps-gui/chartviewer.cpp index 0150133954..919a3bf5fe 100644 --- a/tools/lammps-gui/chartviewer.cpp +++ b/tools/lammps-gui/chartviewer.cpp @@ -253,7 +253,7 @@ void ChartWindow::closeEvent(QCloseEvent *event) bool ChartWindow::eventFilter(QObject *watched, QEvent *event) { if (event->type() == QEvent::ShortcutOverride) { - QKeyEvent *keyEvent = dynamic_cast(event); + auto *keyEvent = dynamic_cast(event); if (!keyEvent) return QWidget::eventFilter(watched, event); if (keyEvent->modifiers().testFlag(Qt::ControlModifier) && keyEvent->key() == '/') { stop_run(); diff --git a/tools/lammps-gui/codeeditor.cpp b/tools/lammps-gui/codeeditor.cpp index ab8007805a..1762b0e496 100644 --- a/tools/lammps-gui/codeeditor.cpp +++ b/tools/lammps-gui/codeeditor.cpp @@ -620,7 +620,7 @@ void CodeEditor::dropEvent(QDropEvent *event) if (event->mimeData()->hasUrls()) { event->accept(); auto file = event->mimeData()->urls()[0].toLocalFile(); - auto gui = dynamic_cast(parent()); + auto *gui = dynamic_cast(parent()); if (gui) { moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor); gui->open_file(file); @@ -687,17 +687,17 @@ void CodeEditor::contextMenuEvent(QContextMenuEvent *event) auto *menu = createStandardContextMenu(); menu->addSeparator(); if (textCursor().hasSelection()) { - auto action1 = menu->addAction("Comment out selection"); + auto *action1 = menu->addAction("Comment out selection"); action1->setIcon(QIcon(":/icons/expand-text.png")); connect(action1, &QAction::triggered, this, &CodeEditor::comment_selection); - auto action2 = menu->addAction("Uncomment selection"); + auto *action2 = menu->addAction("Uncomment selection"); action2->setIcon(QIcon(":/icons/expand-text.png")); connect(action2, &QAction::triggered, this, &CodeEditor::uncomment_selection); } else { - auto action1 = menu->addAction("Comment out line"); + auto *action1 = menu->addAction("Comment out line"); action1->setIcon(QIcon(":/icons/expand-text.png")); connect(action1, &QAction::triggered, this, &CodeEditor::comment_line); - auto action2 = menu->addAction("Uncomment line"); + auto *action2 = menu->addAction("Uncomment line"); action2->setIcon(QIcon(":/icons/expand-text.png")); connect(action2, &QAction::triggered, this, &CodeEditor::uncomment_line); } @@ -705,14 +705,14 @@ void CodeEditor::contextMenuEvent(QContextMenuEvent *event) // print augmented context menu if an entry was found if (!help.isEmpty()) { - auto action = menu->addAction(QString("Display available completions for '%1'").arg(help)); + auto *action = menu->addAction(QString("Display available completions for '%1'").arg(help)); action->setIcon(QIcon(":/icons/expand-text.png")); connect(action, &QAction::triggered, this, &CodeEditor::runCompletion); menu->addSeparator(); } if (!page.isEmpty()) { - auto action = menu->addAction(QString("Reformat '%1' command").arg(help)); + auto *action = menu->addAction(QString("Reformat '%1' command").arg(help)); action->setIcon(QIcon(":/icons/format-indent-less-3.png")); connect(action, &QAction::triggered, this, &CodeEditor::reformatCurrentLine); @@ -728,13 +728,13 @@ void CodeEditor::contextMenuEvent(QContextMenuEvent *event) help = words.at(0); page = words.at(0); page += ".html"; - auto action2 = menu->addAction(QString("View Documentation for '%1'").arg(help)); + auto *action2 = menu->addAction(QString("View Documentation for '%1'").arg(help)); action2->setIcon(QIcon(":/icons/system-help.png")); action2->setData(page); connect(action2, &QAction::triggered, this, &CodeEditor::open_help); } } - auto action = menu->addAction(QString("LAMMPS Manual")); + auto *action = menu->addAction(QString("LAMMPS Manual")); action->setIcon(QIcon(":/icons/help-browser.png")); action->setData(QString()); connect(action, &QAction::triggered, this, &CodeEditor::open_help); @@ -1166,7 +1166,7 @@ void CodeEditor::find_help(QString &page, QString &help) void CodeEditor::open_help() { - QAction *act = qobject_cast(sender()); + auto *act = qobject_cast(sender()); QDesktopServices::openUrl( QUrl(QString("https://docs.lammps.org/%1").arg(act->data().toString()))); } diff --git a/tools/lammps-gui/helpers.cpp b/tools/lammps-gui/helpers.cpp index 8db7cd0d68..bc158f3bb5 100644 --- a/tools/lammps-gui/helpers.cpp +++ b/tools/lammps-gui/helpers.cpp @@ -21,7 +21,7 @@ // duplicate string, STL version char *mystrdup(const std::string &text) { - auto tmp = new char[text.size() + 1]; + auto *tmp = new char[text.size() + 1]; memcpy(tmp, text.c_str(), text.size() + 1); return tmp; } diff --git a/tools/lammps-gui/imageviewer.cpp b/tools/lammps-gui/imageviewer.cpp index 1d00dd7c1d..faa18d7faf 100644 --- a/tools/lammps-gui/imageviewer.cpp +++ b/tools/lammps-gui/imageviewer.cpp @@ -143,7 +143,7 @@ ImageViewer::ImageViewer(const QString &fileName, LammpsWrapper *_lammps, QWidge scrollArea->setWidget(imageLabel); scrollArea->setVisible(false); - QVBoxLayout *mainLayout = new QVBoxLayout; + auto *mainLayout = new QVBoxLayout; QSettings settings; @@ -223,7 +223,7 @@ ImageViewer::ImageViewer(const QString &fileName, LammpsWrapper *_lammps, QWidge combo->addItem(gname); } - QHBoxLayout *menuLayout = new QHBoxLayout; + auto *menuLayout = new QHBoxLayout; menuLayout->addWidget(menuBar); menuLayout->addWidget(renderstatus); menuLayout->addWidget(new QLabel(" Width: ")); @@ -324,7 +324,7 @@ void ImageViewer::reset_view() void ImageViewer::edit_size() { - QSpinBox *field = qobject_cast(sender()); + auto *field = qobject_cast(sender()); if (field->objectName() == "xsize") { xsize = field->value(); } else if (field->objectName() == "ysize") { @@ -335,7 +335,7 @@ void ImageViewer::edit_size() void ImageViewer::toggle_ssao() { - QPushButton *button = qobject_cast(sender()); + auto *button = qobject_cast(sender()); usessao = !usessao; button->setChecked(usessao); createImage(); @@ -343,7 +343,7 @@ void ImageViewer::toggle_ssao() void ImageViewer::toggle_anti() { - QPushButton *button = qobject_cast(sender()); + auto *button = qobject_cast(sender()); antialias = !antialias; button->setChecked(antialias); createImage(); @@ -351,7 +351,7 @@ void ImageViewer::toggle_anti() void ImageViewer::toggle_vdw() { - QPushButton *button = qobject_cast(sender()); + auto *button = qobject_cast(sender()); if (vdwfactor > 1.0) vdwfactor = 0.5; else @@ -362,7 +362,7 @@ void ImageViewer::toggle_vdw() void ImageViewer::toggle_box() { - QPushButton *button = qobject_cast(sender()); + auto *button = qobject_cast(sender()); showbox = !showbox; button->setChecked(showbox); createImage(); @@ -370,7 +370,7 @@ void ImageViewer::toggle_box() void ImageViewer::toggle_axes() { - QPushButton *button = qobject_cast(sender()); + auto *button = qobject_cast(sender()); showaxes = !showaxes; button->setChecked(showaxes); createImage(); @@ -420,14 +420,14 @@ void ImageViewer::do_rot_up() void ImageViewer::change_group(int) { - QComboBox *box = findChild("group"); + auto *box = findChild("group"); if (box) group = box->currentText(); createImage(); } void ImageViewer::createImage() { - QLabel *renderstatus = findChild("renderstatus"); + auto *renderstatus = findChild("renderstatus"); if (renderstatus) renderstatus->setEnabled(true); repaint(); @@ -443,7 +443,7 @@ void ImageViewer::createImage() // determine elements from masses and set their covalent radii int ntypes = lammps->extract_setting("ntypes"); int nbondtypes = lammps->extract_setting("nbondtypes"); - double *masses = (double *)lammps->extract_atom("mass"); + auto *masses = (double *)lammps->extract_atom("mass"); QString units = (const char *)lammps->extract_global("units"); QString elements = "element "; QString adiams; diff --git a/tools/lammps-gui/lammpsgui.cpp b/tools/lammps-gui/lammpsgui.cpp index a78d891318..1d132003b2 100644 --- a/tools/lammps-gui/lammpsgui.cpp +++ b/tools/lammps-gui/lammpsgui.cpp @@ -300,14 +300,14 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) : const char *varstyles[] = {"delete", "atomfile", "file", "format", "getenv", "index", "internal", "loop", "python", "string", "timer", "uloop", "universe", "world", "equal", "vector", "atom"}; - for (const auto var : varstyles) + for (const auto *const var : varstyles) style_list << var; style_list.sort(); ui->textEdit->setVariableList(style_list); style_list.clear(); const char *unitstyles[] = {"lj", "real", "metal", "si", "cgs", "electron", "micro", "nano"}; - for (const auto unit : unitstyles) + for (const auto *const unit : unitstyles) style_list << unit; style_list.sort(); ui->textEdit->setUnitsList(style_list); @@ -392,14 +392,14 @@ void LammpsGui::open() void LammpsGui::open_recent() { - QAction *act = qobject_cast(sender()); + auto *act = qobject_cast(sender()); if (act) open_file(act->data().toString()); } void LammpsGui::start_exe() { if (!lammps.extract_setting("box_exists")) return; - QAction *act = qobject_cast(sender()); + auto *act = qobject_cast(sender()); if (act) { auto exe = act->data().toString(); QString datacmd = "write_data '"; @@ -1052,7 +1052,7 @@ void LammpsGui::do_run(bool use_buffer) logwindow->document()->setDefaultFont(text_font); logwindow->setLineWrapMode(LogWindow::NoWrap); logwindow->setMinimumSize(400, 300); - QShortcut *shortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_W), logwindow); + auto *shortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_W), logwindow); QObject::connect(shortcut, &QShortcut::activated, logwindow, &LogWindow::close); shortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Slash), logwindow); QObject::connect(shortcut, &QShortcut::activated, this, &LammpsGui::stop_run); @@ -1244,7 +1244,7 @@ void LammpsGui::about() msg.setFont(font); auto *minwidth = new QSpacerItem(700, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); - QGridLayout *layout = (QGridLayout *)msg.layout(); + auto *layout = (QGridLayout *)msg.layout(); layout->addItem(minwidth, layout->rowCount(), 0, 1, layout->columnCount()); msg.exec(); diff --git a/tools/lammps-gui/logwindow.cpp b/tools/lammps-gui/logwindow.cpp index 73ec81d06c..05887c329c 100644 --- a/tools/lammps-gui/logwindow.cpp +++ b/tools/lammps-gui/logwindow.cpp @@ -35,7 +35,7 @@ LogWindow::LogWindow(const QString &_filename, QWidget *parent) : QSettings settings; resize(settings.value("logx", 500).toInt(), settings.value("logy", 320).toInt()); - auto action = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_S), this); + auto *action = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_S), this); connect(action, &QShortcut::activated, this, &LogWindow::save_as); action = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q), this); connect(action, &QShortcut::activated, this, &LogWindow::quit); @@ -99,7 +99,7 @@ void LogWindow::contextMenuEvent(QContextMenuEvent *event) // show augmented context menu auto *menu = createStandardContextMenu(); menu->addSeparator(); - auto action = menu->addAction(QString("Save Log to File ...")); + auto *action = menu->addAction(QString("Save Log to File ...")); action->setIcon(QIcon(":/icons/document-save-as.png")); action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); connect(action, &QAction::triggered, this, &LogWindow::save_as); @@ -114,7 +114,7 @@ void LogWindow::contextMenuEvent(QContextMenuEvent *event) bool LogWindow::eventFilter(QObject *watched, QEvent *event) { if (event->type() == QEvent::ShortcutOverride) { - QKeyEvent *keyEvent = dynamic_cast(event); + auto *keyEvent = dynamic_cast(event); if (!keyEvent) return QWidget::eventFilter(watched, event); if (keyEvent->modifiers().testFlag(Qt::ControlModifier) && keyEvent->key() == '/') { stop_run(); diff --git a/tools/lammps-gui/preferences.cpp b/tools/lammps-gui/preferences.cpp index 27cc106008..71910346fb 100644 --- a/tools/lammps-gui/preferences.cpp +++ b/tools/lammps-gui/preferences.cpp @@ -93,25 +93,25 @@ void Preferences::accept() // store selected accelerator QList allButtons = tabWidget->findChildren(); - for (int i = 0; i < allButtons.size(); ++i) { - if (allButtons[i]->isChecked()) { - if (allButtons[i]->objectName() == "none") + for (auto & allButton : allButtons) { + if (allButton->isChecked()) { + if (allButton->objectName() == "none") settings->setValue("accelerator", QString::number(AcceleratorTab::None)); - if (allButtons[i]->objectName() == "opt") + if (allButton->objectName() == "opt") settings->setValue("accelerator", QString::number(AcceleratorTab::Opt)); - if (allButtons[i]->objectName() == "openmp") + if (allButton->objectName() == "openmp") settings->setValue("accelerator", QString::number(AcceleratorTab::OpenMP)); - if (allButtons[i]->objectName() == "intel") + if (allButton->objectName() == "intel") settings->setValue("accelerator", QString::number(AcceleratorTab::Intel)); - if (allButtons[i]->objectName() == "kokkos") + if (allButton->objectName() == "kokkos") settings->setValue("accelerator", QString::number(AcceleratorTab::Kokkos)); - if (allButtons[i]->objectName() == "gpu") + if (allButton->objectName() == "gpu") settings->setValue("accelerator", QString::number(AcceleratorTab::Gpu)); } } // store number of threads, reset to 1 for "None" and "Opt" settings - QLineEdit *field = tabWidget->findChild("nthreads"); + auto *field = tabWidget->findChild("nthreads"); if (field) { int accel = settings->value("accelerator", AcceleratorTab::None).toInt(); if ((accel == AcceleratorTab::None) || (accel == AcceleratorTab::Opt)) @@ -132,7 +132,7 @@ void Preferences::accept() field = tabWidget->findChild("zoom"); if (field) if (field->hasAcceptableInput()) settings->setValue("zoom", field->text()); - QCheckBox *box = tabWidget->findChild("anti"); + auto *box = tabWidget->findChild("anti"); if (box) settings->setValue("antialias", box->isChecked()); box = tabWidget->findChild("ssao"); if (box) settings->setValue("ssao", box->isChecked()); @@ -142,7 +142,7 @@ void Preferences::accept() if (box) settings->setValue("axes", box->isChecked()); box = tabWidget->findChild("vdwstyle"); if (box) settings->setValue("vdwstyle", box->isChecked()); - QComboBox *combo = tabWidget->findChild("background"); + auto *combo = tabWidget->findChild("background"); if (combo) settings->setValue("background", combo->currentText()); combo = tabWidget->findChild("boxcolor"); if (combo) settings->setValue("boxcolor", combo->currentText()); @@ -166,7 +166,7 @@ void Preferences::accept() box = tabWidget->findChild("viewslide"); if (box) settings->setValue("viewslide", box->isChecked()); - auto spin = tabWidget->findChild("updfreq"); + auto *spin = tabWidget->findChild("updfreq"); if (spin) settings->setValue("updfreq", spin->value()); if (need_relaunch) { @@ -324,7 +324,7 @@ void GeneralTab::newtextfont() void GeneralTab::pluginpath() { - QLineEdit *field = findChild("pluginedit"); + auto *field = findChild("pluginedit"); QString pluginfile = QFileDialog::getOpenFileName(this, "Select Shared LAMMPS Library to Load", field->text(), "Shared Objects (*.so *.dll *.dylib)"); diff --git a/tools/lammps-gui/slideshow.cpp b/tools/lammps-gui/slideshow.cpp index 140c703ca3..9275842b78 100644 --- a/tools/lammps-gui/slideshow.cpp +++ b/tools/lammps-gui/slideshow.cpp @@ -281,7 +281,7 @@ void SlideShow::play() } // reset push button state. use findChild() if not triggered from button. - QPushButton *button = qobject_cast(sender()); + auto *button = qobject_cast(sender()); if (!button) button = findChild("play"); if (button) button->setChecked(playtimer); } @@ -315,7 +315,7 @@ void SlideShow::prev() void SlideShow::loop() { - QPushButton *button = qobject_cast(sender()); + auto *button = qobject_cast(sender()); do_loop = !do_loop; button->setChecked(do_loop); }