@ -17,11 +17,13 @@
@@ -17,11 +17,13 @@
# include <QNetworkRequest>
# include <QNetworkProxy>
# include <QNetworkReply>
# include <QSslConfiguration>
# include <QJsonDocument>
# include <QJsonObject>
# include <QJsonArray>
# include <QTimer>
# include <QtLocation/private/qgeotilespec_p.h>
# include <cmath>
QGC_LOGGING_CATEGORY ( TerrainQueryLog , " TerrainQueryLog " )
@ -33,7 +35,7 @@ Q_GLOBAL_STATIC(TerrainTileManager, _terrainTileManager)
@@ -33,7 +35,7 @@ Q_GLOBAL_STATIC(TerrainTileManager, _terrainTileManager)
TerrainAirMapQuery : : TerrainAirMapQuery ( QObject * parent )
: TerrainQueryInterface ( parent )
{
qCDebug ( TerrainQueryVerboseLog ) < < " supportsSsl " < < QSslSocket : : supportsSsl ( ) < < " sslLibraryBuildVersionString " < < QSslSocket : : sslLibraryBuildVersionString ( ) ;
}
void TerrainAirMapQuery : : requestCoordinateHeights ( const QList < QGeoCoordinate > & coordinates )
@ -107,18 +109,24 @@ void TerrainAirMapQuery::_sendQuery(const QString& path, const QUrlQuery& urlQue
@@ -107,18 +109,24 @@ void TerrainAirMapQuery::_sendQuery(const QString& path, const QUrlQuery& urlQue
QNetworkRequest request ( url ) ;
QSslConfiguration sslConf = request . sslConfiguration ( ) ;
sslConf . setPeerVerifyMode ( QSslSocket : : VerifyNone ) ;
request . setSslConfiguration ( sslConf ) ;
QNetworkProxy tProxy ;
tProxy . setType ( QNetworkProxy : : DefaultProxy ) ;
_networkManager . setProxy ( tProxy ) ;
QNetworkReply * networkReply = _networkManager . get ( request ) ;
if ( ! networkReply ) {
qCDebu g ( TerrainQueryLog ) < < " QNetworkManager::Get did not return QNetworkReply " ;
qCWarnin g ( TerrainQueryLog ) < < " QNetworkManager::Get did not return QNetworkReply " ;
_requestFailed ( ) ;
return ;
}
networkReply - > ignoreSslErrors ( ) ;
connect ( networkReply , & QNetworkReply : : finished , this , & TerrainAirMapQuery : : _requestFinished ) ;
connect ( networkReply , & QNetworkReply : : sslErrors , this , & TerrainAirMapQuery : : _sslErrors ) ;
connect ( networkReply , QOverload < QNetworkReply : : NetworkError > : : of ( & QNetworkReply : : error ) , this , & TerrainAirMapQuery : : _requestError ) ;
}
@ -127,17 +135,29 @@ void TerrainAirMapQuery::_requestError(QNetworkReply::NetworkError code)
@@ -127,17 +135,29 @@ void TerrainAirMapQuery::_requestError(QNetworkReply::NetworkError code)
QNetworkReply * reply = qobject_cast < QNetworkReply * > ( QObject : : sender ( ) ) ;
if ( code ! = QNetworkReply : : NoError ) {
qCDebu g ( TerrainQueryLog ) < < " _requestError error:url:data " < < reply - > error ( ) < < reply - > url ( ) < < reply - > readAll ( ) ;
qCWarnin g ( TerrainQueryLog ) < < " _requestError error:url:data " < < reply - > error ( ) < < reply - > url ( ) < < reply - > readAll ( ) ;
return ;
}
}
void TerrainAirMapQuery : : _sslErrors ( const QList < QSslError > & errors )
{
for ( const auto & error : errors ) {
qCWarning ( TerrainQueryLog ) < < " SSL error: " < < error . errorString ( ) ;
const auto & certificate = error . certificate ( ) ;
if ( ! certificate . isNull ( ) ) {
qCWarning ( TerrainQueryLog ) < < " SSL Certificate problem: " < < certificate . toText ( ) ;
}
}
}
void TerrainAirMapQuery : : _requestFinished ( void )
{
QNetworkReply * reply = qobject_cast < QNetworkReply * > ( QObject : : sender ( ) ) ;
if ( reply - > error ( ) ! = QNetworkReply : : NoError ) {
qCDebug ( TerrainQueryLog ) < < " _requestFinished error:url:data " < < reply - > error ( ) < < reply - > url ( ) < < reply - > readAll ( ) ;
qCWarnin g ( TerrainQueryLog ) < < " _requestFinished error:url:data " < < reply - > error ( ) < < reply - > url ( ) < < reply - > readAll ( ) ;
reply - > deleteLater ( ) ;
_requestFailed ( ) ;
return ;
@ -150,7 +170,7 @@ void TerrainAirMapQuery::_requestFinished(void)
@@ -150,7 +170,7 @@ void TerrainAirMapQuery::_requestFinished(void)
QJsonParseError parseError ;
QJsonDocument responseJson = QJsonDocument : : fromJson ( responseBytes , & parseError ) ;
if ( parseError . error ! = QJsonParseError : : NoError ) {
qCDebu g ( TerrainQueryLog ) < < " _requestFinished unable to parse json: " < < parseError . errorString ( ) ;
qCWarnin g ( TerrainQueryLog ) < < " _requestFinished unable to parse json: " < < parseError . errorString ( ) ;
_requestFailed ( ) ;
return ;
}
@ -159,7 +179,7 @@ void TerrainAirMapQuery::_requestFinished(void)
@@ -159,7 +179,7 @@ void TerrainAirMapQuery::_requestFinished(void)
QJsonObject rootObject = responseJson . object ( ) ;
QString status = rootObject [ " status " ] . toString ( ) ;
if ( status ! = " success " ) {
qCDebu g ( TerrainQueryLog ) < < " _requestFinished status != success: " < < status ;
qCWarnin g ( TerrainQueryLog ) < < " _requestFinished status != success: " < < status ;
_requestFailed ( ) ;
return ;
}
@ -252,7 +272,7 @@ void TerrainAirMapQuery::_parseCarpetData(const QJsonValue& carpetJson)
@@ -252,7 +272,7 @@ void TerrainAirMapQuery::_parseCarpetData(const QJsonValue& carpetJson)
TerrainOfflineAirMapQuery : : TerrainOfflineAirMapQuery ( QObject * parent )
: TerrainQueryInterface ( parent )
{
qCDebug ( TerrainQueryVerboseLog ) < < " supportsSsl " < < QSslSocket : : supportsSsl ( ) < < " sslLibraryBuildVersionString " < < QSslSocket : : sslLibraryBuildVersionString ( ) ;
}
void TerrainOfflineAirMapQuery : : requestCoordinateHeights ( const QList < QGeoCoordinate > & coordinates )
@ -385,7 +405,7 @@ bool TerrainTileManager::_getAltitudesForCoordinates(const QList<QGeoCoordinate>
@@ -385,7 +405,7 @@ bool TerrainTileManager::_getAltitudesForCoordinates(const QList<QGeoCoordinate>
if ( _tiles [ tileHash ] . isIn ( coordinate ) ) {
altitudes . push_back ( _tiles [ tileHash ] . elevation ( coordinate ) ) ;
} else {
qCDebu g ( TerrainQueryLog ) < < " Error: coordinate not in tile region " ;
qCWarnin g ( TerrainQueryLog ) < < " Error: coordinate not in tile region " ;
altitudes . push_back ( - 1.0 ) ;
}
}
@ -412,7 +432,7 @@ void TerrainTileManager::_terrainDone(QByteArray responseBytes, QNetworkReply::N
@@ -412,7 +432,7 @@ void TerrainTileManager::_terrainDone(QByteArray responseBytes, QNetworkReply::N
_state = State : : Idle ;
if ( ! reply ) {
qCDebu g ( TerrainQueryLog ) < < " Elevation tile fetched but invalid reply data type. " ;
qCWarnin g ( TerrainQueryLog ) < < " Elevation tile fetched but invalid reply data type. " ;
return ;
}
@ -422,13 +442,13 @@ void TerrainTileManager::_terrainDone(QByteArray responseBytes, QNetworkReply::N
@@ -422,13 +442,13 @@ void TerrainTileManager::_terrainDone(QByteArray responseBytes, QNetworkReply::N
// handle potential errors
if ( error ! = QNetworkReply : : NoError ) {
qCDebu g ( TerrainQueryLog ) < < " Elevation tile fetching returned error ( " < < error < < " ) " ;
qCWarnin g ( TerrainQueryLog ) < < " Elevation tile fetching returned error ( " < < error < < " ) " ;
_tileFailed ( ) ;
reply - > deleteLater ( ) ;
return ;
}
if ( responseBytes . isEmpty ( ) ) {
qCDebu g ( TerrainQueryLog ) < < " Error in fetching elevation tile. Empty response. " ;
qCWarnin g ( TerrainQueryLog ) < < " Error in fetching elevation tile. Empty response. " ;
_tileFailed ( ) ;
reply - > deleteLater ( ) ;
return ;
@ -446,7 +466,7 @@ void TerrainTileManager::_terrainDone(QByteArray responseBytes, QNetworkReply::N
@@ -446,7 +466,7 @@ void TerrainTileManager::_terrainDone(QByteArray responseBytes, QNetworkReply::N
}
_tilesMutex . unlock ( ) ;
} else {
qCDebu g ( TerrainQueryLog ) < < " Received invalid tile " ;
qCWarnin g ( TerrainQueryLog ) < < " Received invalid tile " ;
}
reply - > deleteLater ( ) ;