Skip to content

Commit

Permalink
[browser] Restore preview functionality from old 2.x standalone
Browse files Browse the repository at this point in the history
browser into inbuilt browser dock panel layer properties widget

(cherry picked from commit 17447e4)
  • Loading branch information
nyalldawson committed Nov 10, 2018
1 parent a46ac23 commit d43d28b
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 13 deletions.
Binary file not shown.
34 changes: 26 additions & 8 deletions src/gui/qgsbrowserdockwidget_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "qgsmeshlayer.h"
#include "qgsgui.h"
#include "qgsnative.h"
#include "qgsmaptoolpan.h"
#include <QDesktopServices>

#include <QDragEnterEvent>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -159,7 +173,7 @@ void QgsBrowserLayerProperties::setItem( QgsDataItem *item )
ProjectionSettingRestorer restorer;
( void )restorer; // no warnings

std::unique_ptr<QgsMapLayer> layer;
mLayer.reset();

// find root item
// we need to create a temporary layer to get metadata
Expand All @@ -169,30 +183,34 @@ void QgsBrowserLayerProperties::setItem( QgsDataItem *item )
{
QgsDebugMsg( QStringLiteral( "creating raster layer" ) );
// should copy code from addLayer() to split uri ?
layer = qgis::make_unique< QgsRasterLayer >( layerItem->uri(), layerItem->name(), layerItem->providerKey() );
mLayer = qgis::make_unique< QgsRasterLayer >( layerItem->uri(), layerItem->uri(), layerItem->providerKey() );
}
else if ( type == QgsMapLayer::MeshLayer )
{
QgsDebugMsg( QStringLiteral( "creating mesh layer" ) );
layer = qgis::make_unique < QgsMeshLayer >( layerItem->uri(), layerItem->name(), layerItem->providerKey() );
mLayer = qgis::make_unique < QgsMeshLayer >( layerItem->uri(), layerItem->uri(), layerItem->providerKey() );
}
else if ( type == QgsMapLayer::VectorLayer )
{
QgsDebugMsg( QStringLiteral( "creating vector layer" ) );
layer = qgis::make_unique < QgsVectorLayer>( layerItem->uri(), layerItem->name(), layerItem->providerKey() );
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 ( layer && layer->isValid() )
if ( mLayer && mLayer->isValid() )
{
bool ok = false;
layer->loadDefaultMetadata( ok );
layerCrs = layer->crs();
layerMetadata = layer->htmlMetadata();
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();
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsbrowserdockwidget_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ class QgsBrowserLayerProperties : public QgsBrowserPropertiesWidget, private Ui:
private slots:

void urlClicked( const QUrl &url );

private:
std::unique_ptr<QgsMapLayer> mLayer;

};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
64 changes: 60 additions & 4 deletions src/ui/qgsbrowserlayerpropertiesbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -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 d43d28b

Please sign in to comment.