Skip to content

Commit

Permalink
[vectortiles] Make information tab appearance/content consistent
Browse files Browse the repository at this point in the history
with other layer types
  • Loading branch information
nyalldawson committed Sep 7, 2020
1 parent 9eea1c0 commit 88f9dae
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 17 deletions.
Expand Up @@ -99,6 +99,8 @@ Constructs a new vector tile layer

virtual QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const ${SIP_FINAL};

virtual QString htmlMetadata() const;



QString sourceType() const;
Expand Down
47 changes: 38 additions & 9 deletions src/app/vectortile/qgsvectortilelayerproperties.cpp
Expand Up @@ -22,11 +22,14 @@
#include "qgsvectortilebasicrendererwidget.h"
#include "qgsvectortilebasiclabelingwidget.h"
#include "qgsvectortilelayer.h"
#include "qgsgui.h"
#include "qgsnative.h"
#include "qgsapplication.h"

#include <QFileDialog>
#include <QMenu>
#include <QMessageBox>

#include <QDesktopServices>

QgsVectorTileLayerProperties::QgsVectorTileLayerProperties( QgsVectorTileLayer *lyr, QgsMapCanvas *canvas, QgsMessageBar *messageBar, QWidget *parent, Qt::WindowFlags flags )
: QgsOptionsDialogBase( QStringLiteral( "VectorTileLayerProperties" ), parent, flags )
Expand All @@ -51,6 +54,27 @@ QgsVectorTileLayerProperties::QgsVectorTileLayerProperties( QgsVectorTileLayer *
// and connecting QDialogButtonBox's accepted/rejected signals to dialog's accept/reject slots
initOptionsBase( false );

#ifdef WITH_QTWEBKIT
// Setup information tab

#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
const int horizontalDpi = qApp->desktop()->screen()->logicalDpiX();
#else
const int horizontalDpi = logicalDpiX();
#endif

// Adjust zoom: text is ok, but HTML seems rather big at least on Linux/KDE
if ( horizontalDpi > 96 )
{
mMetadataViewer->setZoomFactor( mMetadataViewer->zoomFactor() * 0.9 );
}
mMetadataViewer->page()->setLinkDelegationPolicy( QWebPage::LinkDelegationPolicy::DelegateAllLinks );
connect( mMetadataViewer->page(), &QWebPage::linkClicked, this, &QgsVectorTileLayerProperties::urlClicked );
mMetadataViewer->page()->settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, true );
mMetadataViewer->page()->settings()->setAttribute( QWebSettings::JavascriptEnabled, true );

#endif

// update based on lyr's current state
syncToLayer();

Expand Down Expand Up @@ -93,14 +117,10 @@ void QgsVectorTileLayerProperties::syncToLayer()
/*
* Information Tab
*/
QString info;
info += QStringLiteral( "<table>" );
info += QStringLiteral( "<tr><td>%1: </td><td>%2</td><tr>" ).arg( tr( "Uri" ) ).arg( mLayer->source() );
info += QStringLiteral( "<tr><td>%1: </td><td>%2</td><tr>" ).arg( tr( "Source Type" ) ).arg( mLayer->sourceType() );
info += QStringLiteral( "<tr><td>%1: </td><td>%2</td><tr>" ).arg( tr( "Source Path" ) ).arg( mLayer->sourcePath() );
info += QStringLiteral( "<tr><td>%1: </td><td>%2 - %3</td><tr>" ).arg( tr( "Zoom Levels" ) ).arg( mLayer->sourceMinZoom() ).arg( mLayer->sourceMaxZoom() );
info += QStringLiteral( "</table>" );
mInformationTextBrowser->setText( info );
const QString myStyle = QgsApplication::reportStyleSheet( QgsApplication::StyleSheetType::WebBrowser );
// Inject the stylesheet
const QString html { mLayer->htmlMetadata().replace( QStringLiteral( "<head>" ), QStringLiteral( R"raw(<head><style type="text/css">%1</style>)raw" ) ).arg( myStyle ) };
mMetadataViewer->setHtml( html );

/*
* Symbology Tab
Expand Down Expand Up @@ -236,3 +256,12 @@ void QgsVectorTileLayerProperties::showHelp()
QgsHelp::openHelp( QStringLiteral( "working_with_vector_tiles/vector_tiles_properties.html" ) );
}
}

void QgsVectorTileLayerProperties::urlClicked( const QUrl &url )
{
QFileInfo file( url.toLocalFile() );
if ( file.exists() && !file.isDir() )
QgsGui::instance()->nativePlatformInterface()->openFileExplorerAndSelectFile( url.toLocalFile() );
else
QDesktopServices::openUrl( url );
}
1 change: 1 addition & 0 deletions src/app/vectortile/qgsvectortilelayerproperties.h
Expand Up @@ -43,6 +43,7 @@ class QgsVectorTileLayerProperties : public QgsOptionsDialogBase, private Ui::Qg
void saveStyleAs();
void aboutToShowStyleMenu();
void showHelp();
void urlClicked( const QUrl &url );

private:
void syncToLayer();
Expand Down
61 changes: 61 additions & 0 deletions src/core/vectortile/qgsvectortilelayer.cpp
Expand Up @@ -25,6 +25,7 @@
#include "qgsvectortileutils.h"

#include "qgsdatasourceuri.h"
#include "qgslayermetadataformatter.h"


QgsVectorTileLayer::QgsVectorTileLayer( const QString &uri, const QString &baseName )
Expand Down Expand Up @@ -286,6 +287,66 @@ QString QgsVectorTileLayer::decodedSource( const QString &source, const QString
return source;
}

QString QgsVectorTileLayer::htmlMetadata() const
{
QgsLayerMetadataFormatter htmlFormatter( metadata() );

QString info = QStringLiteral( "<html><head></head>\n<body>\n" );

info += QStringLiteral( "<h1>" ) + tr( "Information from provider" ) + QStringLiteral( "</h1>\n<hr>\n" ) %
QStringLiteral( "<table class=\"list-view\">\n" ) %

// name
QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "Name" ) % QStringLiteral( "</td><td>" ) % name() % QStringLiteral( "</td></tr>\n" );

info += QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "URI" ) % QStringLiteral( "</td><td>" ) % source() % QStringLiteral( "</td></tr>\n" );
info += QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "Source type" ) % QStringLiteral( "</td><td>" ) % sourceType() % QStringLiteral( "</td></tr>\n" );

const QString url = sourcePath();
info += QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "Source path" ) % QStringLiteral( "</td><td>%1" ).arg( QStringLiteral( "<a href=\"%1\">%2</a>" ).arg( QUrl( url ).toString(), sourcePath() ) ) + QStringLiteral( "</td></tr>\n" );

info += QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "Zoom levels" ) % QStringLiteral( "</td><td>" ) % QStringLiteral( "%1 - %2" ).arg( sourceMinZoom() ).arg( sourceMaxZoom() ) % QStringLiteral( "</td></tr>\n" );
info += QStringLiteral( "</table>" );

// End Provider section
info += QStringLiteral( "</table>\n<br><br>" );

// Identification section
info += QStringLiteral( "<h1>" ) % tr( "Identification" ) % QStringLiteral( "</h1>\n<hr>\n" ) %
htmlFormatter.identificationSectionHtml() %
QStringLiteral( "<br><br>\n" ) %

// extent section
QStringLiteral( "<h1>" ) % tr( "Extent" ) % QStringLiteral( "</h1>\n<hr>\n" ) %
htmlFormatter.extentSectionHtml( ) %
QStringLiteral( "<br><br>\n" ) %

// Start the Access section
QStringLiteral( "<h1>" ) % tr( "Access" ) % QStringLiteral( "</h1>\n<hr>\n" ) %
htmlFormatter.accessSectionHtml( ) %
QStringLiteral( "<br><br>\n" ) %


// Start the contacts section
QStringLiteral( "<h1>" ) % tr( "Contacts" ) % QStringLiteral( "</h1>\n<hr>\n" ) %
htmlFormatter.contactsSectionHtml( ) %
QStringLiteral( "<br><br>\n" ) %

// Start the links section
QStringLiteral( "<h1>" ) % tr( "References" ) % QStringLiteral( "</h1>\n<hr>\n" ) %
htmlFormatter.linksSectionHtml( ) %
QStringLiteral( "<br><br>\n" ) %

// Start the history section
QStringLiteral( "<h1>" ) % tr( "History" ) % QStringLiteral( "</h1>\n<hr>\n" ) %
htmlFormatter.historySectionHtml( ) %
QStringLiteral( "<br><br>\n" ) %

QStringLiteral( "\n</body>\n</html>\n" );

return info;
}

QByteArray QgsVectorTileLayer::getRawTile( QgsTileXYZ tileID )
{
QgsTileMatrix tileMatrix = QgsTileMatrix::fromWebMercator( tileID.zoomLevel() );
Expand Down
1 change: 1 addition & 0 deletions src/core/vectortile/qgsvectortilelayer.h
Expand Up @@ -109,6 +109,7 @@ class CORE_EXPORT QgsVectorTileLayer : public QgsMapLayer

QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const FINAL;
QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const FINAL;
QString htmlMetadata() const override;

// new methods

Expand Down
66 changes: 58 additions & 8 deletions src/ui/qgsvectortilelayerpropertiesbase.ui
Expand Up @@ -48,7 +48,16 @@
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand Down Expand Up @@ -137,7 +146,16 @@
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand All @@ -152,21 +170,39 @@
<enum>QFrame::Plain</enum>
</property>
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<widget class="QWidget" name="mOptsPage_Information">
<layout class="QVBoxLayout" name="verticalLayout_20">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTextBrowser" name="mInformationTextBrowser"/>
<widget class="QgsWebView" name="mMetadataViewer" native="true"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="mOptsPage_Style">
<layout class="QVBoxLayout" name="verticalLayout_14">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
Expand Down Expand Up @@ -195,7 +231,16 @@
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0" colspan="2">
Expand All @@ -219,11 +264,16 @@
<extends>QLineEdit</extends>
<header>qgsfilterlineedit.h</header>
</customwidget>
<customwidget>
<class>QgsWebView</class>
<extends>QWidget</extends>
<header>qgswebview.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mSearchLineEdit</tabstop>
<tabstop>mOptionsListWidget</tabstop>
<tabstop>mInformationTextBrowser</tabstop>
</tabstops>
<resources>
<include location="../../images/images.qrc"/>
Expand Down

0 comments on commit 88f9dae

Please sign in to comment.