summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2019-04-26 16:02:30 +0200
committerpaolo <paolo.angelelli@qt.io>2019-07-18 14:54:51 +0200
commitf13a93cf4c6f874e9d737e83182e0ab6aadb7de0 (patch)
tree8a5faf1a619a194ca6148be4cbd45f3c4869aba6
parent436d103654ec3382669625128fc6d074b10f03ff (diff)
downloadqtlocation-f13a93cf4c6f874e9d737e83182e0ab6aadb7de0.tar.gz
Support specifying serial port via PluginParameter in serialnmea plugin
This patch supports the serialnmea.serial_port plugin parameter. Task-number: QTBUG-66304 Change-Id: I1d1e3083f50c25e2ba2fd24ddb300e73b1f883f9 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/plugins/position/serialnmea/qgeopositioninfosourcefactory_serialnmea.cpp33
-rw-r--r--src/plugins/position/serialnmea/qgeopositioninfosourcefactory_serialnmea.h8
2 files changed, 33 insertions, 8 deletions
diff --git a/src/plugins/position/serialnmea/qgeopositioninfosourcefactory_serialnmea.cpp b/src/plugins/position/serialnmea/qgeopositioninfosourcefactory_serialnmea.cpp
index 58092ea3..043f7682 100644
--- a/src/plugins/position/serialnmea/qgeopositioninfosourcefactory_serialnmea.cpp
+++ b/src/plugins/position/serialnmea/qgeopositioninfosourcefactory_serialnmea.cpp
@@ -49,18 +49,22 @@ Q_LOGGING_CATEGORY(lcSerial, "qt.positioning.serialnmea")
class NmeaSource : public QNmeaPositionInfoSource
{
public:
- NmeaSource(QObject *parent);
+ NmeaSource(QObject *parent, const QVariantMap &parameters);
bool isValid() const { return !m_port.isNull(); }
private:
QScopedPointer<QSerialPort> m_port;
};
-NmeaSource::NmeaSource(QObject *parent)
+NmeaSource::NmeaSource(QObject *parent, const QVariantMap &parameters)
: QNmeaPositionInfoSource(RealTimeMode, parent),
m_port(new QSerialPort)
{
- QByteArray requestedPort = qgetenv("QT_NMEA_SERIAL_PORT");
+ QByteArray requestedPort;
+ if (parameters.contains(QStringLiteral("serialnmea.serial_port")))
+ requestedPort = parameters.value(QStringLiteral("serialnmea.serial_port")).toString().toLatin1();
+ else
+ requestedPort = qgetenv("QT_NMEA_SERIAL_PORT");
if (requestedPort.isEmpty()) {
const QList<QSerialPortInfo> ports = QSerialPortInfo::availablePorts();
qCDebug(lcSerial) << "Found" << ports.count() << "serial ports";
@@ -110,18 +114,35 @@ NmeaSource::NmeaSource(QObject *parent)
QGeoPositionInfoSource *QGeoPositionInfoSourceFactorySerialNmea::positionInfoSource(QObject *parent)
{
- QScopedPointer<NmeaSource> src(new NmeaSource(parent));
- return src->isValid() ? src.take() : nullptr;
+ return positionInfoSourceWithParameters(parent, QVariantMap());
}
QGeoSatelliteInfoSource *QGeoPositionInfoSourceFactorySerialNmea::satelliteInfoSource(QObject *parent)
{
+ return satelliteInfoSourceWithParameters(parent, QVariantMap());
+}
+
+QGeoAreaMonitorSource *QGeoPositionInfoSourceFactorySerialNmea::areaMonitor(QObject *parent)
+{
+ return areaMonitorWithParameters(parent, QVariantMap());
+}
+
+QGeoPositionInfoSource *QGeoPositionInfoSourceFactorySerialNmea::positionInfoSourceWithParameters(QObject *parent, const QVariantMap &parameters)
+{
+ QScopedPointer<NmeaSource> src(new NmeaSource(parent, parameters));
+ return src->isValid() ? src.take() : nullptr;
+}
+
+QGeoSatelliteInfoSource *QGeoPositionInfoSourceFactorySerialNmea::satelliteInfoSourceWithParameters(QObject *parent, const QVariantMap &parameters)
+{
Q_UNUSED(parent);
+ Q_UNUSED(parameters)
return nullptr;
}
-QGeoAreaMonitorSource *QGeoPositionInfoSourceFactorySerialNmea::areaMonitor(QObject *parent)
+QGeoAreaMonitorSource *QGeoPositionInfoSourceFactorySerialNmea::areaMonitorWithParameters(QObject *parent, const QVariantMap &parameters)
{
Q_UNUSED(parent);
+ Q_UNUSED(parameters)
return nullptr;
}
diff --git a/src/plugins/position/serialnmea/qgeopositioninfosourcefactory_serialnmea.h b/src/plugins/position/serialnmea/qgeopositioninfosourcefactory_serialnmea.h
index e372d56f..c8ca0e7e 100644
--- a/src/plugins/position/serialnmea/qgeopositioninfosourcefactory_serialnmea.h
+++ b/src/plugins/position/serialnmea/qgeopositioninfosourcefactory_serialnmea.h
@@ -43,17 +43,21 @@
#include <QObject>
#include <qgeopositioninfosourcefactory.h>
-class QGeoPositionInfoSourceFactorySerialNmea : public QObject, public QGeoPositionInfoSourceFactory
+class QGeoPositionInfoSourceFactorySerialNmea : public QObject, public QGeoPositionInfoSourceFactoryV2
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.qt.position.sourcefactory/5.0"
FILE "plugin.json")
- Q_INTERFACES(QGeoPositionInfoSourceFactory)
+ Q_INTERFACES(QGeoPositionInfoSourceFactoryV2)
public:
QGeoPositionInfoSource *positionInfoSource(QObject *parent);
QGeoSatelliteInfoSource *satelliteInfoSource(QObject *parent);
QGeoAreaMonitorSource *areaMonitor(QObject *parent);
+
+ QGeoPositionInfoSource *positionInfoSourceWithParameters(QObject *parent, const QVariantMap &parameters);
+ QGeoSatelliteInfoSource *satelliteInfoSourceWithParameters(QObject *parent, const QVariantMap &parameters);
+ QGeoAreaMonitorSource *areaMonitorWithParameters(QObject *parent, const QVariantMap &parameters);
};
#endif