From 0ad111b1bf5a3a8aeb5d82623c02cac792792936 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Fri, 24 Aug 2012 12:37:05 +0200 Subject: 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 Reviewed-by: Lorn Potter --- src/sensors/qsensor.cpp | 19 ++++++++++++++++--- src/sensors/qsensor.h | 2 ++ src/sensors/qsensor_p.h | 6 +++++- 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 \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 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 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 -- cgit v1.2.3