summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@qt.io>2023-02-17 13:40:13 +0200
committerJuha Vuolle <juha.vuolle@qt.io>2023-02-22 08:37:59 +0200
commitf5426ddda0c8e022d55290de70f96cb4db1801bb (patch)
treead5cf038654f1a69ad1e86aea12bc1513a699202
parent20373cfd4019c66884fb63a4316b1c60ede089ca (diff)
downloadqtsensors-f5426ddda0c8e022d55290de70f96cb4db1801bb.tar.gz
Move sensor_explorer QML example to manual tests
The example is useful as a sensor testing tool, but less necessary as an example. The primary demonstrative element of the example was how to iterate the available sensors, which is covered in a documentation snippet (followup commit). This commit also renames the pre-existing widget-based sensor_explorer manual test to avoid name conflicts, as well as removes the qdoc and qmake support from the now-a-manual-test application. Task-number: QTBUG-110939 Pick-to: 6.5 Change-Id: I422f62f852d0a7e40a76f555ec8aa98404164f7a Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
-rw-r--r--examples/sensors/CMakeLists.txt7
-rw-r--r--examples/sensors/sensor_explorer/CMakeLists.txt44
-rw-r--r--examples/sensors/sensor_explorer/doc/images/qtsensors-examples-sensor-explorer.pngbin47605 -> 0 bytes
-rw-r--r--examples/sensors/sensor_explorer/doc/src/sensor_explorer.qdoc118
-rw-r--r--examples/sensors/sensor_explorer/sensor_explorer.pro22
-rw-r--r--examples/sensors/sensors.pro4
-rw-r--r--src/sensors/qsensor.cpp3
-rw-r--r--tests/manual/CMakeLists.txt3
-rw-r--r--tests/manual/sensor_explorer_qml/CMakeLists.txt32
-rw-r--r--tests/manual/sensor_explorer_qml/main.cpp (renamed from examples/sensors/sensor_explorer/main.cpp)0
-rw-r--r--tests/manual/sensor_explorer_qml/qml.qrc (renamed from examples/sensors/sensor_explorer/qml.qrc)0
-rw-r--r--tests/manual/sensor_explorer_qml/sensor_explorer.qml (renamed from examples/sensors/sensor_explorer/sensor_explorer.qml)8
-rw-r--r--tests/manual/sensor_explorer_qml/sensormodels.cpp (renamed from examples/sensors/sensor_explorer/sensormodels.cpp)6
-rw-r--r--tests/manual/sensor_explorer_qml/sensormodels.h (renamed from examples/sensors/sensor_explorer/sensormodels.h)2
-rw-r--r--tests/manual/sensor_explorer_widgets/CMakeLists.txt (renamed from tests/manual/sensor_explorer/CMakeLists.txt)2
-rw-r--r--tests/manual/sensor_explorer_widgets/explorer.cpp (renamed from tests/manual/sensor_explorer/explorer.cpp)0
-rw-r--r--tests/manual/sensor_explorer_widgets/explorer.h (renamed from tests/manual/sensor_explorer/explorer.h)0
-rw-r--r--tests/manual/sensor_explorer_widgets/explorer.ui (renamed from tests/manual/sensor_explorer/explorer.ui)0
-rw-r--r--tests/manual/sensor_explorer_widgets/main.cpp (renamed from tests/manual/sensor_explorer/main.cpp)0
19 files changed, 37 insertions, 214 deletions
diff --git a/examples/sensors/CMakeLists.txt b/examples/sensors/CMakeLists.txt
index ef323ef..ecbd35f 100644
--- a/examples/sensors/CMakeLists.txt
+++ b/examples/sensors/CMakeLists.txt
@@ -1,9 +1,6 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-if(TARGET Qt::Quick)
- qt_internal_add_example(sensor_explorer)
- if(TARGET Qt::Svg)
- qt_internal_add_example(sensorsshowcase)
- endif()
+if(TARGET Qt::Quick AND TARGET Qt::Svg)
+ qt_internal_add_example(sensorsshowcase)
endif()
diff --git a/examples/sensors/sensor_explorer/CMakeLists.txt b/examples/sensors/sensor_explorer/CMakeLists.txt
deleted file mode 100644
index 33fc7ea..0000000
--- a/examples/sensors/sensor_explorer/CMakeLists.txt
+++ /dev/null
@@ -1,44 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(sensor_explorer LANGUAGES CXX)
-
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/sensors/sensor_explorer")
-
-find_package(Qt6 REQUIRED COMPONENTS Qml Quick Sensors)
-
-qt_add_executable(sensor_explorer
- main.cpp
- sensormodels.cpp sensormodels.h
-)
-
-set_target_properties(sensor_explorer PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(sensor_explorer PUBLIC
- Qt::Qml
- Qt::Quick
- Qt::Sensors
-)
-
-qt_add_qml_module(sensor_explorer
- URI SensorModels
- VERSION 1.0
- QML_FILES sensor_explorer.qml
- NO_RESOURCE_TARGET_PATH
-)
-
-install(TARGETS sensor_explorer
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/sensors/sensor_explorer/doc/images/qtsensors-examples-sensor-explorer.png b/examples/sensors/sensor_explorer/doc/images/qtsensors-examples-sensor-explorer.png
deleted file mode 100644
index 830f959..0000000
--- a/examples/sensors/sensor_explorer/doc/images/qtsensors-examples-sensor-explorer.png
+++ /dev/null
Binary files differ
diff --git a/examples/sensors/sensor_explorer/doc/src/sensor_explorer.qdoc b/examples/sensors/sensor_explorer/doc/src/sensor_explorer.qdoc
deleted file mode 100644
index f4d7c6b..0000000
--- a/examples/sensors/sensor_explorer/doc/src/sensor_explorer.qdoc
+++ /dev/null
@@ -1,118 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example sensor_explorer
- \title Qt Sensors - Explorer QML Example
- \ingroup qtsensors-examples
- \brief Demonstrates how to read the meta-data of available sensors.
-
- \image qtsensors-examples-sensor-explorer.png
-
- The example is implemented as a typical model-view application. The
- models are written with C++ and exposed to QML, and the views are
- implemented as QML types in the QML application.
-
- \section1 Exposing and Importing the Models
-
- The QML models written in C++ are exposed in the project build files
- as a \c SensorModels QML module.
-
- \e CMake:
- \code
- qt_add_qml_module(sensor_explorer
- URI SensorModels
- VERSION 1.0
- )
- \endcode
-
- \e qmake:
- \code
- CONFIG += qmltypes
- QML_IMPORT_NAME = SensorModels
- QML_IMPORT_MAJOR_VERSION = 1
- \endcode
-
- The individual model elements are exposed as part of the model
- code by using the \c QML_ELEMENT macro as illustrated here:
- \snippet sensor_explorer/sensormodels.h 0
-
- To access the models in the QML application, the module is imported
- by the application QML:
- \snippet sensor_explorer/sensor_explorer.qml 0
-
- \section1 Populating the Model of Available Sensors
-
- The \c AvailableSensorsModel is a list model that provides information on
- available sensors on the device. The model is populated once at the
- element's construction time:
-
- \snippet sensor_explorer/sensormodels.cpp 0
-
- The model's \c data() function returns a pointer to the requested sensor
- object.
-
- \snippet sensor_explorer/sensormodels.cpp 1
-
- Since the sensor (QSensor) is a QObject, the QML is then able to directly
- access all metaproperties and -functions directly.
-
- \note It would be possible to refresh the sensor list later at will, but for
- the simplicity of the example such functionality is not exposed to QML.
-
- \section1 Populating the Model of Sensor Properties
-
- The \c SensorPropertyModel is a table model that provides individual
- sensor's property-value pairs as columns. The column \c 0 provides the
- property's name and the column \c 1 provides the property's value. The
- population of the properties is done by reading the metadata of the sensors.
- The model reads both the sensor's metadata as well as the sensor's reading's
- metadata. The code below illustrates the reading of the \c reading metadata:
-
- \snippet sensor_explorer/sensormodels.cpp 2
-
- This metadata access allows providing the model data for all sensors
- without prior compile-time understanding of their properties.
-
- Once the metadata is set, the code then subscribes to the
- QSensor::readingChanged() signal to detect sensor reading changes.
- Upon such changes (for example a rotation value changes), the model data
- is updated accordingly.
-
- \section1 Viewing the Models
-
- The QML application is based on two views. The first view shows the available
- sensors as a selectable list. The second view shows the selected sensor's
- properties and their values. The delegates for viewing the individual items
- are simplistic \e {rectangle and text} items.
-
- Binding the two views functionally together is done by binding the property
- model's \c sensor property to the current selection of the available sensors
- model:
-
- \snippet sensor_explorer/sensor_explorer.qml 1
-
- When the selected sensor changes, the \c sensor of the property model changes
- accordingly.
-
- The following snippet illustrates how the property view is implemented. For
- more details about QML models and views, please see
- \l{Models and Views in Qt Quick}.
-
- \snippet sensor_explorer/sensor_explorer.qml 3
-
- For clarity it should be mentioned that the \c display attribute used by
- the text element refers to the Qt::DisplayRole role of the model, which is
- provided by default by Qt models.
-
- \section1 Activating the Sensors
-
- The example has a button for activating and deactivating the currently
- selected sensor. The button is enabled only if a sensor is currently
- selected, as illustrated below.
-
- \snippet sensor_explorer/sensor_explorer.qml 2
-
- On clicking the button, the sensor's active property is toggled on/off.
-
-*/
diff --git a/examples/sensors/sensor_explorer/sensor_explorer.pro b/examples/sensors/sensor_explorer/sensor_explorer.pro
deleted file mode 100644
index a27681e..0000000
--- a/examples/sensors/sensor_explorer/sensor_explorer.pro
+++ /dev/null
@@ -1,22 +0,0 @@
-TEMPLATE = app
-TARGET = sensor_explorer
-QT += qml quick sensors
-
-# Avoid going to release/debug subdirectory
-win32: DESTDIR = ./
-
-SOURCES = main.cpp sensormodels.cpp
-HEADERS = sensormodels.h
-
-CONFIG += qmltypes
-QML_IMPORT_NAME = SensorModels
-QML_IMPORT_MAJOR_VERSION = 1
-
-OTHER_FILES = \
- sensor_explorer.qml
-
-target.path = $$[QT_INSTALL_EXAMPLES]/sensors/sensor_explorer
-INSTALLS += target
-
-RESOURCES += \
- qml.qrc
diff --git a/examples/sensors/sensors.pro b/examples/sensors/sensors.pro
index 984d761..566e172 100644
--- a/examples/sensors/sensors.pro
+++ b/examples/sensors/sensors.pro
@@ -1,6 +1,2 @@
TEMPLATE = subdirs
-qtHaveModule(quick) {
- SUBDIRS += \
- sensor_explorer
-}
diff --git a/src/sensors/qsensor.cpp b/src/sensors/qsensor.cpp
index d2f748a..72c58fe 100644
--- a/src/sensors/qsensor.cpp
+++ b/src/sensors/qsensor.cpp
@@ -527,9 +527,6 @@ void QSensor::setSkipDuplicates(bool skipDuplicates)
continuous range of rates.
A discrete rate is noted by having both values the same.
- See the sensor_explorer example for an example of how to interpret and use
- this information.
-
Note that this information is not mandatory as not all sensors have a rate at which
they run. In such cases, the list will be empty.
diff --git a/tests/manual/CMakeLists.txt b/tests/manual/CMakeLists.txt
index a23fbcd..8686f85 100644
--- a/tests/manual/CMakeLists.txt
+++ b/tests/manual/CMakeLists.txt
@@ -2,8 +2,9 @@
# SPDX-License-Identifier: BSD-3-Clause
if(TARGET Qt::Widgets)
- add_subdirectory(sensor_explorer)
+ add_subdirectory(sensor_explorer_widgets)
endif()
if (TARGET Qt::Quick)
add_subdirectory(sensorclerk)
+ add_subdirectory(sensor_explorer_qml)
endif()
diff --git a/tests/manual/sensor_explorer_qml/CMakeLists.txt b/tests/manual/sensor_explorer_qml/CMakeLists.txt
new file mode 100644
index 0000000..e68fce6
--- /dev/null
+++ b/tests/manual/sensor_explorer_qml/CMakeLists.txt
@@ -0,0 +1,32 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(tst_manual_sensor_explorer_qml LANGUAGES CXX)
+
+set(CMAKE_AUTOMOC ON)
+
+find_package(Qt6 REQUIRED COMPONENTS Qml Quick Sensors)
+
+qt_add_executable(tst_manual_sensor_explorer_qml
+ main.cpp
+ sensormodels.cpp sensormodels.h
+)
+
+set_target_properties(tst_manual_sensor_explorer_qml PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(tst_manual_sensor_explorer_qml PUBLIC
+ Qt::Qml
+ Qt::Quick
+ Qt::Sensors
+)
+
+qt_add_qml_module(tst_manual_sensor_explorer_qml
+ URI SensorModels
+ VERSION 1.0
+ QML_FILES sensor_explorer.qml
+ NO_RESOURCE_TARGET_PATH
+)
diff --git a/examples/sensors/sensor_explorer/main.cpp b/tests/manual/sensor_explorer_qml/main.cpp
index 4eeaa14..4eeaa14 100644
--- a/examples/sensors/sensor_explorer/main.cpp
+++ b/tests/manual/sensor_explorer_qml/main.cpp
diff --git a/examples/sensors/sensor_explorer/qml.qrc b/tests/manual/sensor_explorer_qml/qml.qrc
index df6160a..df6160a 100644
--- a/examples/sensors/sensor_explorer/qml.qrc
+++ b/tests/manual/sensor_explorer_qml/qml.qrc
diff --git a/examples/sensors/sensor_explorer/sensor_explorer.qml b/tests/manual/sensor_explorer_qml/sensor_explorer.qml
index 9fe59ba..f1c4d3c 100644
--- a/examples/sensors/sensor_explorer/sensor_explorer.qml
+++ b/tests/manual/sensor_explorer_qml/sensor_explorer.qml
@@ -6,9 +6,7 @@ import QtQuick.Window
import QtQuick.Controls
import QtQuick.Layouts
-//! [0]
import SensorModels
-//! [0]
Window {
id: window
@@ -74,14 +72,11 @@ Window {
}
}
- //! [1]
SensorPropertyModel {
id: propertyModel
sensor: availableSensorsModel.get(sensorsView.currentIndex)
}
- //! [1]
- //! [2]
Button {
id: activateButton
Layout.preferredHeight: 30
@@ -92,7 +87,6 @@ Window {
: qsTr("Activate sensor"))
onClicked: propertyModel.sensor.active = !propertyModel.sensor.active
}
- //! [2]
GroupBox {
title: qsTr("Selected sensor's properties")
@@ -101,7 +95,6 @@ Window {
Layout.margins: 2
enabled: sensorsView.currentIndex != -1
- //! [3]
TableView {
id: propertyView
anchors.fill: parent
@@ -121,7 +114,6 @@ Window {
}
}
}
- //! [3]
}
}
}
diff --git a/examples/sensors/sensor_explorer/sensormodels.cpp b/tests/manual/sensor_explorer_qml/sensormodels.cpp
index f9ed4d9..ed365e5 100644
--- a/examples/sensors/sensor_explorer/sensormodels.cpp
+++ b/tests/manual/sensor_explorer_qml/sensormodels.cpp
@@ -51,7 +51,6 @@ AvailableSensorsModel::AvailableSensorsModel(QObject* parent) : QAbstractListMod
*/
void AvailableSensorsModel::loadSensors()
{
- //! [0]
beginResetModel();
m_availableSensors.clear();
@@ -66,7 +65,6 @@ void AvailableSensorsModel::loadSensors()
}
}
endResetModel();
- //! [0]
}
int AvailableSensorsModel::rowCount(const QModelIndex&) const
@@ -74,14 +72,12 @@ int AvailableSensorsModel::rowCount(const QModelIndex&) const
return m_availableSensors.size();
}
-//! [1]
QVariant AvailableSensorsModel::data(const QModelIndex &index, int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
return QVariant::fromValue<QSensor*>(m_availableSensors.at(index.row()));
}
-//! [1]
QSensor* AvailableSensorsModel::get(int index) const
{
@@ -134,7 +130,6 @@ void SensorPropertyModel::setSensor(QSensor *sensor)
// available sensors without knowing their properties in advance / compile-time.
// 1. Read properties of the 'reading' object if available
- //! [2]
int firstProperty = QSensorReading::staticMetaObject.propertyOffset();
QSensorReading *reading = m_sensor->reading();
if (reading) {
@@ -145,7 +140,6 @@ void SensorPropertyModel::setSensor(QSensor *sensor)
(name, reading->property(name).toByteArray()));
}
}
- //! [2]
// 2. Read properties of the 'sensor' object
const QMetaObject *mo1 = m_sensor->metaObject();
diff --git a/examples/sensors/sensor_explorer/sensormodels.h b/tests/manual/sensor_explorer_qml/sensormodels.h
index 02de2a8..80f4bcb 100644
--- a/examples/sensors/sensor_explorer/sensormodels.h
+++ b/tests/manual/sensor_explorer_qml/sensormodels.h
@@ -12,12 +12,10 @@
QT_BEGIN_NAMESPACE
-//! [0]
class AvailableSensorsModel: public QAbstractListModel
{
Q_OBJECT
QML_ELEMENT
-//! [0]
public:
explicit AvailableSensorsModel(QObject* parent = nullptr);
int rowCount(const QModelIndex & = QModelIndex()) const override;
diff --git a/tests/manual/sensor_explorer/CMakeLists.txt b/tests/manual/sensor_explorer_widgets/CMakeLists.txt
index 2f32dc9..357eb02 100644
--- a/tests/manual/sensor_explorer/CMakeLists.txt
+++ b/tests/manual/sensor_explorer_widgets/CMakeLists.txt
@@ -5,7 +5,7 @@
## sensor_explorer Binary:
#####################################################################
-qt_internal_add_manual_test(tst_manual_sensor_explorer
+qt_internal_add_manual_test(tst_manual_sensor_explorer_widgets
GUI
SOURCES
explorer.cpp explorer.h explorer.ui
diff --git a/tests/manual/sensor_explorer/explorer.cpp b/tests/manual/sensor_explorer_widgets/explorer.cpp
index e6353c0..e6353c0 100644
--- a/tests/manual/sensor_explorer/explorer.cpp
+++ b/tests/manual/sensor_explorer_widgets/explorer.cpp
diff --git a/tests/manual/sensor_explorer/explorer.h b/tests/manual/sensor_explorer_widgets/explorer.h
index 92aa6f4..92aa6f4 100644
--- a/tests/manual/sensor_explorer/explorer.h
+++ b/tests/manual/sensor_explorer_widgets/explorer.h
diff --git a/tests/manual/sensor_explorer/explorer.ui b/tests/manual/sensor_explorer_widgets/explorer.ui
index 166e9c3..166e9c3 100644
--- a/tests/manual/sensor_explorer/explorer.ui
+++ b/tests/manual/sensor_explorer_widgets/explorer.ui
diff --git a/tests/manual/sensor_explorer/main.cpp b/tests/manual/sensor_explorer_widgets/main.cpp
index 0e2ea93..0e2ea93 100644
--- a/tests/manual/sensor_explorer/main.cpp
+++ b/tests/manual/sensor_explorer_widgets/main.cpp