From 9f479b8f76238a03bce5d13aee14efd34e659c6e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Sun, 30 Oct 2022 20:34:23 +0100 Subject: Clean up and modernize code - static "new-style" signal->slot connections - Fix a lot of things Clang-Tidy complained about - Move includes to .cpp files and use forward decls in .h - Don't use and , but specific includes instead --- src/client/connectwindow/connectwindow.cpp | 30 +++++++++++++++--------------- src/client/connectwindow/connectwindow.h | 21 +++++++++++---------- 2 files changed, 26 insertions(+), 25 deletions(-) (limited to 'src/client/connectwindow') diff --git a/src/client/connectwindow/connectwindow.cpp b/src/client/connectwindow/connectwindow.cpp index 8c47eea..0bc6835 100644 --- a/src/client/connectwindow/connectwindow.cpp +++ b/src/client/connectwindow/connectwindow.cpp @@ -7,13 +7,14 @@ #include #include "../../shared/settings.h" -#include "../../shared/network.h" #include "../../shared/util.h" #include "../net/serverconnection.h" #include "../clientapp/clientapp.h" #include "connectwindow.h" #include "ui_connectwindow.h" +#include + #define UDPBUFSIZ 9000 #define SALT_LEN 18 @@ -43,17 +44,16 @@ ConnectWindow::ConnectWindow(QWidget *parent) : QWidget(parent) _ui->stackedWidget->setCurrentIndex(0); // Set actions of buttons - connect(_ui->btn_connection, SIGNAL(clicked()), this, SLOT(onBtnConnection())); - connect(_ui->btn_hide, SIGNAL(clicked()), this, SLOT(onBtnHide())); + connect(_ui->btn_connection, &QPushButton::clicked, this, &ConnectWindow::onBtnConnection); + connect(_ui->btn_hide, &QPushButton::clicked, this, &ConnectWindow::onBtnHide); - connect(_ui->comboBox_rooms, SIGNAL(currentIndexChanged(int)), this, SLOT(onRoomSelection(int))); + connect(_ui->comboBox_rooms, QOverload::of(&QComboBox::currentIndexChanged), this, &ConnectWindow::onRoomSelection); // React on discovery signal - connect(&_serverDiscovery, SIGNAL(serverDetected(QString, quint16, QByteArray, QByteArray, bool)), - this, SLOT(onServerDetected(QString, quint16, QByteArray, QByteArray, bool))); + connect(&_serverDiscovery, &ServerDiscovery::serverDetected, this, &ConnectWindow::onServerDetected); /* finally the most requested feature: connect on press of the enter key */ - connect(_ui->lineEditName, SIGNAL(returnPressed()), _ui->btn_connection, SIGNAL(clicked())); + connect(_ui->lineEditName, &QLineEdit::returnPressed, this, &ConnectWindow::onBtnConnection); /* by default don't show the manual connection box */ _ui->box_manual->setVisible(false); @@ -64,7 +64,7 @@ ConnectWindow::ConnectWindow(QWidget *parent) : QWidget(parent) /** * @brief ConnectWindow::~ConnectWindow */ -ConnectWindow::~ConnectWindow() {} +ConnectWindow::~ConnectWindow() = default; @@ -181,7 +181,7 @@ void ConnectWindow::showEvent(QShowEvent* /* event */ ) * if not --> connect to given sessionName. * @param sessionName */ -void ConnectWindow::connectToSession(const QByteArray sessionName, QString mgrIP) +void ConnectWindow::connectToSession(const QByteArray& sessionName, const QString &mgrIP) { if (_state != Idle) return; @@ -254,7 +254,7 @@ void ConnectWindow::onBtnConnection() /** set the available rooms. * If the list of rooms is empty, switches automatically to the "manual * connection" page */ -void ConnectWindow::setAvailableRooms(QList m) +void ConnectWindow::setAvailableRooms(const QList& m) { _ui->comboBox_rooms->clear(); foreach (Room r, m) { @@ -298,9 +298,9 @@ void ConnectWindow::onRoomSelection(int index) void ConnectWindow::onServerDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect) { _pendingConnection = new ServerConnection(host, port, sessionName, certHash, autoConnect); - connect(_pendingConnection, SIGNAL(stateChange(ConnectWindow::ConnectionState)), this, SLOT(onConnectionStateChange(ConnectWindow::ConnectionState))); - connect(_pendingConnection, SIGNAL(destroyed(QObject*)), this, SLOT(onConnectionClosed(QObject*))); - connect(_pendingConnection, SIGNAL(disconnected(ServerConnection*)), this, SLOT(onConnectionDisconnected(ServerConnection*))); + connect(_pendingConnection, &ServerConnection::stateChange, this, &ConnectWindow::onConnectionStateChange); + connect(_pendingConnection, &ServerConnection::destroyed, this, &ConnectWindow::onConnectionClosed); + connect(_pendingConnection, &ServerConnection::disconnected, this, &ConnectWindow::onConnectionDisconnected); } @@ -321,8 +321,8 @@ void ConnectWindow::onConnectionStateChange(ConnectWindow::ConnectionState state _state = Scanning; } if (state == Connected) { - QObject::disconnect(_pendingConnection, SIGNAL(stateChange(ConnectWindow::ConnectionState)), this, SLOT(onConnectionStateChange(ConnectWindow::ConnectionState))); - QObject::disconnect(_pendingConnection, SIGNAL(destroyed(QObject*)), this, SLOT(onConnectionClosed(QObject*))); + QObject::disconnect(_pendingConnection, &ServerConnection::stateChange, this, &ConnectWindow::onConnectionStateChange); + QObject::disconnect(_pendingConnection, &ServerConnection::destroyed, this, &ConnectWindow::onConnectionClosed); emit connected(_pendingConnection); _pendingConnection = nullptr; _timerHide = startTimer(2000); diff --git a/src/client/connectwindow/connectwindow.h b/src/client/connectwindow/connectwindow.h index 2df672d..4a0ae7d 100644 --- a/src/client/connectwindow/connectwindow.h +++ b/src/client/connectwindow/connectwindow.h @@ -16,7 +16,7 @@ #ifndef PVSCONNECTWINDOW_H_ #define PVSCONNECTWINDOW_H_ -#include +#include #include #include #include @@ -56,10 +56,10 @@ public: }; explicit ConnectWindow(QWidget *parent = nullptr); - virtual ~ConnectWindow(); + ~ConnectWindow() override; - void connectToSession(const QByteArray sessionName, QString mgrIP); - void setAvailableRooms(QList m); + void connectToSession(const QByteArray& sessionName, const QString &mgrIP); + void setAvailableRooms(const QList& m); private: Ui::ConnectWindow *_ui; @@ -71,18 +71,17 @@ private: QString _currentIp; QString _defaultSessionName; NetworkMessage _packet; - bool _tryReconnect; + bool _tryReconnect{}; int _timerHide; void updateUserInterface(); protected: - void timerEvent(QTimerEvent* event); - void closeEvent(QCloseEvent *e); - void showEvent(QShowEvent* event); + void timerEvent(QTimerEvent* event) override; + void closeEvent(QCloseEvent *e) override; + void showEvent(QShowEvent* event) override; protected slots: - void doShow(); void onBtnConnection(); void onBtnHide(); @@ -92,13 +91,15 @@ protected slots: void onConnectionClosed(QObject* connection); void onConnectionDisconnected(ServerConnection* connection); // void onUdpReadyRead(); - void onServerDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect); + void onServerDetected(const QString& host, quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect); public slots: /** actually connects the connection **/ void DoConnect(); /** actually disconnects the connection **/ void DoDisconnect(); + + void doShow(); signals: void disconnect(); void connected(ServerConnection* connection); -- cgit v1.2.3-55-g7522