qtmobility/src/sensors/qsensor.cpp
changeset 14 6fbed849b4f4
parent 11 06b8e2af4411
--- a/qtmobility/src/sensors/qsensor.cpp	Fri Jun 11 14:26:25 2010 +0300
+++ b/qtmobility/src/sensors/qsensor.cpp	Wed Jun 23 19:08:38 2010 +0300
@@ -179,10 +179,7 @@
     if (d->backend)
         return true;
 
-    int rate = d->dataRate;
     d->backend = QSensorManager::createBackend(this);
-    if (rate != 0)
-        setDataRate(rate);
     return (d->backend != 0);
 }
 
@@ -253,11 +250,23 @@
 
     Measured in Hertz.
 
-    The default value is determined by the backend.
+    The data rate is the maximum frequency at which the sensor can detect changes.
+
+    Setting this property is not portable and can cause conflicts with other
+    applications. Check with the sensor backend and platform documentation for
+    any policy regarding multiple applications requesting a data rate.
+
+    The default value (0) means that the app does not care what the data rate is.
+    Applications should consider using a timer-based poll of the current value or
+    ensure that the code that processes values can run very quickly as the platform
+    may provide updates hundreds of times each second.
 
     This should be set before calling start() because the sensor may not
     notice changes to this value while it is running.
 
+    Note that there is no mechanism to determine the current data rate in use by the
+    platform.
+
     \sa QSensor::availableDataRates
 */
 
@@ -268,6 +277,10 @@
 
 void QSensor::setDataRate(int rate)
 {
+    if (rate == 0) {
+        d->dataRate = rate;
+        return;
+    }
     bool warn = true;
     Q_FOREACH (const qrange &range, d->availableDataRates) {
         if (rate >= range.first && rate <= range.second) {
@@ -295,8 +308,6 @@
         return true;
     if (!connectToBackend())
         return false;
-    if (d->availableDataRates.count() == 0)
-        return false;
     // Set these flags to their defaults
     d->active = true;
     d->busy = false;
@@ -398,8 +409,16 @@
     \property QSensor::outputRange
     \brief the output range in use by the sensor.
 
-    A sensor may have more than one output range. Typically this is done
-    to give a greater measurement range at the cost of lowering accuracy.
+    This value represents the index in the QSensor::outputRanges list to use.
+
+    Setting this property is not portable and can cause conflicts with other
+    applications. Check with the sensor backend and platform documentation for
+    any policy regarding multiple applications requesting an output range.
+
+    The default value (-1) means that the app does not care what the output range is.
+
+    Note that there is no mechanism to determine the current output range in use by the
+    platform.
 
     \sa QSensor::outputRanges
 */
@@ -411,7 +430,7 @@
 
 void QSensor::setOutputRange(int index)
 {
-    if (index < 0 || index >= d->outputRanges.count()) {
+    if (index < -1 || index >= d->outputRanges.count()) {
         qWarning() << "ERROR: Output range" << index << "is not valid";
         return;
     }
@@ -529,16 +548,11 @@
 */
 QSensorReading::QSensorReading(QObject *parent, QSensorReadingPrivate *_d)
     : QObject(parent)
-    , d(_d)
+    , d(_d?_d:new QSensorReadingPrivate)
 {
 }
 
 /*!
-    \fn QSensorReading::d_ptr()
-    \internal
-*/
-
-/*!
     \internal
 */
 QSensorReading::~QSensorReading()
@@ -638,6 +652,13 @@
 
     Note that this method should only be called by QSensorBackend.
 */
+void QSensorReading::copyValuesFrom(QSensorReading *other)
+{
+    QSensorReadingPrivate *my_ptr = d.data();
+    QSensorReadingPrivate *other_ptr = other->d.data();
+    /* Do a direct copy of the private class */
+    *(my_ptr) = *(other_ptr);
+}
 
 /*!
     \macro DECLARE_READING(classname)