diff options
Diffstat (limited to 'tests/manual')
22 files changed, 571 insertions, 411 deletions
diff --git a/tests/manual/CMakeLists.txt b/tests/manual/CMakeLists.txt new file mode 100644 index 00000000..8686f854 --- /dev/null +++ b/tests/manual/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(TARGET Qt::Widgets) + 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/explorer.h b/tests/manual/sensor_explorer/explorer.h deleted file mode 100644 index 7e7acccd..00000000 --- a/tests/manual/sensor_explorer/explorer.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef EXPLORER_H -#define EXPLORER_H - -#include <QMainWindow> -#include <ui_explorer.h> -#include <qsensor.h> - - -class Explorer : public QMainWindow, public QSensorFilter -{ - Q_OBJECT -public: - Explorer(QWidget *parent = 0); - ~Explorer(); - - bool filter(QSensorReading *reading); - -private slots: - void loadSensors(); - void on_sensors_currentItemChanged(); - void on_sensorprops_itemChanged(QTableWidgetItem *item); - void on_start_clicked(); - void on_stop_clicked(); - void sensor_changed(); - void adjustSizes(); - void loadSensorProperties(); - -private: - void showEvent(QShowEvent *event); - void resizeEvent(QResizeEvent *event); - - void clearReading(); - void loadReading(); - void clearSensorProperties(); - void adjustTableColumns(QTableWidget *table); - void resizeSensors(); - - Ui::Explorer ui; - QSensor *m_sensor; - bool ignoreItemChanged; -}; - -#endif - diff --git a/tests/manual/sensor_explorer/main.cpp b/tests/manual/sensor_explorer/main.cpp deleted file mode 100644 index 4b5dca92..00000000 --- a/tests/manual/sensor_explorer/main.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "explorer.h" - -int main(int argc, char **argv) -{ - QApplication app(argc, argv); - Explorer explorer; - explorer.show(); - return app.exec(); -} - diff --git a/tests/manual/sensor_explorer/sensor_explorer.pro b/tests/manual/sensor_explorer/sensor_explorer.pro deleted file mode 100644 index 353c49e0..00000000 --- a/tests/manual/sensor_explorer/sensor_explorer.pro +++ /dev/null @@ -1,16 +0,0 @@ -TEMPLATE=app -TARGET=sensor_explorer - -QT = widgets sensors - -FORMS=\ - explorer.ui - -HEADERS=\ - explorer.h - -SOURCES=\ - explorer.cpp\ - main.cpp - - diff --git a/tests/manual/sensor_explorer_qml/CMakeLists.txt b/tests/manual/sensor_explorer_qml/CMakeLists.txt new file mode 100644 index 00000000..e68fce62 --- /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/tests/manual/sensor_explorer_qml/main.cpp b/tests/manual/sensor_explorer_qml/main.cpp new file mode 100644 index 00000000..604a6d36 --- /dev/null +++ b/tests/manual/sensor_explorer_qml/main.cpp @@ -0,0 +1,20 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QtQml> +#include <QtQuick/QQuickWindow> +#include <QtGui/QGuiApplication> + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + QQmlApplicationEngine engine(QUrl("qrc:///sensor_explorer.qml")); + QObject *topLevel = engine.rootObjects().value(0); + QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel); + if (!window) { + qWarning("Error: Your root item has to be a Window."); + return -1; + } + window->show(); + return app.exec(); +} diff --git a/tests/manual/sensor_explorer_qml/qml.qrc b/tests/manual/sensor_explorer_qml/qml.qrc new file mode 100644 index 00000000..df6160ae --- /dev/null +++ b/tests/manual/sensor_explorer_qml/qml.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>sensor_explorer.qml</file> + </qresource> +</RCC> diff --git a/tests/manual/sensor_explorer_qml/sensor_explorer.qml b/tests/manual/sensor_explorer_qml/sensor_explorer.qml new file mode 100644 index 00000000..e80fb0a4 --- /dev/null +++ b/tests/manual/sensor_explorer_qml/sensor_explorer.qml @@ -0,0 +1,119 @@ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick +import QtQuick.Window +import QtQuick.Controls +import QtQuick.Layouts + +import SensorModels + +Window { + id: window + width: 400 + height: 600 + + AvailableSensorsModel { + id: availableSensorsModel + } + + ColumnLayout { + + GroupBox { + id: availableSensorsModelGroup + title: qsTr("Available Sensors") + Layout.preferredWidth: window.width - 4 // 4 = 2x2 margins + Layout.preferredHeight: window.height * 0.4 + Layout.margins: 2 + + ListView { + id: sensorsView + anchors.fill: parent + currentIndex: -1 // no initial selection + spacing: 1 + clip: true + model: availableSensorsModel + delegate: Item { + id: sensorRow + width: sensorsView.width + height: 30 + property color rowColor: { + if (sensorsView.currentIndex == index) + return "lightsteelblue" // highlight + return (index % 2 == 0) ? "#CCCCCC" : "#AAAAAA" + } + RowLayout { + spacing: 1 + anchors.fill: parent + Rectangle { + color: sensorRow.rowColor + Layout.preferredWidth: sensorRow.width * 0.8 + Layout.preferredHeight: sensorRow.height + Text { + anchors.centerIn: parent + text: display.type + "::" + display.identifier + } + } + Rectangle { + color: sensorRow.rowColor + Layout.preferredWidth: sensorRow.width * 0.2 + Layout.preferredHeight: sensorRow.height + Text { + anchors.centerIn: parent + text: display.active ? qsTr("Active") : qsTr("Inactive") + } + } + } + MouseArea { + anchors.fill: parent + onClicked: sensorsView.currentIndex = index + } + } + } + } + + SensorPropertyModel { + id: propertyModel + sensor: availableSensorsModel.get(sensorsView.currentIndex) + } + + Button { + id: activateButton + Layout.preferredHeight: 30 + Layout.alignment: Qt.AlignCenter + enabled: propertyModel.sensor + text: !propertyModel.sensor ? qsTr("Select sensor") + : (propertyModel.sensor.active ? qsTr("Deactivate sensor") + : qsTr("Activate sensor")) + onClicked: propertyModel.sensor.active = !propertyModel.sensor.active + } + + GroupBox { + title: qsTr("Selected sensor's properties") + Layout.preferredWidth: window.width - 4 // 4 = 2x2 margins + Layout.preferredHeight: window.height * 0.55 - activateButton.height + Layout.margins: 2 + enabled: sensorsView.currentIndex != -1 + + TableView { + id: propertyView + anchors.fill: parent + model: propertyModel + columnSpacing: 1 + rowSpacing: 1 + boundsMovement: Flickable.StopAtBounds + clip: true + + delegate: Rectangle { + implicitHeight: 30 + implicitWidth: propertyView.width * 0.5 + color: (model.row % 2 == 0) ? "#CCCCCC" : "#AAAAAA" + Text { + anchors.centerIn: parent + text: display + } + } + } + } + } +} diff --git a/tests/manual/sensor_explorer_qml/sensormodels.cpp b/tests/manual/sensor_explorer_qml/sensormodels.cpp new file mode 100644 index 00000000..36de4412 --- /dev/null +++ b/tests/manual/sensor_explorer_qml/sensormodels.cpp @@ -0,0 +1,185 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "sensormodels.h" +#include "qsensor.h" +#include "qorientationsensor.h" +#include <QtCore/QDebug> +#include <qsensor.h> +#include <QMetaObject> +#include <QMetaProperty> + +QT_BEGIN_NAMESPACE + +QByteArray rangelistToByteArray(const qrangelist& list) +{ + QStringList ranges; + for (const qrange &r : list) { + if (r.first == r.second) + ranges << QString("%1 Hz").arg(r.first); + else + ranges << QString("%1-%2 Hz").arg(r.first).arg(r.second); + } + if (ranges.size() > 0) + return ranges.join(", ").toLatin1(); + return "-"; +} + +QByteArray outputrangelistToByteArray(const qoutputrangelist& list) +{ + QStringList ranges; + for (const qoutputrange &r : list) { + ranges << QString("(%1, %2) += %3").arg(r.minimum).arg(r.maximum).arg(r.accuracy); + } + if (ranges.size() > 0) + return ranges.join(", ").toLatin1(); + return "-"; +} + +AvailableSensorsModel::AvailableSensorsModel(QObject* parent) : QAbstractListModel(parent) +{ + // Some valuetypes do not convert nicely to presentable strings, add converters for them + QMetaType::registerConverter<qrangelist, QByteArray>(rangelistToByteArray); + QMetaType::registerConverter<qoutputrangelist, QByteArray>(outputrangelistToByteArray); + + // Populate the available sensors list + loadSensors(); +} + +/* + Load all available sensors and store them in a list. +*/ +void AvailableSensorsModel::loadSensors() +{ + beginResetModel(); + m_availableSensors.clear(); + + for (const QByteArray &type : QSensor::sensorTypes()) { + for (const QByteArray &identifier : QSensor::sensorsForType(type)) { + QSensor* sensor = new QSensor(type, this); + sensor->setIdentifier(identifier); + // Don't put in sensors we can't connect to + if (!sensor->connectToBackend()) + continue; + m_availableSensors.append(sensor); + } + } + endResetModel(); +} + +int AvailableSensorsModel::rowCount(const QModelIndex&) const +{ + return m_availableSensors.size(); +} + +QVariant AvailableSensorsModel::data(const QModelIndex &index, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + return QVariant::fromValue<QSensor*>(m_availableSensors.at(index.row())); +} + +QSensor* AvailableSensorsModel::get(int index) const +{ + if (index < 0 || index >= m_availableSensors.size()) + return nullptr; + return m_availableSensors[index]; +} + +// -- SensorPropertyModel + +static QSet<QByteArray> ignoredProperties = {"reading", "identifier", "active", + "connectedToBackend", "busy"}; + +SensorPropertyModel::SensorPropertyModel(QObject* parent) : QAbstractTableModel(parent) +{ +} + +int SensorPropertyModel::rowCount(const QModelIndex&) const +{ + if (!m_sensor) + return 0; + return m_values.size(); +} + +int SensorPropertyModel::columnCount(const QModelIndex&) const +{ + return 2; // 2 = property name + value columns +} + +QVariant SensorPropertyModel::data(const QModelIndex &index, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + return (index.column() == 0) ? std::get<0>(m_values.at(index.row())) + : std::get<1>(m_values.at(index.row())); +} + +void SensorPropertyModel::setSensor(QSensor *sensor) +{ + if (m_sensor == sensor) + return; + if (m_sensor) + m_sensor->disconnect(this); + m_sensor = sensor; + + beginResetModel(); + m_values.clear(); + if (m_sensor) { + // Use metobject to read the available properties. This allows the model to support all + // available sensors without knowing their properties in advance / compile-time. + + // 1. Read properties of the 'reading' object if available + int firstProperty = QSensorReading::staticMetaObject.propertyOffset(); + QSensorReading *reading = m_sensor->reading(); + if (reading) { + const QMetaObject *mo = reading->metaObject(); + for (int i = firstProperty; i < mo->propertyCount(); ++i) { + QByteArray name = mo->property(i).name(); + m_values.append(std::tuple<QByteArray, QByteArray> + (name, reading->property(name).toByteArray())); + } + } + + // 2. Read properties of the 'sensor' object + const QMetaObject *mo1 = m_sensor->metaObject(); + firstProperty = QSensorReading::staticMetaObject.propertyOffset(); + for (int i = firstProperty; i < mo1->propertyCount(); ++i) { + QByteArray name = mo1->property(i).name(); + if (ignoredProperties.contains(name)) + continue; + m_values.append(std::tuple<QByteArray, QByteArray> + (name, m_sensor->property(name).toByteArray())); + } + QObject::connect(m_sensor, &QSensor::readingChanged, + this, &SensorPropertyModel::onReadingChanged); + } + endResetModel(); + emit sensorChanged(); +} + +QSensor* SensorPropertyModel::sensor() const +{ + return m_sensor; +} + +void SensorPropertyModel::onReadingChanged() +{ + QSensorReading *reading = m_sensor->reading(); + const QMetaObject *mo = reading->metaObject(); + int firstProperty = QSensorReading::staticMetaObject.propertyOffset(); + + int valueMapIndex = 0; + for (int i = firstProperty; i < mo->propertyCount(); ++i) { + QByteArray name = mo->property(i).name(); + // Update the value and signal the change. Note: here we rely that the "reading" + // properties are first on the m_values, and in same order as after the initial + // population. This should be true as we access the static metabobject (dynamic + // property changes shouldn't impact) + m_values[valueMapIndex++] = std::tuple<QByteArray, QByteArray> + (name, reading->property(name).toByteArray()); + } + emit dataChanged(createIndex(0,1), createIndex(valueMapIndex,1), {Qt::DisplayRole}); +} + +QT_END_NAMESPACE diff --git a/tests/manual/sensor_explorer_qml/sensormodels.h b/tests/manual/sensor_explorer_qml/sensormodels.h new file mode 100644 index 00000000..4f16d6fd --- /dev/null +++ b/tests/manual/sensor_explorer_qml/sensormodels.h @@ -0,0 +1,61 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef QSEONSOREXPLORER_H +#define QSEONSOREXPLORER_H + +#include <QtSensors/qsensor.h> + +#include <QtQml/qqml.h> +#include <QtCore/QAbstractListModel> +#include <QtCore/QAbstractTableModel> + +QT_BEGIN_NAMESPACE + +class AvailableSensorsModel: public QAbstractListModel +{ + Q_OBJECT + QML_ELEMENT +public: + explicit AvailableSensorsModel(QObject* parent = nullptr); + int rowCount(const QModelIndex & = QModelIndex()) const override; + QVariant data(const QModelIndex &index, int role) const override; + Q_INVOKABLE QSensor* get(int index) const; + +private: + void loadSensors(); + QList<QSensor*> m_availableSensors; +}; + +class SensorPropertyModel: public QAbstractTableModel +{ + Q_OBJECT + Q_PROPERTY(QSensor* sensor READ sensor WRITE setSensor NOTIFY sensorChanged) + QML_ELEMENT + +public: + explicit SensorPropertyModel(QObject* parent = nullptr); + + int rowCount(const QModelIndex & = QModelIndex()) const override; + int columnCount(const QModelIndex & = QModelIndex()) const override; + QVariant data(const QModelIndex &index, int role) const override; + + void setSensor(QSensor* sensor); + QSensor* sensor() const; + +signals: + void sensorChanged(); + +private slots: + void onReadingChanged(); + +private: + QSensor* m_sensor = nullptr; + // m_values is used to cache sensor property values to avoid + // full metaobject iteration on every sensor reading change + QList<std::tuple<QByteArray, QByteArray>> m_values; +}; + +QT_END_NAMESPACE + +#endif // QSEONSOREXPLORER_H diff --git a/tests/manual/sensor_explorer_widgets/CMakeLists.txt b/tests/manual/sensor_explorer_widgets/CMakeLists.txt new file mode 100644 index 00000000..357eb02e --- /dev/null +++ b/tests/manual/sensor_explorer_widgets/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## sensor_explorer Binary: +##################################################################### + +qt_internal_add_manual_test(tst_manual_sensor_explorer_widgets + GUI + SOURCES + explorer.cpp explorer.h explorer.ui + main.cpp + LIBRARIES + Qt::Sensors + Qt::Widgets + ENABLE_AUTOGEN_TOOLS + uic +) diff --git a/tests/manual/sensor_explorer/explorer.cpp b/tests/manual/sensor_explorer_widgets/explorer.cpp index d2a85f91..16a4582b 100644 --- a/tests/manual/sensor_explorer/explorer.cpp +++ b/tests/manual/sensor_explorer_widgets/explorer.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "explorer.h" #include <QTimer> @@ -62,9 +37,9 @@ void Explorer::loadSensors() // Clear out anything that's in there now ui.sensors->clear(); - foreach (const QByteArray &type, QSensor::sensorTypes()) { + for (const QByteArray &type : QSensor::sensorTypes()) { qDebug() << "Found type" << type; - foreach (const QByteArray &identifier, QSensor::sensorsForType(type)) { + for (const QByteArray &identifier : QSensor::sensorsForType(type)) { qDebug() << "Found identifier" << identifier; // Don't put in sensors we can't connect to QSensor sensor(type); @@ -158,6 +133,8 @@ void Explorer::loadReading() { // Probe the reading using Qt's meta-object facilities QSensorReading *reading = m_sensor->reading(); + if (!reading) + return; const QMetaObject *mo = reading->metaObject(); int firstProperty = QSensorReading::staticMetaObject.propertyOffset(); @@ -173,9 +150,9 @@ void Explorer::loadReading() index = new QTableWidgetItem(QVariant(row - 1).toString()); QTableWidgetItem *prop = new QTableWidgetItem(mo->property(i).name()); QString typeName = QLatin1String(mo->property(i).typeName()); - int crap = typeName.lastIndexOf("::"); - if (crap != -1) - typeName = typeName.mid(crap + 2); + int delimiter = typeName.lastIndexOf("::"); + if (delimiter != -1) + typeName = typeName.mid(delimiter + 2); QTableWidgetItem *type = new QTableWidgetItem(typeName); QTableWidgetItem *value = new QTableWidgetItem(); @@ -222,16 +199,16 @@ void Explorer::loadSensorProperties() } QTableWidgetItem *prop = new QTableWidgetItem(name); QString typeName = QLatin1String(mo->property(i).typeName()); - int crap = typeName.lastIndexOf("::"); - if (crap != -1) - typeName = typeName.mid(crap + 2); + int delimiter = typeName.lastIndexOf("::"); + if (delimiter != -1) + typeName = typeName.mid(delimiter + 2); QTableWidgetItem *type = new QTableWidgetItem(typeName); QVariant v = mo->property(i).read(m_sensor); QString val; if (typeName == "qrangelist") { qrangelist rl = v.value<qrangelist>(); QStringList out; - foreach (const qrange &r, rl) { + for (const qrange &r : rl) { if (r.first == r.second) out << QString("%1 Hz").arg(r.first); else @@ -241,9 +218,8 @@ void Explorer::loadSensorProperties() } else if (typeName == "qoutputrangelist") { qoutputrangelist rl = v.value<qoutputrangelist>(); QStringList out; - foreach (const qoutputrange &r, rl) { + for (const qoutputrange &r : rl) out << QString("(%1, %2) += %3").arg(r.minimum).arg(r.maximum).arg(r.accuracy); - } val = out.join(", "); } else { val = v.toString(); @@ -371,9 +347,9 @@ bool Explorer::filter(QSensorReading *reading) for (int i = firstProperty; i < mo->propertyCount(); ++i) { int row = i - firstProperty; QString typeName = QLatin1String(mo->property(i).typeName()); - int crap = typeName.lastIndexOf("::"); - if (crap != -1) - typeName = typeName.mid(crap + 2); + int delimiter = typeName.lastIndexOf("::"); + if (delimiter != -1) + typeName = typeName.mid(delimiter + 2); QLatin1String name(mo->property(i).name()); QTableWidgetItem *value = ui.reading->item(row, 3); QVariant val = mo->property(i).read(reading); diff --git a/tests/manual/sensor_explorer_widgets/explorer.h b/tests/manual/sensor_explorer_widgets/explorer.h new file mode 100644 index 00000000..05e200f3 --- /dev/null +++ b/tests/manual/sensor_explorer_widgets/explorer.h @@ -0,0 +1,47 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef EXPLORER_H +#define EXPLORER_H + +#include <QMainWindow> +#include <ui_explorer.h> +#include <qsensor.h> + + +class Explorer : public QMainWindow, public QSensorFilter +{ + Q_OBJECT +public: + Explorer(QWidget *parent = 0); + ~Explorer(); + + bool filter(QSensorReading *reading) override; + +private slots: + void loadSensors(); + void on_sensors_currentItemChanged(); + void on_sensorprops_itemChanged(QTableWidgetItem *item); + void on_start_clicked(); + void on_stop_clicked(); + void sensor_changed(); + void adjustSizes(); + void loadSensorProperties(); + +private: + void showEvent(QShowEvent *event) override; + void resizeEvent(QResizeEvent *event) override; + + void clearReading(); + void loadReading(); + void clearSensorProperties(); + void adjustTableColumns(QTableWidget *table); + void resizeSensors(); + + Ui::Explorer ui; + QSensor *m_sensor; + bool ignoreItemChanged; +}; + +#endif + diff --git a/tests/manual/sensor_explorer/explorer.ui b/tests/manual/sensor_explorer_widgets/explorer.ui index 166e9c36..166e9c36 100644 --- a/tests/manual/sensor_explorer/explorer.ui +++ b/tests/manual/sensor_explorer_widgets/explorer.ui diff --git a/tests/manual/sensor_explorer_widgets/main.cpp b/tests/manual/sensor_explorer_widgets/main.cpp new file mode 100644 index 00000000..005ec17d --- /dev/null +++ b/tests/manual/sensor_explorer_widgets/main.cpp @@ -0,0 +1,13 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "explorer.h" + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + Explorer explorer; + explorer.show(); + return app.exec(); +} + diff --git a/tests/manual/sensorclerk/CMakeLists.txt b/tests/manual/sensorclerk/CMakeLists.txt new file mode 100644 index 00000000..18a487b3 --- /dev/null +++ b/tests/manual/sensorclerk/CMakeLists.txt @@ -0,0 +1,28 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## sensorclerk Binary: +##################################################################### + +qt_internal_add_manual_test(tst_manual_sensor_clerk + GUI + SOURCES + collector.cpp collector.h + main.cpp + LIBRARIES + Qt::Gui + Qt::Quick + Qt::Sensors +) + +set(qml_files + "qml/main.qml" +) + +qt_internal_add_resource(tst_manual_sensor_clerk "qml_files" + PREFIX + "/" + FILES + ${qml_files} +) diff --git a/tests/manual/sensorclerk/collector.cpp b/tests/manual/sensorclerk/collector.cpp index 98e1ccad..4ebc7203 100644 --- a/tests/manual/sensorclerk/collector.cpp +++ b/tests/manual/sensorclerk/collector.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Lorn Potter. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Lorn Potter. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtQml/qqml.h> #include <QtCore/QFile> @@ -135,7 +110,7 @@ void Collector::startCollecting() { if (dataFile.exists()) { fileCounter++; - for (int i = 0; i < fileCounter; i++) { + for (size_t i = 0; i < fileCounter; i++) { if (!QFileInfo(QString(QDir::tempPath()+"/sensordump_%1.dat").arg(fileCounter)).exists()) dataFile.setFileName(QString(QDir::tempPath()+"/sensordump_%1.dat").arg(fileCounter)); break; diff --git a/tests/manual/sensorclerk/collector.h b/tests/manual/sensorclerk/collector.h index 855c5843..0f1098c9 100644 --- a/tests/manual/sensorclerk/collector.h +++ b/tests/manual/sensorclerk/collector.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Lorn Potter. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Lorn Potter. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef COLLECTOR_H #define COLLECTOR_H @@ -68,7 +43,7 @@ private: QFile dataFile; bool isActive; - int fileCounter; + size_t fileCounter; Q_DISABLE_COPY(Collector) }; diff --git a/tests/manual/sensorclerk/main.cpp b/tests/manual/sensorclerk/main.cpp index 9265dcc8..468f1d88 100644 --- a/tests/manual/sensorclerk/main.cpp +++ b/tests/manual/sensorclerk/main.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Lorn Potter. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Lorn Potter. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QGuiApplication> #include <QtQuick/QQuickView> @@ -40,7 +15,7 @@ int main( int argc, char** argv ) qmlRegisterType<Collector>("Collector", 1, 0, "Collector"); QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); - view.setSource( QUrl( "qml/main.qml" ) ); + view.setSource(QUrl("qrc:qml/main.qml")); view.show(); return app.exec(); } diff --git a/tests/manual/sensorclerk/qml/Button.qml b/tests/manual/sensorclerk/qml/Button.qml deleted file mode 100644 index 0889e07b..00000000 --- a/tests/manual/sensorclerk/qml/Button.qml +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//Import the declarative plugins -import QtQuick 2.0 - -//Implementation of the Button control. -Item { - id: button - width: 250 - height: 150 - property alias text: innerText.text; - property color color: "white" - property color hoverColor: "#aaaaaa" - property color pressColor: "slategray" - property int fontSize: 10 - property int borderWidth: 1 - property int borderRadius: 2 - scale: state === "Pressed" ? 0.96 : 1.0 - onEnabledChanged: state = "" - signal clicked - - //define a scale animation - Behavior on scale { - NumberAnimation { - duration: 100 - easing.type: Easing.InOutQuad - } - } - - //Rectangle to draw the button - Rectangle { - id: rectangleButton - anchors.fill: parent - radius: borderRadius - color: button.enabled ? button.color : "grey" - border.width: borderWidth - border.color: "black" - - Text { - id: innerText - font.pointSize: fontSize - anchors.centerIn: parent - } - } - - //change the color of the button in differen button states - states: [ - State { - name: "Hovering" - PropertyChanges { - target: rectangleButton - color: hoverColor - } - }, - State { - name: "Pressed" - PropertyChanges { - target: rectangleButton - color: pressColor - } - } - ] - - //define transmission for the states - transitions: [ - Transition { - from: ""; to: "Hovering" - ColorAnimation { duration: 200 } - }, - Transition { - from: "*"; to: "Pressed" - ColorAnimation { duration: 10 } - } - ] - - //Mouse area to react on click events - MouseArea { - hoverEnabled: true - anchors.fill: button - onEntered: { button.state='Hovering'} - onExited: { button.state=''} - onClicked: { button.clicked();} - onPressed: { button.state="Pressed" } - onReleased: { - if (containsMouse) - button.state="Hovering"; - else - button.state=""; - } - } -} diff --git a/tests/manual/sensorclerk/qml/main.qml b/tests/manual/sensorclerk/qml/main.qml index e8b74ff2..0853599c 100644 --- a/tests/manual/sensorclerk/qml/main.qml +++ b/tests/manual/sensorclerk/qml/main.qml @@ -1,34 +1,9 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Lorn Potter. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import Collector 1.0 -import QtSensors 5.0 +// Copyright (C) 2017 Lorn Potter. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only +import QtQuick +import QtQuick.Controls +import Collector +import QtSensors Rectangle { Collector { @@ -47,7 +22,7 @@ Rectangle { property bool depressed: false anchors.top: label.bottom enabled: true; - anchors.horizontalCenter: parent + anchors.horizontalCenter: parent.horizontalCenter onClicked: { if (!depressed) { writer.startCollecting() diff --git a/tests/manual/sensorclerk/sensorclerk.pro b/tests/manual/sensorclerk/sensorclerk.pro deleted file mode 100644 index 61eeef15..00000000 --- a/tests/manual/sensorclerk/sensorclerk.pro +++ /dev/null @@ -1,11 +0,0 @@ -TEMPLATE = app - -QT += quick sensors - -SOURCES += main.cpp \ - collector.cpp - -HEADERS += collector.h - -OTHER_FILES += qml/main.qml \ - qml/Button.qml |