Skip to content
Permalink
Browse files

[FEATURE] Add hyperlink to local vector,raster datasets in informatio…

…n panel
  • Loading branch information
nirvn committed Aug 8, 2018
1 parent f4a0e74 commit 45b209c2c1e38fa8c81c18e61704e27f5cc78366
@@ -19,6 +19,7 @@
#include <typeinfo>

#include "qgisapp.h"
#include "qgsgui.h"
#include "qgsapplication.h"
#include "qgsbilinearrasterresampler.h"
#include "qgsbrightnesscontrastfilter.h"
@@ -34,6 +35,7 @@
#include "qgsmetadatawidget.h"
#include "qgsmultibandcolorrenderer.h"
#include "qgsmultibandcolorrendererwidget.h"
#include "qgsnative.h"
#include "qgspalettedrendererwidget.h"
#include "qgsproject.h"
#include "qgsrasterbandstats.h"
@@ -54,9 +56,11 @@
#include "qgshillshaderendererwidget.h"
#include "qgssettings.h"

#include <QDesktopServices>
#include <QTableWidgetItem>
#include <QHeaderView>
#include <QTextStream>
#include <QFile>
#include <QFileDialog>
#include <QMessageBox>
#include <QPainter>
@@ -67,6 +71,7 @@
#include <QList>
#include <QMouseEvent>
#include <QVector>
#include <QUrl>

QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanvas *canvas, QWidget *parent, Qt::WindowFlags fl )
: QgsOptionsDialogBase( QStringLiteral( "RasterLayerProperties" ), parent, fl )
@@ -760,6 +765,8 @@ void QgsRasterLayerProperties::sync()
myStyle.append( QStringLiteral( "body { margin: 10px; }\n " ) );
teMetadataViewer->document()->setDefaultStyleSheet( myStyle );
teMetadataViewer->setHtml( mRasterLayer->htmlMetadata() );
teMetadataViewer->setOpenLinks( false );
connect( teMetadataViewer, &QTextBrowser::anchorClicked, this, &QgsRasterLayerProperties::urlClicked );
mMetadataFilled = true;

// WMS Name as layer short name
@@ -1173,6 +1180,15 @@ void QgsRasterLayerProperties::buttonBuildPyramids_clicked()
teMetadataViewer->document()->setDefaultStyleSheet( myStyle );
}

void QgsRasterLayerProperties::urlClicked( const QUrl &url )
{
QFileInfo file( url.toLocalFile() );
if ( file.exists() && !file.isDir() )
QgsGui::instance()->nativePlatformInterface()->openFileExplorerAndSelectFile( url.toLocalFile() );
else
QDesktopServices::openUrl( url );
}

void QgsRasterLayerProperties::mRenderTypeComboBox_currentIndexChanged( int index )
{
if ( index < 0 || mDisableRenderTypeComboBoxCurrentIndexChanged )
@@ -137,6 +137,8 @@ class APP_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
//! Make GUI reflect the layer's state
void syncToLayer();

void urlClicked( const QUrl &url );

signals:
//! Emitted when changes to layer were saved to update legend
void refreshLegend( const QString &layerID, bool expandItem );
@@ -39,6 +39,7 @@
#include "qgsmaplayerconfigwidgetfactory.h"
#include "qgsmaplayerstyleguiutils.h"
#include "qgsmetadatawidget.h"
#include "qgsnative.h"
#include "qgspluginmetadata.h"
#include "qgspluginregistry.h"
#include "qgsproject.h"
@@ -65,6 +66,7 @@
#include "layertree/qgslayertreelayer.h"
#include "qgslayertree.h"

#include <QDesktopServices>
#include <QMessageBox>
#include <QDir>
#include <QFile>
@@ -75,6 +77,7 @@
#include <QCheckBox>
#include <QHeaderView>
#include <QColorDialog>
#include <QUrl>

#include "qgsrendererpropertiesdialog.h"
#include "qgsstyle.h"
@@ -348,6 +351,8 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
teMetadataViewer->clear();
teMetadataViewer->document()->setDefaultStyleSheet( myStyle );
teMetadataViewer->setHtml( htmlMetadata() );
teMetadataViewer->setOpenLinks( false );
connect( teMetadataViewer, &QTextBrowser::anchorClicked, this, &QgsVectorLayerProperties::urlClicked );
mMetadataFilled = true;

QgsSettings settings;
@@ -798,6 +803,15 @@ void QgsVectorLayerProperties::onCancel()
}
}

void QgsVectorLayerProperties::urlClicked( const QUrl &url )
{
QFileInfo file( url.toLocalFile() );
if ( file.exists() && !file.isDir() )
QgsGui::instance()->nativePlatformInterface()->openFileExplorerAndSelectFile( url.toLocalFile() );
else
QDesktopServices::openUrl( url );
}

void QgsVectorLayerProperties::pbnQueryBuilder_clicked()
{
// launch the query builder
@@ -169,6 +169,8 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private

void onAuxiliaryLayerExport();

void urlClicked( const QUrl &url );

private:

enum PropertyType
@@ -1190,7 +1190,6 @@ QString QgsApplication::reportStyleSheet()
"}"
"a{ color: #729FCF;"
" font-family: arial,sans-serif;"
" font-size: small;"
"}"
"label{ background-color: #FFFFCC;"
" border: 1px solid black;"
@@ -23,6 +23,7 @@

#include <limits>

#include <QFile>
#include <QImage>
#include <QPainter>
#include <QPainterPath>
@@ -32,6 +33,7 @@
#include <QDomNode>
#include <QVector>
#include <QStringBuilder>
#include <QUrl>
#if QT_VERSION >= 0x050900
#include <QUndoCommand>
#endif
@@ -4162,7 +4164,11 @@ QString QgsVectorLayer::htmlMetadata() const
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Name" ) + QStringLiteral( "</td><td>" ) + name() + QStringLiteral( "</td></tr>\n" );

// data source
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Source" ) + QStringLiteral( "</td><td>" ) + publicSource() + QStringLiteral( "</td></tr>\n" );
QVariantMap uriComponents = QgsProviderRegistry::instance()->decodeUri( mProviderKey, publicSource() );
QString path;
if ( uriComponents.contains( QStringLiteral( "path" ) ) )
path = uriComponents[QStringLiteral( "path" )].toString();
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Source" ) + QStringLiteral( "</td><td>%1" ).arg( QFile::exists( path ) ? QStringLiteral( "<a href=\"%1\">%2</a>" ).arg( QUrl::fromLocalFile( path ).toString(), publicSource() ) : publicSource() ) + QStringLiteral( "</td></tr>\n" );

// storage type
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Storage" ) + QStringLiteral( "</td><td>" ) + storageType() + QStringLiteral( "</td></tr>\n" );
@@ -318,7 +318,11 @@ QString QgsRasterLayer::htmlMetadata() const
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Name" ) + QStringLiteral( "</td><td>" ) + name() + QStringLiteral( "</td></tr>\n" );

// data source
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Source" ) + QStringLiteral( "</td><td>" ) + publicSource() + QStringLiteral( "</td></tr>\n" );
QVariantMap uriComponents = QgsProviderRegistry::instance()->decodeUri( mProviderKey, publicSource() );
QString path;
if ( uriComponents.contains( QStringLiteral( "path" ) ) )
path = uriComponents[QStringLiteral( "path" )].toString();
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Source" ) + QStringLiteral( "</td><td>%1" ).arg( QFile::exists( path ) ? QStringLiteral( "<a href=\"%1\">%2</a>" ).arg( QUrl::fromLocalFile( path ).toString(), publicSource() ) : publicSource() ) + QStringLiteral( "</td></tr>\n" );

// storage type
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Provider" ) + QStringLiteral( "</td><td>" ) + providerType() + QStringLiteral( "</td></tr>\n" );

0 comments on commit 45b209c

Please sign in to comment.
You can’t perform that action at this time.