From 45cd17af84f51ac56942620f1a5b0e84940627c3 Mon Sep 17 00:00:00 2001 From: Dave Page Date: Thu, 6 Dec 2018 10:17:47 +0000 Subject: [PATCH] Use nullptr instead of NULL or 0. --- runtime/ConfigWindow.h | 2 +- runtime/FloatingWindow.cpp | 14 +++++++------- runtime/FloatingWindow.h | 2 +- runtime/LogWindow.cpp | 2 +- runtime/LogWindow.h | 2 +- runtime/Logger.cpp | 10 +++++----- runtime/Logger.h | 1 + runtime/MenuActions.cpp | 10 +++++----- runtime/Server.cpp | 18 +++++++++--------- runtime/pgAdmin4.cpp | 34 +++++++++++++++++----------------- 10 files changed, 48 insertions(+), 47 deletions(-) diff --git a/runtime/ConfigWindow.h b/runtime/ConfigWindow.h index f2a9ce1f6..beae2b095 100644 --- a/runtime/ConfigWindow.h +++ b/runtime/ConfigWindow.h @@ -23,7 +23,7 @@ class ConfigWindow : public QDialog Q_OBJECT public: - explicit ConfigWindow(QWidget *parent = 0); + explicit ConfigWindow(QWidget *parent = nullptr); ~ConfigWindow(); QString getBrowserCommand(); diff --git a/runtime/FloatingWindow.cpp b/runtime/FloatingWindow.cpp index 9439e42f6..bab6bd0cb 100644 --- a/runtime/FloatingWindow.cpp +++ b/runtime/FloatingWindow.cpp @@ -16,12 +16,12 @@ FloatingWindow::FloatingWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::FloatingWindow) { - m_newAction = NULL; - m_configAction = NULL; - m_logAction = NULL; - m_quitAction = NULL; - m_menuActions = NULL; - m_floatingWindowMenu = NULL; + m_newAction = nullptr; + m_configAction = nullptr; + m_logAction = nullptr; + m_quitAction = nullptr; + m_menuActions = nullptr; + m_floatingWindowMenu = nullptr; ui->setupUi(this); } @@ -87,7 +87,7 @@ void FloatingWindow::createActions() void FloatingWindow::enableShutdownMenu() { - if (m_quitAction != NULL) + if (m_quitAction != nullptr) { m_quitAction->setEnabled(true); } diff --git a/runtime/FloatingWindow.h b/runtime/FloatingWindow.h index 6875ad0d7..0b896efcf 100644 --- a/runtime/FloatingWindow.h +++ b/runtime/FloatingWindow.h @@ -27,7 +27,7 @@ class FloatingWindow : public QMainWindow Q_OBJECT public: - explicit FloatingWindow(QWidget *parent = 0); + explicit FloatingWindow(QWidget *parent = nullptr); ~FloatingWindow(); bool Init(); diff --git a/runtime/LogWindow.cpp b/runtime/LogWindow.cpp index 250070a03..e474d80c8 100644 --- a/runtime/LogWindow.cpp +++ b/runtime/LogWindow.cpp @@ -55,7 +55,7 @@ void LogWindow::ReadLog() // Attempt to open the file log = fopen(m_logFile.toUtf8().data(), "r"); - if (log == NULL) + if (log == nullptr) { ui->textLog->setPlainText(QString(tr("The log file (%1) could not be opened.")).arg(m_logFile)); this->setDisabled(false); diff --git a/runtime/LogWindow.h b/runtime/LogWindow.h index 2df552400..4c4be88aa 100644 --- a/runtime/LogWindow.h +++ b/runtime/LogWindow.h @@ -23,7 +23,7 @@ class LogWindow : public QDialog Q_OBJECT public: - explicit LogWindow(QWidget *parent = 0, QString logFile = ""); + explicit LogWindow(QWidget *parent = nullptr, QString logFile = ""); ~LogWindow(); void ReadLog(); diff --git a/runtime/Logger.cpp b/runtime/Logger.cpp index b060421dc..bc84aed78 100644 --- a/runtime/Logger.cpp +++ b/runtime/Logger.cpp @@ -24,7 +24,7 @@ Logger::~Logger() Logger* Logger::GetLogger() { - if (m_pThis == NULL) + if (m_pThis == nullptr) { m_pThis = new Logger(); m_sFileName = QDir::homePath() + (QString("/.%1.startup.log").arg(PGA_APP_NAME)).remove(" "); @@ -40,7 +40,7 @@ Logger* Logger::GetLogger() void Logger::Log(const QString& sMessage) { QString text = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss ") + sMessage + "\n"; - if (m_Logfile != NULL) + if (m_Logfile != nullptr) { QTextStream out(m_Logfile); out << text; @@ -49,11 +49,11 @@ void Logger::Log(const QString& sMessage) void Logger::ReleaseLogger() { - if (m_pThis != NULL) + if (m_pThis != nullptr) { - if(m_Logfile != NULL) + if(m_Logfile != nullptr) m_Logfile->close(); delete m_pThis; - m_pThis = NULL; + m_pThis = nullptr; } } diff --git a/runtime/Logger.h b/runtime/Logger.h index f8ffba03b..be777a65a 100644 --- a/runtime/Logger.h +++ b/runtime/Logger.h @@ -13,6 +13,7 @@ #define LOGGER_H #include +#include class Logger : public QObject { diff --git a/runtime/MenuActions.cpp b/runtime/MenuActions.cpp index 1adc34bc8..e22cbe75a 100644 --- a/runtime/MenuActions.cpp +++ b/runtime/MenuActions.cpp @@ -17,7 +17,7 @@ MenuActions::MenuActions() { - m_logWindow = NULL; + m_logWindow = nullptr; m_logFile = ""; m_appServerUrl = ""; } @@ -52,7 +52,7 @@ void MenuActions::onNew() if (!QDesktopServices::openUrl(m_appServerUrl)) { QString error(QWidget::tr("Failed to open the system default web browser. Is one installed?.")); - QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); + QMessageBox::critical(nullptr, QString(QWidget::tr("Fatal Error")), error); exit(1); } @@ -105,7 +105,7 @@ void MenuActions::onConfig() if (needRestart) { - if (QMessageBox::Yes == QMessageBox::question(NULL, tr("Shut down server?"), QString(tr("The %1 server must be restarted for changes to take effect. Do you want to shut down the server now?")).arg(PGA_APP_NAME), QMessageBox::Yes | QMessageBox::No)) + if (QMessageBox::Yes == QMessageBox::question(nullptr, tr("Shut down server?"), QString(tr("The %1 server must be restarted for changes to take effect. Do you want to shut down the server now?")).arg(PGA_APP_NAME), QMessageBox::Yes | QMessageBox::No)) { exit(0); } @@ -121,7 +121,7 @@ void MenuActions::onLog() if (!m_logWindow) { - m_logWindow = new LogWindow(NULL, m_logFile); + m_logWindow = new LogWindow(nullptr, m_logFile); m_logWindow->setWindowTitle(QString(tr("%1 Log")).arg(PGA_APP_NAME)); } @@ -138,7 +138,7 @@ void MenuActions::onLog() // Exit void MenuActions::onQuit() { - if (QMessageBox::Yes == QMessageBox::question(NULL, tr("Shut down server?"), QString(tr("Are you sure you want to shut down the %1 server?")).arg(PGA_APP_NAME), QMessageBox::Yes | QMessageBox::No)) + if (QMessageBox::Yes == QMessageBox::question(nullptr, tr("Shut down server?"), QString(tr("Are you sure you want to shut down the %1 server?")).arg(PGA_APP_NAME), QMessageBox::Yes | QMessageBox::No)) { // Emit the signal to shut down the python server. emit shutdownSignal(m_appServerUrl); diff --git a/runtime/Server.cpp b/runtime/Server.cpp index 48756e3e5..e28e20807 100644 --- a/runtime/Server.cpp +++ b/runtime/Server.cpp @@ -61,8 +61,8 @@ Server::Server(quint16 port, QString key, QString logFileName) m_port = port; m_key = key; m_logFileName = logFileName; - m_wcAppName = NULL; - m_wcPythonHome = NULL; + m_wcAppName = nullptr; + m_wcPythonHome = nullptr; // Initialise Python Py_NoSiteFlag=1; @@ -201,7 +201,7 @@ Server::Server(quint16 port, QString key, QString logFileName) // Get the current path PyObject* sysPath = PySys_GetObject((char*)"path"); - if (sysPath != NULL) + if (sysPath != nullptr) { // Add new additional path elements Logger::GetLogger()->Log("Adding new additional path elements"); @@ -224,13 +224,13 @@ Server::Server(quint16 port, QString key, QString logFileName) // Redirect stderr Logger::GetLogger()->Log("Redirecting stderr..."); PyObject *sys = PyImport_ImportModule("sys"); - if (sys != NULL) + if (sys != nullptr) { - PyObject *err = NULL; + PyObject *err = nullptr; #ifdef PYTHON2 err = PyFile_FromString(m_logFileName.toUtf8().data(), (char *)"w"); #else - FILE *log = NULL; + FILE *log = nullptr; #if defined(Q_OS_WIN) char *logFile = m_logFileName.toUtf8().data(); @@ -242,10 +242,10 @@ Server::Server(quint16 port, QString key, QString logFileName) #else log = fopen(m_logFileName.toUtf8().data(), (char *)"w"); #endif - if (log != NULL) + if (log != nullptr) { int fd = fileno(log); - err = PyFile_FromFd(fd, NULL, (char *)"w", -1, NULL, NULL, NULL, 0); + err = PyFile_FromFd(fd, nullptr, (char *)"w", -1, nullptr, nullptr, nullptr, 0); } else Logger::GetLogger()->Log(QString("Failed to open log file: %1").arg(m_logFileName)); @@ -259,7 +259,7 @@ Server::Server(quint16 port, QString key, QString logFileName) #endif #endif QFile(m_logFileName).setPermissions(QFile::ReadOwner|QFile::WriteOwner); - if (err != NULL) + if (err != nullptr) { PyObject_SetAttrString(sys, "stderr", err); Logger::GetLogger()->Log("stderr redirected successfully."); diff --git a/runtime/pgAdmin4.cpp b/runtime/pgAdmin4.cpp index a379cacec..06b82bec8 100644 --- a/runtime/pgAdmin4.cpp +++ b/runtime/pgAdmin4.cpp @@ -214,22 +214,22 @@ int main(int argc, char * argv[]) // Create Menu Actions MenuActions *menuActions = new MenuActions(); - if(menuActions != NULL) + if(menuActions != nullptr) menuActions->setLogFile(logFileName); splash->showMessage(QString(QWidget::tr("Checking for system tray...")), Qt::AlignBottom | Qt::AlignCenter); Logger::GetLogger()->Log("Checking for system tray..."); // Check system tray is available or not. If not then create one floating window. - FloatingWindow *floatingWindow = NULL; - TrayIcon *trayicon = NULL; + FloatingWindow *floatingWindow = nullptr; + TrayIcon *trayicon = nullptr; if (QSystemTrayIcon::isSystemTrayAvailable()) { // Start the tray service trayicon = new TrayIcon(); // Set the MenuActions object to connect to slot - if (trayicon != NULL) + if (trayicon != nullptr) trayicon->setMenuActions(menuActions); trayicon->Init(); @@ -240,10 +240,10 @@ int main(int argc, char * argv[]) Logger::GetLogger()->Log("System tray not found, creating floating window..."); // Unable to find tray icon, so creating floting window floatingWindow = new FloatingWindow(); - if (floatingWindow == NULL) + if (floatingWindow == nullptr) { QString error = QString(QWidget::tr("Unable to initialize either a tray icon or control window.")); - QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); + QMessageBox::critical(nullptr, QString(QWidget::tr("Fatal Error")), error); Logger::GetLogger()->Log(error); Logger::ReleaseLogger(); exit(1); @@ -270,12 +270,12 @@ int main(int argc, char * argv[]) Logger::GetLogger()->Log("Initializing server..."); if (!server->Init()) { - splash->finish(NULL); + splash->finish(nullptr); qDebug() << server->getError(); QString error = QString(QWidget::tr("An error occurred initialising the application server:\n\n%1")).arg(server->getError()); - QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); + QMessageBox::critical(nullptr, QString(QWidget::tr("Fatal Error")), error); Logger::GetLogger()->Log(error); Logger::ReleaseLogger(); @@ -297,12 +297,12 @@ int main(int argc, char * argv[]) // Any errors? if (server->isFinished() || server->getError().length() > 0) { - splash->finish(NULL); + splash->finish(nullptr); qDebug() << server->getError(); QString error = QString(QWidget::tr("An error occurred initialising the application server:\n\n%1")).arg(server->getError()); - QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); + QMessageBox::critical(nullptr, QString(QWidget::tr("Fatal Error")), error); Logger::GetLogger()->Log(error); // Allow the user to tweak the Python Path if needed @@ -372,9 +372,9 @@ int main(int argc, char * argv[]) Logger::GetLogger()->Log("Attempt to connect one more time in case of a long network timeout while looping"); if (!alive && !PingServer(QUrl(appServerUrl))) { - splash->finish(NULL); + splash->finish(nullptr); QString error(QWidget::tr("The application server could not be contacted.")); - QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); + QMessageBox::critical(nullptr, QString(QWidget::tr("Fatal Error")), error); Logger::ReleaseLogger(); exit(1); @@ -392,9 +392,9 @@ int main(int argc, char * argv[]) menuActions->setAppServerUrl(appServerUrl); // Enable the shutdown server menu as server started successfully. - if (trayicon != NULL) + if (trayicon != nullptr) trayicon->enableShutdownMenu(); - if (floatingWindow != NULL) + if (floatingWindow != nullptr) floatingWindow->enableShutdownMenu(); QString cmd = settings.value("BrowserCommand").toString(); @@ -409,7 +409,7 @@ int main(int argc, char * argv[]) if (!QDesktopServices::openUrl(appServerUrl)) { QString error(QWidget::tr("Failed to open the system default web browser. Is one installed?.")); - QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); + QMessageBox::critical(nullptr, QString(QWidget::tr("Fatal Error")), error); Logger::GetLogger()->Log(error); Logger::ReleaseLogger(); @@ -418,9 +418,9 @@ int main(int argc, char * argv[]) } QObject::connect(menuActions, SIGNAL(shutdownSignal(QUrl)), server, SLOT(shutdown(QUrl))); - splash->finish(NULL); + splash->finish(nullptr); - if (floatingWindow != NULL) + if (floatingWindow != nullptr) floatingWindow->show(); Logger::GetLogger()->Log("Everything works fine, successfully started pgAdmin4.");