summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas McGuire <thomas.mcguire@kdab.com>2012-08-24 12:37:05 +0200
committerLorn Potter <lorn.potter@gmail.com>2012-11-28 20:43:15 +0100
commit0ad111b1bf5a3a8aeb5d82623c02cac792792936 (patch)
treed8ad007423bff40efa5a8e8266660019ea224bac
parent2a524d5fbf49d97f716c9889114a0dae7b208931 (diff)
Provide d-pointers for QSensor subclasses in a different way
Adds a ctor that can take a QSensorPrivate sub-class. Change-Id: Ib239dd211be6038ccbb5c8bad87411dba428c68a Reviewed-by: Thomas McGuire <thomas.mcguire@kdab.com> Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
-rw-r--r--src/sensors/qsensor.cpp19
-rw-r--r--src/sensors/qsensor.h2
-rw-r--r--src/sensors/qsensor_p.h6
3 files changed, 23 insertions, 4 deletions
diff --git a/src/sensors/qsensor.cpp b/src/sensors/qsensor.cpp
index e3298ae62f..405347bebe 100644
--- a/src/sensors/qsensor.cpp
+++ b/src/sensors/qsensor.cpp
@@ -196,16 +196,29 @@ static int qoutputrangelist_id = qRegisterMetaType<QtMobility::qoutputrangelist>
\since 1.0
*/
+void QSensorPrivate::init(const QByteArray &sensorType)
+{
+ type = sensorType;
+ q->registerInstance(); // so the availableSensorsChanged() signal works
+}
/*!
Construct the \a type sensor as a child of \a parent.
\since 1.0
*/
QSensor::QSensor(const QByteArray &type, QObject *parent)
: QObject(parent)
- , d(new QSensorPrivate)
+ , d(new QSensorPrivate(this))
+{
+ d->init(type);
+}
+
+/*!
+ \internal
+ */
+QSensor::QSensor(const QByteArray &type, QSensorPrivate *dd, QObject *parent)
+ : QObject(parent), d(dd)
{
- d->type = type;
- registerInstance(); // so the availableSensorsChanged() signal works
+ d->init(type);
}
/*!
diff --git a/src/sensors/qsensor.h b/src/sensors/qsensor.h
index a75a9c6611..dc003bddf6 100644
--- a/src/sensors/qsensor.h
+++ b/src/sensors/qsensor.h
@@ -171,12 +171,14 @@ Q_SIGNALS:
void dataRateChanged();
protected:
+ QSensor(const QByteArray &type, QSensorPrivate *dd, QObject* parent = 0);
// called by the back end
QSensorPrivate *d_func() const { return d.data(); }
private:
void registerInstance();
+ friend class QSensorPrivate;
QScopedPointer<QSensorPrivate> d;
Q_DISABLE_COPY(QSensor)
};
diff --git a/src/sensors/qsensor_p.h b/src/sensors/qsensor_p.h
index 1aa3fdef16..02f31c7c59 100644
--- a/src/sensors/qsensor_p.h
+++ b/src/sensors/qsensor_p.h
@@ -62,7 +62,7 @@ typedef QList<QSensorFilter*> QFilterList;
class QSensorPrivate
{
public:
- QSensorPrivate()
+ QSensorPrivate(QSensor *sensor)
: identifier()
, type()
, outputRange(-1)
@@ -76,9 +76,12 @@ public:
, error(0)
, alwaysOn(false)
, skipDuplicates(false)
+ , q(sensor)
{
}
+ void init(const QByteArray &sensorType);
+
// meta-data
QByteArray identifier;
QByteArray type;
@@ -104,6 +107,7 @@ public:
bool alwaysOn;
bool skipDuplicates;
+ QSensor *q;
};
class QSensorReadingPrivate