Skip to content
Permalink
Browse files
improve html viewing in identify results window:
- add print to normal context menu instead of replacing it completely
- enable inspection with QGISDEBUG
- allow accessing remote urls
- use QgsNetworkManager (eg. to allow skip SSL errors or do
  authenticaton)
  • Loading branch information
jef-n committed Dec 12, 2012
1 parent 51d7d56 commit c7fb23079779444b29cc83fecff0d147ecd04a15
Showing with 46 additions and 25 deletions.
  1. +33 −24 src/app/qgsidentifyresults.cpp
  2. +13 −1 src/app/qgsidentifyresults.h
@@ -28,6 +28,8 @@
#include "qgsmapcanvas.h"
#include "qgsattributeaction.h"
#include "qgsfeatureaction.h"
#include "qgslogger.h"
#include "qgsnetworkaccessmanager.h"

#include <QCloseEvent>
#include <QLabel>
@@ -46,7 +48,36 @@
#include <QDesktopServices>
#include <QMessageBox>

#include "qgslogger.h"
QgsWebView::QgsWebView( QWidget *parent ) : QWebView( parent )
{
page()->setNetworkAccessManager( QgsNetworkAccessManager::instance() );
page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );
settings()->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls, true );
#ifdef QGISDEBUG
settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, true );
#endif
}

void QgsWebView::print( void )
{
QPrinter printer;
QPrintDialog *dialog = new QPrintDialog( &printer );
if ( dialog->exec() == QDialog::Accepted )
QWebView::print( &printer );
}

void QgsWebView::contextMenuEvent( QContextMenuEvent *e )
{
QMenu *menu = page()->createStandardContextMenu();
if ( menu )
{
QAction *action = new QAction( tr( "Print" ), this );
connect( action, SIGNAL( triggered() ), this, SLOT( print() ) );
menu->addAction( action );
menu->exec( e->globalPos() );
delete menu;
}
}

class QgsIdentifyResultsDock : public QDockWidget
{
@@ -289,15 +320,9 @@ void QgsIdentifyResults::addFeature( QgsRasterLayer *layer,
QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << attributes.begin().key() << "" );
featItem->addChild( attrItem );

QWebView *wv = new QWebView( attrItem->treeWidget() );
QgsWebView *wv = new QgsWebView( attrItem->treeWidget() );
wv->setHtml( attributes.begin().value() );
wv->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );

QAction *action = new QAction( tr( "Print" ), wv );
connect( action, SIGNAL( triggered() ), this, SLOT( print() ) );
wv->insertAction( 0, action );

wv->setContextMenuPolicy( Qt::ActionsContextMenu );
mPrintToolButton->setVisible( true );

connect( wv, SIGNAL( linkClicked( const QUrl & ) ), this, SLOT( openUrl( const QUrl & ) ) );
@@ -1040,22 +1065,6 @@ void QgsIdentifyResults::openUrl( const QUrl &url )
}
}

void QgsIdentifyResults::print()
{
QAction *action = qobject_cast<QAction*>( sender() );
if ( !action )
return;

QWebView *wv = qobject_cast<QWebView*>( action->parent() );
if ( !wv )
return;

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

void QgsIdentifyResults::printCurrentItem()
{
QTreeWidgetItem *item = lstResults->currentItem();
@@ -25,6 +25,7 @@

#include <QWidget>
#include <QList>
#include <QWebView>

class QCloseEvent;
class QTreeWidgetItem;
@@ -119,7 +120,6 @@ class QgsIdentifyResults: public QDialog, private Ui::QgsIdentifyResultsBase
void on_mCollapseToolButton_clicked( bool checked ) { Q_UNUSED( checked ); collapseAll(); }

void openUrl( const QUrl &url );
void print();
void printCurrentItem();

private:
@@ -148,4 +148,16 @@ class QgsIdentifyResults: public QDialog, private Ui::QgsIdentifyResultsBase
QDockWidget *mDock;
};

class QgsWebView : public QWebView
{
Q_OBJECT;
public:
QgsWebView( QWidget *parent = 0 );
public slots:
void print( void );
protected:
void contextMenuEvent( QContextMenuEvent* );
};


#endif

0 comments on commit c7fb230

Please sign in to comment.