Skip to content

Commit

Permalink
improve html viewing in identify results window:
Browse files Browse the repository at this point in the history
- 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 c7fb230
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 25 deletions.
57 changes: 33 additions & 24 deletions src/app/qgsidentifyresults.cpp
Expand Up @@ -28,6 +28,8 @@
#include "qgsmapcanvas.h"
#include "qgsattributeaction.h"
#include "qgsfeatureaction.h"
#include "qgslogger.h"
#include "qgsnetworkaccessmanager.h"

#include <QCloseEvent>
#include <QLabel>
Expand All @@ -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
{
Expand Down Expand Up @@ -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 & ) ) );
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 13 additions & 1 deletion src/app/qgsidentifyresults.h
Expand Up @@ -25,6 +25,7 @@

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

class QCloseEvent;
class QTreeWidgetItem;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.