Skip to content

Commit db95b46

Browse files
committed
Html identify result print fix
1 parent ddaded8 commit db95b46

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

src/app/qgsidentifyresultsdialog.cpp

+29-13
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ void QgsWebView::print( void )
7070
QPrinter printer;
7171
QPrintDialog *dialog = new QPrintDialog( &printer );
7272
if ( dialog->exec() == QDialog::Accepted )
73+
{
7374
QWebView::print( &printer );
75+
}
7476
}
7577

7678
void QgsWebView::contextMenuEvent( QContextMenuEvent *e )
@@ -502,8 +504,6 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
502504
featItem->addChild( attrItem ); // before setHtml()!
503505
attrItem->setHtml( attributes.begin().value() );
504506
connect( attrItem->webView(), SIGNAL( linkClicked( const QUrl & ) ), this, SLOT( openUrl( const QUrl & ) ) );
505-
506-
mPrintToolButton->setVisible( true );
507507
}
508508
else
509509
{
@@ -757,8 +757,9 @@ void QgsIdentifyResultsDialog::clear()
757757
lstResults->clear();
758758
clearHighlights();
759759

760+
// keep it visible but disabled, it can switch from disabled/enabled
761+
// after raster format change
760762
mPrintToolButton->setDisabled( true );
761-
mPrintToolButton->setHidden( true );
762763
}
763764

764765
void QgsIdentifyResultsDialog::activate()
@@ -929,6 +930,8 @@ void QgsIdentifyResultsDialog::handleCurrentItemChanged( QTreeWidgetItem *curren
929930
{
930931
Q_UNUSED( previous );
931932

933+
mPrintToolButton->setEnabled( false );
934+
932935
QgsIdentifyResultsFeatureItem *featItem = dynamic_cast<QgsIdentifyResultsFeatureItem *>( featureItem( current ) );
933936
mCopyToolButton->setEnabled( featItem && featItem->feature().isValid() );
934937

@@ -938,8 +941,16 @@ void QgsIdentifyResultsDialog::handleCurrentItemChanged( QTreeWidgetItem *curren
938941
return;
939942
}
940943

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+
}
943954

944955
QTreeWidgetItem *layItem = layerItem( current );
945956
if ( current == layItem )
@@ -1264,17 +1275,22 @@ void QgsIdentifyResultsDialog::openUrl( const QUrl &url )
12641275
void QgsIdentifyResultsDialog::printCurrentItem()
12651276
{
12661277
QTreeWidgetItem *item = lstResults->currentItem();
1267-
if ( !item )
1268-
return;
1278+
if ( !item ) { return; }
12691279

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" ) );
12721290
return;
1291+
}
12731292

1274-
QPrinter printer;
1275-
QPrintDialog *dialog = new QPrintDialog( &printer );
1276-
if ( dialog->exec() == QDialog::Accepted )
1277-
wv->print( &printer );
1293+
wv->webView()->print();
12781294
}
12791295

12801296
void QgsIdentifyResultsDialog::on_mExpandNewToolButton_toggled( bool checked )

0 commit comments

Comments
 (0)