Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow Qt5::Positioning as alternative to QtMobility/QtLocation
  • Loading branch information
m-kuhn committed May 4, 2015
1 parent 72cfe46 commit 72eb1aa
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 16 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -242,6 +242,7 @@ IF (ENABLE_QT5)
FIND_PACKAGE(Qt5Svg REQUIRED)
FIND_PACKAGE(Qt5Concurrent REQUIRED)
FIND_PACKAGE(Qt5PrintSupport REQUIRED)
FIND_PACKAGE(Qt5Positioning)
FIND_PACKAGE(Qt5WebKit REQUIRED)
FIND_PACKAGE(Qt5WebKitWidgets REQUIRED)
FIND_PACKAGE(Qt5Test REQUIRED)
Expand Down
21 changes: 14 additions & 7 deletions src/core/CMakeLists.txt
Expand Up @@ -337,11 +337,11 @@ ELSE (WITH_INTERNAL_QEXTSERIALPORT)
INCLUDE_DIRECTORIES(${QEXTSERIALPORT_INCLUDE_DIR})
ENDIF (WITH_INTERNAL_QEXTSERIALPORT)

IF (QT_MOBILITY_LOCATION_FOUND)
IF (QT_MOBILITY_LOCATION_FOUND OR Qt5Positioning_FOUND)
SET(QGIS_CORE_SRCS ${QGIS_CORE_SRCS}
gps/qgsqtlocationconnection.cpp
)
ENDIF (QT_MOBILITY_LOCATION_FOUND)
ENDIF (QT_MOBILITY_LOCATION_FOUND OR Qt5Positioning_FOUND)

ADD_FLEX_FILES(QGIS_CORE_SRCS qgsexpressionlexer.ll)

Expand Down Expand Up @@ -450,11 +450,11 @@ IF (WITH_INTERNAL_QEXTSERIALPORT)
)
ENDIF (WITH_INTERNAL_QEXTSERIALPORT)

IF (QT_MOBILITY_LOCATION_FOUND)
IF (QT_MOBILITY_LOCATION_FOUND OR Qt5Positioning_FOUND)
SET(QGIS_CORE_MOC_HDRS ${QGIS_CORE_MOC_HDRS}
gps/qgsqtlocationconnection.h
)
ENDIF (QT_MOBILITY_LOCATION_FOUND)
ENDIF (QT_MOBILITY_LOCATION_FOUND OR Qt5Positioning_FOUND)

QT4_WRAP_CPP(QGIS_CORE_MOC_SRCS ${QGIS_CORE_MOC_HDRS})

Expand Down Expand Up @@ -666,11 +666,12 @@ SET(QGIS_CORE_HDRS
layertree/qgslayertreeutils.h
)

IF (QT_MOBILITY_LOCATION_FOUND)
IF (QT_MOBILITY_LOCATION_FOUND OR Qt5Positioning_FOUND)
SET(QGIS_CORE_HDRS ${QGIS_CORE_HDRS}
gps/qgsqtlocationconnection.h
gps/qgsgpsconnectionregistry.h
)
ENDIF (QT_MOBILITY_LOCATION_FOUND)
ENDIF (QT_MOBILITY_LOCATION_FOUND OR Qt5Positioning_FOUND)

INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
Expand Down Expand Up @@ -762,7 +763,7 @@ IF (NOT WITH_INTERNAL_QEXTSERIALPORT)
ENDIF (NOT WITH_INTERNAL_QEXTSERIALPORT)

IF (QT_MOBILITY_LOCATION_FOUND)
TARGET_LINK_LIBRARIES(qgis_core ${QT_MOBILITY_LOCATION_LIBRARY})
TARGET_LINK_LIBRARIES(qgis_core ${QT_MOBILITY_LOCATION_LIBRARY})
ENDIF (QT_MOBILITY_LOCATION_FOUND)

TARGET_LINK_LIBRARIES(qgis_core
Expand All @@ -783,6 +784,12 @@ TARGET_LINK_LIBRARIES(qgis_core
${SPATIALITE_LIBRARY}
)

IF (Qt5Positioning_FOUND)
TARGET_LINK_LIBRARIES(qgis_core
Qt5::Positioning
)
ENDIF (Qt5Positioning_FOUND)

# install

INSTALL(TARGETS qgis_core
Expand Down
6 changes: 3 additions & 3 deletions src/core/gps/qgsgpsdetector.cpp
Expand Up @@ -22,7 +22,7 @@
#include "qgsnmeaconnection.h"
#include "qgsgpsdconnection.h"

#ifdef HAVE_QT_MOBILITY_LOCATION
#if defined(HAVE_QT_MOBILITY_LOCATION ) || defined(QT_POSITIONING_LIB)
#include "qgsqtlocationconnection.h"
#endif

Expand All @@ -35,7 +35,7 @@ QList< QPair<QString, QString> > QgsGPSDetector::availablePorts()
QList< QPair<QString, QString> > devs;

// try local QtLocation first
#ifdef HAVE_QT_MOBILITY_LOCATION
#if defined(HAVE_QT_MOBILITY_LOCATION ) || defined(QT_POSITIONING_LIB)
devs << QPair<QString, QString>( "internalGPS", tr( "internal GPS" ) );
#endif
// try local gpsd first
Expand Down Expand Up @@ -155,7 +155,7 @@ void QgsGPSDetector::advance()
}
else if ( mPortList[ mPortIndex ].first.contains( "internalGPS" ) )
{
#ifdef HAVE_QT_MOBILITY_LOCATION
#if defined(HAVE_QT_MOBILITY_LOCATION ) || defined(QT_POSITIONING_LIB)
mConn = new QgsQtLocationConnection();
#else
qWarning( "QT_MOBILITY_LOCATION not found and mPortList matches internalGPS, this should never happen" );
Expand Down
16 changes: 14 additions & 2 deletions src/core/gps/qgsqtlocationconnection.cpp
Expand Up @@ -27,8 +27,8 @@ QgsQtLocationConnection::QgsQtLocationConnection(): QgsGPSConnection( new QLocal
//needed to fix https://sourceforge.net/p/necessitas/tickets/146/
qRegisterMetaType< QList<QGeoSatelliteInfo> >( "QList<QGeoSatelliteInfo>" );

startGPS();
startSatelliteMonitor();
startGPS();

//HACK to signal the gpsinformationwidget that we have a QtLocationConnection
QTimer::singleShot( 500, this, SLOT( broadcastConnectionAvailable() ) );
Expand Down Expand Up @@ -65,7 +65,6 @@ void QgsQtLocationConnection::parseData()
{
mStatus = GPSDataReceived;
//const QGeoPositionInfo &info = locationDataSource->lastKnownPosition();
qDebug() << mInfo;
if ( mInfo.isValid() )
{
// mInfo.HorizontalAccuracy;
Expand Down Expand Up @@ -110,7 +109,11 @@ void QgsQtLocationConnection::satellitesInViewUpdated(
QgsSatelliteInfo satelliteInfo;
satelliteInfo.azimuth = currentSatellite.attribute( QGeoSatelliteInfo::Azimuth );
satelliteInfo.elevation = currentSatellite.attribute( QGeoSatelliteInfo::Elevation );
#if defined(HAVE_QT_MOBILITY_LOCATION )
satelliteInfo.id = currentSatellite.prnNumber();
#else // QtPositioning
satelliteInfo.id = currentSatellite.satelliteIdentifier();
#endif
satelliteInfo.signal = currentSatellite.signalStrength();
mLastGPSInformation.satellitesInView.append( satelliteInfo );
}
Expand All @@ -130,13 +133,21 @@ void QgsQtLocationConnection::satellitesInUseUpdated(
{
QGeoSatelliteInfo currentSatellite = satellites.at( i );
//add pnr to mLastGPSInformation.satPrn
#if defined(HAVE_QT_MOBILITY_LOCATION )
mLastGPSInformation.satPrn.append( currentSatellite.prnNumber() );
#else // QtPositioning
mLastGPSInformation.satPrn.append( currentSatellite.satelliteIdentifier() );
#endif

//set QgsSatelliteInfo.inuse to true for the satellites in use
for ( int i = 0; i < mLastGPSInformation.satellitesInView.size(); ++i )
{
QgsSatelliteInfo satInView = mLastGPSInformation.satellitesInView.at( i );
#if defined(HAVE_QT_MOBILITY_LOCATION )
if ( satInView.id == currentSatellite.prnNumber() )
#else // QtPositioning
if ( satInView.id == currentSatellite.satelliteIdentifier() )
#endif
{
satInView.inUse = true;
break;
Expand Down Expand Up @@ -184,6 +195,7 @@ void QgsQtLocationConnection::startGPS()
void QgsQtLocationConnection::startSatelliteMonitor()
{
QgsDebugMsg( "Starting GPS QtLocation satellite monitor" );

if ( !satelliteInfoSource )
{
satelliteInfoSource = QGeoSatelliteInfoSource::createDefaultSource( this );
Expand Down
16 changes: 12 additions & 4 deletions src/core/gps/qgsqtlocationconnection.h
Expand Up @@ -19,12 +19,20 @@
#define QGSQTLOCATIONCONNECTION_H

#include "qgsgpsconnection.h"

#include <QtCore/QPointer>
#include <QtLocation/QGeoPositionInfoSource>
#include <QtLocation/QGeoSatelliteInfo>
#include <QtLocation/QGeoSatelliteInfoSource>

QTM_USE_NAMESPACE
#if defined(HAVE_QT_MOBILITY_LOCATION )
#include <QtLocation/QGeoPositionInfoSource>
#include <QtLocation/QGeoSatelliteInfo>
#include <QtLocation/QGeoSatelliteInfoSource>

QTM_USE_NAMESPACE
#else // Using QtPositioning
#include <QtPositioning/QGeoPositionInfoSource>
#include <QtPositioning/QGeoSatelliteInfo>
#include <QtPositioning/QGeoSatelliteInfoSource>
#endif

class CORE_EXPORT QgsQtLocationConnection: public QgsGPSConnection
{
Expand Down

0 comments on commit 72eb1aa

Please sign in to comment.