Qt5SerialPort optional

This commit is contained in:
Peter Petrik 2018-10-10 18:05:45 +02:00
parent 3b97096202
commit bfdb3ec489
6 changed files with 32 additions and 6 deletions

View File

@ -316,6 +316,15 @@ IF(WITH_CORE)
#############################################################
# search for Qt5
SET(QT_MIN_VERSION 5.9.0)
# Use Qt5SerialPort optionally for GPS
SET (WITH_QT5SERIALPORT TRUE CACHE BOOL "Determines whether Qt5SerialPort should be tried for GPS positioning")
IF (WITH_QT5SERIALPORT)
FIND_PACKAGE(Qt5SerialPort REQUIRED)
# following variable is used in qgsconfig.h
SET (HAVE_QT5SERIALPORT TRUE)
ENDIF(WITH_QT5SERIALPORT)
FIND_PACKAGE(Qt5Core QUIET)
FIND_PACKAGE(Qt5Gui REQUIRED)
FIND_PACKAGE(Qt5Widgets REQUIRED)
@ -324,7 +333,6 @@ IF(WITH_CORE)
FIND_PACKAGE(Qt5Svg REQUIRED)
FIND_PACKAGE(Qt5Concurrent REQUIRED)
FIND_PACKAGE(Qt5PrintSupport REQUIRED)
FIND_PACKAGE(Qt5SerialPort REQUIRED)
FIND_PACKAGE(Qt5Positioning)
IF (WITH_QTWEBKIT)
FIND_PACKAGE(Qt5WebKit REQUIRED)
@ -352,7 +360,7 @@ IF(WITH_CORE)
IF(${CMAKE_SYSTEM_NAME} MATCHES "Android")
FIND_PACKAGE(Qt5AndroidExtras)
ELSE(${CMAKE_SYSTEM_NAME} MATCHES "Android")
FIND_PACKAGE(QtQmlTools REQUIRED)
FIND_PACKAGE(QtQmlTools)
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Android")
# following variable is used in qgsconfig.h

View File

@ -69,5 +69,7 @@
#cmakedefine HAVE_QUICK
#cmakedefine HAVE_QT5SERIALPORT
#endif

View File

@ -1362,9 +1362,14 @@ TARGET_LINK_LIBRARIES(qgis_core
${SQLITE3_LIBRARY}
${SPATIALITE_LIBRARY}
${LIBZIP_LIBRARY}
Qt5::SerialPort
)
IF (Qt5SerialPort_FOUND)
TARGET_LINK_LIBRARIES(qgis_core
Qt5::SerialPort
)
ENDIF (Qt5SerialPort_FOUND)
IF (Qt5Positioning_FOUND)
TARGET_LINK_LIBRARIES(qgis_core
Qt5::Positioning

View File

@ -22,8 +22,6 @@
#include <QIODevice>
#include <QStringList>
#include <QFileInfo>
#include <QSerialPort>
#include <QSerialPortInfo>
#include "qgsnmeaconnection.h"
#include "qgslogger.h"

View File

@ -29,7 +29,11 @@
#include <QStringList>
#include <QFileInfo>
#include <QTimer>
#if defined( HAVE_QT5SERIALPORT )
#include <QSerialPortInfo>
#include <QSerialPort>
#endif
QList< QPair<QString, QString> > QgsGpsDetector::availablePorts()
{
@ -43,10 +47,13 @@ QList< QPair<QString, QString> > QgsGpsDetector::availablePorts()
// try local gpsd first
devs << QPair<QString, QString>( QStringLiteral( "localhost:2947:" ), tr( "local gpsd" ) );
// try serial ports
#if defined( HAVE_QT5SERIALPORT )
for ( auto p : QSerialPortInfo::availablePorts() )
{
devs << QPair<QString, QString>( p.portName(), tr( "%1: %2" ).arg( p.portName(), p.description() ) );
}
#endif
return devs;
}
@ -54,7 +61,10 @@ QList< QPair<QString, QString> > QgsGpsDetector::availablePorts()
QgsGpsDetector::QgsGpsDetector( const QString &portName )
{
mConn = nullptr;
#if defined( HAVE_QT5SERIALPORT )
mBaudList << QSerialPort::Baud4800 << QSerialPort::Baud9600 << QSerialPort::Baud38400 << QSerialPort::Baud57600 << QSerialPort::Baud115200; //add 57600 for SXBlueII GPS unit
#endif
if ( portName.isEmpty() )
{
@ -116,6 +126,7 @@ void QgsGpsDetector::advance()
}
else
{
#if defined( HAVE_QT5SERIALPORT )
QSerialPort *serial = new QSerialPort( mPortList.at( mPortIndex ).first );
serial->setBaudRate( mBaudList[ mBaudIndex ] );
@ -132,6 +143,9 @@ void QgsGpsDetector::advance()
{
delete serial;
}
#else
qWarning( "QT5SERIALPORT not found and mPortList matches serial port, this should never happen" );
#endif
}
}

View File

@ -21,7 +21,6 @@
#include <QObject>
#include <QList>
#include <QPair>
#include <QSerialPort>
#include "qgis_core.h"