From ffc47cb633031e980cf47fb1c131ab04ef243774 Mon Sep 17 00:00:00 2001 From: Bernd Lamecker Date: Tue, 2 Nov 2010 12:02:27 +0100 Subject: Changes: Made MComponentData a "real" Singleton RevBy: Stanislav Ionascu, Michael Hasselmann, Tomas Junnonen Merge-Request: 824 --- src/corelib/core/mapplication.cpp | 2 +- src/corelib/core/mcomponentdata.cpp | 29 +++++++++++++++++++++++++---- src/corelib/core/mcomponentdata.h | 16 +++++++++++++++- 3 files changed, 41 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/corelib/core/mapplication.cpp b/src/corelib/core/mapplication.cpp index 6785d24b..f387deab 100644 --- a/src/corelib/core/mapplication.cpp +++ b/src/corelib/core/mapplication.cpp @@ -225,7 +225,7 @@ MApplication::MApplication(int &argc, char **argv, MApplicationService *service) void MApplicationPrivate::init(int &argc, char **argv, const QString &appIdentifier, MApplicationService *newService) { - componentData = new MComponentData(argc, argv, appIdentifier, newService); + componentData = MComponentData::createInstance(argc, argv, appIdentifier, newService); } void MApplicationPrivate::releasePrestart() diff --git a/src/corelib/core/mcomponentdata.cpp b/src/corelib/core/mcomponentdata.cpp index 7d890085..a01395f4 100644 --- a/src/corelib/core/mcomponentdata.cpp +++ b/src/corelib/core/mcomponentdata.cpp @@ -299,6 +299,23 @@ MComponentData *MComponentData::instance() return self; } +MComponentData* MComponentData::createInstance(int &argc, char **argv, const QString &appIdentifier /*= QString()*/, MApplicationService *service /*= 0*/) +{ + if(!self) { + self = new MComponentData(argc, argv, appIdentifier, service); + } + return self; +} + +MComponentData* MComponentData::createInstance(MApplicationService *service) +{ + if(!self) { + self = new MComponentData(service); + } + return self; +} + + static MComponentDataPrivate *gMComponentDataPrivate = 0; MComponentData::MComponentData(int &argc, char **argv, const QString &appIdentifier, MApplicationService *service) @@ -308,8 +325,10 @@ MComponentData::MComponentData(int &argc, char **argv, const QString &appIdentif Q_D(MComponentData); d->q_ptr = this; - Q_ASSERT_X(!self, "MComponentData", "There should be one component data object only."); - MComponentData::self = this; + if(self) + qWarning() << "MComponentData instantiated although there is already an instance!\n Maybe you called the MComponentData Contructor directly, what is deprecated. Use MComponentData::createInstance() instead."; + + self = this; d->init(argc, argv, appIdentifier, service); } @@ -321,8 +340,10 @@ MComponentData::MComponentData(MApplicationService *service) : Q_D(MComponentData); d->q_ptr = this; - Q_ASSERT_X(!self, "MComponentData", "There should be one component data object only."); - MComponentData::self = this; + if(self) + qWarning() << "MComponentData instantiated although there is already an instance!\n Maybe you called the MComponentData Contructor directly, what is deprecated. Use MComponentData::createInstance() instead."; + + self = this; int argc = 0; char *argv[] = {0}; diff --git a/src/corelib/core/mcomponentdata.h b/src/corelib/core/mcomponentdata.h index 589470d8..2207b447 100644 --- a/src/corelib/core/mcomponentdata.h +++ b/src/corelib/core/mcomponentdata.h @@ -83,15 +83,29 @@ public: * an empty string is given (the default) the application binary file * name is used. */ + // \deprecated Ctor is deprecated for public usage and should be made protected during next API break. MComponentData(int &argc, char **argv, const QString &appIdentifier = QString(), MApplicationService *service = 0); explicit MComponentData(MApplicationService *service); //! Cleans up any window system resources that were allocated by this application. virtual ~MComponentData(); - //! returns the MComponentData instance + //! returns the MComponentData instance or 0 if no instance is created yet + /*! + * \see createInstance() + */ static MComponentData *instance(); + //! returns the MComponentData instance + /*! + * always returns a MComponentData pointer + * if no instance was created yet, it creates a new instance and returns the pointer + * if an instance was already created it returns the pointer to the existing instance + * \see instance() + */ + static MComponentData* createInstance(int &argc, char **argv, const QString &appIdentifier = QString(), MApplicationService *service = 0); + static MComponentData* createInstance(MApplicationService *service); + //! Target device name static QString deviceName(); //! Software rendering command line option set -- cgit v1.2.3