summaryrefslogtreecommitdiffstats
path: root/doc/src
diff options
context:
space:
mode:
authorLincoln Ramsay <lincoln.ramsay@nokia.com>2010-03-08 13:42:18 +1000
committerLincoln Ramsay <lincoln.ramsay@nokia.com>2010-03-08 13:42:56 +1000
commit98a5e032e94ba77bb67a615e2042462b5e6f2923 (patch)
tree2a344b2d3d08bbc77d4b5ac3228b7c65a89bb1d3 /doc/src
parentac758f6ec4667e22e62be4dd6a25975112abc972 (diff)
replace \code blocks with \snippet statements.
This will let the compiler notify us when our example snippets are no longer valid.
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sensors.qdoc48
-rw-r--r--doc/src/snippets/sensors/creating.cpp22
-rw-r--r--doc/src/snippets/sensors/main.cpp5
-rw-r--r--doc/src/snippets/sensors/mybackend.h20
-rw-r--r--doc/src/snippets/sensors/plugin.cpp28
-rw-r--r--doc/src/snippets/sensors/sensors.pro12
-rw-r--r--doc/src/snippets/sensors/start.cpp18
-rw-r--r--doc/src/snippets/snippets.pro1
8 files changed, 109 insertions, 45 deletions
diff --git a/doc/src/sensors.qdoc b/doc/src/sensors.qdoc
index fbaf8d91fe..3c8737386f 100644
--- a/doc/src/sensors.qdoc
+++ b/doc/src/sensors.qdoc
@@ -89,13 +89,7 @@ The life cycle of a sensor is typically:
Here is an example of creating a sensor on the heap and on the stack.
-\code
-// On the heap (deleted when this object is deleted)
-QAccelerationSensor *sensor = new QAccelerationSensor(this);
-
-// On the stack (deleted when the current scope ends)
-QOrientationSensor orient_sensor;
-\endcode
+\snippet snippets/sensors/creating.cpp Creating a sensor
The API supports sensors that poll for their data and sensors that push
data to the app as it arrives. Each sensor will support certain update
@@ -122,17 +116,7 @@ For example, here is an example of how you can access a property of the accelero
This code does not require any compile-time links to \l QAccelerometer or
\l QAccelerometerReading.
-\code
-// start the sensor
-QSensor sensor;
-sensor.setType("QAccelerometer");
-sensor.start();
-
-// later
-QSensorReading *reading = sensor.reading();
-qreal x = reading->property("x").value<qreal>();
-qreal y = reading->value(1).value<qreal>();
-\endcode
+\snippet snippets/sensors/start.cpp Starting a sensor
You can discover all of this information at runtime too. The sensor_explorer example
shows you information about available sensors.
@@ -226,33 +210,7 @@ that multiple sensor backends cannot be in a plugin.
An example follows.
-\code
-#include "mybackend.h"
-#include <qsensorplugin.h>
-#include <qsensormanager.h>
-
-class MyPluginClass : public QtMobility::QSensorPluginInterface, public QtMobility::QSensorBackendFactory
-{
- Q_OBJECT
- Q_INTERFACES(QtMobility::QSensorPluginInterface)
-public:
- void registerSensors()
- {
- QSensorManager::registerBackend(QAccelerationSensor::type, MyBackend::id, this);
- }
-
- QSensorBackend *createBackend(QSensor *sensor)
- {
- if (sensor->identifier() == MyBackend::id)
- return new MyBackend(sensor);
- return 0;
- }
-};
-
-Q_EXPORT_PLUGIN2(libmy_plugin_file_name, MyPluginClass);
-
-#include "main.moc"
-\endcode
+\snippet snippets/sensors/plugin.cpp Plugin
If you woud like to build a backend into a library or application you can use the
REGISTER_STATIC_PLUGIN() macro although it may not work in all situations as it
diff --git a/doc/src/snippets/sensors/creating.cpp b/doc/src/snippets/sensors/creating.cpp
new file mode 100644
index 0000000000..30d8503610
--- /dev/null
+++ b/doc/src/snippets/sensors/creating.cpp
@@ -0,0 +1,22 @@
+#include <QWidget>
+#include <qaccelerometer.h>
+#include <qorientationsensor.h>
+
+QTM_USE_NAMESPACE
+
+class MyWidget : public QWidget
+{
+ void create();
+};
+
+void MyWidget::create()
+{
+//! [Creating a sensor]
+// On the heap (deleted when this object is deleted)
+QAccelerometer *sensor = new QAccelerometer(this);
+
+// On the stack (deleted when the current scope ends)
+QOrientationSensor orient_sensor;
+//! [Creating a sensor]
+}
+
diff --git a/doc/src/snippets/sensors/main.cpp b/doc/src/snippets/sensors/main.cpp
new file mode 100644
index 0000000000..d7ab4e54f7
--- /dev/null
+++ b/doc/src/snippets/sensors/main.cpp
@@ -0,0 +1,5 @@
+int main(int argc, char **argv)
+{
+ return 0;
+}
+
diff --git a/doc/src/snippets/sensors/mybackend.h b/doc/src/snippets/sensors/mybackend.h
new file mode 100644
index 0000000000..ea726aecf6
--- /dev/null
+++ b/doc/src/snippets/sensors/mybackend.h
@@ -0,0 +1,20 @@
+#ifndef MYBACKEND_H
+#define MYBACKEND_H
+
+#include <qaccelerometer.h>
+#include <qsensorbackend.h>
+
+QTM_USE_NAMESPACE
+
+class MyBackend : public QSensorBackend
+{
+public:
+ MyBackend(QSensor *sensor) : QSensorBackend(sensor) {}
+ void stop() {}
+ void start() {}
+ void poll() {}
+
+ static const char *id;
+};
+
+#endif
diff --git a/doc/src/snippets/sensors/plugin.cpp b/doc/src/snippets/sensors/plugin.cpp
new file mode 100644
index 0000000000..a4855659ca
--- /dev/null
+++ b/doc/src/snippets/sensors/plugin.cpp
@@ -0,0 +1,28 @@
+#include "mybackend.h"
+#include <qsensorplugin.h>
+#include <qsensormanager.h>
+
+const char *MyBackend::id = "mybackend";
+
+//! [Plugin]
+class MyPluginClass : public QObject, QSensorPluginInterface, public QSensorBackendFactory
+{
+ Q_OBJECT
+ Q_INTERFACES(QtMobility::QSensorPluginInterface)
+public:
+ void registerSensors()
+ {
+ QSensorManager::registerBackend(QAccelerometer::type, MyBackend::id, this);
+ }
+
+ QSensorBackend *createBackend(QSensor *sensor)
+ {
+ if (sensor->identifier() == MyBackend::id)
+ return new MyBackend(sensor);
+ return 0;
+ }
+};
+//! [Plugin]
+
+//Q_EXPORT_PLUGIN2(libmy_plugin_file_name, MyPluginClass);
+#include "plugin.moc"
diff --git a/doc/src/snippets/sensors/sensors.pro b/doc/src/snippets/sensors/sensors.pro
new file mode 100644
index 0000000000..08701269a2
--- /dev/null
+++ b/doc/src/snippets/sensors/sensors.pro
@@ -0,0 +1,12 @@
+TEMPLATE=app
+TARGET=sensors
+include(../../../../common.pri)
+INCLUDEPATH += ../../../../src/sensors
+SOURCES+=main.cpp\
+ creating.cpp\
+ start.cpp\
+ plugin.cpp
+HEADERS+=myplugin.h
+LIBS+=-rdynamic
+CONFIG+=mobility
+MOBILITY+=sensors
diff --git a/doc/src/snippets/sensors/start.cpp b/doc/src/snippets/sensors/start.cpp
new file mode 100644
index 0000000000..dc30cc76fb
--- /dev/null
+++ b/doc/src/snippets/sensors/start.cpp
@@ -0,0 +1,18 @@
+#include <qsensor.h>
+
+QTM_USE_NAMESPACE
+
+void start()
+{
+//! [Starting a sensor]
+// start the sensor
+QSensor sensor;
+sensor.setType("QAccelerometer");
+sensor.start();
+
+// later
+QSensorReading *reading = sensor.reading();
+qreal x = reading->property("x").value<qreal>();
+qreal y = reading->value(1).value<qreal>();
+//! [Starting a sensor]
+}
diff --git a/doc/src/snippets/snippets.pro b/doc/src/snippets/snippets.pro
index d8e37b1951..a9dff0cb5a 100644
--- a/doc/src/snippets/snippets.pro
+++ b/doc/src/snippets/snippets.pro
@@ -2,3 +2,4 @@ include(../../../staticconfig.pri)
TEMPLATE = subdirs
contains(mobility_modules,contacts): SUBDIRS += qtcontactsdocsample
+contains(mobility_modules,sensors): SUBDIRS += sensors