From: Enar Vaikene Date: Thu, 9 May 2019 11:53:08 +0000 (+0300) Subject: Mac OS changes and switched to c++11. X-Git-Url: https://vaikene.ee/gitweb/overview.html?a=commitdiff_plain;h=de270ece1b764b19968e14420f538321f1c06b15;p=evaf Mac OS changes and switched to c++11. --- diff --git a/CMakeLinux.txt b/CMakeLinux.txt index f45ee04..2513d1b 100644 --- a/CMakeLinux.txt +++ b/CMakeLinux.txt @@ -9,4 +9,6 @@ ELSE(CMAKE_BUILD_TYPE STREQUAL Release) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") ENDIF(CMAKE_BUILD_TYPE STREQUAL Release) -set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined") +if(NOT APPLE) + set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined") +endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fbcdd6..b801d0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ project(eVaf) -cmake_minimum_required(VERSION 2.8.9) +cmake_minimum_required(VERSION 3.1) +set (CMAKE_CXX_STANDARD 11) if(COMMAND cmake_policy) cmake_policy(SET CMP0003 NEW) diff --git a/src/apps/PswGen/GUI/gui.cpp b/src/apps/PswGen/GUI/gui.cpp index 6f94ce9..99cd6cb 100644 --- a/src/apps/PswGen/GUI/gui.cpp +++ b/src/apps/PswGen/GUI/gui.cpp @@ -44,8 +44,8 @@ int const Module::DefaultPasswordLength = 16; Module::Module() : Plugins::iPlugin() , mReady(false) - , mGenerator(0) - , mStorage(0) + , mGenerator(NULL) + , mStorage(NULL) { setObjectName(QString("%1.%2").arg(VER_MODULE_NAME_STR).arg(__FUNCTION__)); diff --git a/src/libs/Common/app.cpp b/src/libs/Common/app.cpp index 60ee5bf..f6668d9 100644 --- a/src/libs/Common/app.cpp +++ b/src/libs/Common/app.cpp @@ -3,7 +3,7 @@ * @brief Application interface implementation * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -31,10 +31,18 @@ using namespace eVaf::Common; +namespace +{ + static Internal::App * singleton = nullptr; +} + iApp * iApp::instance() { - static Internal::App singleton; - return &singleton; + if (nullptr == singleton) + { + singleton = new Internal::App; + } + return singleton; } char const * const iApp::EV_QUIT = "iApp::quit"; @@ -47,6 +55,15 @@ char const * const iApp::EV_TERMINATING = "iApp::terminating"; using namespace eVaf::Common::Internal; +void App::destroyInstance() +{ + if (nullptr != singleton) + { + delete singleton; + singleton = nullptr; + } +} + App::App() : iApp() , mReady(false) @@ -57,11 +74,12 @@ App::App() , mEvTerminating(0) { setObjectName(QString("%1.iApp").arg(VER_MODULE_NAME_STR)); - + EVAF_INFO("%s-App created", VER_MODULE_NAME_STR); } App::~App() { + EVAF_INFO("%s-App destroyed", VER_MODULE_NAME_STR); } bool App::init() @@ -206,7 +224,7 @@ bool App::event(QEvent * e) QString const App::dataRootDir() const { if (mDataRootDir.isEmpty()) { -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) QString dataLoc = QDir::homePath(); if (!dataLoc.endsWith('/')) dataLoc.append('/'); diff --git a/src/libs/Common/app.h b/src/libs/Common/app.h index 34f7a5d..58b3401 100644 --- a/src/libs/Common/app.h +++ b/src/libs/Common/app.h @@ -3,7 +3,7 @@ * @brief Application interface implementation * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -40,6 +40,11 @@ class App : public iApp public: + /** + * Destroys the iApp interface instance + */ + static void destroyInstance(); + App(); virtual ~App(); diff --git a/src/libs/Common/config.cpp b/src/libs/Common/config.cpp index 5303bb8..7ddc61e 100644 --- a/src/libs/Common/config.cpp +++ b/src/libs/Common/config.cpp @@ -3,7 +3,7 @@ * @brief eVaf configuration interface implementation * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -30,10 +30,18 @@ using namespace eVaf::Common; +namespace +{ + static Internal::Config * singleton = nullptr; +} + iConfig * iConfig::instance() { - static Internal::Config singleton; - return singleton._interface(); + if (nullptr == singleton) + { + singleton = new Internal::Config; + } + return singleton->_interface(); } @@ -41,6 +49,15 @@ iConfig * iConfig::instance() using namespace eVaf::Common::Internal; +void Config::destroyInstance() +{ + if (nullptr != singleton) + { + delete singleton; + singleton = nullptr; + } +} + Config::Config() : iConfig() { @@ -48,11 +65,14 @@ Config::Config() // Register the iConfig interface iRegistry::instance()->registerInterface("iConfig", this); + + EVAF_INFO("%s-Config created", VER_MODULE_NAME_STR); } Config::~Config() { done(); + EVAF_INFO("%s-Config destroyed", VER_MODULE_NAME_STR); } iConfig * Config::_interface() const @@ -101,7 +121,7 @@ QVariant Config::getValue(QString const & paramName, QVariant const & defaultVal if (file.isEmpty() || file == "*") file = iApp::instance()->name(); - IniFile * ini = 0; + IniFile * ini = nullptr; // Is this INI file already opened? QHash::const_iterator it = mIniFiles.constFind(file); @@ -176,7 +196,7 @@ bool Config::writeValue(QString const & paramName, QVariant const & value) if (file.isEmpty() || file == "*") file = iApp::instance()->name(); - IniFile * ini = 0; + IniFile * ini = nullptr; // Is this INI file already opened? QHash::const_iterator it = mIniFiles.constFind(file); diff --git a/src/libs/Common/config.h b/src/libs/Common/config.h index 49f2c8e..6abdda5 100644 --- a/src/libs/Common/config.h +++ b/src/libs/Common/config.h @@ -3,7 +3,7 @@ * @brief eVaf configuration interface implementation * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -58,6 +58,11 @@ class Config : public iConfig public: + /** + * Destroys the iConfig interface instance. + */ + static void destroyInstance(); + Config(); virtual ~Config(); diff --git a/src/libs/Common/event.h b/src/libs/Common/event.h index 960b53e..44396c1 100644 --- a/src/libs/Common/event.h +++ b/src/libs/Common/event.h @@ -3,7 +3,7 @@ * @brief Base class for all the events * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -58,7 +58,7 @@ public: * is decreased by 1 when the event object is destroyed. If nobody else claimed the ownership, then * the shared data object is destroyed too. */ - Event(uint eventId, quint32 intValue = 0, QSharedData * dataObj = 0) + Event(uint eventId, quint32 intValue = 0, QSharedData * dataObj = nullptr) : QEvent(eVafEvent) , mId(eventId) , mValue(intValue) @@ -82,7 +82,7 @@ public: * is finished, the event and shared data attached to it are destroyed. To keep the shared * data object, use QExplicitlySharedDataPointer<> to claim ownership. */ - inline QSharedData * data() const { return mData ? mData.data() : 0; } + inline QSharedData * data() const { return mData != nullptr ? mData.data() : nullptr; } private: diff --git a/src/libs/Common/eventqueue.cpp b/src/libs/Common/eventqueue.cpp index 647d892..91539a4 100644 --- a/src/libs/Common/eventqueue.cpp +++ b/src/libs/Common/eventqueue.cpp @@ -3,7 +3,7 @@ * @brief Event queue interface implementation * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -59,7 +59,7 @@ bool EventQueue::event(QEvent * e) Event * event = static_cast(e); - uint id = event->id(); + uint const id = event->id(); // Verify that this event is registered Events::const_iterator eventsIt = mEvents.constFind(id); diff --git a/src/libs/Common/eventqueue.h b/src/libs/Common/eventqueue.h index a4b834b..730801b 100644 --- a/src/libs/Common/eventqueue.h +++ b/src/libs/Common/eventqueue.h @@ -3,7 +3,7 @@ * @brief Event queue interface implementation * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -83,7 +83,7 @@ private slots: /// One of the subscribers is destroyed /// We need to remove it from the list of subscribers. - void subscriberDestroyed(QObject * obj = 0); + void subscriberDestroyed(QObject * obj = nullptr); }; diff --git a/src/libs/Common/globals.cpp b/src/libs/Common/globals.cpp index 5054bd1..6814648 100644 --- a/src/libs/Common/globals.cpp +++ b/src/libs/Common/globals.cpp @@ -3,7 +3,7 @@ * @brief Global constants and macros for eVaf * @author Enar Vaikene * - * Copyright (c) 2011-2012 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -24,6 +24,7 @@ #include "logger.h" #include "version.h" #include "ilogger.h" +#include "iregistry.h" #include @@ -32,7 +33,7 @@ bool eVaf::Common::init() { - if (QCoreApplication::instance() == 0) { + if (QCoreApplication::instance() == nullptr) { EVAF_FATAL_ERROR("QApplication is not instantiated"); return false; } @@ -70,3 +71,15 @@ bool eVaf::Common::init() return true; } + +void eVaf::Common::done() +{ + EVAF_INFO("Finalizing %s-Globals", VER_MODULE_NAME_STR); + + //eVaf::Common::Internal::Logger::destroyInstance(); + eVaf::Common::Internal::Prop::destroyInstance(); + eVaf::Common::Internal::Config::destroyInstance(); + eVaf::Common::Internal::App::destroyInstance(); + + EVAF_INFO("%s-Globals finalized", VER_MODULE_NAME_STR); +} diff --git a/src/libs/Common/globals.h b/src/libs/Common/globals.h index bac62ae..ca36050 100644 --- a/src/libs/Common/globals.h +++ b/src/libs/Common/globals.h @@ -3,7 +3,7 @@ * @brief Global constants and macros for eVaf * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -71,7 +71,7 @@ namespace eVaf { namespace Common { /** - * eVaf common library initialized + * eVaf common library initializer * @return True if ok; false if the initialization failed * * Call this function to initialize the common eVaf library after creating the Qt application @@ -79,6 +79,14 @@ namespace Common { */ extern bool COMMON_EXPORT init(); +/** + * eVaf common library finalizer + * + * Call this function to finalize the common eVaf library after destroying the Qt application + * object and unloading all the modules. + */ +extern void COMMON_EXPORT done(); + /** * Internal implementation of the common eVaf library. */ diff --git a/src/libs/Common/iapp.h b/src/libs/Common/iapp.h index 31390e3..5a61eda 100644 --- a/src/libs/Common/iapp.h +++ b/src/libs/Common/iapp.h @@ -3,7 +3,7 @@ * @brief eVaf application interface * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * diff --git a/src/libs/Common/iconfig.h b/src/libs/Common/iconfig.h index 454ec83..83fe3f1 100644 --- a/src/libs/Common/iconfig.h +++ b/src/libs/Common/iconfig.h @@ -3,7 +3,7 @@ * @brief eVaf configuration interface * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * diff --git a/src/libs/Common/ieventqueue.h b/src/libs/Common/ieventqueue.h index f3134cc..b239e1d 100644 --- a/src/libs/Common/ieventqueue.h +++ b/src/libs/Common/ieventqueue.h @@ -3,7 +3,7 @@ * @brief Event queue interface * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * diff --git a/src/libs/Common/ilogger.h b/src/libs/Common/ilogger.h index 4d865c9..d9660d4 100644 --- a/src/libs/Common/ilogger.h +++ b/src/libs/Common/ilogger.h @@ -3,7 +3,7 @@ * @brief Logger interface for eVaf * @author Enar Vaikene * - * Copyright (c) 2011-2012 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -102,7 +102,7 @@ public: * Returns the current severity level * @param source Name of the source or default if omitted. */ - virtual Severity severity(QString const & source = 0) = 0; + virtual Severity severity(QString const & source = QString()) = 0; /** * Changes the current severity level. @@ -113,13 +113,13 @@ public: * are output. With this function the severity level can be changed so that also less important * messages are output. */ - virtual void setSeverity(Severity severity, QString const & source = 0) = 0; + virtual void setSeverity(Severity severity, QString const & source = QString()) = 0; /** * Returns the current maximum size of log files in KiB. * @param source Name of the source or default if omitted. */ - virtual uint maxSize(QString const & source = 0) = 0; + virtual uint maxSize(QString const & source = QString()) = 0; /** * Changes the maximum size of log files for the given source @@ -133,13 +133,13 @@ public: * * Set the maximum size to 0 for no limits (dangerous!). */ - virtual void setMaxSize(uint maxSize, QString const & source = 0) = 0; + virtual void setMaxSize(uint maxSize, QString const & source = QString()) = 0; /** * Returns the maximum number of log files. * @param source Name of the source or default if omitted. */ - virtual uint maxCount(QString const & source = 0) = 0; + virtual uint maxCount(QString const & source = QString()) = 0; /** * Changes the maximum number of log files @@ -155,7 +155,7 @@ public: * * Set the maximum number of log files to 0 for no limits (dangerous!). */ - virtual void setMaxCount(uint maxCount, QString const & source = 0) = 0; + virtual void setMaxCount(uint maxCount, QString const & source = QString()) = 0; /** * Returns the current console severity level. @@ -190,7 +190,7 @@ public: * Messages for the default source are also output to the console if the console severity * level is high enough. */ - virtual void write(Severity severity, QString const & msg, QString const & source = 0, QString const & where = 0) = 0; + virtual void write(Severity severity, QString const & msg, QString const & source = QString(), QString const & where = QString()) = 0; /** * Helper function for formatting messages using the standard printf() function. @@ -199,7 +199,7 @@ public: * @return The formatted string */ virtual QString printf(char const * const fmt, ...) const -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) __attribute__((format(printf, 2, 3))) #endif = 0; @@ -261,7 +261,7 @@ signals: eVaf::Common::iLogger::instance()->write( \ eVaf::Common::iLogger::Fatal, \ eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \ - 0, \ + QString(), \ eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \ ); \ } while (0) @@ -277,7 +277,7 @@ signals: eVaf::Common::iLogger::instance()->write( \ eVaf::Common::iLogger::Error, \ eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \ - 0, \ + QString(), \ eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \ ); \ } while (0) @@ -293,7 +293,7 @@ signals: eVaf::Common::iLogger::instance()->write( \ eVaf::Common::iLogger::Warning, \ eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \ - 0, \ + QString(), \ eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \ ); \ } while (0) @@ -309,7 +309,7 @@ signals: eVaf::Common::iLogger::instance()->write( \ eVaf::Common::iLogger::Info, \ eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \ - 0, \ + QString(), \ eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \ ); \ } while (0) @@ -326,7 +326,7 @@ signals: eVaf::Common::iLogger::instance()->write( \ eVaf::Common::iLogger::Debug, \ eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \ - 0, \ + QString(), \ eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \ ); \ } while (0) diff --git a/src/libs/Common/inifile.cpp b/src/libs/Common/inifile.cpp index 838ff72..55b9fd7 100644 --- a/src/libs/Common/inifile.cpp +++ b/src/libs/Common/inifile.cpp @@ -37,13 +37,13 @@ using namespace eVaf::Common; //------------------------------------------------------------------- IniFile::IniFile(QString const & fileName, QIODevice::OpenMode mode) + : d(new Internal::IniFileImpl(fileName, mode)) { - d = new Internal::IniFileImpl(fileName, mode); } IniFile::~IniFile() { - delete d; + d.reset(); } bool IniFile::isValid() const @@ -207,7 +207,7 @@ QExplicitlySharedDataPointer IniFileImpl::getParameter(QFile & fil // Check for the 'windows:' or 'linux:' prefix in the parameter name bool thisOsOnly = false; -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) if (name.startsWith("windows:")) continue; if (name.startsWith("linux:")) { diff --git a/src/libs/Common/inifile.h b/src/libs/Common/inifile.h index ecf8737..6bcf86b 100644 --- a/src/libs/Common/inifile.h +++ b/src/libs/Common/inifile.h @@ -3,7 +3,7 @@ * @brief Class for reading and writing parameter values in INI files. * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -25,6 +25,7 @@ #include #include #include +#include namespace eVaf { namespace Common { @@ -150,7 +151,7 @@ public: private: /// Pointer to the internal implementation of the class - Internal::IniFileImpl * d; + QScopedPointer d; }; diff --git a/src/libs/Common/inifile_p.h b/src/libs/Common/inifile_p.h index ffb7a1e..07ac793 100644 --- a/src/libs/Common/inifile_p.h +++ b/src/libs/Common/inifile_p.h @@ -3,7 +3,7 @@ * @brief Internal implementation of the class for reading and writing parameter values in INI files. * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * diff --git a/src/libs/Common/logger.cpp b/src/libs/Common/logger.cpp index 358b314..870af5f 100644 --- a/src/libs/Common/logger.cpp +++ b/src/libs/Common/logger.cpp @@ -40,7 +40,7 @@ //------------------------------------------------------------------- -void eVaf::Common::Internal::defFatalMsgHandler(QString const & msg, QString const & source, QString const & where) +[[noreturn]] void eVaf::Common::Internal::defFatalMsgHandler(QString const & msg, QString const & source, QString const & where) { Q_UNUSED(source); @@ -58,10 +58,18 @@ void eVaf::Common::Internal::defFatalMsgHandler(QString const & msg, QString con using namespace eVaf::Common; +namespace +{ + static Internal::Logger * singleton = nullptr; +} + iLogger * iLogger::instance() { - static Internal::Logger singleton; - return &singleton; + if (nullptr == singleton) + { + singleton = new Internal::Logger; + } + return singleton; } @@ -101,28 +109,31 @@ void LoggerSource::init(QString const & source) IniFile ini(confFileName, QIODevice::ReadOnly); // Default values for all sources - maxSize = 1024 * ini.getValue(".default/log_size", maxSize / 1024).toInt(); - maxCount = ini.getValue(".default/log_count", maxCount).toInt(); + maxSize = 1024 * ini.getValue(".default/log_size", maxSize / 1024).toUInt(); + maxCount = ini.getValue(".default/log_count", maxCount).toUInt(); // Default values for this source - maxSize = 1024 * ini.getValue(source.toLatin1() + "/log_size", maxSize / 1024).toInt(); - maxCount = ini.getValue(source.toLatin1() + "/log_count", maxCount).toInt(); + maxSize = 1024 * ini.getValue(source.toLatin1() + "/log_size", maxSize / 1024).toUInt(); + maxCount = ini.getValue(source.toLatin1() + "/log_count", maxCount).toUInt(); } } //------------------------------------------------------------------- -/// Recursively renames backup files -void renameBackupFile(QDir & dir, QString const & baseName, int idx) +namespace { - QString f1 = QString("%1.%2").arg(baseName).arg(idx); - QString f2 = QString("%1.%2").arg(baseName).arg(idx + 1); + /// Recursively renames backup files + void renameBackupFile(QDir & dir, QString const & baseName, int idx) + { + QString f1 = QString("%1.%2").arg(baseName).arg(idx); + QString f2 = QString("%1.%2").arg(baseName).arg(idx + 1); - if (dir.exists(f2)) - renameBackupFile(dir, baseName, idx + 1); + if (dir.exists(f2)) + renameBackupFile(dir, baseName, idx + 1); - dir.rename(f1, f2); + dir.rename(f1, f2); + } } void LoggerWorker::writeToLogFile(LoggerSource const & src, QString const & msg) @@ -168,13 +179,20 @@ void LoggerWorker::writeToLogFile(LoggerSource const & src, QString const & msg) //------------------------------------------------------------------- +void Logger::destroyInstance() +{ + if (singleton != nullptr) + { + delete singleton; + singleton = nullptr; + } +} + Logger::Logger() : iLogger() , mReady(false) , mFatalMsgHandler(defFatalMsgHandler) , mConsoleSeverity(iLogger::Fatal) - , mThread(0) - , mWorker(0) { setObjectName(QString("%1-iLogger").arg(VER_MODULE_NAME_STR)); @@ -184,25 +202,25 @@ Logger::Logger() mDefaultSource = new LoggerSource; mDefaultSource->name = "common"; - write(Info, QString("%1 created").arg(objectName()), 0, printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__)); + write(Info, QString("%1 created").arg(objectName()), QString(), printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__)); } Logger::~Logger() { // Disconnect any potential receivers from this object - disconnect(this, SIGNAL(loggerEvent(Common::iLogger::Severity,QString,QString,QString)), 0, 0); + disconnect(this, SIGNAL(loggerEvent(Common::iLogger::Severity,QString,QString,QString)), nullptr, nullptr); // Destroy the worker thread if (mWorker) { - delete mWorker; + mWorker.reset(); if (mThread) { mThread->quit(); mThread->wait(); - delete mThread; + mThread.reset(); } } - write(Info, QString("%1 destroyed").arg(objectName()), 0, printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__)); + write(Info, QString("%1 destroyed").arg(objectName()), QString(), printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__)); } bool Logger::init() @@ -228,25 +246,21 @@ bool Logger::init() setMaxCount(v.toUInt()); // Destroy the previous worker thread - if (mWorker) { - delete mWorker; - if (mThread) { - mThread->quit(); - mThread->wait(); - delete mThread; - } + if (mThread) { + mThread->quit(); + mThread->wait(); } // Create the worker thread - mWorker = new LoggerWorker; - mThread = new QThread; - mWorker->moveToThread(mThread); + mWorker.reset(new LoggerWorker); + mThread.reset(new QThread); + mWorker->moveToThread(mThread.data()); mThread->start(QThread::IdlePriority); - connect(this, SIGNAL(writeToLogFile(LoggerSource,QString)), mWorker, SLOT(writeToLogFile(LoggerSource,QString)), Qt::QueuedConnection); + connect(this, SIGNAL(writeToLogFile(LoggerSource,QString)), mWorker.data(), SLOT(writeToLogFile(LoggerSource,QString)), Qt::QueuedConnection); mReady = true; - write(Info, QString("%1 initialized").arg(objectName()), 0, printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__)); + write(Info, QString("%1 initialized").arg(objectName()), QString(), printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__)); return true; } @@ -346,25 +360,25 @@ void Logger::write(Severity severity, QString const & msg, QString const & sourc FILE * f = (severity < iLogger::Info) ? stderr : stdout; // Set text colors -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) switch (severity) { case iLogger::Info: - fprintf(f, "\e[32m"); // Green + fprintf(f, "\033[32m"); // Green break; case iLogger::Warning: - fprintf(f, "\e[1m"); // Bold + fprintf(f, "\033[1m"); // Bold break; case iLogger::Error: - fprintf(f, "\e[31m"); // Red + fprintf(f, "\033[31m"); // Red break; case iLogger::Fatal: - fprintf(f, "\e[31m\e[1m"); // Bold Red + fprintf(f, "\033[31m\033[1m"); // Bold Red break; default: - fprintf(f, "\e[34m"); // Blue + fprintf(f, "\033[34m"); // Blue break; } -#elif defined Q_OS_WIN32 +#elif defined(Q_OS_WIN32) switch (severity) { case iLogger::Info: setColor(FOREGROUND_GREEN); @@ -392,9 +406,9 @@ void Logger::write(Severity severity, QString const & msg, QString const & sourc fprintf(f, "\t(occurred in %s)\n\n", qPrintable(where)); // Reset text colors -#ifdef Q_OS_LINUX - fputs("\e[0m", f); -#elif defined Q_OS_WIN32 +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) + fputs("\033[0m", f); +#elif defined(Q_OS_WIN32) setColor(7); #endif @@ -415,7 +429,7 @@ QString Logger::printf(char const * const fmt, ...) const #ifdef Q_OS_WIN32 char str[4096]; #else - char * str = 0; + char * str = nullptr; #endif va_list ap; diff --git a/src/libs/Common/logger.h b/src/libs/Common/logger.h index 6e49ef7..742ab90 100644 --- a/src/libs/Common/logger.h +++ b/src/libs/Common/logger.h @@ -3,7 +3,7 @@ * @brief iLogger interface implementation * @author Enar Vaikene * - * Copyright (c) 2011-2012 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -27,6 +27,7 @@ #include #include #include +#include class QThread; @@ -36,7 +37,7 @@ namespace Common { namespace Internal { /// Default fatal error message handler -void defFatalMsgHandler(QString const & msg, QString const & source, QString const & where); +[[noreturn]] void defFatalMsgHandler(QString const & msg, QString const & source, QString const & where); /** * Logger source. @@ -138,6 +139,11 @@ class Logger : public iLogger public: + /** + * Destroys the iLogger interface instance + */ + static void destroyInstance(); + Logger(); virtual ~Logger(); @@ -156,23 +162,23 @@ public: virtual void setDefaultSource(QString const & source); - virtual iLogger::Severity severity(QString const & source = 0); + virtual iLogger::Severity severity(QString const & source = QString()); - virtual void setSeverity(iLogger::Severity severity, QString const & source = 0); + virtual void setSeverity(iLogger::Severity severity, QString const & source = QString()); - virtual uint maxSize(QString const & source = 0); + virtual uint maxSize(QString const & source = QString()); - virtual void setMaxSize(uint maxSize, QString const & source = 0); + virtual void setMaxSize(uint maxSize, QString const & source = QString()); - virtual uint maxCount(QString const & source = 0); + virtual uint maxCount(QString const & source = QString()); - virtual void setMaxCount(uint maxCount, QString const & source = 0); + virtual void setMaxCount(uint maxCount, QString const & source = QString()); virtual iLogger::Severity consoleSeverity() const { return mConsoleSeverity; } virtual void setConsoleSeverity(iLogger::Severity severity); - virtual void write(Severity severity, QString const & msg, QString const & source = 0, QString const & where = 0); + virtual void write(Severity severity, QString const & msg, QString const & source = QString(), QString const & where = QString()); virtual QString printf(char const * const fmt, ...) const; @@ -204,10 +210,10 @@ private: // Members QHash > mSources; /// Worker thread - QThread * mThread; + QScopedPointer mThread; /// Worker object - LoggerWorker * mWorker; + QScopedPointer mWorker; private: // Methods diff --git a/src/libs/Common/prop.cpp b/src/libs/Common/prop.cpp index f6cfec6..b76c3c5 100644 --- a/src/libs/Common/prop.cpp +++ b/src/libs/Common/prop.cpp @@ -3,7 +3,7 @@ * @brief Implementation of the iProp interface * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -31,10 +31,18 @@ using namespace eVaf::Common; +namespace +{ + static Internal::Prop * singleton = nullptr; +} + iProp * iProp::instance() { - static Internal::Prop singleton; - return singleton._interface(); + if (nullptr == singleton) + { + singleton = new Internal::Prop; + } + return singleton->_interface(); } @@ -42,19 +50,30 @@ iProp * iProp::instance() using namespace eVaf::Common::Internal; +void Prop::destroyInstance() +{ + if (nullptr != singleton) + { + delete singleton; + singleton = nullptr; + } +} + Prop::Prop() : iProp() - , mPersistentProps(0) { setObjectName(QString("%1.iProp").arg(VER_MODULE_NAME_STR)); // Register the iProp interface iRegistry::instance()->registerInterface("iProp", this); + + EVAF_INFO("%s-Prop created", VER_MODULE_NAME_STR); } Prop::~Prop() { done(); + EVAF_INFO("%s-Prop destroyed", VER_MODULE_NAME_STR); } iProp * Prop::_interface() const @@ -80,7 +99,7 @@ bool Prop::init() isProp = true; } else if (isProp && xml.name() == "property") { -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) if (isTrue(xml.attributes().value("windowsonly").toString())) continue; #endif @@ -116,9 +135,10 @@ bool Prop::init() } // Initialize persistent properties - if (mPersistentProps) - delete mPersistentProps; - mPersistentProps = new QSettings(QString("%1/.%2.dat").arg(iApp::instance()->dataRootDir()).arg(iApp::instance()->name()), QSettings::IniFormat); + mPersistentProps.reset(new QSettings(QString("%1/.%2.dat") + .arg(iApp::instance()->dataRootDir()) + .arg(iApp::instance()->name()), + QSettings::IniFormat)); QStringList keys = mPersistentProps->allKeys(); for (int i = 0; i < keys.size(); ++i) { QString key = keys.at(i); @@ -130,10 +150,7 @@ bool Prop::init() void Prop::done() { - if (mPersistentProps) { - delete mPersistentProps; - mPersistentProps = 0; - } + mPersistentProps.reset(); } QVariant Prop::getValue(QString const & name, QVariant const & defaultValue) const diff --git a/src/libs/Common/prop.h b/src/libs/Common/prop.h index 1574f25..605a1d8 100644 --- a/src/libs/Common/prop.h +++ b/src/libs/Common/prop.h @@ -3,7 +3,7 @@ * @brief Implementation of the iProp interface * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -23,6 +23,7 @@ #include "iprop.h" #include +#include class QSettings; @@ -44,6 +45,11 @@ class Prop : public iProp public: + /** + * Destroys the iProp interface instance + */ + static void destroyInstance(); + Prop(); virtual ~Prop(); @@ -79,7 +85,7 @@ private: // Members QHash mProps; /// Persistent property values - QSettings * mPersistentProps; + QScopedPointer mPersistentProps; }; diff --git a/src/libs/Gui/panel.h b/src/libs/Gui/panel.h index 8c70ba6..3ac0b57 100644 --- a/src/libs/Gui/panel.h +++ b/src/libs/Gui/panel.h @@ -52,7 +52,7 @@ class GUI_EXPORT Panel : public QWidget public: - Panel(QWidget * parent = 0, Qt::WindowFlags f = 0); + Panel(QWidget * parent = nullptr, Qt::WindowFlags f = 0); virtual ~Panel(); diff --git a/src/libs/Plugins/pluginmanager.cpp b/src/libs/Plugins/pluginmanager.cpp index 5d08dcb..5fea828 100644 --- a/src/libs/Plugins/pluginmanager.cpp +++ b/src/libs/Plugins/pluginmanager.cpp @@ -35,7 +35,7 @@ namespace Plugins { namespace Internal { // Plugin manager interface implementation - static eVaf::Plugins::PluginManager * mPluginManager = 0; + static eVaf::Plugins::PluginManager * mPluginManager = nullptr; } // namespace eVaf::Plugins::Internal } // namespace eVaf::Plugins @@ -49,21 +49,20 @@ using namespace eVaf::Plugins; PluginManager::PluginManager() : QObject() + , d(new Internal::PluginManagerPrivate) { setObjectName(QString("%1-PluginManager").arg(VER_MODULE_NAME_STR)); Internal::mPluginManager = this; - d = new Internal::PluginManagerPrivate; - EVAF_INFO("%s created", qPrintable(objectName())); } PluginManager::~PluginManager() { - delete d; + d.reset(); - Internal::mPluginManager = 0; + Internal::mPluginManager = nullptr; EVAF_INFO("%s destroyed", qPrintable(objectName())); } @@ -188,7 +187,7 @@ bool PluginManagerPrivate::loadPlugins() if (!isPlugins && !isQtPlugins) { if (xml.name() == "plugins") { // Check for windows and linux only sections -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) if (Common::isTrue(xml.attributes().value("windowsonly").toString())) continue; #endif @@ -201,7 +200,7 @@ bool PluginManagerPrivate::loadPlugins() else if (xml.name() == "qtplugins") { // Check for windows and linux only sections -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) if (Common::isTrue(xml.attributes().value("windowsonly").toString())) continue; #endif @@ -217,7 +216,7 @@ bool PluginManagerPrivate::loadPlugins() // An individual plugin? else if (isPlugins && xml.name() == "plugin") { // Check for windows and linux only plugins -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) if (Common::isTrue(xml.attributes().value("windowsonly").toString())) { EVAF_INFO("Plugin '%s' is for Windows only", qPrintable(xml.attributes().value("name").toString())); continue; @@ -252,7 +251,7 @@ bool PluginManagerPrivate::loadPlugins() // An individual Qt plugin? else if (isQtPlugins && xml.name() == "plugin") { // Check for windows and linux only plugins -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) if (Common::isTrue(xml.attributes().value("windowsonly").toString())) { EVAF_INFO("Qt plugin '%s' is for Windows only", qPrintable(xml.attributes().value("name").toString())); continue; @@ -339,7 +338,7 @@ Module * PluginManagerPrivate::moduleByName(QString const & name) const if (mModules.at(i)->name() == name) return mModules.at(i).data(); } - return 0; + return nullptr; } @@ -348,17 +347,16 @@ Module * PluginManagerPrivate::moduleByName(QString const & name) const Module::Module(QString const & name) : QSharedData() , mName(name) - , mLoader(0) - , mRoot(0) - , mPlugin(0) - , mPluginFactory(0) + , mRoot(nullptr) + , mPlugin(nullptr) + , mPluginFactory(nullptr) {} Module::~Module() { if (mLoader) { mLoader->unload(); - delete mLoader; + mLoader.reset(); } } @@ -378,29 +376,28 @@ bool Module::load() QObject * root = p->instance(); // Does the module implement the iPluginFactory interface? - if ((mPluginFactory = qobject_cast(root)) == 0) { + if ((mPluginFactory = qobject_cast(root)) == nullptr) { // If not, then it has to implement the iPlugin interface - if (qobject_cast(root) == 0) { + if (qobject_cast(root) == nullptr) { EVAF_FATAL_ERROR("Module '%s' is not a valid eVaf module", qPrintable(mName)); return false; } } mRoot = root; - mLoader = p.take(); + mLoader.reset(p.take()); return true; } void Module::unload() { - mRoot = 0; - mPluginFactory = 0; - mPlugin = 0; + mRoot = nullptr; + mPluginFactory = nullptr; + mPlugin = nullptr; if (mLoader) { mLoader->unload(); - delete mLoader; - mLoader = 0; + mLoader.reset(); } } @@ -409,18 +406,18 @@ iPlugin * Module::create(QString const & name) // If the module is not loaded, load it now if (!mLoader) { if (!load()) - return 0; + return nullptr; } - iPlugin * i = 0; + iPlugin * i = nullptr; // Does the module implement the iPluginFactory interface? if (mPluginFactory) { // Use the iPluginFactory interface to create the requested interface i = qobject_cast(mPluginFactory->create(name)); - if (i == 0) { + if (i == nullptr) { EVAF_FATAL_ERROR("Module '%s' failed to create the iPlugin interface with name '%s'", qPrintable(mName), qPrintable(name)); - return 0; + return nullptr; } } @@ -429,13 +426,13 @@ iPlugin * Module::create(QString const & name) if (mPlugin) { EVAF_FATAL_ERROR("Module '%s' can implement only one iPlugin interface and one with the name '%s' is already created", qPrintable(mName), qPrintable(mPlugin->objectName())); - return 0; + return nullptr; } i = qobject_cast(mRoot); - if (i == 0) { + if (i == nullptr) { EVAF_FATAL_ERROR("Module '%s' does not implement the iPlugin interface", qPrintable(mName)); - return 0; + return nullptr; } mPlugin = i; @@ -452,7 +449,7 @@ Plugin::Plugin(Module * module, QString const & name, QString const & args) , mModule(module) , mName(name) , mArgs(args) - , mPlugin(0) + , mPlugin(nullptr) {} Plugin::~Plugin() @@ -464,12 +461,12 @@ bool Plugin::load() mPlugin = mModule->create(mName); if (mPlugin && !mPlugin->objectName().isEmpty()) mName = mPlugin->objectName(); - return mPlugin != 0; + return mPlugin != nullptr; } void Plugin::unload() { - mPlugin = 0; + mPlugin = nullptr; } bool Plugin::init() diff --git a/src/libs/Plugins/pluginmanager.h b/src/libs/Plugins/pluginmanager.h index e560922..91a5b00 100644 --- a/src/libs/Plugins/pluginmanager.h +++ b/src/libs/Plugins/pluginmanager.h @@ -2,7 +2,7 @@ * @file Plugins/pluginmanager.h * @brief Manager for loadable modules (plugins) * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -25,6 +25,7 @@ #include #include +#include namespace eVaf { @@ -67,6 +68,8 @@ inline QString expandPluginName(QString const & name) return "lib" + name + ".so"; #elif defined Q_OS_CYGWIN return "cyg" + name + ".dll"; +#elif defined Q_OS_MACOS + return "lib" + name + ".dylib"; #else return name; #endif @@ -129,7 +132,7 @@ signals: private: - Internal::PluginManagerPrivate * d; + QScopedPointer d; }; diff --git a/src/libs/Plugins/pluginmanager_p.h b/src/libs/Plugins/pluginmanager_p.h index 9033d15..31cc18c 100644 --- a/src/libs/Plugins/pluginmanager_p.h +++ b/src/libs/Plugins/pluginmanager_p.h @@ -2,7 +2,7 @@ * @file Plugins/pluginmanager_p.h * @brief Private implementation of the plugin manager * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -22,6 +22,7 @@ #include #include #include +#include #include namespace eVaf { @@ -140,7 +141,7 @@ private: // Members QString mName; /// Plugin loader - QPluginLoader * mLoader; + QScopedPointer mLoader; /// Plugin's root component QObject * mRoot; diff --git a/src/main/CLI/exithandler.cpp b/src/main/CLI/exithandler.cpp index a96842d..dac8008 100644 --- a/src/main/CLI/exithandler.cpp +++ b/src/main/CLI/exithandler.cpp @@ -24,7 +24,7 @@ #include -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) # include #endif @@ -36,7 +36,7 @@ namespace eVaf { namespace CLI { namespace Internal { -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) /** * Signal handler on Linux @@ -111,7 +111,7 @@ static BOOL WINAPI signalHandler(DWORD sig) bool eVaf::CLI::Internal::installExitHandler() { -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = signalHandler; diff --git a/src/main/CLI/main.cpp b/src/main/CLI/main.cpp index 691db7a..c795bba 100644 --- a/src/main/CLI/main.cpp +++ b/src/main/CLI/main.cpp @@ -92,13 +92,12 @@ static void messageOutput(QtMsgType type, QMessageLogContext const &, QString co * If the critical error message is shown, then the user has an option to ignore the error. In this * case the application is not terminated. */ -static void fatalMsgHandler(QString const & msg, QString const & source, QString const & where) +[[noreturn]] static void fatalMsgHandler(QString const & msg, QString const & source, QString const & where) { -#ifdef Q_OS_LINUX - abort(); -#else + Q_UNUSED(msg); + Q_UNUSED(source); + Q_UNUSED(where); exit(1); -#endif } } // namespace eVaf::CLI::Internal diff --git a/src/main/GUI/exithandler.cpp b/src/main/GUI/exithandler.cpp index f0ad4bd..80c364c 100644 --- a/src/main/GUI/exithandler.cpp +++ b/src/main/GUI/exithandler.cpp @@ -24,7 +24,7 @@ #include -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) # include #endif @@ -36,7 +36,7 @@ namespace eVaf { namespace GUI { namespace Internal { -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) /** * Signal handler on Linux @@ -111,7 +111,7 @@ static BOOL WINAPI signalHandler(DWORD sig) bool eVaf::GUI::Internal::installExitHandler() { -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = signalHandler; diff --git a/src/main/GUI/main.cpp b/src/main/GUI/main.cpp index 313d210..cffe9ba 100644 --- a/src/main/GUI/main.cpp +++ b/src/main/GUI/main.cpp @@ -127,20 +127,18 @@ static void messageOutput(QtMsgType type, QMessageLogContext const &, QString co */ static void fatalMsgHandler(QString const & msg, QString const & source, QString const & where) { + Q_UNUSED(source); + // Show the message on the screen if (BeVerbose) { if (FatalErr::message(QObject::tr("Fatal Error"), QObject::tr("%1\n\nOccurred in '%2'") .arg(msg) .arg(where), - 0) == FatalErr::Ignore) + nullptr) == FatalErr::Ignore) return; } -#ifdef Q_OS_LINUX - abort(); -#else exit(1); -#endif } } // namespace eVaf::GUI::Internal @@ -389,34 +387,39 @@ int main(int argc, char ** argv) if (!Internal::installExitHandler()) return 1; - // Plugin manager - Plugins::PluginManager pluginManager; + int rval = 0; + { + // Plugin manager + Plugins::PluginManager pluginManager; - // The main run loop - bool quit = false; - int rval; - while (!quit) { + // The main run loop + bool quit = false; + while (!quit) { - EVAF_INFO("%s is starting up", VER_MODULE_NAME_STR); + EVAF_INFO("%s is starting up", VER_MODULE_NAME_STR); - // Initialize the common library - if (!Common::init()) - return 1; + // Initialize the common library + if (!Common::init()) + return 1; - // Initialize the plugin manager and load plugins - if (!pluginManager.init()) - return 1; + // Initialize the plugin manager and load plugins + if (!pluginManager.init()) + return 1; - // Run the application - EVAF_INFO("Running %s", VER_MODULE_NAME_STR); - rval = Common::iApp::instance()->exec(); + // Run the application + EVAF_INFO("Running %s", VER_MODULE_NAME_STR); + rval = Common::iApp::instance()->exec(); - quit = rval != Common::iApp::RC_Restart; + quit = rval != Common::iApp::RC_Restart; - EVAF_INFO("%s is %s", VER_MODULE_NAME_STR, quit ? "exiting" : "restarting"); + EVAF_INFO("%s is %s", VER_MODULE_NAME_STR, quit ? "exiting" : "restarting"); - // Unload plugins and finalize the plugin manager - pluginManager.done(); + // Unload plugins and finalize the plugin manager + pluginManager.done(); + + // Finalize the common library + Common::done(); + } } EVAF_INFO("%s exit with code %d", VER_MODULE_NAME_STR, rval); diff --git a/src/plugins/SdiWindow/factory.cpp b/src/plugins/SdiWindow/factory.cpp index a8a9a8b..24aa0e5 100644 --- a/src/plugins/SdiWindow/factory.cpp +++ b/src/plugins/SdiWindow/factory.cpp @@ -3,7 +3,7 @@ * @brief SDI module's factory class * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -33,7 +33,6 @@ VER_EXPORT_VERSION_INFO() Factory::Factory() : Plugins::iPluginFactory() - , mPlugin(0) { setObjectName(QString("%1-Factory").arg(VER_MODULE_NAME_STR)); @@ -42,8 +41,7 @@ Factory::Factory() Factory::~Factory() { - if (mPlugin) - delete mPlugin; + mPlugin.reset(); EVAF_INFO("%s destroyed", qPrintable(objectName())); } @@ -52,7 +50,7 @@ QObject * Factory::create(QString const & name) { Q_UNUSED(name); - if (mPlugin == 0) - mPlugin = new Internal::SdiWindowPlugin; - return mPlugin; + if (!mPlugin) + mPlugin.reset(new Internal::SdiWindowPlugin); + return mPlugin.data(); } diff --git a/src/plugins/SdiWindow/factory.h b/src/plugins/SdiWindow/factory.h index 78b2f72..ff97172 100644 --- a/src/plugins/SdiWindow/factory.h +++ b/src/plugins/SdiWindow/factory.h @@ -3,7 +3,7 @@ * @brief SDI module's factory class * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -22,6 +22,7 @@ #include "version.h" #include +#include namespace eVaf { @@ -60,7 +61,7 @@ public: private: // Members - Internal::SdiWindowPlugin * mPlugin; + QScopedPointer mPlugin; }; diff --git a/src/plugins/SdiWindow/sdiwindow.cpp b/src/plugins/SdiWindow/sdiwindow.cpp index c6e1de2..25a86ac 100644 --- a/src/plugins/SdiWindow/sdiwindow.cpp +++ b/src/plugins/SdiWindow/sdiwindow.cpp @@ -3,7 +3,7 @@ * @brief SdiWindow module's implementation * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -32,7 +32,7 @@ namespace eVaf { namespace SdiWindow { namespace Internal { /// iSdiWindow interface instance singleton - static iSdiWindow * mSdiWindow = 0; + static iSdiWindow * mSdiWindow = nullptr; } // namespace eVaf::SdiWindow::Internal } // namespace eVaf::SdiWindow } // namespace eVaf @@ -53,7 +53,7 @@ SdiWindow::iSdiWindow * SdiWindow::iSdiWindow::instance() SdiWindow::Internal::MainWindow::MainWindow(QWidget * parent, Qt::WindowFlags flags) : QWidget(parent, flags) , mReady(false) - , mMainPanel(0) + , mMainPanel(nullptr) { setObjectName(QString("%1-%2").arg(VER_MODULE_NAME_STR).arg(__FUNCTION__)); @@ -74,7 +74,7 @@ SdiWindow::Internal::MainWindow::MainWindow(QWidget * parent, Qt::WindowFlags fl SdiWindow::Internal::MainWindow::~MainWindow() { - mSdiWindow = 0; + mSdiWindow = nullptr; // Save geometry saveSettings(); @@ -126,7 +126,7 @@ void SdiWindow::Internal::MainWindow::done() mPanels.clear(); mMinimizedPanels.clear(); mPanelNames.clear(); - mMainPanel = 0; + mMainPanel = nullptr; mMainPanelName.clear(); EVAF_INFO("%s finalized", qPrintable(objectName())); @@ -160,7 +160,7 @@ Gui::Panel * SdiWindow::Internal::MainWindow::panel(QString const & name) const QHash::const_iterator it = mPanelNames.constFind(name); if (it != mPanelNames.constEnd()) return it.value(); - return 0; + return nullptr; } bool SdiWindow::Internal::MainWindow::showPanel(QString const & name) @@ -322,7 +322,7 @@ void SdiWindow::Internal::MainWindow::panelDestroyed(QObject * obj) // If it was the main panel, set the main panel to NULL if (mMainPanel == obj) { - mMainPanel = 0; + mMainPanel = nullptr; } } @@ -331,17 +331,16 @@ void SdiWindow::Internal::MainWindow::panelDestroyed(QObject * obj) SdiWindow::Internal::SdiWindowPlugin::SdiWindowPlugin() : Plugins::iPlugin() + , mWindow(new MainWindow) { setObjectName(VER_MODULE_NAME_STR); - mWindow = new MainWindow; - EVAF_INFO("%s created", qPrintable(objectName())); } SdiWindow::Internal::SdiWindowPlugin::~SdiWindowPlugin() { - delete mWindow; + mWindow.reset(); EVAF_INFO("%s destroyed", qPrintable(objectName())); } diff --git a/src/plugins/SdiWindow/sdiwindow.h b/src/plugins/SdiWindow/sdiwindow.h index 4c46eea..40c7211 100644 --- a/src/plugins/SdiWindow/sdiwindow.h +++ b/src/plugins/SdiWindow/sdiwindow.h @@ -3,7 +3,7 @@ * @brief SdiWindow module's implementation * @author Enar Vaikene * - * Copyright (c) 2011 Enar Vaikene + * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -31,6 +31,7 @@ #include #include #include +#include class QVBoxLayout; @@ -48,7 +49,7 @@ class MainWindow : public QWidget, public iSdiWindow public: - MainWindow(QWidget * parent = 0, Qt::WindowFlags flags = 0); + MainWindow(QWidget * parent = nullptr, Qt::WindowFlags flags = 0); virtual ~MainWindow(); @@ -115,7 +116,7 @@ private slots: /// Panel destroyed signal. We need to remove the panel from all the /// lists. - void panelDestroyed(QObject * obj = 0); + void panelDestroyed(QObject * obj = nullptr); }; @@ -137,13 +138,13 @@ public: virtual void done(); - virtual bool isReady() const { return mWindow != 0 && mWindow->isReady(); } + virtual bool isReady() const { return mWindow != nullptr && mWindow->isReady(); } private: /// iSdiWindow interface implementation - MainWindow * mWindow; + QScopedPointer mWindow; }; } // namespace eVaf::SdiWindow::Internal