From 0f7b405aa7b8a04770483ecfea13b37b5464922a Mon Sep 17 00:00:00 2001 From: Radim Blazek Date: Fri, 8 Feb 2013 00:10:33 +0100 Subject: [PATCH] GML GetFeatureInfo XSD validation, disabled --- src/gui/qgsmaptoolidentify.cpp | 19 +++++++++++ src/providers/wms/qgswmsprovider.cpp | 50 ++++++++++++++++++++++++++-- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/src/gui/qgsmaptoolidentify.cpp b/src/gui/qgsmaptoolidentify.cpp index cfc737a38bb1..b665634a631f 100644 --- a/src/gui/qgsmaptoolidentify.cpp +++ b/src/gui/qgsmaptoolidentify.cpp @@ -439,6 +439,25 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList *results, Qg { foreach ( int i, values.keys() ) { + QVariant value = values.value( i ); + if ( value.type() == QVariant::Bool && !value.toBool() ) + { + // sublayer not visible or not queryable + continue; + } + + if ( value.type() == QVariant::String ) + { + // error + // TODO: better error reporting + QString label = layer->subLayers().value( i ); + attributes.clear(); + attributes.insert( tr( "Error" ), value.toString() ); + + results->append( IdentifyResult( qobject_cast( layer ), label, attributes, derivedAttributes ) ); + continue; + } + // list of feature stores for a single sublayer QgsFeatureStoreList featureStoreList = values.value( i ).value(); diff --git a/src/providers/wms/qgswmsprovider.cpp b/src/providers/wms/qgswmsprovider.cpp index ea444bf26fa6..f368daa7a2f6 100644 --- a/src/providers/wms/qgswmsprovider.cpp +++ b/src/providers/wms/qgswmsprovider.cpp @@ -48,6 +48,11 @@ #include #endif +#if QT_VERSION >= 0x40600 +#include +#include +#endif + #include #include #include @@ -3919,7 +3924,7 @@ QMap QgsWmsProvider::identify( const QgsPoint & thePoint, Identif //QgsFeatureList featureList; - int count = 0; + int count = -1; // Test for which layers are suitable for querying with for ( QStringList::const_iterator layers = mActiveSubLayers.begin(), @@ -3927,13 +3932,23 @@ QMap QgsWmsProvider::identify( const QgsPoint & thePoint, Identif layers != mActiveSubLayers.end(); ++layers, ++styles ) { + count++; + // Is sublayer visible? if ( !mActiveSubLayerVisibility.find( *layers ).value() ) + { + // TODO: something better? + // we need to keep all sublayers so that we can get their names in identify tool + results.insert( count, false ); continue; + } // Is sublayer queryable? if ( !mQueryableForLayer.find( *layers ).value() ) + { + results.insert( count, false ); continue; + } QgsDebugMsg( "Layer '" + *layers + "' is queryable." ); @@ -4047,6 +4062,38 @@ QMap QgsWmsProvider::identify( const QgsPoint & thePoint, Identif if ( xsdPart >= 0 ) // XSD available { +#if QT_VERSION >= 0x40600 +#if 0 + // Validate GML by schema + // Loading schema takes ages! It needs to load all XSD referenced in the schema, + // for example: + // http://schemas.opengis.net/gml/2.1.2/feature.xsd + // http://schemas.opengis.net/gml/2.1.2/gml.xsd + // http://schemas.opengis.net/gml/2.1.2/geometry.xsd + // http://www.w3.org/1999/xlink.xsd + // http://www.w3.org/2001/xml.xsd <- this takes 30s to download (2/2013) + + QXmlSchema schema; + schema.load( mIdentifyResultBodies.value( xsdPart ) ); + // Unfortunately the schema cannot be successfully loaded, it reports error + // "Element {http://www.opengis.net/gml}_Feature already defined" + // there is probably a bug in QXmlSchema: + // https://bugreports.qt-project.org/browse/QTBUG-8394 + // xmlpatternsvalidator gives the same error on XSD generated by OGR + if ( !schema.isValid() ) + { + // TODO: return QgsError + results.insert( count, tr( "GML schema is not valid" ) ); + continue; + } + QXmlSchemaValidator validator( schema ); + if ( !validator.validate( mIdentifyResultBodies.value( gmlPart ) ) ) + { + results.insert( count, tr( "GML is not valid" ) ); + continue; + } +#endif +#endif gmlSchema.parseXSD( mIdentifyResultBodies.value( xsdPart ) ); } else @@ -4101,7 +4148,6 @@ QMap QgsWmsProvider::identify( const QgsPoint & thePoint, Identif } results.insert( count, qVariantFromValue( featureStoreList ) ); } - count++; } QString str;