|
@@ -806,13 +806,13 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer, |
|
|
// Add all supported formats, best first. HTML is considered the best because |
|
|
// it usually holds most information. |
|
|
int capabilities = layer->dataProvider()->capabilities(); |
|
|
QList<QgsRaster::IdentifyFormat> formats; |
|
|
formats << QgsRaster::IdentifyFormatHtml |
|
|
<< QgsRaster::IdentifyFormatFeature |
|
|
<< QgsRaster::IdentifyFormatText |
|
|
<< QgsRaster::IdentifyFormatValue; |
|
|
const auto constFormats = formats; |
|
|
for ( QgsRaster::IdentifyFormat f : constFormats ) |
|
|
const QList<QgsRaster::IdentifyFormat> formats |
|
|
{ |
|
|
QgsRaster::IdentifyFormatHtml, |
|
|
QgsRaster::IdentifyFormatFeature, |
|
|
QgsRaster::IdentifyFormatText, |
|
|
QgsRaster::IdentifyFormatValue }; |
|
|
for ( const auto &f : formats ) |
|
|
{ |
|
|
if ( !( QgsRasterDataProvider::identifyFormatToCapability( f ) & capabilities ) ) |
|
|
continue; |
|
@@ -829,8 +829,8 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer, |
|
|
QTreeWidgetItem *formatItem = new QTreeWidgetItem( QStringList() << ' ' + tr( "Format" ) ); |
|
|
layItem->addChild( formatItem ); |
|
|
lstResults->setItemWidget( formatItem, 1, formatCombo ); |
|
|
connect( formatCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), |
|
|
this, static_cast<void ( QgsIdentifyResultsDialog::* )( int )>( &QgsIdentifyResultsDialog::formatChanged ) ); |
|
|
connect( formatCombo, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), |
|
|
this, qgis::overload<int>::of( &QgsIdentifyResultsDialog::formatChanged ) ); |
|
|
} |
|
|
else |
|
|
{ |
|
@@ -856,23 +856,46 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer, |
|
|
if ( i >= fields.count() ) |
|
|
continue; |
|
|
|
|
|
QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << QString::number( i ) << attrs.at( i ).toString() ); |
|
|
|
|
|
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() ); |
|
|
|
|
|
QVariant value = attrs.at( i ); |
|
|
attrItem->setData( 1, Qt::DisplayRole, value ); |
|
|
attrItem->setData( 1, Qt::DisplayRole, attrs.at( i ) ); |
|
|
featItem->addChild( attrItem ); |
|
|
bool foundLinks = false; |
|
|
const auto links { QgsStringUtils::insertLinks( value, &foundLinks ) }; |
|
|
if ( foundLinks ) |
|
|
{ |
|
|
auto valueLabel { qgis::make_unique<QLabel>( links ) }; |
|
|
attrItem->setText( 1, QString( ) ); |
|
|
valueLabel->setOpenExternalLinks( true ); |
|
|
lstResults->setItemWidget( attrItem, 1, valueLabel.release() ); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if ( currentFormat == QgsRaster::IdentifyFormatHtml || currentFormat == QgsRaster::IdentifyFormatText ) |
|
|
{ |
|
|
QgsIdentifyResultsWebViewItem *attrItem = new QgsIdentifyResultsWebViewItem( lstResults ); |
|
|
attrItem->webView()->page()->setLinkDelegationPolicy( QWebPage::DelegateExternalLinks ); |
|
|
const int horizontalDpi = qApp->desktop()->screen()->logicalDpiX(); |
|
|
// Adjust zoom: text is ok, but HTML seems rather big at least on Linux/KDE |
|
|
if ( horizontalDpi > 96 ) |
|
|
{ |
|
|
attrItem->webView()->setZoomFactor( attrItem->webView()->zoomFactor() * ( currentFormat == QgsRaster::IdentifyFormatHtml ? 0.7 : 0.9 ) ); |
|
|
} |
|
|
connect( attrItem->webView(), &QWebView::linkClicked, [ ]( const QUrl & url ) |
|
|
{ |
|
|
QDesktopServices::openUrl( url ); |
|
|
} ); |
|
|
featItem->addChild( attrItem ); // before setHtml()! |
|
|
if ( !attributes.isEmpty() ) |
|
|
{ |
|
|
attrItem->setContent( attributes.begin().value().toUtf8(), currentFormat == QgsRaster::IdentifyFormatHtml ? "text/html" : "text/plain; charset=utf-8" ); |
|
|
auto value { QgsStringUtils::insertLinks( attributes.begin().value() ) }; |
|
|
if ( currentFormat == QgsRaster::IdentifyFormatText ) |
|
|
{ |
|
|
value.prepend( QStringLiteral( "<pre style=\"font-family: monospace;\">" ) ).append( QStringLiteral( "</pre>" ) ); |
|
|
} |
|
|
attrItem->setHtml( value ); |
|
|
} |
|
|
else |
|
|
{ |
|
@@ -914,7 +937,20 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer, |
|
|
tblResults->setItem( j, 0, item ); |
|
|
tblResults->setItem( j, 1, new QTableWidgetItem( QString::number( i + 1 ) ) ); |
|
|
tblResults->setItem( j, 2, new QTableWidgetItem( it.key() ) ); |
|
|
tblResults->setItem( j, 3, new QTableWidgetItem( it.value() ) ); |
|
|
|
|
|
bool foundLinks = false; |
|
|
QString links = QgsStringUtils::insertLinks( it.value(), &foundLinks ); |
|
|
if ( foundLinks ) |
|
|
{ |
|
|
auto valueLabel { qgis::make_unique<QLabel>( links ) }; |
|
|
valueLabel->setOpenExternalLinks( true ); |
|
|
tblResults->setItem( j, 3, item ); |
|
|
tblResults->setCellWidget( j, 3, valueLabel.release() ); |
|
|
} |
|
|
else |
|
|
{ |
|
|
tblResults->setItem( j, 3, new QTableWidgetItem( it.value() ) ); |
|
|
} |
|
|
|
|
|
tblResults->resizeRowToContents( j ); |
|
|
|
|
|