Skip to content
Permalink
Browse files

[FEATURE][browser] Restore preview functionality from old 2.x standalone

browser into inbuilt browser dock panel layer properties widget
  • Loading branch information
nyalldawson committed Oct 31, 2018
1 parent 7f332fb commit 17447e4b5ca6cde9e349c55daed558a85766debb
Binary file not shown.
@@ -1559,6 +1559,13 @@ QgisApp::~QgisApp()
delete canvas;
}

// these may have references to map layers which need to be cleaned up
delete mBrowserWidget;
mBrowserWidget = nullptr;
delete mBrowserWidget2;
mBrowserWidget2 = nullptr;
delete mBrowserModel;

QgsGui::instance()->nativePlatformInterface()->cleanup();

// This function *MUST* be the last one called, as it destroys in
@@ -40,6 +40,7 @@
#include "qgsmeshlayer.h"
#include "qgsgui.h"
#include "qgsnative.h"
#include "qgsmaptoolpan.h"
#include <QDesktopServices>

#include <QDragEnterEvent>
@@ -119,6 +120,19 @@ QgsBrowserLayerProperties::QgsBrowserLayerProperties( QWidget *parent )
// we don't want links to open in the little widget, open them externally instead
mMetadataTextBrowser->setOpenLinks( false );
connect( mMetadataTextBrowser, &QTextBrowser::anchorClicked, this, &QgsBrowserLayerProperties::urlClicked );

mMapCanvas->setLayers( QList< QgsMapLayer * >() );
mMapCanvas->setMapTool( new QgsMapToolPan( mMapCanvas ) );
mMapCanvas->freeze( true );

connect( mTabWidget, &QTabWidget::currentChanged, this, [ = ]
{
if ( mTabWidget->currentWidget() == mPreviewTab && mMapCanvas->isFrozen() )
{
mMapCanvas->freeze( false );
mMapCanvas->refresh();
}
} );
}

class ProjectionSettingRestorer
@@ -159,6 +173,8 @@ void QgsBrowserLayerProperties::setItem( QgsDataItem *item )
ProjectionSettingRestorer restorer;
( void )restorer; // no warnings

mLayer.reset();

// find root item
// we need to create a temporary layer to get metadata
// we could use a provider but the metadata is not as complete and "pretty" and this is easier
@@ -167,59 +183,41 @@ void QgsBrowserLayerProperties::setItem( QgsDataItem *item )
{
QgsDebugMsg( QStringLiteral( "creating raster layer" ) );
// should copy code from addLayer() to split uri ?
std::unique_ptr<QgsRasterLayer> layer( new QgsRasterLayer( layerItem->uri(), layerItem->uri(), layerItem->providerKey() ) );
if ( layer )
{
if ( layer->isValid() )
{
bool ok = false;
layer->loadDefaultMetadata( ok );
layerCrs = layer->crs();
layerMetadata = layer->htmlMetadata();
}
}
mLayer = qgis::make_unique< QgsRasterLayer >( layerItem->uri(), layerItem->uri(), layerItem->providerKey() );
}
else if ( type == QgsMapLayer::MeshLayer )
{
QgsDebugMsg( QStringLiteral( "creating mesh layer" ) );
std::unique_ptr<QgsMeshLayer> layer( new QgsMeshLayer( layerItem->uri(), layerItem->uri(), layerItem->providerKey() ) );
if ( layer )
{
if ( layer->isValid() )
{
bool ok = false;
layer->loadDefaultMetadata( ok );
layerCrs = layer->crs();
layerMetadata = layer->htmlMetadata();
}
}
mLayer = qgis::make_unique < QgsMeshLayer >( layerItem->uri(), layerItem->uri(), layerItem->providerKey() );
}
else if ( type == QgsMapLayer::VectorLayer )
{
QgsDebugMsg( QStringLiteral( "creating vector layer" ) );
std::unique_ptr<QgsVectorLayer> layer( new QgsVectorLayer( layerItem->uri(), layerItem->name(), layerItem->providerKey() ) );
if ( layer )
{
if ( layer->isValid() )
{
bool ok = false;
layer->loadDefaultMetadata( ok );
layerCrs = layer->crs();
layerMetadata = layer->htmlMetadata();
}
}
mLayer = qgis::make_unique < QgsVectorLayer>( layerItem->uri(), layerItem->name(), layerItem->providerKey() );
}
else if ( type == QgsMapLayer::PluginLayer )
{
// TODO: support display of properties for plugin layers
return;
}

if ( mLayer && mLayer->isValid() )
{
bool ok = false;
mLayer->loadDefaultMetadata( ok );
layerCrs = mLayer->crs();
layerMetadata = mLayer->htmlMetadata();

mMapCanvas->setDestinationCrs( mLayer->crs() );
mMapCanvas->setLayers( QList< QgsMapLayer * >() << mLayer.get() );
mMapCanvas->zoomToFullExtent();
}

QString myStyle = QgsApplication::reportStyleSheet();
mMetadataTextBrowser->document()->setDefaultStyleSheet( myStyle );
mMetadataTextBrowser->setHtml( layerMetadata );

// report if layer was set to to project crs without prompt (may give a false positive)
// report if layer was set to to project crs without prompt (may give a false positive)
if ( defaultProjectionOption == QLatin1String( "prompt" ) )
{
QgsCoordinateReferenceSystem defaultCrs =
@@ -126,6 +126,10 @@ class QgsBrowserLayerProperties : public QgsBrowserPropertiesWidget, private Ui:
private slots:

void urlClicked( const QUrl &url );

private:
std::unique_ptr<QgsMapLayer> mLayer;

};

/**
@@ -174,7 +174,7 @@ QgsMapCanvas::QgsMapCanvas( QWidget *parent )
// keep device pixel ratio up to date on screen or resolution change
connect( window()->windowHandle(), &QWindow::screenChanged, this, [ = ]( QScreen * ) {mSettings.setDevicePixelRatio( devicePixelRatio() );} );
if ( window()->windowHandle() )
connect( window()->windowHandle()->screen(), &QScreen::physicalDotsPerInchChanged, [ = ]( qreal ) {mSettings.setDevicePixelRatio( devicePixelRatio() );} );
connect( window()->windowHandle()->screen(), &QScreen::physicalDotsPerInchChanged, this, [ = ]( qreal ) {mSettings.setDevicePixelRatio( devicePixelRatio() );} );

connect( &mMapUpdateTimer, &QTimer::timeout, this, &QgsMapCanvas::mapUpdateTimeout );
mMapUpdateTimer.setInterval( 250 );
@@ -24,7 +24,58 @@
<number>0</number>
</property>
<item>
<widget class="QTextBrowser" name="mMetadataTextBrowser"/>
<widget class="QTabWidget" name="mTabWidget">
<property name="tabShape">
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Metadata</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<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="mMetadataTextBrowser"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="mPreviewTab">
<attribute name="title">
<string>Preview</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout">
<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="QgsMapCanvas" name="mMapCanvas" native="true"/>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QLabel" name="mNoticeLabel">
@@ -38,9 +89,14 @@
</item>
</layout>
</widget>
<tabstops>
<tabstop>mMetadataTextBrowser</tabstop>
</tabstops>
<customwidgets>
<customwidget>
<class>QgsMapCanvas</class>
<extends>QWidget</extends>
<header>qgsmapcanvas.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

0 comments on commit 17447e4

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