make more use of auto and thus avoid having to specify the same type twice

This commit is contained in:
Axel Kohlmeyer
2024-07-04 11:12:40 -04:00
parent 10e3595b57
commit cefe76919c
8 changed files with 47 additions and 47 deletions

View File

@ -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<QKeyEvent *>(event);
auto *keyEvent = dynamic_cast<QKeyEvent *>(event);
if (!keyEvent) return QWidget::eventFilter(watched, event);
if (keyEvent->modifiers().testFlag(Qt::ControlModifier) && keyEvent->key() == '/') {
stop_run();

View File

@ -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<LammpsGui *>(parent());
auto *gui = dynamic_cast<LammpsGui *>(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<QAction *>(sender());
auto *act = qobject_cast<QAction *>(sender());
QDesktopServices::openUrl(
QUrl(QString("https://docs.lammps.org/%1").arg(act->data().toString())));
}

View File

@ -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;
}

View File

@ -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<QSpinBox *>(sender());
auto *field = qobject_cast<QSpinBox *>(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<QPushButton *>(sender());
auto *button = qobject_cast<QPushButton *>(sender());
usessao = !usessao;
button->setChecked(usessao);
createImage();
@ -343,7 +343,7 @@ void ImageViewer::toggle_ssao()
void ImageViewer::toggle_anti()
{
QPushButton *button = qobject_cast<QPushButton *>(sender());
auto *button = qobject_cast<QPushButton *>(sender());
antialias = !antialias;
button->setChecked(antialias);
createImage();
@ -351,7 +351,7 @@ void ImageViewer::toggle_anti()
void ImageViewer::toggle_vdw()
{
QPushButton *button = qobject_cast<QPushButton *>(sender());
auto *button = qobject_cast<QPushButton *>(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<QPushButton *>(sender());
auto *button = qobject_cast<QPushButton *>(sender());
showbox = !showbox;
button->setChecked(showbox);
createImage();
@ -370,7 +370,7 @@ void ImageViewer::toggle_box()
void ImageViewer::toggle_axes()
{
QPushButton *button = qobject_cast<QPushButton *>(sender());
auto *button = qobject_cast<QPushButton *>(sender());
showaxes = !showaxes;
button->setChecked(showaxes);
createImage();
@ -420,14 +420,14 @@ void ImageViewer::do_rot_up()
void ImageViewer::change_group(int)
{
QComboBox *box = findChild<QComboBox *>("group");
auto *box = findChild<QComboBox *>("group");
if (box) group = box->currentText();
createImage();
}
void ImageViewer::createImage()
{
QLabel *renderstatus = findChild<QLabel *>("renderstatus");
auto *renderstatus = findChild<QLabel *>("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;

View File

@ -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<QAction *>(sender());
auto *act = qobject_cast<QAction *>(sender());
if (act) open_file(act->data().toString());
}
void LammpsGui::start_exe()
{
if (!lammps.extract_setting("box_exists")) return;
QAction *act = qobject_cast<QAction *>(sender());
auto *act = qobject_cast<QAction *>(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();

View File

@ -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<QKeyEvent *>(event);
auto *keyEvent = dynamic_cast<QKeyEvent *>(event);
if (!keyEvent) return QWidget::eventFilter(watched, event);
if (keyEvent->modifiers().testFlag(Qt::ControlModifier) && keyEvent->key() == '/') {
stop_run();

View File

@ -93,25 +93,25 @@ void Preferences::accept()
// store selected accelerator
QList<QRadioButton *> allButtons = tabWidget->findChildren<QRadioButton *>();
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<QLineEdit *>("nthreads");
auto *field = tabWidget->findChild<QLineEdit *>("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<QLineEdit *>("zoom");
if (field)
if (field->hasAcceptableInput()) settings->setValue("zoom", field->text());
QCheckBox *box = tabWidget->findChild<QCheckBox *>("anti");
auto *box = tabWidget->findChild<QCheckBox *>("anti");
if (box) settings->setValue("antialias", box->isChecked());
box = tabWidget->findChild<QCheckBox *>("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<QCheckBox *>("vdwstyle");
if (box) settings->setValue("vdwstyle", box->isChecked());
QComboBox *combo = tabWidget->findChild<QComboBox *>("background");
auto *combo = tabWidget->findChild<QComboBox *>("background");
if (combo) settings->setValue("background", combo->currentText());
combo = tabWidget->findChild<QComboBox *>("boxcolor");
if (combo) settings->setValue("boxcolor", combo->currentText());
@ -166,7 +166,7 @@ void Preferences::accept()
box = tabWidget->findChild<QCheckBox *>("viewslide");
if (box) settings->setValue("viewslide", box->isChecked());
auto spin = tabWidget->findChild<QSpinBox *>("updfreq");
auto *spin = tabWidget->findChild<QSpinBox *>("updfreq");
if (spin) settings->setValue("updfreq", spin->value());
if (need_relaunch) {
@ -324,7 +324,7 @@ void GeneralTab::newtextfont()
void GeneralTab::pluginpath()
{
QLineEdit *field = findChild<QLineEdit *>("pluginedit");
auto *field = findChild<QLineEdit *>("pluginedit");
QString pluginfile =
QFileDialog::getOpenFileName(this, "Select Shared LAMMPS Library to Load", field->text(),
"Shared Objects (*.so *.dll *.dylib)");

View File

@ -281,7 +281,7 @@ void SlideShow::play()
}
// reset push button state. use findChild() if not triggered from button.
QPushButton *button = qobject_cast<QPushButton *>(sender());
auto *button = qobject_cast<QPushButton *>(sender());
if (!button) button = findChild<QPushButton *>("play");
if (button) button->setChecked(playtimer);
}
@ -315,7 +315,7 @@ void SlideShow::prev()
void SlideShow::loop()
{
QPushButton *button = qobject_cast<QPushButton *>(sender());
auto *button = qobject_cast<QPushButton *>(sender());
do_loop = !do_loop;
button->setChecked(do_loop);
}