summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@insta.fi>2021-08-17 11:32:17 +0300
committerJuha Vuolle <juha.vuolle@insta.fi>2021-08-18 13:46:35 +0300
commitdcf80c8bc52d8c74cb20c1e42abfd85d7eb89aef (patch)
tree8a00975e0392c575d78b22acd327bfbb3a597fab
parentdb9f0807ac3a7edccf46d845dac65aa13caff461 (diff)
Update make_sensor.pl script to Qt 6
The make_sensor script can be used to create new sensor frontends. This commit updates the script from Qt 5 => Qt 6. Pick-to: 6.2 Task-number: QTBUG-92939 Change-Id: Idda4f0eb5f34b4fd9deec7008c4adb444f454a82 Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
-rwxr-xr-xsrc/sensors/make_sensor.pl86
1 files changed, 56 insertions, 30 deletions
diff --git a/src/sensors/make_sensor.pl b/src/sensors/make_sensor.pl
index 5f9a6e62..289e0dd7 100755
--- a/src/sensors/make_sensor.pl
+++ b/src/sensors/make_sensor.pl
@@ -1,7 +1,7 @@
#!/usr/bin/perl
#############################################################################
##
-## Copyright (C) 2016 The Qt Company Ltd.
+## Copyright (C) 2021 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of the QtSensors module of the Qt Toolkit.
@@ -38,6 +38,25 @@
##
#############################################################################
+# About this script
+#
+# The make_sensor.pl creates new sensor frontend placeholder implementations.
+# Both C++ and QML classes are generated. As the script makes assumptions on the
+# naming conventions and source file locations, the main
+# intended use case is adding new sensor frontends to the QtSensors module.
+#
+# To run the script, provide the sensor name starting with 'Q' as an argument
+# (here "QFlow"):
+#
+# perl make_sensor.pl QFlow
+#
+# This will generate the following files:
+# ../sensorsquick/qmlflow_p.h
+# ../sensorsquick/qmlflow.cpp
+# qflow_p.h
+# qflow.h
+# qflow.cpp
+
use strict;
use warnings;
@@ -75,8 +94,8 @@ $qmlfilebase = "qml".$qmlfilebase;
my $pheader = $filebase."_p.h";
my $header = $filebase.".h";
my $source = $filebase.".cpp";
-my $qmlsource = "../imports/sensors/".$qmlfilebase.".cpp";
-my $qmlheader = "../imports/sensors/".$qmlfilebase.".h";
+my $qmlsource = "../sensorsquick/".$qmlfilebase.".cpp";
+my $qmlheader = "../sensorsquick/".$qmlfilebase."_p.h";
my $pguard = uc($pheader);
$pguard =~ s/\./_/g;
@@ -93,45 +112,53 @@ if (! -e $qmlheader) {
#ifndef '.$qmlguard.'
#define '.$qmlguard.'
-#include "qmlsensor.h"
+#include "qmlsensor_p.h"
QT_BEGIN_NAMESPACE
class '.$sensor.';
-class '.$qmlsensor.' : public QmlSensor
+class Q_SENSORSQUICK_PRIVATE_EXPORT '.$qmlsensor.' : public QmlSensor
{
Q_OBJECT
+ QML_NAMED_ELEMENT('.$no_q_sensor.')
+ QML_ADDED_IN_VERSION(6,2) // CHANGE VERSION
public:
explicit '.$qmlsensor.'(QObject *parent = 0);
~'.$qmlsensor.'();
-private:
QSensor *sensor() const override;
+
+private:
QmlSensorReading *createReading() const override;
'.$sensor.' *m_sensor;
};
-class '.$qmlreading.' : public QmlSensorReading
+class Q_SENSORSQUICK_PRIVATE_EXPORT '.$qmlreading.' : public QmlSensorReading
{
Q_OBJECT
- Q_PROPERTY(qreal prop1 READ prop1 NOTIFY prop1Changed)
+ Q_PROPERTY(qreal myprop READ myprop NOTIFY mypropChanged BINDABLE bindableMyprop)
+ QML_NAMED_ELEMENT('.$no_q_reading.')
+ QML_UNCREATABLE("Cannot create '.$no_q_reading.'")
+ QML_ADDED_IN_VERSION(6,2) // CHANGE VERSION
public:
explicit '.$qmlreading.'('.$sensor.' *sensor);
~'.$qmlreading.'();
- qreal prop1() const;
+ qreal myprop() const;
+ QBindable<qreal> bindableMyprop() const;
Q_SIGNALS:
- void prop1Changed();
+ void mypropChanged();
private:
QSensorReading *reading() const override;
void readingUpdate() override;
'.$sensor.' *m_sensor;
- qreal m_prop1;
+ Q_OBJECT_BINDABLE_PROPERTY('.$qmlreading.', qreal,
+ m_myprop, &'.$qmlreading.'::mypropChanged);
};
QT_END_NAMESPACE
@@ -144,7 +171,7 @@ if (! -e $qmlsource) {
print "Creating $qmlsource\n";
open OUT, ">$qmlsource" or die $!;
print OUT '
-#include "qml'.lc($no_q_sensor).'.h"
+#include "qml'.lc($no_q_sensor).'_p.h"
#include <'.$sensor.'>
/*!
@@ -152,7 +179,7 @@ if (! -e $qmlsource) {
\instantiates '.$qmlsensor.'
\ingroup qml-sensors_type
\inqmlmodule QtSensors
- \since QtSensors 5.[INSERT VERSION HERE]
+ \since QtSensors 6.[INSERT VERSION HERE]
\inherits Sensor
\brief The '.$no_q_sensor.' element reports on fubbleness.
@@ -189,7 +216,7 @@ QSensor *'.$qmlsensor.'::sensor() const
\instantiates '.$qmlreading.'
\ingroup qml-sensors_reading
\inqmlmodule QtSensors
- \since QtSensors 5.[INSERT VERSION HERE]
+ \since QtSensors 6.[INSERT VERSION HERE]
\inherits SensorReading
\brief The '.$no_q_reading.' element holds the most recent '.$no_q_sensor.' reading.
@@ -202,9 +229,7 @@ QSensor *'.$qmlsensor.'::sensor() const
*/
'.$qmlreading.'::'.$qmlreading.'('.$sensor.' *sensor)
- : QmlSensorReading(sensor)
- , m_sensor(sensor)
- , m_prop1(0)
+ : m_sensor(sensor)
{
}
@@ -213,15 +238,20 @@ QSensor *'.$qmlsensor.'::sensor() const
}
/*!
- \qmlproperty qreal '.$no_q_reading.'::prop1
+ \qmlproperty qreal '.$no_q_reading.'::myprop
This property holds the fubble of the device.
- Please see '.$reading.'::prop1 for information about this property.
+ Please see '.$reading.'::myprop for information about this property.
*/
-qreal '.$qmlreading.'::prop1() const
+qreal '.$qmlreading.'::myprop() const
{
- return m_prop1;
+ return m_myprop;
+}
+
+QBindable<qreal> '.$qmlreading.'::bindableMyprop() const
+{
+ return &m_myprop;
}
QSensorReading *'.$qmlreading.'::reading() const
@@ -231,11 +261,7 @@ QSensorReading *'.$qmlreading.'::reading() const
void '.$qmlreading.'::readingUpdate()
{
- qreal prop1 = m_sensor->reading()->prop1();
- if (m_prop1 != prop1) {
- m_prop1 = prop1;
- Q_EMIT prop1Changed();
- }
+ m_myprop = m_sensor->reading()->myprop();
}
';
close OUT;
@@ -351,7 +377,7 @@ IMPLEMENT_READING('.$reading.')
\class '.$reading.'
\ingroup sensors_reading
\inmodule QtSensors
- \since 5.[INSERT VERSION HERE]
+ \since 6.[INSERT VERSION HERE]
\brief The '.$reading.' class holds readings from the [X] sensor.
@@ -389,7 +415,7 @@ void '.$reading.'::setMyprop(qreal myprop)
\class '.$filter.'
\ingroup sensors_filter
\inmodule QtSensors
- \since 5.[INSERT VERSION HERE]
+ \since 6.[INSERT VERSION HERE]
\brief The '.$filter.' class is a convenience wrapper around QSensorFilter.
@@ -416,7 +442,7 @@ char const * const '.$sensor.'::sensorType("'.$sensor.'");
\class '.$sensor.'
\ingroup sensors_type
\inmodule QtSensors
- \since 5.[INSERT VERSION HERE]
+ \since 6.[INSERT VERSION HERE]
\brief The '.$sensor.' class is a convenience wrapper around QSensor.
@@ -469,7 +495,7 @@ exit 0;
sub get_arg
{
if (scalar(@ARGV) == 0) {
- croak "Missing arg(s)";
+ croak "Missing sensor name argument (e.g. 'QFlow')";
}
return shift(@ARGV);
}