mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-07 00:03:52 -05:00
Address PR comments
This commit is contained in:
parent
f6e2c0dee8
commit
a90e34a765
@ -2,7 +2,7 @@
|
||||
"name": "url_encode",
|
||||
"type": "function",
|
||||
"groups": ["Maps"],
|
||||
"description": "Returns an URL encoded string from a map.<br>The underlying function uses <a href='https://doc.qt.io/qt-5/qurlquery.html#toString'>QUrlQuery::toString</a> with <a href='https://doc.qt.io/qt-5/qurl.html#ComponentFormattingOption-enum'>QUrl::FullyEncoded</a> flags.<br>Note that the plus sign '+' is not converted.",
|
||||
"description": "Returns an URL encoded string from a map. Transforms all characters in their properly-encoded form producing a fully-compliant query string.<br>Note that the plus sign '+' is not converted.",
|
||||
"arguments": [
|
||||
{
|
||||
"arg": "map",
|
||||
|
||||
@ -65,30 +65,8 @@ void QgsAction::run( QgsVectorLayer *layer, const QgsFeature &feature, const Qgs
|
||||
run( actionContext );
|
||||
}
|
||||
|
||||
void QgsAction::run( const QgsExpressionContext &expressionContext ) const
|
||||
void QgsAction::handleFormSubmitAction( const QString &expandedAction ) const
|
||||
{
|
||||
if ( !isValid() )
|
||||
{
|
||||
QgsDebugMsg( QStringLiteral( "Invalid action cannot be run" ) );
|
||||
return;
|
||||
}
|
||||
|
||||
QgsExpressionContextScope *scope = new QgsExpressionContextScope( mExpressionContextScope );
|
||||
QgsExpressionContext context( expressionContext );
|
||||
context << scope;
|
||||
|
||||
const QString expandedAction = QgsExpression::replaceExpressionText( mCommand, &context );
|
||||
|
||||
if ( mType == QgsAction::OpenUrl )
|
||||
{
|
||||
const QFileInfo finfo( expandedAction );
|
||||
if ( finfo.exists() && finfo.isFile() )
|
||||
QDesktopServices::openUrl( QUrl::fromLocalFile( expandedAction ) );
|
||||
else
|
||||
QDesktopServices::openUrl( QUrl( expandedAction, QUrl::TolerantMode ) );
|
||||
}
|
||||
else if ( mType == QgsAction::SubmitUrlEncoded || mType == QgsAction::SubmitUrlMultipart )
|
||||
{
|
||||
|
||||
QUrl url{ expandedAction };
|
||||
|
||||
@ -127,8 +105,8 @@ void QgsAction::run( const QgsExpressionContext &expressionContext ) const
|
||||
else
|
||||
{
|
||||
QHttpMultiPart *multiPart = new QHttpMultiPart( QHttpMultiPart::FormDataType );
|
||||
const auto queryItems { queryString.queryItems( QUrl::ComponentFormattingOption::FullyDecoded ) };
|
||||
for ( const auto &queryItem : std::as_const( queryItems ) )
|
||||
const QList<QPair<QString, QString>> queryItems { queryString.queryItems( QUrl::ComponentFormattingOption::FullyDecoded ) };
|
||||
for ( const QPair<QString, QString> &queryItem : std::as_const( queryItems ) )
|
||||
{
|
||||
QHttpPart part;
|
||||
part.setHeader( QNetworkRequest::ContentDispositionHeader,
|
||||
@ -152,17 +130,17 @@ void QgsAction::run( const QgsExpressionContext &expressionContext ) const
|
||||
const QByteArray replyData = reply->readAll();
|
||||
|
||||
QString filename { "download.bin" };
|
||||
if ( const auto header = reply->header( QNetworkRequest::KnownHeaders::ContentDispositionHeader ).toString().toStdString(); ! header.empty() )
|
||||
if ( const std::string header = reply->header( QNetworkRequest::KnownHeaders::ContentDispositionHeader ).toString().toStdString(); ! header.empty() )
|
||||
{
|
||||
|
||||
std::string ascii;
|
||||
const std::string q1 { R"(filename=")" };
|
||||
if ( const auto pos = header.find( q1 ); pos != std::string::npos )
|
||||
if ( const unsigned long pos = header.find( q1 ); pos != std::string::npos )
|
||||
{
|
||||
const auto len = pos + q1.size();
|
||||
const unsigned long len = pos + q1.size();
|
||||
|
||||
const std::string q2 { R"(")" };
|
||||
if ( auto pos = header.find( q2, len ); pos != std::string::npos )
|
||||
if ( unsigned long pos = header.find( q2, len ); pos != std::string::npos )
|
||||
{
|
||||
bool escaped = false;
|
||||
while ( pos != std::string::npos && header[pos - 1] == '\\' )
|
||||
@ -196,7 +174,7 @@ void QgsAction::run( const QgsExpressionContext &expressionContext ) const
|
||||
std::string utf8;
|
||||
|
||||
const std::string u { R"(UTF-8'')" };
|
||||
if ( const auto pos = header.find( u ); pos != std::string::npos )
|
||||
if ( const unsigned long pos = header.find( u ); pos != std::string::npos )
|
||||
{
|
||||
utf8 = header.substr( pos + u.size() );
|
||||
}
|
||||
@ -252,16 +230,33 @@ void QgsAction::run( const QgsExpressionContext &expressionContext ) const
|
||||
reply->deleteLater();
|
||||
} );
|
||||
|
||||
#if 0 // Not sure we need this: error is checked in finished() anyway
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
|
||||
QObject::connect( reply, qOverload<QNetworkReply::NetworkError>( QNetworkReply::error error ), reply, [ reply ] {} );
|
||||
#else
|
||||
QObject::connect( reply, &QNetworkReply::errorOccurred, reply, [ reply ]( QNetworkReply::NetworkError )
|
||||
}
|
||||
|
||||
void QgsAction::run( const QgsExpressionContext &expressionContext ) const
|
||||
{
|
||||
if ( !isValid() )
|
||||
{
|
||||
QgsMessageLog::logMessage( reply->errorString(), QStringLiteral( "Form Submit Action" ), Qgis::MessageLevel::Critical );
|
||||
} );
|
||||
#endif
|
||||
#endif
|
||||
QgsDebugMsg( QStringLiteral( "Invalid action cannot be run" ) );
|
||||
return;
|
||||
}
|
||||
|
||||
QgsExpressionContextScope *scope = new QgsExpressionContextScope( mExpressionContextScope );
|
||||
QgsExpressionContext context( expressionContext );
|
||||
context << scope;
|
||||
|
||||
const QString expandedAction = QgsExpression::replaceExpressionText( mCommand, &context );
|
||||
|
||||
if ( mType == QgsAction::OpenUrl )
|
||||
{
|
||||
const QFileInfo finfo( expandedAction );
|
||||
if ( finfo.exists() && finfo.isFile() )
|
||||
QDesktopServices::openUrl( QUrl::fromLocalFile( expandedAction ) );
|
||||
else
|
||||
QDesktopServices::openUrl( QUrl( expandedAction, QUrl::TolerantMode ) );
|
||||
}
|
||||
else if ( mType == QgsAction::SubmitUrlEncoded || mType == QgsAction::SubmitUrlMultipart )
|
||||
{
|
||||
handleFormSubmitAction( expandedAction );
|
||||
|
||||
}
|
||||
else if ( mType == QgsAction::GenericPython )
|
||||
|
||||
@ -257,6 +257,8 @@ class CORE_EXPORT QgsAction
|
||||
QString html( ) const;
|
||||
|
||||
private:
|
||||
|
||||
void handleFormSubmitAction( const QString &expandedAction ) const;
|
||||
ActionType mType = Generic;
|
||||
QString mDescription;
|
||||
QString mShortTitle;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user