Skip to content

Commit

Permalink
Qt5SerialPort optional
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed Nov 13, 2018
1 parent 3b97096 commit bfdb3ec
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
12 changes: 10 additions & 2 deletions CMakeLists.txt
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cmake_templates/qgsconfig.h.in
Expand Up @@ -69,5 +69,7 @@

#cmakedefine HAVE_QUICK

#cmakedefine HAVE_QT5SERIALPORT

#endif

7 changes: 6 additions & 1 deletion src/core/CMakeLists.txt
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/core/gps/qgsgpsconnection.cpp
Expand Up @@ -22,8 +22,6 @@
#include <QIODevice>
#include <QStringList>
#include <QFileInfo>
#include <QSerialPort>
#include <QSerialPortInfo>

#include "qgsnmeaconnection.h"
#include "qgslogger.h"
Expand Down
14 changes: 14 additions & 0 deletions src/core/gps/qgsgpsdetector.cpp
Expand Up @@ -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()
{
Expand All @@ -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() )
{
Expand Down Expand Up @@ -116,6 +126,7 @@ void QgsGpsDetector::advance()
}
else
{
#if defined( HAVE_QT5SERIALPORT )
QSerialPort *serial = new QSerialPort( mPortList.at( mPortIndex ).first );

serial->setBaudRate( mBaudList[ mBaudIndex ] );
Expand All @@ -132,6 +143,9 @@ void QgsGpsDetector::advance()
{
delete serial;
}
#else
qWarning( "QT5SERIALPORT not found and mPortList matches serial port, this should never happen" );
#endif
}
}

Expand Down
1 change: 0 additions & 1 deletion src/core/gps/qgsgpsdetector.h
Expand Up @@ -21,7 +21,6 @@
#include <QObject>
#include <QList>
#include <QPair>
#include <QSerialPort>

#include "qgis_core.h"

Expand Down

0 comments on commit bfdb3ec

Please sign in to comment.