Skip to content

Commit ab2442b

Browse files
committedNov 3, 2012
allow printing of html results in identify window (implements #6575)
1 parent 744314d commit ab2442b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
 

‎src/app/qgsidentifyresults.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include <QMenuBar>
4242
#include <QPushButton>
4343
#include <QWebView>
44+
#include <QPrinter>
45+
#include <QPrintDialog>
4446
#include <QDesktopServices>
4547
#include <QMessageBox>
4648

@@ -286,6 +288,13 @@ void QgsIdentifyResults::addFeature( QgsRasterLayer *layer,
286288
QWebView *wv = new QWebView( attrItem->treeWidget() );
287289
wv->setHtml( attributes.begin().value() );
288290
wv->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );
291+
292+
QAction *action = new QAction( tr( "Print" ), wv );
293+
connect( action, SIGNAL( triggered() ), this, SLOT( print() ) );
294+
wv->insertAction( 0, action );
295+
296+
wv->setContextMenuPolicy( Qt::ActionsContextMenu );
297+
289298
connect( wv, SIGNAL( linkClicked( const QUrl & ) ), this, SLOT( openUrl( const QUrl & ) ) );
290299
attrItem->treeWidget()->setItemWidget( attrItem, 1, wv );
291300
}
@@ -1020,6 +1029,22 @@ void QgsIdentifyResults::openUrl( const QUrl &url )
10201029
}
10211030
}
10221031

1032+
void QgsIdentifyResults::print()
1033+
{
1034+
QAction *action = qobject_cast<QAction*>( sender() );
1035+
if ( !action )
1036+
return;
1037+
1038+
QWebView *wv = qobject_cast<QWebView*>( action->parent() );
1039+
if ( !wv )
1040+
return;
1041+
1042+
QPrinter printer;
1043+
QPrintDialog *dialog = new QPrintDialog( &printer );
1044+
if ( dialog->exec() == QDialog::Accepted )
1045+
wv->print( &printer );
1046+
}
1047+
10231048
void QgsIdentifyResults:: on_mExpandNewToolButton_toggled( bool checked )
10241049
{
10251050
QSettings settings;

‎src/app/qgsidentifyresults.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class QgsIdentifyResults: public QDialog, private Ui::QgsIdentifyResultsBase
119119
void on_mCollapseToolButton_clicked( bool checked ) { Q_UNUSED( checked ); collapseAll(); }
120120

121121
void openUrl( const QUrl &url );
122+
void print();
122123

123124
private:
124125
QMenu *mActionPopup;

0 commit comments

Comments
 (0)
Please sign in to comment.