From cb1b04bb50d7e9c729341a29e9d6c4a60977e42c Mon Sep 17 00:00:00 2001 From: Vitaly Slobodin Date: Mon, 13 Jan 2020 18:11:46 +0300 Subject: [PATCH] Replace NULL (or 0) with Q_NULLPTR --- src/childprocess.cpp | 4 ++-- src/cookiejar.h | 2 +- src/encoding.cpp | 12 ++++++++---- src/env.cpp | 4 ++-- src/filesystem.cpp | 8 ++++---- src/networkaccessmanager.cpp | 6 +++--- src/phantom.cpp | 6 +++--- src/phantom.h | 2 +- src/repl.cpp | 6 +++--- src/system.cpp | 30 +++++++++++++++--------------- src/webpage.cpp | 22 +++++++++++----------- src/webpage.h | 4 ++-- src/webserver.cpp | 2 +- 13 files changed, 56 insertions(+), 52 deletions(-) diff --git a/src/childprocess.cpp b/src/childprocess.cpp index 1ad43b2d3..49970b45a 100644 --- a/src/childprocess.cpp +++ b/src/childprocess.cpp @@ -92,11 +92,11 @@ qint64 ChildProcessContext::_write(const QString& chunk, const QString& encoding QTextCodec* codec = QTextCodec::codecForName(encoding.toLatin1()); // If unavailable, attempt UTF-8 codec - if ((QTextCodec*)NULL == codec) { + if (!codec) { codec = QTextCodec::codecForName("UTF-8"); // Don't even try to write if UTF-8 codec is unavailable - if ((QTextCodec*)NULL == codec) { + if (!codec) { return -1; } } diff --git a/src/cookiejar.h b/src/cookiejar.h index 6fa3c53ca..49386f625 100644 --- a/src/cookiejar.h +++ b/src/cookiejar.h @@ -43,7 +43,7 @@ class CookieJar : public QNetworkCookieJar { Q_PROPERTY(QVariantList cookies READ cookiesToMap WRITE addCookiesFromMap) public: - CookieJar(QString cookiesFile, QObject* parent = NULL); + CookieJar(QString cookiesFile, QObject* parent = Q_NULLPTR); virtual ~CookieJar(); bool setCookiesFromUrl(const QList& cookieList, const QUrl& url); diff --git a/src/encoding.cpp b/src/encoding.cpp index 1033d0ee4..e117834fb 100644 --- a/src/encoding.cpp +++ b/src/encoding.cpp @@ -35,7 +35,7 @@ Encoding::Encoding() QTextCodec* codec = QTextCodec::codecForName(DEFAULT_CODEC_NAME); // Fall back to locale codec - if ((QTextCodec*)NULL == codec) { + if (!codec) { codec = QTextCodec::codecForLocale(); } @@ -49,7 +49,11 @@ Encoding::Encoding(const QString& encoding) Encoding::~Encoding() { - m_codec = (QTextCodec*)NULL; + if (m_codec) { + // TODO: Encoding class does not inherit QObject, so + // we have to nullifyt m_codec member manually; + m_codec = Q_NULLPTR; + } } QString Encoding::decode(const QByteArray& bytes) const @@ -73,7 +77,7 @@ void Encoding::setEncoding(const QString& encoding) if (!encoding.isEmpty()) { QTextCodec* codec = QTextCodec::codecForName(encoding.toLatin1()); - if ((QTextCodec*)NULL != codec) { + if (codec) { m_codec = codec; } } @@ -86,7 +90,7 @@ QTextCodec* Encoding::getCodec() const { QTextCodec* codec = m_codec; - if ((QTextCodec*)NULL == codec) { + if (!codec) { codec = QTextCodec::codecForLocale(); } diff --git a/src/env.cpp b/src/env.cpp index 0c20c42f6..a449ba8d8 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -34,11 +34,11 @@ #include #include -static Env* env_instance = NULL; +static Env* env_instance = Q_NULLPTR; Env* Env::instance() { - if (NULL == env_instance) { + if (!env_instance) { env_instance = new Env(); } diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 16a7d6ffe..70e7595c9 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -216,7 +216,7 @@ void File::close() if (m_file) { m_file->close(); delete m_file; - m_file = NULL; + m_file = Q_NULLPTR; } deleteLater(); } @@ -228,7 +228,7 @@ bool File::setEncoding(const QString& encoding) } // "Binary" mode doesn't use/need text codecs - if ((QTextStream*)NULL == m_fileStream) { + if (!m_fileStream) { // TODO: Should we switch to "text" mode? return false; } @@ -237,7 +237,7 @@ bool File::setEncoding(const QString& encoding) // "utf-8"), we need to get the codec in the system first and use its // canonical name QTextCodec* codec = QTextCodec::codecForName(encoding.toLatin1()); - if ((QTextCodec*)NULL == codec) { + if (!codec) { return false; } @@ -258,7 +258,7 @@ QString File::getEncoding() const { QString encoding; - if ((QTextStream*)NULL != m_fileStream) { + if (m_fileStream) { encoding = QString(m_fileStream->codec()->name()); } diff --git a/src/networkaccessmanager.cpp b/src/networkaccessmanager.cpp index b5faadd00..ac539c3e8 100644 --- a/src/networkaccessmanager.cpp +++ b/src/networkaccessmanager.cpp @@ -49,7 +49,7 @@ const qint64 MAX_REQUEST_POST_BODY_SIZE = 10 * 1000 * 1000; static const char* toString(QNetworkAccessManager::Operation op) { - const char* str = 0; + const char* str = Q_NULLPTR; switch (op) { case QNetworkAccessManager::HeadOperation: str = "HEAD"; @@ -157,7 +157,7 @@ NetworkAccessManager::NetworkAccessManager(QObject* parent, const Config* config , m_maxAuthAttempts(3) , m_resourceTimeout(0) , m_idCounter(0) - , m_networkDiskCache(0) + , m_networkDiskCache(Q_NULLPTR) , m_sslConfiguration(QSslConfiguration::defaultConfiguration()) { if (config->diskCacheEnabled()) { @@ -242,7 +242,7 @@ void NetworkAccessManager::prepareSslConfiguration(const Config* config) m_sslConfiguration.setCaCertificates(caCerts); m_sslConfiguration.setLocalCertificate(clientCert); - QFile* keyFile = NULL; + QFile* keyFile = Q_NULLPTR; if (config->sslClientKeyFile().isEmpty()) { keyFile = new QFile(config->sslClientCertificateFile()); } else { diff --git a/src/phantom.cpp b/src/phantom.cpp index 12d5bcb67..7744b0800 100644 --- a/src/phantom.cpp +++ b/src/phantom.cpp @@ -57,7 +57,7 @@ #error "This version of QtWebKit is not supported. Please use QtWebKit >= 5.212" #endif -static Phantom* phantomInstance = NULL; +static Phantom* phantomInstance = Q_NULLPTR; // private: Phantom::Phantom(QObject* parent) @@ -157,7 +157,7 @@ void Phantom::init() // public: Phantom* Phantom::instance() { - if (NULL == phantomInstance) { + if (!phantomInstance) { phantomInstance = new Phantom(); phantomInstance->init(); } @@ -405,7 +405,7 @@ QString Phantom::proxy() { QNetworkProxy proxy = QNetworkProxy::applicationProxy(); if (proxy.hostName().isEmpty()) { - return NULL; + return QString(); } return proxy.hostName() + ":" + QString::number(proxy.port()); } diff --git a/src/phantom.h b/src/phantom.h index a509ee288..e36f23347 100644 --- a/src/phantom.h +++ b/src/phantom.h @@ -167,7 +167,7 @@ public slots: * @param port The proxy port * @param proxyType The type of this proxy */ - void setProxy(const QString& ip, const qint64& port = 80, const QString& proxyType = "http", const QString& user = NULL, const QString& password = NULL); + void setProxy(const QString& ip, const qint64& port = 80, const QString& proxyType = "http", const QString& user = QString(), const QString& password = QString()); QString proxy(); diff --git a/src/repl.cpp b/src/repl.cpp index 01474f5e1..da1c15db5 100644 --- a/src/repl.cpp +++ b/src/repl.cpp @@ -66,12 +66,12 @@ // public: bool REPL::instanceExists() { - return REPL::getInstance() != NULL; + return REPL::getInstance() != Q_NULLPTR; } REPL* REPL::getInstance(QWebFrame* webframe, Phantom* parent) { - static REPL* singleton = NULL; + static REPL* singleton = Q_NULLPTR; if (!singleton && webframe && parent) { // This will create the singleton only when all the parameters are given singleton = new REPL(webframe, parent); @@ -202,7 +202,7 @@ void REPL::startLoop() // Load REPL history linenoiseHistoryLoad(m_historyFilepath.data()); //< requires "char *" - while (m_looping && (userInput = linenoise(PROMPT)) != NULL) { + while (m_looping && (userInput = linenoise(PROMPT)) != Q_NULLPTR) { if (userInput[0] != '\0') { // Send the user input to the main Phantom frame for evaluation m_webframe->evaluateJavaScript( diff --git a/src/system.cpp b/src/system.cpp index f83daa18a..18c670935 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -54,9 +54,9 @@ QString getOSRelease() System::System(QObject* parent) : QObject(parent) - , m_stdout((File*)NULL) - , m_stderr((File*)NULL) - , m_stdin((File*)NULL) + , m_stdout(Q_NULLPTR) + , m_stderr(Q_NULLPTR) + , m_stdin(Q_NULLPTR) { // Populate "env" m_env = Env::instance()->asVariantMap(); @@ -165,17 +165,17 @@ System::System(QObject* parent) System::~System() { // Clean-up standard streams - if ((File*)NULL != m_stdout) { + if (m_stdout) { delete m_stdout; - m_stdout = (File*)NULL; + m_stdout = Q_NULLPTR; } - if ((File*)NULL != m_stderr) { + if (m_stderr) { delete m_stderr; - m_stderr = (File*)NULL; + m_stderr = Q_NULLPTR; } - if ((File*)NULL != m_stdin) { + if (m_stdin) { delete m_stdin; - m_stdin = (File*)NULL; + m_stdin = Q_NULLPTR; } } @@ -211,7 +211,7 @@ bool System::isSSLSupported() const QObject* System::_stdout() { - if ((File*)NULL == m_stdout) { + if (!m_stdout) { QFile* f = new QFile(); f->open(stdout, QIODevice::WriteOnly | QIODevice::Unbuffered); m_stdout = createFileInstance(f); @@ -222,7 +222,7 @@ QObject* System::_stdout() QObject* System::_stderr() { - if ((File*)NULL == m_stderr) { + if (!m_stderr) { QFile* f = new QFile(); f->open(stderr, QIODevice::WriteOnly | QIODevice::Unbuffered); m_stderr = createFileInstance(f); @@ -233,7 +233,7 @@ QObject* System::_stderr() QObject* System::_stdin() { - if ((File*)NULL == m_stdin) { + if (!m_stdin) { QFile* f = new QFile(); f->open(stdin, QIODevice::ReadOnly | QIODevice::Unbuffered); m_stdin = createFileInstance(f); @@ -246,15 +246,15 @@ QObject* System::_stdin() void System::_onTerminalEncodingChanged(const QString& encoding) { - if ((File*)NULL != m_stdin) { + if (!m_stdin) { m_stdin->setEncoding(encoding); } - if ((File*)NULL != m_stdout) { + if (!m_stdout) { m_stdout->setEncoding(encoding); } - if ((File*)NULL != m_stderr) { + if (!m_stderr) { m_stderr->setEncoding(encoding); } } diff --git a/src/webpage.cpp b/src/webpage.cpp index 3bc6e45ea..f74d3c552 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -89,7 +89,7 @@ class CustomPage : public QWebPage { Q_OBJECT public: - CustomPage(WebPage* parent = 0) + CustomPage(WebPage* parent = Q_NULLPTR) : QWebPage(parent) , m_webPage(parent) { @@ -265,13 +265,13 @@ class WebpageCallbacks : public QObject { Q_OBJECT public: - WebpageCallbacks(QObject* parent = 0) + WebpageCallbacks(QObject* parent = Q_NULLPTR) : QObject(parent) - , m_genericCallback(NULL) - , m_filePickerCallback(NULL) - , m_jsConfirmCallback(NULL) - , m_jsPromptCallback(NULL) - , m_jsInterruptCallback(NULL) + , m_genericCallback(Q_NULLPTR) + , m_filePickerCallback(Q_NULLPTR) + , m_jsConfirmCallback(Q_NULLPTR) + , m_jsPromptCallback(Q_NULLPTR) + , m_jsInterruptCallback(Q_NULLPTR) { } @@ -1603,7 +1603,7 @@ QObject* WebPage::getPage(const QString& windowName) const return childPages.at(i); } } - return NULL; + return Q_NULLPTR; } bool WebPage::ownsPages() const @@ -1720,7 +1720,7 @@ void WebPage::switchToMainFrame() bool WebPage::switchToParentFrame() { - if (m_currentFrame->parentFrame() != NULL) { + if (m_currentFrame->parentFrame()) { this->changeCurrentFrame(m_currentFrame->parentFrame()); return true; } @@ -1759,10 +1759,10 @@ static void injectCallbacksObjIntoFrame(QWebFrame* frame, WebpageCallbacks* call void WebPage::setupFrame(QWebFrame* frame) { - qDebug() << "WebPage - setupFrame" << (frame == NULL ? "" : frame->frameName()); + qDebug() << "WebPage - setupFrame" << (frame == Q_NULLPTR ? "" : frame->frameName()); // Inject the Callbacks object in the main frame - injectCallbacksObjIntoFrame(frame == NULL ? m_mainFrame : frame, m_callbacks); + injectCallbacksObjIntoFrame(frame == Q_NULLPTR ? m_mainFrame : frame, m_callbacks); } void WebPage::updateLoadingProgress(int progress) diff --git a/src/webpage.h b/src/webpage.h index 3559be83e..633c038d8 100644 --- a/src/webpage.h +++ b/src/webpage.h @@ -275,7 +275,7 @@ public slots: * @brief getPage * @param windowName * @return Returns the page that matches 'window.name', - * or NULL if none is found + * or Q_NULLPTR if none is found */ QObject* getPage(const QString& windowName) const; @@ -507,7 +507,7 @@ signals: private slots: void finish(bool ok); - void setupFrame(QWebFrame* frame = NULL); + void setupFrame(QWebFrame* frame = Q_NULLPTR); void updateLoadingProgress(int progress); void handleRepaintRequested(const QRect& dirtyRect); void handleUrlChanged(const QUrl& url); diff --git a/src/webserver.cpp b/src/webserver.cpp index d82681b46..5f80ee713 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -119,7 +119,7 @@ bool WebServer::listenOnPort(const QString& port, const QVariantMap& opts) options << "enable_keep_alive" << "yes"; } - options << NULL; + options << 0; // Start the server m_ctx = mg_start(&callback, this, options.data());