Skip to content

Commit

Permalink
[FEATURE] Add hyperlink to local vector,raster datasets in informatio…
Browse files Browse the repository at this point in the history
…n panel
  • Loading branch information
nirvn committed Aug 16, 2018
1 parent f4a0e74 commit 45b209c
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -19,6 +19,7 @@
#include <typeinfo>

#include "qgisapp.h"
#include "qgsgui.h"
#include "qgsapplication.h"
#include "qgsbilinearrasterresampler.h"
#include "qgsbrightnesscontrastfilter.h"
Expand All @@ -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"
Expand All @@ -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>
Expand All @@ -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 )
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 )
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsrasterlayerproperties.h
Expand Up @@ -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 );
Expand Down
14 changes: 14 additions & 0 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -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"
Expand All @@ -65,6 +66,7 @@
#include "layertree/qgslayertreelayer.h"
#include "qgslayertree.h"

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

#include "qgsrendererpropertiesdialog.h"
#include "qgsstyle.h"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsvectorlayerproperties.h
Expand Up @@ -169,6 +169,8 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private

void onAuxiliaryLayerExport();

void urlClicked( const QUrl &url );

private:

enum PropertyType
Expand Down
1 change: 0 additions & 1 deletion src/core/qgsapplication.cpp
Expand Up @@ -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;"
Expand Down
8 changes: 7 additions & 1 deletion src/core/qgsvectorlayer.cpp
Expand Up @@ -23,6 +23,7 @@

#include <limits>

#include <QFile>
#include <QImage>
#include <QPainter>
#include <QPainterPath>
Expand All @@ -32,6 +33,7 @@
#include <QDomNode>
#include <QVector>
#include <QStringBuilder>
#include <QUrl>
#if QT_VERSION >= 0x050900
#include <QUndoCommand>
#endif
Expand Down Expand Up @@ -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" );
Expand Down
6 changes: 5 additions & 1 deletion src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -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" );
Expand Down

0 comments on commit 45b209c

Please sign in to comment.