Skip to content

Commit

Permalink
Merge pull request #9879 from elpaso/bugfix-21735-gfi-json
Browse files Browse the repository at this point in the history
 Fix identify for WMS client with json format
  • Loading branch information
elpaso committed Apr 27, 2019
2 parents 6fa5663 + a884448 commit ffaa64e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 12 deletions.
76 changes: 65 additions & 11 deletions src/app/qgsidentifyresultsdialog.cpp
Expand Up @@ -781,6 +781,8 @@ QString QgsIdentifyResultsDialog::representValue( QgsVectorLayer *vlayer, const
return fieldFormatter->representValue( vlayer, idx, setup.config(), cache, value );
}


// Raster variant of addFeature
void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
const QString &label,
const QMap<QString, QString> &attributes,
Expand Down Expand Up @@ -856,19 +858,71 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
if ( i >= fields.count() )
continue;

const auto value { attrs.at( i ).toString() };
QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << QString::number( i ) << value );
attrItem->setData( 0, Qt::DisplayRole, fields.at( i ).name() );
attrItem->setData( 1, Qt::DisplayRole, attrs.at( i ) );
// We have no vector layer here (can't use the formatters), let's guess the format from the QVariant type
const auto value { attrs.at( i ) };
auto formattedValue { value.toString() };
bool isString = false;
if ( value.isValid( ) )
{
if ( value.type() == QVariant::Double )
{
bool ok;
double val( value.toDouble( &ok ) );
if ( ok )
{
// Precision is not set, let's guess it from the
// standard conversion to string
const auto strVal { value.toString() };
int dotPosition { strVal.indexOf( '.' ) };
int precision;
if ( dotPosition < 0 )
{
precision = 0;
}
else
{
precision = strVal.length() - dotPosition - 1;
}
formattedValue = QLocale().toString( val, 'f', precision );
}
}
else if ( value.type() == QVariant::Int )
{
bool ok;
double val( value.toInt( &ok ) );
if ( ok )
{
formattedValue = QLocale().toString( val, 'f', 0 );
}
}
else if ( value.type() == QVariant::LongLong )
{
bool ok;
double val( value.toLongLong( &ok ) );
if ( ok )
{
formattedValue = QLocale().toString( val, 'f', 0 );
}
}
else
{
isString = true;
}
}
QTreeWidgetItem *attrItem = new QTreeWidgetItem( { fields.at( i ).name(), formattedValue } );
featItem->addChild( attrItem );
bool foundLinks = false;
const auto links { QgsStringUtils::insertLinks( value, &foundLinks ) };
if ( foundLinks )
// If not numeric, convert links
if ( isString )
{
auto valueLabel { qgis::make_unique<QLabel>( links ) };
attrItem->setText( 1, QString( ) );
valueLabel->setOpenExternalLinks( true );
lstResults->setItemWidget( attrItem, 1, valueLabel.release() );
bool foundLinks = false;
const auto links { QgsStringUtils::insertLinks( formattedValue, &foundLinks ) };
if ( foundLinks )
{
auto valueLabel { qgis::make_unique<QLabel>( links ) };
attrItem->setText( 1, QString( ) );
valueLabel->setOpenExternalLinks( true );
lstResults->setItemWidget( attrItem, 1, valueLabel.release() );
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -3089,7 +3089,7 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPointXY &point, QgsRa
fieldIterator = properties.constBegin();
for ( ; fieldIterator != properties.constEnd(); ++fieldIterator )
{
feature.setAttribute( j++, fieldIterator.value().toString() );
feature.setAttribute( j++, fieldIterator.value().toVariant() );
}

QgsFeatureStore featureStore( fields, crs() );
Expand Down

0 comments on commit ffaa64e

Please sign in to comment.