Skip to content

Commit

Permalink
Merge pull request #4683 from rldhont/server-string-list-exceptions
Browse files Browse the repository at this point in the history
[Server] bulk enhancements: string, list and exceptions
  • Loading branch information
rldhont committed Jun 6, 2017
2 parents 38d905f + ad14373 commit dbedd7e
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 84 deletions.
6 changes: 3 additions & 3 deletions src/server/qgsinterpolationlayerbuilder.cpp
Expand Up @@ -52,7 +52,7 @@ QgsMapLayer *QgsInterpolationLayerBuilder::createMapLayer( const QDomElement &el
}

QDomNodeList interpolationList = elem.elementsByTagName( QStringLiteral( "Interpolation" ) );
if ( interpolationList.size() < 1 )
if ( interpolationList.isEmpty() )
{
QgsDebugMsg( "No Interpolation element found" );
return nullptr;
Expand All @@ -68,7 +68,7 @@ QgsMapLayer *QgsInterpolationLayerBuilder::createMapLayer( const QDomElement &el
QgsInterpolator::LayerData currentLayerData;
currentLayerData.vectorLayer = mVectorLayer;
QDomNodeList propertyNameList = interpolationElem.elementsByTagName( QStringLiteral( "PropertyName" ) );
if ( propertyNameList.size() < 1 )
if ( propertyNameList.isEmpty() )
{
currentLayerData.zCoordInterpolation = true;
}
Expand Down Expand Up @@ -110,7 +110,7 @@ QgsMapLayer *QgsInterpolationLayerBuilder::createMapLayer( const QDomElement &el
int nCols, nRows;

QDomNodeList resolutionNodeList = elem.elementsByTagName( QStringLiteral( "Resolution" ) );
if ( resolutionNodeList.size() < 1 )
if ( resolutionNodeList.isEmpty() )
{
//use default values...
nCols = 100;
Expand Down
2 changes: 1 addition & 1 deletion src/server/qgsserver.cpp
Expand Up @@ -124,7 +124,7 @@ QFileInfo QgsServer::defaultProjectFile()
{
QgsMessageLog::logMessage( projectFiles.at( x ).absoluteFilePath(), QStringLiteral( "Server" ), QgsMessageLog::INFO );
}
if ( projectFiles.size() < 1 )
if ( projectFiles.isEmpty() )
{
return QFileInfo();
}
Expand Down
4 changes: 2 additions & 2 deletions src/server/services/wcs/qgswcsdescribecoverage.cpp
Expand Up @@ -87,7 +87,7 @@ namespace QgsWcs
QStringList coveNameList;
if ( !coveNames.isEmpty() )
{
coveNameList = coveNames.split( QStringLiteral( "," ) );
coveNameList = coveNames.split( ',' );
for ( int i = 0; i < coveNameList.size(); ++i )
{
coveNameList.replace( i, coveNameList.at( i ).trimmed() );
Expand All @@ -111,7 +111,7 @@ namespace QgsWcs
QString name = layer->name();
if ( !layer->shortName().isEmpty() )
name = layer->shortName();
name = name.replace( QLatin1String( " " ), QLatin1String( "_" ) );
name = name.replace( ' ', '_' );

if ( coveNameList.size() == 0 || coveNameList.contains( name ) )
{
Expand Down
6 changes: 3 additions & 3 deletions src/server/services/wcs/qgswcsutils.cpp
Expand Up @@ -45,7 +45,7 @@ namespace QgsWcs
QString name = layer->name();
if ( !layer->shortName().isEmpty() )
name = layer->shortName();
name = name.replace( QLatin1String( " " ), QLatin1String( "_" ) );
name = name.replace( ' ', '_' );
QDomText nameText = doc.createTextNode( name );
nameElem.appendChild( nameText );
layerElem.appendChild( nameElem );
Expand Down Expand Up @@ -260,15 +260,15 @@ namespace QgsWcs

QgsRectangle parseBbox( const QString &bboxStr )
{
QStringList lst = bboxStr.split( QStringLiteral( "," ) );
QStringList lst = bboxStr.split( ',' );
if ( lst.count() != 4 )
return QgsRectangle();

double d[4];
bool ok;
for ( int i = 0; i < 4; i++ )
{
lst[i].replace( QLatin1String( " " ), QLatin1String( "+" ) );
lst[i].replace( ' ', '+' );
d[i] = lst[i].toDouble( &ok );
if ( !ok )
return QgsRectangle();
Expand Down
14 changes: 7 additions & 7 deletions src/server/services/wfs/qgswfsdescribefeaturetype.cpp
Expand Up @@ -90,8 +90,8 @@ namespace QgsWfs
if ( docChildElem.tagName() == QLatin1String( "TypeName" ) )
{
QString typeName = docChildElem.text().trimmed();
if ( typeName.contains( QLatin1String( ":" ) ) )
typeNameList << typeName.section( QStringLiteral( ":" ), 1, 1 );
if ( typeName.contains( ':' ) )
typeNameList << typeName.section( ':', 1, 1 );
else
typeNameList << typeName;
}
Expand All @@ -103,12 +103,12 @@ namespace QgsWfs
QString typeNames = request.parameter( QStringLiteral( "TYPENAME" ) );
if ( !typeNames.isEmpty() )
{
QStringList typeNameSplit = typeNames.split( QStringLiteral( "," ) );
QStringList typeNameSplit = typeNames.split( ',' );
for ( int i = 0; i < typeNameSplit.size(); ++i )
{
QString typeName = typeNameSplit.at( i ).trimmed();
if ( typeName.contains( QLatin1String( ":" ) ) )
typeNameList << typeName.section( QStringLiteral( ":" ), 1, 1 );
if ( typeName.contains( ':' ) )
typeNameList << typeName.section( ':', 1, 1 );
else
typeNameList << typeName;
}
Expand All @@ -127,7 +127,7 @@ namespace QgsWfs
QString name = layer->name();
if ( !layer->shortName().isEmpty() )
name = layer->shortName();
name = name.replace( QLatin1String( " " ), QLatin1String( "_" ) );
name = name.replace( ' ', '_' );

if ( !typeNameList.isEmpty() && !typeNameList.contains( name ) )
{
Expand Down Expand Up @@ -168,7 +168,7 @@ namespace QgsWfs
QString typeName = layer->name();
if ( !layer->shortName().isEmpty() )
typeName = layer->shortName();
typeName = typeName.replace( QLatin1String( " " ), QLatin1String( "_" ) );
typeName = typeName.replace( ' ', '_' );

//xsd:element
QDomElement elementElem = doc.createElement( QStringLiteral( "element" )/*xsd:element*/ );
Expand Down
54 changes: 27 additions & 27 deletions src/server/services/wfs/qgswfsgetfeature.cpp
Expand Up @@ -121,7 +121,7 @@ namespace QgsWfs
QString name = layer->name();
if ( !layer->shortName().isEmpty() )
name = layer->shortName();
name = name.replace( QLatin1String( " " ), QLatin1String( "_" ) );
name = name.replace( ' ', '_' );

if ( typeNameList.contains( name ) )
{
Expand Down Expand Up @@ -387,7 +387,7 @@ namespace QgsWfs
// parse FEATUREID
if ( parameters.contains( QStringLiteral( "FEATUREID" ) ) )
{
QStringList fidList = parameters.value( QStringLiteral( "FEATUREID" ) ).split( QStringLiteral( "," ) );
QStringList fidList = parameters.value( QStringLiteral( "FEATUREID" ) ).split( ',' );
// Verifying the 1:1 mapping between FEATUREID and PROPERTYNAME
if ( !propertyNameList.isEmpty() && propertyNameList.size() != fidList.size() )
{
Expand Down Expand Up @@ -417,13 +417,13 @@ namespace QgsWfs
propertyName = *propertyNameIt;
}
// testing typename in the WFS featureID
if ( !fid.contains( QLatin1String( "." ) ) )
if ( !fid.contains( '.' ) )
{
throw QgsRequestNotWellFormedException( QStringLiteral( "FEATUREID has to have TYPENAME in the values" ) );
}

QString typeName = fid.section( QStringLiteral( "." ), 0, 0 );
fid = fid.section( QStringLiteral( "." ), 1, 1 );
QString typeName = fid.section( '.', 0, 0 );
fid = fid.section( '.', 1, 1 );
if ( !typeNameList.contains( typeName ) )
{
typeNameList << typeName;
Expand Down Expand Up @@ -467,23 +467,23 @@ namespace QgsWfs
{
QStringList propertyList;

QStringList attrList = propertyName.split( QStringLiteral( "," ) );
QStringList attrList = propertyName.split( ',' );
QStringList::const_iterator alstIt;
for ( alstIt = attrList.begin(); alstIt != attrList.end(); ++alstIt )
{
QString fieldName = *alstIt;
fieldName = fieldName.trimmed();
if ( fieldName.contains( QLatin1String( ":" ) ) )
if ( fieldName.contains( ':' ) )
{
fieldName = fieldName.section( QStringLiteral( ":" ), 1, 1 );
fieldName = fieldName.section( ':', 1, 1 );
}
if ( fieldName.contains( QLatin1String( "/" ) ) )
if ( fieldName.contains( '/' ) )
{
if ( fieldName.section( QStringLiteral( "/" ), 0, 0 ) != typeName )
if ( fieldName.section( '/', 0, 0 ) != typeName )
{
throw QgsRequestNotWellFormedException( QStringLiteral( "PropertyName text '%1' has to contain TypeName '%2'" ).arg( fieldName ).arg( typeName ) );
}
fieldName = fieldName.section( QStringLiteral( "/" ), 1, 1 );
fieldName = fieldName.section( '/', 1, 1 );
}
propertyList.append( fieldName );
}
Expand Down Expand Up @@ -513,7 +513,7 @@ namespace QgsWfs
throw QgsRequestNotWellFormedException( QStringLiteral( "TYPENAME is mandatory except if FEATUREID is used" ) );
}

typeNameList = parameters.value( QStringLiteral( "TYPENAME" ) ).split( QStringLiteral( "," ) );
typeNameList = parameters.value( QStringLiteral( "TYPENAME" ) ).split( ',' );
// Verifying the 1:1 mapping between TYPENAME and PROPERTYNAME
if ( !propertyNameList.isEmpty() && typeNameList.size() != propertyNameList.size() )
{
Expand Down Expand Up @@ -549,23 +549,23 @@ namespace QgsWfs
{
QStringList propertyList;

QStringList attrList = propertyName.split( QStringLiteral( "," ) );
QStringList attrList = propertyName.split( ',' );
QStringList::const_iterator alstIt;
for ( alstIt = attrList.begin(); alstIt != attrList.end(); ++alstIt )
{
QString fieldName = *alstIt;
fieldName = fieldName.trimmed();
if ( fieldName.contains( QLatin1String( ":" ) ) )
if ( fieldName.contains( ':' ) )
{
fieldName = fieldName.section( QStringLiteral( ":" ), 1, 1 );
fieldName = fieldName.section( ':', 1, 1 );
}
if ( fieldName.contains( QLatin1String( "/" ) ) )
if ( fieldName.contains( '/' ) )
{
if ( fieldName.section( QStringLiteral( "/" ), 0, 0 ) != typeName )
if ( fieldName.section( '/', 0, 0 ) != typeName )
{
throw QgsRequestNotWellFormedException( QStringLiteral( "PropertyName text '%1' has to contain TypeName '%2'" ).arg( fieldName ).arg( typeName ) );
}
fieldName = fieldName.section( QStringLiteral( "/" ), 1, 1 );
fieldName = fieldName.section( '/', 1, 1 );
}
propertyList.append( fieldName );
}
Expand Down Expand Up @@ -660,7 +660,7 @@ namespace QgsWfs
bool ok;
for ( int i = 0; i < 4; i++ )
{
corners[i].replace( QLatin1String( " " ), QLatin1String( "+" ) );
corners[i].replace( ' ', '+' );
d[i] = corners[i].toDouble( &ok );
if ( !ok )
{
Expand Down Expand Up @@ -769,9 +769,9 @@ namespace QgsWfs
getFeatureQuery parseQueryElement( QDomElement &queryElem )
{
QString typeName = queryElem.attribute( QStringLiteral( "typeName" ), QLatin1String( "" ) );
if ( typeName.contains( QLatin1String( ":" ) ) )
if ( typeName.contains( ':' ) )
{
typeName = typeName.section( QStringLiteral( ":" ), 1, 1 );
typeName = typeName.section( ':', 1, 1 );
}

QgsFeatureRequest featureRequest;
Expand All @@ -785,17 +785,17 @@ namespace QgsWfs
if ( queryChildElem.tagName() == QLatin1String( "PropertyName" ) )
{
QString fieldName = queryChildElem.text().trimmed();
if ( fieldName.contains( QLatin1String( ":" ) ) )
if ( fieldName.contains( ':' ) )
{
fieldName = fieldName.section( QStringLiteral( ":" ), 1, 1 );
fieldName = fieldName.section( ':', 1, 1 );
}
if ( fieldName.contains( QLatin1String( "/" ) ) )
if ( fieldName.contains( '/' ) )
{
if ( fieldName.section( QStringLiteral( "/" ), 0, 0 ) != typeName )
if ( fieldName.section( '/', 0, 0 ) != typeName )
{
throw QgsRequestNotWellFormedException( QStringLiteral( "PropertyName text '%1' has to contain TypeName '%2'" ).arg( fieldName ).arg( typeName ) );
}
fieldName = fieldName.section( QStringLiteral( "/" ), 1, 1 );
fieldName = fieldName.section( '/', 1, 1 );
}
propertyList.append( fieldName );
}
Expand Down Expand Up @@ -878,7 +878,7 @@ namespace QgsWfs
query.removeAllQueryItems( QStringLiteral( "_DC" ) );

query.addQueryItem( QStringLiteral( "REQUEST" ), QStringLiteral( "DescribeFeatureType" ) );
query.addQueryItem( QStringLiteral( "TYPENAME" ), typeNames.join( QStringLiteral( "," ) ) );
query.addQueryItem( QStringLiteral( "TYPENAME" ), typeNames.join( ',' ) );
query.addQueryItem( QStringLiteral( "OUTPUTFORMAT" ), QStringLiteral( "XMLSCHEMA" ) );

mapUrl.setQuery( query );
Expand Down
26 changes: 13 additions & 13 deletions src/server/services/wfs/qgswfstransaction.cpp
Expand Up @@ -243,7 +243,7 @@ namespace QgsWfs
QString name = layer->name();
if ( !layer->shortName().isEmpty() )
name = layer->shortName();
name = name.replace( QLatin1String( " " ), QLatin1String( "_" ) );
name = name.replace( ' ', '_' );

if ( !typeNameList.contains( name ) )
{
Expand Down Expand Up @@ -779,7 +779,7 @@ namespace QgsWfs
// parse FEATUREID
if ( parameters.contains( QStringLiteral( "FEATUREID" ) ) )
{
QStringList fidList = parameters.value( QStringLiteral( "FEATUREID" ) ).split( QStringLiteral( "," ) );
QStringList fidList = parameters.value( QStringLiteral( "FEATUREID" ) ).split( ',' );

QMap<QString, QgsFeatureIds> fidsMap;

Expand All @@ -790,13 +790,13 @@ namespace QgsWfs
QString fid = *fidIt;
fid = fid.trimmed();
// testing typename in the WFS featureID
if ( !fid.contains( QLatin1String( "." ) ) )
if ( !fid.contains( '.' ) )
{
throw QgsRequestNotWellFormedException( QStringLiteral( "FEATUREID has to have TYPENAME in the values" ) );
}

QString typeName = fid.section( QStringLiteral( "." ), 0, 0 );
fid = fid.section( QStringLiteral( "." ), 1, 1 );
QString typeName = fid.section( '.', 0, 0 );
fid = fid.section( '.', 1, 1 );
if ( !typeNameList.contains( typeName ) )
{
typeNameList << typeName;
Expand Down Expand Up @@ -830,7 +830,7 @@ namespace QgsWfs
throw QgsRequestNotWellFormedException( QStringLiteral( "TYPENAME is mandatory except if FEATUREID is used" ) );
}

typeNameList = parameters.value( QStringLiteral( "TYPENAME" ) ).split( QStringLiteral( "," ) );
typeNameList = parameters.value( QStringLiteral( "TYPENAME" ) ).split( ',' );

// Create actions based on TypeName
QStringList::const_iterator typeNameIt = typeNameList.constBegin();
Expand Down Expand Up @@ -925,7 +925,7 @@ namespace QgsWfs
bool ok;
for ( int i = 0; i < 4; i++ )
{
corners[i].replace( QLatin1String( " " ), QLatin1String( "+" ) );
corners[i].replace( ' ', '+' );
d[i] = corners[i].toDouble( &ok );
if ( !ok )
{
Expand Down Expand Up @@ -1038,8 +1038,8 @@ namespace QgsWfs
transactionDelete parseDeleteActionElement( QDomElement &actionElem )
{
QString typeName = actionElem.attribute( QStringLiteral( "typeName" ) );
if ( typeName.contains( QLatin1String( ":" ) ) )
typeName = typeName.section( QStringLiteral( ":" ), 1, 1 );
if ( typeName.contains( ':' ) )
typeName = typeName.section( ':', 1, 1 );

QDomElement filterElem = actionElem.firstChild().toElement();
if ( filterElem.tagName() != QLatin1String( "Filter" ) )
Expand All @@ -1065,8 +1065,8 @@ namespace QgsWfs
transactionUpdate parseUpdateActionElement( QDomElement &actionElem )
{
QString typeName = actionElem.attribute( QStringLiteral( "typeName" ) );
if ( typeName.contains( QLatin1String( ":" ) ) )
typeName = typeName.section( QStringLiteral( ":" ), 1, 1 );
if ( typeName.contains( ':' ) )
typeName = typeName.section( ':', 1, 1 );

QDomNodeList propertyNodeList = actionElem.elementsByTagName( QStringLiteral( "Property" ) );
if ( propertyNodeList.size() != 1 )
Expand Down Expand Up @@ -1130,8 +1130,8 @@ namespace QgsWfs
for ( int i = 0; i < featureNodeList.count(); ++i )
{
QString tempTypeName = featureNodeList.at( i ).toElement().localName();
if ( tempTypeName.contains( QLatin1String( ":" ) ) )
tempTypeName = tempTypeName.section( QStringLiteral( ":" ), 1, 1 );
if ( tempTypeName.contains( ':' ) )
tempTypeName = tempTypeName.section( ':', 1, 1 );

if ( typeName.isEmpty() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/server/services/wfs/qgswfsutils.cpp
Expand Up @@ -85,7 +85,7 @@ namespace QgsWfs
fids.insert( fid.toInt() );
}

if ( fids.size() > 0 )
if ( !fids.isEmpty() )
{
request.setFilterFids( fids );
}
Expand Down
6 changes: 3 additions & 3 deletions src/server/services/wms/qgsdxfwriter.cpp
Expand Up @@ -31,10 +31,10 @@ namespace QgsWms
{
QMap<QString, QString> options;

QStringList optionsList = optionString.split( QStringLiteral( ";" ) );
QStringList optionsList = optionString.split( ';' );
for ( auto optionsIt = optionsList.constBegin(); optionsIt != optionsList.constEnd(); ++optionsIt )
{
int equalIdx = optionsIt->indexOf( QLatin1String( ":" ) );
int equalIdx = optionsIt->indexOf( ':' );
if ( equalIdx > 0 && equalIdx < ( optionsIt->length() - 1 ) )
{
options.insert( optionsIt->left( equalIdx ).toUpper(),
Expand All @@ -54,7 +54,7 @@ namespace QgsWms
QMap<QString, QString>::const_iterator layerAttributesIt = options.find( QStringLiteral( "LAYERATTRIBUTES" ) );
if ( layerAttributesIt != options.constEnd() )
{
layerAttributes = options.value( QStringLiteral( "LAYERATTRIBUTES" ) ).split( QStringLiteral( "," ) );
layerAttributes = options.value( QStringLiteral( "LAYERATTRIBUTES" ) ).split( ',' );
}

//LAYERS and STYLES
Expand Down

0 comments on commit dbedd7e

Please sign in to comment.