@@ -806,13 +806,13 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
806
806
// Add all supported formats, best first. HTML is considered the best because
807
807
// it usually holds most information.
808
808
int capabilities = layer->dataProvider ()->capabilities ();
809
- QList<QgsRaster::IdentifyFormat> formats;
810
- formats << QgsRaster::IdentifyFormatHtml
811
- << QgsRaster::IdentifyFormatFeature
812
- << QgsRaster::IdentifyFormatText
813
- << QgsRaster::IdentifyFormatValue;
814
- const auto constFormats = formats ;
815
- for ( QgsRaster::IdentifyFormat f : constFormats )
809
+ static const QList<QgsRaster::IdentifyFormat> formats
810
+ {
811
+ QgsRaster::IdentifyFormatHtml,
812
+ QgsRaster::IdentifyFormatFeature,
813
+ QgsRaster::IdentifyFormatText,
814
+ QgsRaster::IdentifyFormatValue } ;
815
+ for ( const auto & f : formats )
816
816
{
817
817
if ( !( QgsRasterDataProvider::identifyFormatToCapability ( f ) & capabilities ) )
818
818
continue ;
@@ -829,8 +829,8 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
829
829
QTreeWidgetItem *formatItem = new QTreeWidgetItem ( QStringList () << ' ' + tr ( " Format" ) );
830
830
layItem->addChild ( formatItem );
831
831
lstResults->setItemWidget ( formatItem, 1 , formatCombo );
832
- connect ( formatCombo, static_cast < void ( QComboBox::* )( int )> ( &QComboBox::currentIndexChanged ),
833
- this , static_cast < void ( QgsIdentifyResultsDialog::* )( int )> ( &QgsIdentifyResultsDialog::formatChanged ) );
832
+ connect ( formatCombo, qgis::overload< int >:: of ( &QComboBox::currentIndexChanged ),
833
+ this , qgis::overload< int >:: of ( &QgsIdentifyResultsDialog::formatChanged ) );
834
834
}
835
835
else
836
836
{
@@ -856,23 +856,46 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
856
856
if ( i >= fields.count () )
857
857
continue ;
858
858
859
- QTreeWidgetItem *attrItem = new QTreeWidgetItem ( QStringList () << QString::number ( i ) << attrs.at ( i ).toString () ) ;
860
-
859
+ const auto value { attrs.at ( i ).toString () } ;
860
+ QTreeWidgetItem *attrItem = new QTreeWidgetItem ( QStringList () << QString::number ( i ) << value );
861
861
attrItem->setData ( 0 , Qt::DisplayRole, fields.at ( i ).name () );
862
-
863
- QVariant value = attrs.at ( i );
864
- attrItem->setData ( 1 , Qt::DisplayRole, value );
862
+ attrItem->setData ( 1 , Qt::DisplayRole, attrs.at ( i ) );
865
863
featItem->addChild ( attrItem );
864
+ bool foundLinks = false ;
865
+ const auto links { QgsStringUtils::insertLinks ( value, &foundLinks ) };
866
+ if ( foundLinks )
867
+ {
868
+ auto valueLabel { qgis::make_unique<QLabel>( links ) };
869
+ attrItem->setText ( 1 , QString ( ) );
870
+ valueLabel->setOpenExternalLinks ( true );
871
+ lstResults->setItemWidget ( attrItem, 1 , valueLabel.release () );
872
+ }
866
873
}
867
874
}
868
875
869
876
if ( currentFormat == QgsRaster::IdentifyFormatHtml || currentFormat == QgsRaster::IdentifyFormatText )
870
877
{
871
878
QgsIdentifyResultsWebViewItem *attrItem = new QgsIdentifyResultsWebViewItem ( lstResults );
879
+ attrItem->webView ()->page ()->setLinkDelegationPolicy ( QWebPage::DelegateExternalLinks );
880
+ const int horizontalDpi = qApp->desktop ()->screen ()->logicalDpiX ();
881
+ // Adjust zoom: text is ok, but HTML seems rather big at least on Linux/KDE
882
+ if ( horizontalDpi > 96 )
883
+ {
884
+ attrItem->webView ()->setZoomFactor ( attrItem->webView ()->zoomFactor () * ( currentFormat == QgsRaster::IdentifyFormatHtml ? 0.7 : 0.9 ) );
885
+ }
886
+ connect ( attrItem->webView (), &QWebView::linkClicked, [ ]( const QUrl & url )
887
+ {
888
+ QDesktopServices::openUrl ( url );
889
+ } );
872
890
featItem->addChild ( attrItem ); // before setHtml()!
873
891
if ( !attributes.isEmpty () )
874
892
{
875
- attrItem->setContent ( attributes.begin ().value ().toUtf8 (), currentFormat == QgsRaster::IdentifyFormatHtml ? " text/html" : " text/plain; charset=utf-8" );
893
+ auto value { QgsStringUtils::insertLinks ( attributes.begin ().value () ) };
894
+ if ( currentFormat == QgsRaster::IdentifyFormatText )
895
+ {
896
+ value.prepend ( QStringLiteral ( " <pre style=\" font-family: monospace;\" >" ) ).append ( QStringLiteral ( " </pre>" ) );
897
+ }
898
+ attrItem->setHtml ( value );
876
899
}
877
900
else
878
901
{
@@ -914,7 +937,20 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
914
937
tblResults->setItem ( j, 0 , item );
915
938
tblResults->setItem ( j, 1 , new QTableWidgetItem ( QString::number ( i + 1 ) ) );
916
939
tblResults->setItem ( j, 2 , new QTableWidgetItem ( it.key () ) );
917
- tblResults->setItem ( j, 3 , new QTableWidgetItem ( it.value () ) );
940
+
941
+ bool foundLinks = false ;
942
+ QString links = QgsStringUtils::insertLinks ( it.value (), &foundLinks );
943
+ if ( foundLinks )
944
+ {
945
+ auto valueLabel { qgis::make_unique<QLabel>( links ) };
946
+ valueLabel->setOpenExternalLinks ( true );
947
+ tblResults->setItem ( j, 3 , item );
948
+ tblResults->setCellWidget ( j, 3 , valueLabel.release () );
949
+ }
950
+ else
951
+ {
952
+ tblResults->setItem ( j, 3 , new QTableWidgetItem ( it.value () ) );
953
+ }
918
954
919
955
tblResults->resizeRowToContents ( j );
920
956
0 commit comments