aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBernd Lamecker <bernd.lamecker@basyskom.de>2010-11-02 12:02:27 +0100
committerStanislav Ionascu <stanislav.ionascu@nokia.com>2011-01-05 15:39:47 +0200
commitffc47cb633031e980cf47fb1c131ab04ef243774 (patch)
tree53bc36c1b36cf63dd6f6f60b7368f372a7e69477 /src
parent439c27767edd27bbd9c4ee31362b9689fee272fa (diff)
Changes: Made MComponentData a "real" Singleton
RevBy: Stanislav Ionascu, Michael Hasselmann, Tomas Junnonen Merge-Request: 824
Diffstat (limited to 'src')
-rw-r--r--src/corelib/core/mapplication.cpp2
-rw-r--r--src/corelib/core/mcomponentdata.cpp29
-rw-r--r--src/corelib/core/mcomponentdata.h16
3 files changed, 41 insertions, 6 deletions
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