@@ -70,7 +70,9 @@ void QgsWebView::print( void )
70
70
QPrinter printer;
71
71
QPrintDialog *dialog = new QPrintDialog ( &printer );
72
72
if ( dialog->exec () == QDialog::Accepted )
73
+ {
73
74
QWebView::print ( &printer );
75
+ }
74
76
}
75
77
76
78
void QgsWebView::contextMenuEvent ( QContextMenuEvent *e )
@@ -502,8 +504,6 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
502
504
featItem->addChild ( attrItem ); // before setHtml()!
503
505
attrItem->setHtml ( attributes.begin ().value () );
504
506
connect ( attrItem->webView (), SIGNAL ( linkClicked ( const QUrl & ) ), this , SLOT ( openUrl ( const QUrl & ) ) );
505
-
506
- mPrintToolButton ->setVisible ( true );
507
507
}
508
508
else
509
509
{
@@ -757,8 +757,9 @@ void QgsIdentifyResultsDialog::clear()
757
757
lstResults->clear ();
758
758
clearHighlights ();
759
759
760
+ // keep it visible but disabled, it can switch from disabled/enabled
761
+ // after raster format change
760
762
mPrintToolButton ->setDisabled ( true );
761
- mPrintToolButton ->setHidden ( true );
762
763
}
763
764
764
765
void QgsIdentifyResultsDialog::activate ()
@@ -929,6 +930,8 @@ void QgsIdentifyResultsDialog::handleCurrentItemChanged( QTreeWidgetItem *curren
929
930
{
930
931
Q_UNUSED ( previous );
931
932
933
+ mPrintToolButton ->setEnabled ( false );
934
+
932
935
QgsIdentifyResultsFeatureItem *featItem = dynamic_cast <QgsIdentifyResultsFeatureItem *>( featureItem ( current ) );
933
936
mCopyToolButton ->setEnabled ( featItem && featItem->feature ().isValid () );
934
937
@@ -938,8 +941,16 @@ void QgsIdentifyResultsDialog::handleCurrentItemChanged( QTreeWidgetItem *curren
938
941
return ;
939
942
}
940
943
941
- QWebView *wv = qobject_cast<QWebView*>( current->treeWidget ()->itemWidget ( current, 1 ) );
942
- mPrintToolButton ->setEnabled ( wv != 0 );
944
+ // An item may be printed if a child is QgsIdentifyResultsWebViewItem
945
+ for ( int i = 0 ; i < current->childCount (); i++ )
946
+ {
947
+ QgsIdentifyResultsWebViewItem *wv = dynamic_cast <QgsIdentifyResultsWebViewItem*>( current->child ( i ) );
948
+ if ( wv != 0 )
949
+ {
950
+ mPrintToolButton ->setEnabled ( true );
951
+ break ;
952
+ }
953
+ }
943
954
944
955
QTreeWidgetItem *layItem = layerItem ( current );
945
956
if ( current == layItem )
@@ -1264,17 +1275,22 @@ void QgsIdentifyResultsDialog::openUrl( const QUrl &url )
1264
1275
void QgsIdentifyResultsDialog::printCurrentItem ()
1265
1276
{
1266
1277
QTreeWidgetItem *item = lstResults->currentItem ();
1267
- if ( !item )
1268
- return ;
1278
+ if ( !item ) { return ; }
1269
1279
1270
- QWebView *wv = qobject_cast<QWebView*>( item->treeWidget ()->itemWidget ( item, 1 ) );
1271
- if ( !wv )
1280
+ // There should only be one HTML item / result
1281
+ QgsIdentifyResultsWebViewItem *wv = 0 ;
1282
+ for ( int i = 0 ; i < item->childCount (); i++ )
1283
+ {
1284
+ wv = dynamic_cast <QgsIdentifyResultsWebViewItem*>( item->child ( i ) );
1285
+ if ( wv != 0 ) { break ; }
1286
+ }
1287
+ if ( wv == 0 )
1288
+ {
1289
+ QMessageBox::warning ( this , tr ( " Cannot not print" ), tr ( " Cannot print this item" ) );
1272
1290
return ;
1291
+ }
1273
1292
1274
- QPrinter printer;
1275
- QPrintDialog *dialog = new QPrintDialog ( &printer );
1276
- if ( dialog->exec () == QDialog::Accepted )
1277
- wv->print ( &printer );
1293
+ wv->webView ()->print ();
1278
1294
}
1279
1295
1280
1296
void QgsIdentifyResultsDialog::on_mExpandNewToolButton_toggled ( bool checked )
0 commit comments