187 int valueCount() const; |
187 int valueCount() const; |
188 QVariant value(int index) const; |
188 QVariant value(int index) const; |
189 |
189 |
190 protected: |
190 protected: |
191 explicit QSensorReading(QObject *parent, QSensorReadingPrivate *d); |
191 explicit QSensorReading(QObject *parent, QSensorReadingPrivate *d); |
192 QScopedPointer<QSensorReadingPrivate> *d_ptr() { return &d; } |
192 virtual void copyValuesFrom(QSensorReading *other); |
193 virtual void copyValuesFrom(QSensorReading *other) = 0; |
|
194 |
193 |
195 private: |
194 private: |
196 QScopedPointer<QSensorReadingPrivate> d; |
195 QScopedPointer<QSensorReadingPrivate> d; |
197 Q_DISABLE_COPY(QSensorReading) |
196 Q_DISABLE_COPY(QSensorReading) |
198 }; |
|
199 |
|
200 template <typename T> |
|
201 class qTypedWrapper |
|
202 { |
|
203 public: |
|
204 qTypedWrapper(QScopedPointer<QSensorReadingPrivate> *_ptr) |
|
205 : ptr(_ptr) |
|
206 { |
|
207 } |
|
208 |
|
209 T *operator->() const |
|
210 { |
|
211 return static_cast<T*>(ptr->data()); |
|
212 } |
|
213 |
|
214 private: |
|
215 QScopedPointer<QSensorReadingPrivate> *ptr; |
|
216 }; |
197 }; |
217 |
198 |
218 #define DECLARE_READING(classname)\ |
199 #define DECLARE_READING(classname)\ |
219 DECLARE_READING_D(classname, classname ## Private) |
200 DECLARE_READING_D(classname, classname ## Private) |
220 |
201 |
222 public:\ |
203 public:\ |
223 classname(QObject *parent = 0);\ |
204 classname(QObject *parent = 0);\ |
224 virtual ~classname();\ |
205 virtual ~classname();\ |
225 void copyValuesFrom(QSensorReading *other);\ |
206 void copyValuesFrom(QSensorReading *other);\ |
226 private:\ |
207 private:\ |
227 qTypedWrapper<pclassname> d; |
208 QScopedPointer<pclassname> d; |
228 |
209 |
229 #define IMPLEMENT_READING(classname)\ |
210 #define IMPLEMENT_READING(classname)\ |
230 IMPLEMENT_READING_D(classname, classname ## Private) |
211 IMPLEMENT_READING_D(classname, classname ## Private) |
231 |
212 |
232 #define IMPLEMENT_READING_D(classname, pclassname)\ |
213 #define IMPLEMENT_READING_D(classname, pclassname)\ |
233 classname::classname(QObject *parent)\ |
214 classname::classname(QObject *parent)\ |
234 : QSensorReading(parent, new pclassname)\ |
215 : QSensorReading(parent, 0)\ |
235 , d(d_ptr())\ |
216 , d(new pclassname)\ |
236 {}\ |
217 {}\ |
237 classname::~classname() {}\ |
218 classname::~classname() {}\ |
238 void classname::copyValuesFrom(QSensorReading *_other)\ |
219 void classname::copyValuesFrom(QSensorReading *_other)\ |
239 {\ |
220 {\ |
240 /* No need to verify types, only called by QSensorBackend */\ |
221 /* No need to verify types, only called by QSensorBackend */\ |
241 classname *other = static_cast<classname *>(_other);\ |
222 classname *other = static_cast<classname *>(_other);\ |
242 pclassname *my_ptr = static_cast<pclassname*>(d_ptr()->data());\ |
223 pclassname *my_ptr = d.data();\ |
243 pclassname *other_ptr = static_cast<pclassname*>(other->d_ptr()->data());\ |
224 pclassname *other_ptr = other->d.data();\ |
244 /* Do a direct copy of the private class */\ |
225 /* Do a direct copy of the private class */\ |
245 *(my_ptr) = *(other_ptr);\ |
226 *(my_ptr) = *(other_ptr);\ |
|
227 /* We need to copy the parent too */\ |
|
228 QSensorReading::copyValuesFrom(_other);\ |
246 } |
229 } |
247 |
230 |
248 QTM_END_NAMESPACE |
231 QTM_END_NAMESPACE |
249 |
232 |
250 Q_DECLARE_METATYPE(QtMobility::qtimestamp) |
233 Q_DECLARE_METATYPE(QtMobility::qtimestamp) |