From 092e5f3adadac9cd9610c16ddd07ca8ddeb311f8 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Mon, 30 Dec 2024 14:29:12 -0500 Subject: [PATCH] Switch to compile-time connect calls Signed-off-by: Geoff Hutchison --- avogadro/aboutdialog.cpp | 16 +++++------ avogadro/avogadro.cpp | 15 ++++------ avogadro/mainwindow.cpp | 28 ++++++++----------- avogadro/mainwindow.h | 7 +++-- avogadro/renderingdialog.cpp | 53 +++++++++++++++++++----------------- 5 files changed, 56 insertions(+), 63 deletions(-) diff --git a/avogadro/aboutdialog.cpp b/avogadro/aboutdialog.cpp index 3986846d..44657cfb 100644 --- a/avogadro/aboutdialog.cpp +++ b/avogadro/aboutdialog.cpp @@ -24,17 +24,17 @@ AboutDialog::AboutDialog(QWidget* parent_) "

"); // Add the labels - m_ui->versionLabel->setText(html.arg("20").arg(tr("Version:"))); - m_ui->libsLabel->setText(html.arg("10").arg(tr("Avogadro Library Version:"))); - m_ui->qtVersionLabel->setText(html.arg("10").arg(tr("Qt Version:"))); - m_ui->sslVersionLabel->setText(html.arg("10").arg(tr("SSL Version:"))); + m_ui->versionLabel->setText(html.arg("20", tr("Version:"))); + m_ui->libsLabel->setText(html.arg("10", tr("Avogadro Library Version:"))); + m_ui->qtVersionLabel->setText(html.arg("10", tr("Qt Version:"))); + m_ui->sslVersionLabel->setText(html.arg("10", tr("SSL Version:"))); // Add the version numbers - m_ui->version->setText(html.arg("20").arg(AvogadroApp_VERSION)); - m_ui->libsVersion->setText(html.arg("10").arg(version())); - m_ui->qtVersion->setText(html.arg("10").arg(qVersion())); + m_ui->version->setText(html.arg("20", AvogadroApp_VERSION)); + m_ui->libsVersion->setText(html.arg("10", version())); + m_ui->qtVersion->setText(html.arg("10", qVersion())); m_ui->sslVersion->setText( - html.arg("10").arg(QSslSocket::sslLibraryVersionString())); + html.arg("10", QSslSocket::sslLibraryVersionString())); // Add support for a 2x replacement (mainly Mac OS X retina at this point). if (window()->devicePixelRatio() == 2) { diff --git a/avogadro/avogadro.cpp b/avogadro/avogadro.cpp index 87db840d..e742fb4e 100644 --- a/avogadro/avogadro.cpp +++ b/avogadro/avogadro.cpp @@ -54,37 +54,32 @@ void myMessageOutput(QtMsgType type, const QMessageLogContext& context, switch (type) { case QtInfoMsg: message = QString("Info: %1 (%2:%3, %4)") - .arg(localMsg.constData()) - .arg(file) + .arg(localMsg.constData(), file) .arg(context.line) .arg(function); break; case QtWarningMsg: message = QString("Warning: %1 (%2:%3, %4)") - .arg(localMsg.constData()) - .arg(file) + .arg(localMsg.constData(), file) .arg(context.line) .arg(function); break; case QtCriticalMsg: message = QString("Critical: %1 (%2:%3, %4)") - .arg(localMsg.constData()) - .arg(file) + .arg(localMsg.constData(), file) .arg(context.line) .arg(function); break; case QtFatalMsg: message = QString("Fatal: %1 (%2:%3, %4)") - .arg(localMsg.constData()) - .arg(file) + .arg(localMsg.constData(), file) .arg(context.line) .arg(function); break; case QtDebugMsg: default: message = QString("Debug: %1 (%2:%3, %4)") - .arg(localMsg.constData()) - .arg(file) + .arg(localMsg.constData(), file) .arg(context.line) .arg(function); break; diff --git a/avogadro/mainwindow.cpp b/avogadro/mainwindow.cpp index b12e565e..fba16135 100644 --- a/avogadro/mainwindow.cpp +++ b/avogadro/mainwindow.cpp @@ -714,9 +714,8 @@ void MainWindow::updateWindowTitle() setWindowTitle(tr("%1%2 - Avogadro %3", "window title: %1 = file name, %2 = • for " "modified file, %3 = Avogadro version") - .arg(QFileInfo(fileName).fileName()) - .arg(m_moleculeDirty ? "•" : "") - .arg(AvogadroApp_VERSION)); + .arg(QFileInfo(fileName).fileName(), + m_moleculeDirty ? "•" : "", AvogadroApp_VERSION)); } #ifdef QTTESTING @@ -788,8 +787,7 @@ void MainWindow::openFile() return; QString filter(QString("%1 (*.cml);;%2 (*.cjson)") - .arg(tr("Chemical Markup Language")) - .arg(tr("Chemical JSON"))); + .arg(tr("Chemical Markup Language"), tr("Chemical JSON"))); QSettings settings; QString dir = settings.value("MainWindow/lastOpenDir").toString(); @@ -963,7 +961,7 @@ bool MainWindow::openFile(const QString& fileName, Io::FileFormat* reader) m_progressDialog->setMinimumDuration(750); m_progressDialog->setWindowTitle(tr("Reading File")); m_progressDialog->setLabelText( - tr("Opening file '%1'\nwith '%2'").arg(fileName).arg(ident)); + tr("Opening file '%1'\nwith '%2'").arg(fileName, ident)); /// @todo Add API to abort file ops m_progressDialog->setCancelButton(nullptr); connect(m_fileReadThread, &QThread::started, m_threadedReader, @@ -1030,8 +1028,7 @@ void MainWindow::backgroundReaderFinished() } else { MESSAGEBOX::critical(this, tr("File error"), tr("Error while reading file '%1':\n%2") - .arg(fileName) - .arg(m_threadedReader->error())); + .arg(fileName, m_threadedReader->error())); delete m_fileReadMolecule; } m_fileReadThread->deleteLater(); @@ -1065,8 +1062,7 @@ bool MainWindow::backgroundWriterFinished() MESSAGEBOX::critical( this, tr("Error saving file"), tr("Error while saving '%1':\n%2", "%1 = file name, %2 = error message") - .arg(fileName) - .arg(m_threadedWriter->error())); + .arg(fileName, m_threadedWriter->error())); } } m_fileWriteThread->deleteLater(); @@ -1531,8 +1527,7 @@ bool MainWindow::saveFile(bool async) bool MainWindow::saveFileAs(bool async) { QString filter(QString("%1 (*.cjson);;%2 (*.cml)") - .arg(tr("Chemical JSON")) - .arg(tr("Chemical Markup Language"))); + .arg(tr("Chemical JSON"), tr("Chemical Markup Language"))); QSettings settings; QString dir = settings.value("MainWindow/lastSaveDir").toString(); @@ -1683,8 +1678,7 @@ bool MainWindow::saveFileAs(const QString& fileName, Io::FileFormat* writer, m_progressDialog->setWindowTitle(tr("Saving File in Progress…")); m_progressDialog->setLabelText( tr("Saving file “%1”\nwith “%2”", "%1 = file name, %2 = format") - .arg(fileName) - .arg(ident)); + .arg(fileName, ident)); /// @todo Add API to abort file ops m_progressDialog->setCancelButton(nullptr); connect(m_fileWriteThread, &QThread::started, m_threadedWriter, @@ -2441,8 +2435,8 @@ void MainWindow::checkUpdate() { if (m_network == nullptr) { m_network = new QNetworkAccessManager(this); - connect(m_network, SIGNAL(finished(QNetworkReply*)), this, - SLOT(finishUpdateRequest(QNetworkReply*))); + connect(m_network, &QNetworkAccessManager::finished, this, + &MainWindow::finishUpdateRequest); } m_network->get( @@ -2650,7 +2644,7 @@ bool MainWindow::handleCommand(const QString& command, enableTypes = options.value("types").toStringList(); } else { // list of true / false types - for (auto key : options.keys()) { + for (const auto& key : options.keys()) { if (options.value(key).toBool()) enableTypes << key; else diff --git a/avogadro/mainwindow.h b/avogadro/mainwindow.h index bc41ecb1..dcc82de5 100644 --- a/avogadro/mainwindow.h +++ b/avogadro/mainwindow.h @@ -89,7 +89,8 @@ public slots: * Use the FileFormat @a reader to load @a fileName. This method * takes ownership of @a reader and will delete it before returning. */ - bool openFile(const QString& fileName, Io::FileFormat* reader = nullptr); + bool openFile(const QString& fileName, + Avogadro::Io::FileFormat* reader = nullptr); void exportGraphics(QString fileName); @@ -158,7 +159,7 @@ public slots: /** * Emitted when the active molecule in the application has changed. */ - void moleculeChanged(QtGui::Molecule* molecue); + void moleculeChanged(Avogadro::QtGui::Molecule* molecue); protected: void closeEvent(QCloseEvent* event); @@ -248,7 +249,7 @@ protected slots: * false, the return value indicates whether or not the file was written * successfully. */ - bool saveFileAs(const QString& fileName, Io::FileFormat* writer, + bool saveFileAs(const QString& fileName, Avogadro::Io::FileFormat* writer, bool async = true); /** diff --git a/avogadro/renderingdialog.cpp b/avogadro/renderingdialog.cpp index a3887c19..e416f1af 100644 --- a/avogadro/renderingdialog.cpp +++ b/avogadro/renderingdialog.cpp @@ -8,14 +8,19 @@ namespace Avogadro { -RenderingDialog::RenderingDialog(QWidget *parent_, SolidPipeline &pipeline) - : QDialog(parent_), m_ui(new Ui::RenderingDialog), m_solidPipeline(pipeline) +RenderingDialog::RenderingDialog(QWidget* parent_, SolidPipeline& pipeline) + : QDialog(parent_) + , m_ui(new Ui::RenderingDialog) + , m_solidPipeline(pipeline) { m_ui->setupUi(this); - m_ui->aoEnableCheckBox->setCheckState(pipeline.getAoEnabled()? Qt::Checked : Qt::Unchecked); - m_ui->dofEnableCheckBox->setCheckState(pipeline.getDofEnabled()? Qt::Checked : Qt::Unchecked); - m_ui->fogEnableCheckBox->setCheckState(pipeline.getFogEnabled()? Qt::Checked : Qt::Unchecked); + m_ui->aoEnableCheckBox->setCheckState( + pipeline.getAoEnabled() ? Qt::Checked : Qt::Unchecked); + m_ui->dofEnableCheckBox->setCheckState( + pipeline.getDofEnabled() ? Qt::Checked : Qt::Unchecked); + m_ui->fogEnableCheckBox->setCheckState( + pipeline.getFogEnabled() ? Qt::Checked : Qt::Unchecked); m_ui->aoStrengthDoubleSpinBox->setMinimum(0.0); m_ui->aoStrengthDoubleSpinBox->setValue(pipeline.getAoStrength()); m_ui->aoStrengthDoubleSpinBox->setMaximum(2.0); @@ -28,7 +33,7 @@ RenderingDialog::RenderingDialog(QWidget *parent_, SolidPipeline &pipeline) m_ui->dofStrengthDoubleSpinBox->setSingleStep(0.1); m_ui->dofPositionDoubleSpinBox->setMinimum(0.0); m_ui->dofPositionDoubleSpinBox->setValue(pipeline.getDofPosition()); - // We can adjust the max and min value + // We can adjust the max and min value // after testing with several molecules m_ui->dofPositionDoubleSpinBox->setMaximum(20.0); m_ui->dofPositionDoubleSpinBox->setDecimals(1); @@ -43,18 +48,19 @@ RenderingDialog::RenderingDialog(QWidget *parent_, SolidPipeline &pipeline) m_ui->fogPositionDoubleSpinBox->setMaximum(20.0); m_ui->fogPositionDoubleSpinBox->setDecimals(1); m_ui->fogPositionDoubleSpinBox->setSingleStep(0.1); - m_ui->edEnableCheckBox->setCheckState(pipeline.getEdEnabled()? Qt::Checked : Qt::Unchecked); - - connect(m_ui->aoEnableCheckBox, SIGNAL(stateChanged(int)), - SLOT(aoEnableCheckBoxChanged(int))); - connect(m_ui->dofEnableCheckBox, SIGNAL(stateChanged(int)), - SLOT(dofEnableCheckBoxChanged(int))); - connect(m_ui->fogEnableCheckBox, SIGNAL(stateChanged(int)), - SLOT(fogEnableCheckBoxChanged(int))); - connect(m_ui->saveButton, SIGNAL(clicked()), - SLOT(saveButtonClicked())); - connect(m_ui->closeButton, SIGNAL(clicked()), - SLOT(closeButtonClicked())); + m_ui->edEnableCheckBox->setCheckState( + pipeline.getEdEnabled() ? Qt::Checked : Qt::Unchecked); + + connect(m_ui->aoEnableCheckBox, &QCheckBox::stateChanged, this, + &RenderingDialog::aoEnableCheckBoxChanged); + connect(m_ui->dofEnableCheckBox, &QCheckBox::stateChanged, this, + &RenderingDialog::dofEnableCheckBoxChanged); + connect(m_ui->fogEnableCheckBox, &QCheckBox::stateChanged, this, + &RenderingDialog::fogEnableCheckBoxChanged); + connect(m_ui->saveButton, &QAbstractButton::clicked, this, + &RenderingDialog::saveButtonClicked); + connect(m_ui->closeButton, &QAbstractButton::clicked, this, + &RenderingDialog::closeButtonClicked); } RenderingDialog::~RenderingDialog() @@ -105,14 +111,12 @@ bool RenderingDialog::edEnabled() return m_ui->edEnableCheckBox->checkState() == Qt::Checked; } - void RenderingDialog::dofEnableCheckBoxChanged(int state) { - if (state == Qt::Unchecked){ + if (state == Qt::Unchecked) { m_ui->dofStrengthDoubleSpinBox->setEnabled(false); m_ui->dofPositionDoubleSpinBox->setEnabled(false); - } - else{ + } else { m_ui->dofStrengthDoubleSpinBox->setEnabled(true); m_ui->dofPositionDoubleSpinBox->setEnabled(true); } @@ -120,11 +124,10 @@ void RenderingDialog::dofEnableCheckBoxChanged(int state) void RenderingDialog::fogEnableCheckBoxChanged(int state) { - if (state == Qt::Unchecked){ + if (state == Qt::Unchecked) { m_ui->fogPositionDoubleSpinBox->setEnabled(false); m_ui->fogStrengthDoubleSpinBox->setEnabled(false); - } - else{ + } else { m_ui->fogStrengthDoubleSpinBox->setEnabled(true); m_ui->fogPositionDoubleSpinBox->setEnabled(true); }