Skip to content

Commit

Permalink
Html identify result print fix
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Feb 17, 2013
1 parent ddaded8 commit db95b46
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions src/app/qgsidentifyresultsdialog.cpp
Expand Up @@ -70,7 +70,9 @@ void QgsWebView::print( void )
QPrinter printer;
QPrintDialog *dialog = new QPrintDialog( &printer );
if ( dialog->exec() == QDialog::Accepted )
{
QWebView::print( &printer );
}
}

void QgsWebView::contextMenuEvent( QContextMenuEvent *e )
Expand Down Expand Up @@ -502,8 +504,6 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
featItem->addChild( attrItem ); // before setHtml()!
attrItem->setHtml( attributes.begin().value() );
connect( attrItem->webView(), SIGNAL( linkClicked( const QUrl & ) ), this, SLOT( openUrl( const QUrl & ) ) );

mPrintToolButton->setVisible( true );
}
else
{
Expand Down Expand Up @@ -757,8 +757,9 @@ void QgsIdentifyResultsDialog::clear()
lstResults->clear();
clearHighlights();

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

void QgsIdentifyResultsDialog::activate()
Expand Down Expand Up @@ -929,6 +930,8 @@ void QgsIdentifyResultsDialog::handleCurrentItemChanged( QTreeWidgetItem *curren
{
Q_UNUSED( previous );

mPrintToolButton->setEnabled( false );

QgsIdentifyResultsFeatureItem *featItem = dynamic_cast<QgsIdentifyResultsFeatureItem *>( featureItem( current ) );
mCopyToolButton->setEnabled( featItem && featItem->feature().isValid() );

Expand All @@ -938,8 +941,16 @@ void QgsIdentifyResultsDialog::handleCurrentItemChanged( QTreeWidgetItem *curren
return;
}

QWebView *wv = qobject_cast<QWebView*>( current->treeWidget()->itemWidget( current, 1 ) );
mPrintToolButton->setEnabled( wv != 0 );
// An item may be printed if a child is QgsIdentifyResultsWebViewItem
for ( int i = 0; i < current->childCount(); i++ )
{
QgsIdentifyResultsWebViewItem *wv = dynamic_cast<QgsIdentifyResultsWebViewItem*>( current->child( i ) );
if ( wv != 0 )
{
mPrintToolButton->setEnabled( true );
break;
}
}

QTreeWidgetItem *layItem = layerItem( current );
if ( current == layItem )
Expand Down Expand Up @@ -1264,17 +1275,22 @@ void QgsIdentifyResultsDialog::openUrl( const QUrl &url )
void QgsIdentifyResultsDialog::printCurrentItem()
{
QTreeWidgetItem *item = lstResults->currentItem();
if ( !item )
return;
if ( !item ) { return; }

QWebView *wv = qobject_cast<QWebView*>( item->treeWidget()->itemWidget( item, 1 ) );
if ( !wv )
// There should only be one HTML item / result
QgsIdentifyResultsWebViewItem *wv = 0;
for ( int i = 0; i < item->childCount(); i++ )
{
wv = dynamic_cast<QgsIdentifyResultsWebViewItem*>( item->child( i ) );
if ( wv != 0 ) { break; }
}
if ( wv == 0 )
{
QMessageBox::warning( this, tr( "Cannot not print" ), tr( "Cannot print this item" ) );
return;
}

QPrinter printer;
QPrintDialog *dialog = new QPrintDialog( &printer );
if ( dialog->exec() == QDialog::Accepted )
wv->print( &printer );
wv->webView()->print();
}

void QgsIdentifyResultsDialog::on_mExpandNewToolButton_toggled( bool checked )
Expand Down

0 comments on commit db95b46

Please sign in to comment.