|
28 | 28 | #include "qgsmapcanvas.h"
|
29 | 29 | #include "qgsattributeaction.h"
|
30 | 30 | #include "qgsfeatureaction.h"
|
| 31 | +#include "qgslogger.h" |
| 32 | +#include "qgsnetworkaccessmanager.h" |
31 | 33 |
|
32 | 34 | #include <QCloseEvent>
|
33 | 35 | #include <QLabel>
|
|
46 | 48 | #include <QDesktopServices>
|
47 | 49 | #include <QMessageBox>
|
48 | 50 |
|
49 |
| -#include "qgslogger.h" |
| 51 | +QgsWebView::QgsWebView( QWidget *parent ) : QWebView( parent ) |
| 52 | +{ |
| 53 | + page()->setNetworkAccessManager( QgsNetworkAccessManager::instance() ); |
| 54 | + page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks ); |
| 55 | + settings()->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls, true ); |
| 56 | +#ifdef QGISDEBUG |
| 57 | + settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, true ); |
| 58 | +#endif |
| 59 | +} |
| 60 | + |
| 61 | +void QgsWebView::print( void ) |
| 62 | +{ |
| 63 | + QPrinter printer; |
| 64 | + QPrintDialog *dialog = new QPrintDialog( &printer ); |
| 65 | + if ( dialog->exec() == QDialog::Accepted ) |
| 66 | + QWebView::print( &printer ); |
| 67 | +} |
| 68 | + |
| 69 | +void QgsWebView::contextMenuEvent( QContextMenuEvent *e ) |
| 70 | +{ |
| 71 | + QMenu *menu = page()->createStandardContextMenu(); |
| 72 | + if ( menu ) |
| 73 | + { |
| 74 | + QAction *action = new QAction( tr( "Print" ), this ); |
| 75 | + connect( action, SIGNAL( triggered() ), this, SLOT( print() ) ); |
| 76 | + menu->addAction( action ); |
| 77 | + menu->exec( e->globalPos() ); |
| 78 | + delete menu; |
| 79 | + } |
| 80 | +} |
50 | 81 |
|
51 | 82 | class QgsIdentifyResultsDock : public QDockWidget
|
52 | 83 | {
|
@@ -289,15 +320,9 @@ void QgsIdentifyResults::addFeature( QgsRasterLayer *layer,
|
289 | 320 | QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << attributes.begin().key() << "" );
|
290 | 321 | featItem->addChild( attrItem );
|
291 | 322 |
|
292 |
| - QWebView *wv = new QWebView( attrItem->treeWidget() ); |
| 323 | + QgsWebView *wv = new QgsWebView( attrItem->treeWidget() ); |
293 | 324 | wv->setHtml( attributes.begin().value() );
|
294 |
| - wv->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks ); |
295 |
| - |
296 |
| - QAction *action = new QAction( tr( "Print" ), wv ); |
297 |
| - connect( action, SIGNAL( triggered() ), this, SLOT( print() ) ); |
298 |
| - wv->insertAction( 0, action ); |
299 | 325 |
|
300 |
| - wv->setContextMenuPolicy( Qt::ActionsContextMenu ); |
301 | 326 | mPrintToolButton->setVisible( true );
|
302 | 327 |
|
303 | 328 | connect( wv, SIGNAL( linkClicked( const QUrl & ) ), this, SLOT( openUrl( const QUrl & ) ) );
|
@@ -1040,22 +1065,6 @@ void QgsIdentifyResults::openUrl( const QUrl &url )
|
1040 | 1065 | }
|
1041 | 1066 | }
|
1042 | 1067 |
|
1043 |
| -void QgsIdentifyResults::print() |
1044 |
| -{ |
1045 |
| - QAction *action = qobject_cast<QAction*>( sender() ); |
1046 |
| - if ( !action ) |
1047 |
| - return; |
1048 |
| - |
1049 |
| - QWebView *wv = qobject_cast<QWebView*>( action->parent() ); |
1050 |
| - if ( !wv ) |
1051 |
| - return; |
1052 |
| - |
1053 |
| - QPrinter printer; |
1054 |
| - QPrintDialog *dialog = new QPrintDialog( &printer ); |
1055 |
| - if ( dialog->exec() == QDialog::Accepted ) |
1056 |
| - wv->print( &printer ); |
1057 |
| -} |
1058 |
| - |
1059 | 1068 | void QgsIdentifyResults::printCurrentItem()
|
1060 | 1069 | {
|
1061 | 1070 | QTreeWidgetItem *item = lstResults->currentItem();
|
|
0 commit comments