3 #include <QNetworkAccessManager>
4 #include <QNetworkRequest>
5 #include <QNetworkReply>
13 return "http://overpass-api.de/api/interpreter";
19 return QString(
"(node(%1,%2,%3,%4);<;);out;" ).arg( rect.
yMinimum() ).arg( rect.
xMinimum() )
25 : mServiceUrl( defaultServiceUrl() ), mReply( 0 )
34 mReply->deleteLater();
44 if ( mQuery.isEmpty() )
46 mError =
tr(
"No query has been specified." );
52 mError =
tr(
"There is already a pending request for data." );
56 if ( !mFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
58 mError =
tr(
"Cannot open output file: %1" ).arg( mFile.fileName() );
64 QUrl url( mServiceUrl );
65 url.addQueryItem(
"data", mQuery );
67 QNetworkRequest request( url );
68 request.setRawHeader(
"User-Agent",
"QGIS" );
70 mReply = nwam->get( request );
72 connect( mReply, SIGNAL( readyRead() ),
this, SLOT( onReadyRead() ) );
73 connect( mReply, SIGNAL( error( QNetworkReply::NetworkError ) ),
this, SLOT( onError( QNetworkReply::NetworkError ) ) );
74 connect( mReply, SIGNAL(
finished() ),
this, SLOT( onFinished() ) );
91 void QgsOSMDownload::onReadyRead()
95 QByteArray data = mReply->read( 1024 * 1024 );
100 void QgsOSMDownload::onFinished()
102 qDebug(
"finished" );
105 mReply->deleteLater();
114 void QgsOSMDownload::onError( QNetworkReply::NetworkError err )
116 qDebug(
"error: %d", err );
119 mError = mReply->errorString();
128 return mReply->isFinished();