bool QFormBuilderExtra::applyBuddy(const QString &buddyName, BuddyMode applyMode, QLabel *label) { if (buddyName.isEmpty()) { label->setBuddy(0); return false; } const QWidgetList widgets = qFindChildren<QWidget*>(label->topLevelWidget(), buddyName); if (widgets.empty()) { label->setBuddy(0); return false; } const QWidgetList::const_iterator cend = widgets.constEnd(); for ( QWidgetList::const_iterator it = widgets.constBegin(); it != cend; ++it) { if (applyMode == BuddyApplyAll || !(*it)->isHidden()) { label->setBuddy(*it); return true; } } label->setBuddy(0); return false; }
int QgsGml::getFeatures( const QString &uri, QgsWkbTypes::Type *wkbType, QgsRectangle *extent, const QString &userName, const QString &password, const QString &authcfg ) { //start with empty extent mExtent.setMinimal(); QNetworkRequest request( uri ); if ( !authcfg.isEmpty() ) { if ( !QgsApplication::authManager()->updateNetworkRequest( request, authcfg ) ) { QgsMessageLog::logMessage( tr( "GML Getfeature network request update failed for authcfg %1" ).arg( authcfg ), tr( "Network" ), Qgis::Critical ); return 1; } } else if ( !userName.isNull() || !password.isNull() ) { request.setRawHeader( "Authorization", "Basic " + QStringLiteral( "%1:%2" ).arg( userName, password ).toLatin1().toBase64() ); } QNetworkReply *reply = QgsNetworkAccessManager::instance()->get( request ); if ( !authcfg.isEmpty() ) { if ( !QgsApplication::authManager()->updateNetworkReply( reply, authcfg ) ) { reply->deleteLater(); QgsMessageLog::logMessage( tr( "GML Getfeature network reply update failed for authcfg %1" ).arg( authcfg ), tr( "Network" ), Qgis::Critical ); return 1; } } connect( reply, &QNetworkReply::finished, this, &QgsGml::setFinished ); connect( reply, &QNetworkReply::downloadProgress, this, &QgsGml::handleProgressEvent ); //find out if there is a QGIS main window. If yes, display a progress dialog QProgressDialog *progressDialog = nullptr; QWidget *mainWindow = nullptr; QWidgetList topLevelWidgets = qApp->topLevelWidgets(); for ( QWidgetList::const_iterator it = topLevelWidgets.constBegin(); it != topLevelWidgets.constEnd(); ++it ) { if ( ( *it )->objectName() == QLatin1String( "QgisApp" ) ) { mainWindow = *it; break; } } if ( mainWindow ) { progressDialog = new QProgressDialog( tr( "Loading GML data\n%1" ).arg( mTypeName ), tr( "Abort" ), 0, 0, mainWindow ); progressDialog->setWindowModality( Qt::ApplicationModal ); connect( this, &QgsGml::dataReadProgress, progressDialog, &QProgressDialog::setValue ); connect( this, &QgsGml::totalStepsUpdate, progressDialog, &QProgressDialog::setMaximum ); connect( progressDialog, &QProgressDialog::canceled, this, &QgsGml::setFinished ); progressDialog->show(); } int atEnd = 0; while ( !atEnd ) { if ( mFinished ) { atEnd = 1; } QByteArray readData = reply->readAll(); if ( !readData.isEmpty() ) { QString errorMsg; if ( !mParser.processData( readData, atEnd, errorMsg ) ) QgsMessageLog::logMessage( errorMsg, QObject::tr( "WFS" ) ); } QCoreApplication::processEvents(); } fillMapsFromParser(); QNetworkReply::NetworkError replyError = reply->error(); QString replyErrorString = reply->errorString(); delete reply; delete progressDialog; if ( replyError ) { QgsMessageLog::logMessage( tr( "GML Getfeature network request failed with error: %1" ).arg( replyErrorString ), tr( "Network" ), Qgis::Critical ); return 1; } *wkbType = mParser.wkbType(); if ( *wkbType != QgsWkbTypes::Unknown ) { if ( mExtent.isEmpty() ) { //reading of bbox from the server failed, so we calculate it less efficiently by evaluating the features calculateExtentFromFeatures(); } } if ( extent ) *extent = mExtent; return 0; }
int QgsGml::getFeatures( const QString& uri, QGis::WkbType* wkbType, QgsRectangle* extent, const QString& userName, const QString& password , const QString& authcfg ) { mUri = uri; mWkbType = wkbType; XML_Parser p = XML_ParserCreateNS( nullptr, NS_SEPARATOR ); XML_SetUserData( p, this ); XML_SetElementHandler( p, QgsGml::start, QgsGml::end ); XML_SetCharacterDataHandler( p, QgsGml::chars ); //start with empty extent mExtent.setMinimal(); QNetworkRequest request( mUri ); if ( !authcfg.isEmpty() ) { if ( !QgsAuthManager::instance()->updateNetworkRequest( request, authcfg ) ) { QgsMessageLog::logMessage( tr( "GML Getfeature network request update failed for authcfg %1" ).arg( authcfg ), tr( "Network" ), QgsMessageLog::CRITICAL ); return 1; } } else if ( !userName.isNull() || !password.isNull() ) { request.setRawHeader( "Authorization", "Basic " + QString( "%1:%2" ).arg( userName, password ).toAscii().toBase64() ); } QNetworkReply* reply = QgsNetworkAccessManager::instance()->get( request ); connect( reply, SIGNAL( finished() ), this, SLOT( setFinished() ) ); connect( reply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( handleProgressEvent( qint64, qint64 ) ) ); //find out if there is a QGIS main window. If yes, display a progress dialog QProgressDialog* progressDialog = nullptr; QWidget* mainWindow = nullptr; QWidgetList topLevelWidgets = qApp->topLevelWidgets(); for ( QWidgetList::const_iterator it = topLevelWidgets.constBegin(); it != topLevelWidgets.constEnd(); ++it ) { if (( *it )->objectName() == "QgisApp" ) { mainWindow = *it; break; } } if ( mainWindow ) { progressDialog = new QProgressDialog( tr( "Loading GML data\n%1" ).arg( mTypeName ), tr( "Abort" ), 0, 0, mainWindow ); progressDialog->setWindowModality( Qt::ApplicationModal ); connect( this, SIGNAL( dataReadProgress( int ) ), progressDialog, SLOT( setValue( int ) ) ); connect( this, SIGNAL( totalStepsUpdate( int ) ), progressDialog, SLOT( setMaximum( int ) ) ); connect( progressDialog, SIGNAL( canceled() ), this, SLOT( setFinished() ) ); progressDialog->show(); } int atEnd = 0; while ( !atEnd ) { if ( mFinished ) { atEnd = 1; } QByteArray readData = reply->readAll(); if ( !readData.isEmpty() ) { if ( XML_Parse( p, readData.constData(), readData.size(), atEnd ) == 0 ) { XML_Error errorCode = XML_GetErrorCode( p ); QString errorString = tr( "Error: %1 on line %2, column %3" ) .arg( XML_ErrorString( errorCode ) ) .arg( XML_GetCurrentLineNumber( p ) ) .arg( XML_GetCurrentColumnNumber( p ) ); QgsMessageLog::logMessage( errorString, tr( "WFS" ) ); } } QCoreApplication::processEvents(); } QNetworkReply::NetworkError replyError = reply->error(); QString replyErrorString = reply->errorString(); delete reply; delete progressDialog; if ( replyError ) { QgsMessageLog::logMessage( tr( "GML Getfeature network request failed with error: %1" ).arg( replyErrorString ), tr( "Network" ), QgsMessageLog::CRITICAL ); return 1; } if ( *mWkbType != QGis::WKBNoGeometry ) { if ( mExtent.isEmpty() ) { //reading of bbox from the server failed, so we calculate it less efficiently by evaluating the features calculateExtentFromFeatures(); } } XML_ParserFree( p ); if ( extent ) *extent = mExtent; return 0; }