Skip to content
Permalink
Browse files

Show information in point cloud layer properties

  • Loading branch information
nyalldawson committed Oct 26, 2020
1 parent 88cefcd commit 56f5010947156fbf17de125fbfa24bb8548ca25b
@@ -87,6 +87,8 @@ QgsPointCloudLayer cannot be copied.

virtual void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );

virtual QString htmlMetadata() const;


private:
QgsPointCloudLayer( const QgsPointCloudLayer &rhs );
@@ -115,6 +115,8 @@ SET(QGIS_APP_SRCS
decorations/qgsdecorationgrid.cpp
decorations/qgsdecorationgriddialog.cpp

pointcloud/qgspointcloudlayerproperties.cpp

vectortile/qgsvectortilelayerproperties.cpp

vertextool/qgslockedfeature.cpp
@@ -418,6 +420,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/app/dwg
${CMAKE_SOURCE_DIR}/src/app/mesh
${CMAKE_SOURCE_DIR}/src/app/locator
${CMAKE_SOURCE_DIR}/src/app/pointcloud
${CMAKE_SOURCE_DIR}/src/app/vectortile
${CMAKE_SOURCE_DIR}/src/analysis
${CMAKE_SOURCE_DIR}/src/analysis/raster
@@ -47,26 +47,6 @@ QgsPointCloudLayerProperties::QgsPointCloudLayerProperties( QgsPointCloudLayer *
// 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, &QgsPointCloudLayerProperties::urlClicked );
mMetadataViewer->page()->settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, true );
mMetadataViewer->page()->settings()->setAttribute( QWebSettings::JavascriptEnabled, true );

#endif
mOptsPage_Information->setContentsMargins( 0, 0, 0, 0 );

QVBoxLayout *layout = new QVBoxLayout( metadataFrame );
@@ -139,10 +119,14 @@ void QgsPointCloudLayerProperties::syncToLayer()
/*
* Information Tab
*/
const QString myStyle = QgsApplication::reportStyleSheet( QgsApplication::StyleSheetType::WebBrowser );
// Inject the stylesheet
const QString html { mLayer->htmlMetadata().replace( QLatin1String( "<head>" ), QStringLiteral( R"raw(<head><style type="text/css">%1</style>)raw" ) ).arg( myStyle ) };
mMetadataViewer->setHtml( html );
QString myStyle = QgsApplication::reportStyleSheet();
myStyle.append( QStringLiteral( "body { margin: 10px; }\n " ) );
mInformationTextBrowser->clear();
mInformationTextBrowser->document()->setDefaultStyleSheet( myStyle );
mInformationTextBrowser->setHtml( mLayer->htmlMetadata() );
mInformationTextBrowser->setOpenLinks( false );
connect( mInformationTextBrowser, &QTextBrowser::anchorClicked, this, &QgsPointCloudLayerProperties::urlClicked );

}


@@ -352,6 +352,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgsvectorlayerdigitizingproperties.h"
#include "qgsvectortilelayer.h"
#include "qgsvectortilelayerproperties.h"
#include "qgspointcloudlayerproperties.h"
#include "qgsmapthemes.h"
#include "qgsmessagelogviewer.h"
#include "qgsdataitem.h"

case QgsMapLayerType::PointCloudLayer:
{
QgsPointCloudLayerProperties pointCloudLayerPropertiesDialog( qobject_cast<QgsPointCloudLayer *>( mapLayer ), mMapCanvas, visibleMessageBar(), this );
if ( !page.isEmpty() )
pointCloudLayerPropertiesDialog.setCurrentPage( page );

mMapStyleWidget->blockUpdates( true );
if ( pointCloudLayerPropertiesDialog.exec() )
{
activateDeactivateLayerRelatedActions( mapLayer );
mMapStyleWidget->updateCurrentWidgetLayer();
}
mMapStyleWidget->blockUpdates( false ); // delete since dialog cannot be reused without updating code
break;
}

@@ -22,6 +22,7 @@
#include "qgspointclouddataprovider.h"
#include "qgsproviderregistry.h"
#include "qgslogger.h"
#include "qgslayermetadataformatter.h"

QgsPointCloudLayer::QgsPointCloudLayer( const QString &path,
const QString &baseName,
@@ -195,3 +196,89 @@ void QgsPointCloudLayer::setDataSource( const QString &dataSource, const QString
emit dataSourceChanged();
triggerRepaint();
}

QString QgsPointCloudLayer::htmlMetadata() const
{
QgsLayerMetadataFormatter htmlFormatter( metadata() );
QString myMetadata = QStringLiteral( "<html>\n<body>\n" );

// Begin Provider section
myMetadata += QStringLiteral( "<h1>" ) + tr( "Information from provider" ) + QStringLiteral( "</h1>\n<hr>\n" );
myMetadata += QLatin1String( "<table class=\"list-view\">\n" );

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

// local path
QVariantMap uriComponents = QgsProviderRegistry::instance()->decodeUri( mProviderKey, publicSource() );
QString path;
if ( uriComponents.contains( QStringLiteral( "path" ) ) )
{
path = uriComponents[QStringLiteral( "path" )].toString();
if ( QFile::exists( path ) )
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Path" ) + QStringLiteral( "</td><td>%1" ).arg( QStringLiteral( "<a href=\"%1\">%2</a>" ).arg( QUrl::fromLocalFile( path ).toString(), QDir::toNativeSeparators( path ) ) ) + QStringLiteral( "</td></tr>\n" );
}
if ( uriComponents.contains( QStringLiteral( "url" ) ) )
{
const QString url = uriComponents[QStringLiteral( "url" )].toString();
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "URL" ) + QStringLiteral( "</td><td>%1" ).arg( QStringLiteral( "<a href=\"%1\">%2</a>" ).arg( QUrl( url ).toString(), url ) ) + QStringLiteral( "</td></tr>\n" );
}

// data source
if ( publicSource() != path )
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Source" ) + QStringLiteral( "</td><td>%1" ).arg( publicSource() ) + QStringLiteral( "</td></tr>\n" );

// EPSG
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "CRS" ) + QStringLiteral( "</td><td>" );
if ( crs().isValid() )
{
myMetadata += crs().userFriendlyIdentifier( QgsCoordinateReferenceSystem::FullString ) + QStringLiteral( " - " );
if ( crs().isGeographic() )
myMetadata += tr( "Geographic" );
else
myMetadata += tr( "Projected" );
}
myMetadata += QLatin1String( "</td></tr>\n" );

// Extent
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Extent" ) + QStringLiteral( "</td><td>" ) + extent().toString() + QStringLiteral( "</td></tr>\n" );

// unit
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Unit" ) + QStringLiteral( "</td><td>" ) + QgsUnitTypes::toString( crs().mapUnits() ) + QStringLiteral( "</td></tr>\n" );

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

// identification section
myMetadata += QStringLiteral( "<h1>" ) + tr( "Identification" ) + QStringLiteral( "</h1>\n<hr>\n" );
myMetadata += htmlFormatter.identificationSectionHtml( );
myMetadata += QLatin1String( "<br><br>\n" );

// extent section
myMetadata += QStringLiteral( "<h1>" ) + tr( "Extent" ) + QStringLiteral( "</h1>\n<hr>\n" );
myMetadata += htmlFormatter.extentSectionHtml( isSpatial() );
myMetadata += QLatin1String( "<br><br>\n" );

// Start the Access section
myMetadata += QStringLiteral( "<h1>" ) + tr( "Access" ) + QStringLiteral( "</h1>\n<hr>\n" );
myMetadata += htmlFormatter.accessSectionHtml( );
myMetadata += QLatin1String( "<br><br>\n" );

// Start the contacts section
myMetadata += QStringLiteral( "<h1>" ) + tr( "Contacts" ) + QStringLiteral( "</h1>\n<hr>\n" );
myMetadata += htmlFormatter.contactsSectionHtml( );
myMetadata += QLatin1String( "<br><br>\n" );

// Start the links section
myMetadata += QStringLiteral( "<h1>" ) + tr( "Links" ) + QStringLiteral( "</h1>\n<hr>\n" );
myMetadata += htmlFormatter.linksSectionHtml( );
myMetadata += QLatin1String( "<br><br>\n" );

// Start the history section
myMetadata += QStringLiteral( "<h1>" ) + tr( "History" ) + QStringLiteral( "</h1>\n<hr>\n" );
myMetadata += htmlFormatter.historySectionHtml( );
myMetadata += QLatin1String( "<br><br>\n" );

myMetadata += QLatin1String( "\n</body>\n</html>\n" );
return myMetadata;
}
@@ -112,6 +112,7 @@ class CORE_EXPORT QgsPointCloudLayer : public QgsMapLayer
void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
QString loadDefaultStyle( bool &resultFlag SIP_OUT ) override;
void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false ) override;
QString htmlMetadata() const override;

private:

@@ -167,7 +167,7 @@
<number>0</number>
</property>
<widget class="QWidget" name="mOptsPage_Information">
<layout class="QVBoxLayout" name="verticalLayout_20">
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="leftMargin">
<number>0</number>
</property>
@@ -181,7 +181,7 @@
<number>0</number>
</property>
<item>
<widget class="QgsWebView" name="mMetadataViewer" native="true"/>
<widget class="QTextBrowser" name="mInformationTextBrowser"/>
</item>
</layout>
</widget>
@@ -265,12 +265,6 @@
<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>

0 comments on commit 56f5010

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