Skip to content

Commit

Permalink
Update most code to use newer compile-time SIGNAL / SLOT syntax
Browse files Browse the repository at this point in the history
Used clazy old-style-connect fixit
Some need manual fixes, but a good start

Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Dec 30, 2024
1 parent d231082 commit 1bd2b9e
Show file tree
Hide file tree
Showing 110 changed files with 993 additions and 887 deletions.
4 changes: 2 additions & 2 deletions avogadro/calc/lennardjones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
namespace Avogadro::Calc {

LennardJones::LennardJones()
: m_vdw(true), m_depth(100.0), m_exponent(6), m_cell(nullptr),
m_molecule(nullptr)
: m_molecule(nullptr), m_cell(nullptr), m_vdw(true), m_depth(100.0),
m_exponent(6)
{
// defined for 1-118
for (unsigned int i = 1; i <= 118; ++i) {
Expand Down
25 changes: 11 additions & 14 deletions avogadro/core/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Mesh::Mesh() : m_stable(true), m_other(0), m_cube(0), m_lock(new Mutex)

Mesh::Mesh(const Mesh& other)
: m_vertices(other.m_vertices), m_normals(other.m_normals),
m_colors(other.m_colors), m_name(other.m_name), m_stable(true),
m_isoValue(other.m_isoValue), m_other(other.m_other), m_cube(other.m_cube),
m_lock(new Mutex), m_triangles(other.m_triangles)
m_colors(other.m_colors), m_triangles(other.m_triangles),
m_name(other.m_name), m_stable(true), m_isoValue(other.m_isoValue),
m_other(other.m_other), m_cube(other.m_cube), m_lock(new Mutex)
{
}

Expand Down Expand Up @@ -60,20 +60,18 @@ const Vector3f* Mesh::vertex(int n) const
return &(m_vertices[n * 3]);
}


bool Mesh::setTriangles(const Core::Array<Vector3f>& values)
{
m_triangles.clear();
m_triangles = values;
return true;
}

const Core::Array<Vector3f>&Mesh::triangles() const
const Core::Array<Vector3f>& Mesh::triangles() const
{
return m_triangles;
}


bool Mesh::setVertices(const Core::Array<Vector3f>& values)
{
m_vertices.clear();
Expand All @@ -86,7 +84,7 @@ bool Mesh::addVertices(const Core::Array<Vector3f>& values)
if (m_vertices.capacity() < m_vertices.size() + values.size())
m_vertices.reserve(m_vertices.capacity() * 2);
if (values.size() % 3 == 0) {
for (const auto & value : values)
for (const auto& value : values)
m_vertices.push_back(value);
return true;
} else {
Expand Down Expand Up @@ -116,7 +114,7 @@ bool Mesh::addNormals(const Core::Array<Vector3f>& values)
if (m_normals.capacity() < m_normals.size() + values.size())
m_normals.reserve(m_normals.capacity() * 2);
if (values.size() % 3 == 0) {
for (const auto & value : values)
for (const auto& value : values)
m_normals.push_back(value);
return true;
} else {
Expand Down Expand Up @@ -184,7 +182,8 @@ Mesh& Mesh::operator=(const Mesh& other)
return *this;
}

void Mesh::smooth(int iterationCount) {
void Mesh::smooth(int iterationCount)
{
if (m_vertices.empty() || iterationCount <= 0)
return;

Expand All @@ -206,10 +205,10 @@ void Mesh::smooth(int iterationCount) {
// Remove duplicate neighbors and sort for faster lookups later (if needed)
for (auto& neighbors : adjacencyList) {
std::sort(neighbors.begin(), neighbors.end());
neighbors.erase(std::unique(neighbors.begin(), neighbors.end()), neighbors.end());
neighbors.erase(std::unique(neighbors.begin(), neighbors.end()),
neighbors.end());
}


float weight = 1.0f;
for (int iteration = 0; iteration < iterationCount; ++iteration) {
Array<Vector3f> newVertices = m_vertices; // Store smoothed vertices
Expand All @@ -229,7 +228,6 @@ void Mesh::smooth(int iterationCount) {
m_vertices = newVertices; // Update vertices after processing all
}


m_normals.clear();
m_normals.resize(m_vertices.size(), Vector3f(0.0f, 0.0f, 0.0f));

Expand All @@ -246,8 +244,7 @@ void Mesh::smooth(int iterationCount) {
m_normals[i] += triangleNormal;
m_normals[j] += triangleNormal;
m_normals[k] += triangleNormal;

}
}

for (auto& normal : m_normals) {
normal.normalize();
Expand Down
10 changes: 4 additions & 6 deletions avogadro/core/molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ Molecule::Molecule(const Molecule& other)
m_basisSet(other.m_basisSet ? other.m_basisSet->clone() : nullptr),
m_unitCell(other.m_unitCell ? new UnitCell(*other.m_unitCell) : nullptr),
m_residues(other.m_residues), m_hallNumber(other.m_hallNumber),
m_graph(other.m_graph), m_bondOrders(other.m_bondOrders),
m_atomicNumbers(other.m_atomicNumbers),
m_frozenAtomMask(other.m_frozenAtomMask),
m_frozenAtomMask(other.m_frozenAtomMask), m_graph(other.m_graph),
m_bondOrders(other.m_bondOrders), m_atomicNumbers(other.m_atomicNumbers),
m_layers(LayerManager::getMoleculeLayer(this))
{
// Copy over any meshes
Expand Down Expand Up @@ -142,9 +141,8 @@ Molecule::Molecule(Molecule&& other) noexcept
m_selectedAtoms(std::move(other.m_selectedAtoms)),
m_meshes(std::move(other.m_meshes)), m_cubes(std::move(other.m_cubes)),
m_residues(other.m_residues), m_hallNumber(other.m_hallNumber),
m_graph(other.m_graph), m_bondOrders(other.m_bondOrders),
m_atomicNumbers(other.m_atomicNumbers),
m_frozenAtomMask(other.m_frozenAtomMask),
m_frozenAtomMask(other.m_frozenAtomMask), m_graph(other.m_graph),
m_bondOrders(other.m_bondOrders), m_atomicNumbers(other.m_atomicNumbers),
m_layers(LayerManager::getMoleculeLayer(this))
{
m_basisSet = other.m_basisSet;
Expand Down
18 changes: 9 additions & 9 deletions avogadro/molequeue/batchjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,14 @@ void BatchJob::setup()

MoleQueueManager& mqManager = MoleQueueManager::instance();
Client& client = mqManager.client();
connect(&client, SIGNAL(submitJobResponse(int, uint)),
SLOT(handleSubmissionReply(int, uint)));
connect(&client, SIGNAL(lookupJobResponse(int, QJsonObject)),
SLOT(handleLookupJobReply(int, QJsonObject)));
connect(&client, SIGNAL(jobStateChanged(uint, QString, QString)),
SLOT(handleJobStateChange(uint, QString, QString)));
connect(&client, SIGNAL(errorReceived(int, int, QString, QJsonValue)),
SLOT(handleErrorResponse(int, int, QString, QJsonValue)));
connect(&client, &Client::submitJobResponse, this,
&BatchJob::handleSubmissionReply);
connect(&client, &Client::lookupJobResponse, this,
&BatchJob::handleLookupJobReply);
connect(&client, &Client::jobStateChanged, this,
&BatchJob::handleJobStateChange);
connect(&client, &Client::errorReceived, this,
&BatchJob::handleErrorResponse);
}

} // namespace Avogadro
} // namespace Avogadro::MoleQueue
16 changes: 8 additions & 8 deletions avogadro/molequeue/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ bool Client::connectToServer(const QString& serverName)
{
if (!m_jsonRpcClient) {
m_jsonRpcClient = new JsonRpcClient(this);
connect(m_jsonRpcClient, SIGNAL(resultReceived(QJsonObject)),
SLOT(processResult(QJsonObject)));
connect(m_jsonRpcClient, SIGNAL(notificationReceived(QJsonObject)),
SLOT(processNotification(QJsonObject)));
connect(m_jsonRpcClient, SIGNAL(errorReceived(QJsonObject)),
SLOT(processError(QJsonObject)));
connect(m_jsonRpcClient, SIGNAL(connectionStateChanged()),
SIGNAL(connectionStateChanged()));
connect(m_jsonRpcClient, &JsonRpcClient::resultReceived, this,
&Client::processResult);
connect(m_jsonRpcClient, &JsonRpcClient::notificationReceived, this,
&Client::processNotification);
connect(m_jsonRpcClient, &JsonRpcClient::errorReceived, this,
&Client::processError);
connect(m_jsonRpcClient, &JsonRpcClient::connectionStateChanged, this,
&Client::connectionStateChanged);
}

return m_jsonRpcClient->connectToServer(serverName);
Expand Down
39 changes: 16 additions & 23 deletions avogadro/molequeue/client/jsonrpcclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@

#include "jsonrpcclient.h"

#include <QtCore/QJsonDocument>
#include <QtCore/QDataStream>
#include <QtCore/QJsonDocument>
#include <QtCore/QTimer>
#include <QtNetwork/QLocalSocket>

namespace Avogadro::MoleQueue {

JsonRpcClient::JsonRpcClient(QObject *parent_) :
QObject(parent_),
m_packetCounter(0),
m_socket(nullptr)
JsonRpcClient::JsonRpcClient(QObject* parent_)
: QObject(parent_), m_packetCounter(0), m_socket(nullptr)
{
connect(this, SIGNAL(newPacket(QByteArray)), SLOT(readPacket(QByteArray)),
connect(this, &JsonRpcClient::newPacket, this, &JsonRpcClient::readPacket,
Qt::QueuedConnection);
}

Expand All @@ -34,13 +32,12 @@ bool JsonRpcClient::isConnected() const
return m_socket->isOpen();
}

bool JsonRpcClient::connectToServer(const QString &serverName_)
bool JsonRpcClient::connectToServer(const QString& serverName_)
{
if (m_socket && m_socket->isOpen()) {
if (m_socket->serverName() == serverName_) {
return false;
}
else {
} else {
m_socket->close();
delete m_socket;
m_socket = nullptr;
Expand All @@ -50,13 +47,12 @@ bool JsonRpcClient::connectToServer(const QString &serverName_)
// New connection.
if (m_socket == nullptr) {
m_socket = new QLocalSocket(this);
connect(m_socket, SIGNAL(readyRead()), this, SLOT(readSocket()));
connect(m_socket, &QIODevice::readyRead, this, &JsonRpcClient::readSocket);
}

if (serverName_.isEmpty()) {
return false;
}
else {
} else {
m_socket->connectToServer(serverName_);
return isConnected();
}
Expand Down Expand Up @@ -84,7 +80,7 @@ QJsonObject JsonRpcClient::emptyRequest()
return request;
}

bool JsonRpcClient::sendRequest(const QJsonObject &request)
bool JsonRpcClient::sendRequest(const QJsonObject& request)
{
if (!m_socket)
return false;
Expand All @@ -103,16 +99,14 @@ void JsonRpcClient::readPacket(const QByteArray message)
QJsonDocument reader = QJsonDocument::fromJson(message, &error);

if (error.error != QJsonParseError::NoError) {
emit badPacketReceived("Unparsable message received\n:"
+ error.errorString() + "\nContent: " + message);
emit badPacketReceived("Unparsable message received\n:" +
error.errorString() + "\nContent: " + message);
return;
}
else if (!reader.isObject()) {
} else if (!reader.isObject()) {
// We need a valid object, something bad happened.
emit badPacketReceived("Packet did not contain a valid JSON object.");
return;
}
else {
} else {
QJsonObject root = reader.object();
if (root["method"] != QJsonValue::Null) {
if (root["id"] != QJsonValue::Null)
Expand All @@ -123,8 +117,7 @@ void JsonRpcClient::readPacket(const QByteArray message)
if (root["result"] != QJsonValue::Null) {
// This is a result packet, and should emit a signal.
emit resultReceived(root);
}
else if (root["error"] != QJsonValue::Null) {
} else if (root["error"] != QJsonValue::Null) {
emit errorReceived(root);
}
}
Expand All @@ -138,8 +131,8 @@ void JsonRpcClient::readSocket()
stream >> json;
emit newPacket(json);
if (m_socket->bytesAvailable() > 0)
QTimer::singleShot(0, this, SLOT(readSocket()));
QTimer::singleShot(0, this, &JsonRpcClient::readSocket);
}
}

} // End namespace Avogadro
} // namespace Avogadro::MoleQueue
8 changes: 5 additions & 3 deletions avogadro/molequeue/inputgeneratordialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ InputGeneratorDialog::InputGeneratorDialog(QWidget* parent_)
: QDialog(parent_), ui(new Ui::InputGeneratorDialog)
{
ui->setupUi(this);
connect(ui->widget, SIGNAL(closeClicked()), SLOT(accept()));
connect(ui->widget, &InputGeneratorWidget::closeClicked, this,
&QDialog::accept);
}

InputGeneratorDialog::InputGeneratorDialog(const QString& scriptFileName,
QWidget* parent_)
: QDialog(parent_), ui(new Ui::InputGeneratorDialog)
{
ui->setupUi(this);
connect(ui->widget, SIGNAL(closeClicked()), SLOT(accept()));
connect(ui->widget, &InputGeneratorWidget::closeClicked, this,
&QDialog::accept);
this->setInputGeneratorScript(scriptFileName);
}

Expand Down Expand Up @@ -68,4 +70,4 @@ void InputGeneratorDialog::setMolecule(Molecule* mol)
ui->widget->setMolecule(mol);
}

} // namespace Avogadro
} // namespace Avogadro::MoleQueue
39 changes: 24 additions & 15 deletions avogadro/molequeue/inputgeneratorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ void InputGeneratorWidget::setMolecule(QtGui::Molecule* mol)
// make sure to call the base class method
QtGui::JsonWidget::setMolecule(mol);

connect(mol, SIGNAL(changed(unsigned int)), SLOT(updatePreviewText()));
connect(mol, SIGNAL(changed(unsigned int)), SLOT(updateTitlePlaceholder()));
connect(mol, &QtGui::Molecule::changed, this,
&InputGeneratorWidget::updatePreviewText);
connect(mol, &QtGui::Molecule::changed, this,
&InputGeneratorWidget::updateTitlePlaceholder);
}

updateTitlePlaceholder();
Expand Down Expand Up @@ -132,7 +134,8 @@ void InputGeneratorWidget::showEvent(QShowEvent* e)
// Update the preview text if an update was requested while hidden. Use a
// single shot to allow the dialog to show before popping up any warnings.
if (m_updatePending)
QTimer::singleShot(0, this, SLOT(updatePreviewTextImmediately()));
QTimer::singleShot(0, this,
&InputGeneratorWidget::updatePreviewTextImmediately);
}

void InputGeneratorWidget::updatePreviewText()
Expand All @@ -141,7 +144,8 @@ void InputGeneratorWidget::updatePreviewText()
return;

m_updatePending = true;
QTimer::singleShot(250, this, SLOT(updatePreviewTextImmediately()));
QTimer::singleShot(250, this,
&InputGeneratorWidget::updatePreviewTextImmediately);
}

void InputGeneratorWidget::updatePreviewTextImmediately()
Expand Down Expand Up @@ -234,7 +238,8 @@ void InputGeneratorWidget::updatePreviewTextImmediately()
auto* edit = new QTextEdit(this);
edit->setObjectName(fileName);
edit->setFontFamily("monospace");
connect(edit, SIGNAL(textChanged()), this, SLOT(textEditModified()));
connect(edit, &QTextEdit::textChanged, this,
&InputGeneratorWidget::textEditModified);
m_ui->tabWidget->addTab(edit, fileName);
m_textEdits.insert(fileName, edit);
}
Expand Down Expand Up @@ -623,22 +628,26 @@ QJsonObject InputGeneratorWidget::promptForBatchJobOptions() const

void InputGeneratorWidget::connectButtons()
{
connect(m_ui->debugCheckBox, SIGNAL(toggled(bool)), &m_inputGenerator,
SLOT(setDebug(bool)));
connect(m_ui->debugCheckBox, SIGNAL(toggled(bool)),
SLOT(updatePreviewText()));
connect(m_ui->defaultsButton, SIGNAL(clicked()), SLOT(defaultsClicked()));
connect(m_ui->generateButton, SIGNAL(clicked()), SLOT(generateClicked()));
connect(m_ui->closeButton, SIGNAL(clicked()), SIGNAL(closeClicked()));
connect(m_ui->warningTextButton, SIGNAL(clicked()),
SLOT(toggleWarningText()));
connect(m_ui->debugCheckBox, &QAbstractButton::toggled, &m_inputGenerator,
&InputGenerator::setDebug);
connect(m_ui->debugCheckBox, &QAbstractButton::toggled, this,
&InputGeneratorWidget::updatePreviewText);
connect(m_ui->defaultsButton, &QAbstractButton::clicked, this,
&InputGeneratorWidget::defaultsClicked);
connect(m_ui->generateButton, &QAbstractButton::clicked, this,
&InputGeneratorWidget::generateClicked);
connect(m_ui->closeButton, &QAbstractButton::clicked, this,
&InputGeneratorWidget::closeClicked);
connect(m_ui->warningTextButton, &QAbstractButton::clicked, this,
&InputGeneratorWidget::toggleWarningText);

// disable the compute button if Molequeue is not running
MoleQueueManager& mqManager = MoleQueueManager::instance();
if (!mqManager.connectIfNeeded()) {
m_ui->computeButton->setEnabled(false);
} else {
connect(m_ui->computeButton, SIGNAL(clicked()), SLOT(computeClicked()));
connect(m_ui->computeButton, &QAbstractButton::clicked, this,
&InputGeneratorWidget::computeClicked);
}
}

Expand Down
Loading

0 comments on commit 1bd2b9e

Please sign in to comment.