Skip to content
Permalink
Browse files

Qt5SerialPort optional

  • Loading branch information
PeterPetrik committed Oct 10, 2018
1 parent 3b97096 commit bfdb3ec4890e2a5b164c085d7fc52d7d881b132d
@@ -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
@@ -69,5 +69,7 @@

#cmakedefine HAVE_QUICK

#cmakedefine HAVE_QT5SERIALPORT

#endif

@@ -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
@@ -22,8 +22,6 @@
#include <QIODevice>
#include <QStringList>
#include <QFileInfo>
#include <QSerialPort>
#include <QSerialPortInfo>

#include "qgsnmeaconnection.h"
#include "qgslogger.h"
@@ -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,18 +47,24 @@ 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;
}

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
}
}

@@ -21,7 +21,6 @@
#include <QObject>
#include <QList>
#include <QPair>
#include <QSerialPort>

#include "qgis_core.h"

0 comments on commit bfdb3ec

Please sign in to comment.
You can’t perform that action at this time.