Skip to content

Commit

Permalink
Make map canvas independent from overview canvas, simplify QgsMapCanv…
Browse files Browse the repository at this point in the history
…as API
  • Loading branch information
wonder-sk committed Dec 11, 2016
1 parent 20cdd4f commit 2c9f1ff
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 216 deletions.
3 changes: 3 additions & 0 deletions doc/api_break.dox
Expand Up @@ -249,6 +249,7 @@ should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinat
- addLegendLayerActionForLayer() moved to QgisInterface::addCustomActionForLayer()
- removeLegendLayerAction() moved to QgisInterface::removeCustomActionForLayerType()
- QgsLegendModel was removed.
- QgsMapCanvasLayer. Map canvas and overview canvas are updated separately with their own setLayers() calls.
- QgsMapCanvasMap. It is an internal class used by map canvas.
- QgsMapLayerRegistry. Its functionality has been moved to QgsProject.
- QgsMapRenderer. It has been replaced by QgsMapRendererJob with subclasses and QgsMapSettings.
Expand Down Expand Up @@ -1069,6 +1070,7 @@ and the new ramp can be retrieved after executing the dialog by calling ramp().
QgsMapCanvas {#qgis_api_break_3_0_QgsMapCanvas}
------------

- setLayerSet() has been replaced by setLayers() which accepts list of QgsMapLayer objects instead of QgsMapCanvasLayer objects
- rotationEnabled() and enableRotation() have been removed, since map rotation is now always supported
- The "name" parameter has been removed from constructor. Use QObject::setObjectName() to set canvas name if necessary.
- map() has been removed because QgsMapCanvasMap is not available in API anymore.
Expand All @@ -1081,6 +1083,7 @@ QgsMapCanvas {#qgis_api_break_3_0_QgsMapCanvas}
- setWheelAction() and WheelAction enum have been removed. Custom wheel actions are not supported anymore.
- updateMap(), showError(), useImageToRender() have been removed. They did nothing since 2.4.
- setProgress() signal has been removed. It was not emitted since 2.0.
- enableOverviewMode() and updateOverview() have been removed. Map canvas does not keep pointer to overview canvas anymore. Use QgsLayerTreeMapCanvasBridge::setOverviewCanvas() to set up updates of overview canvas together with main canvas.


QgsMapCanvasItem {#qgis_api_break_3_0_QgsMapCanvasItem}
Expand Down
9 changes: 8 additions & 1 deletion python/gui/layertree/qgslayertreemapcanvasbridge.sip
Expand Up @@ -28,6 +28,13 @@ class QgsLayerTreeMapCanvasBridge : QObject
QgsLayerTreeGroup* rootGroup() const;
QgsMapCanvas* mapCanvas() const;

//! Associates overview canvas with the bridge, so the overview will be updated whenever main canvas is updated
//! @note added in 3.0
void setOvervewCanvas( QgsMapOverviewCanvas* overviewCanvas );
//! Returns associated overview canvas (may be null)
//! @note added in 3.0
QgsMapOverviewCanvas* overviewCanvas() const;

bool hasCustomLayerOrder() const;
QStringList customLayerOrder() const;

Expand Down Expand Up @@ -61,7 +68,7 @@ class QgsLayerTreeMapCanvasBridge : QObject

void defaultLayerOrder( QgsLayerTreeNode* node, QStringList& order ) const;

void setCanvasLayers( QgsLayerTreeNode* node, QList<QgsMapCanvasLayer>& layers );
void setCanvasLayers( QgsLayerTreeNode* node, QList<QgsMapLayer*> &canvasLayers, QList<QgsMapLayer*>& overviewLayers );

void deferredSetCanvasLayers();

Expand Down
33 changes: 3 additions & 30 deletions python/gui/qgsmapcanvas.sip
@@ -1,28 +1,5 @@
%Feature HAVE_TOUCH

/** \ingroup gui
* A class that stores visibility and presence in overview flags together
* with pointer to the layer.
*
*/
class QgsMapCanvasLayer
{
%TypeHeaderCode
#include <qgsmapcanvas.h>
%End
public:
QgsMapCanvasLayer( QgsMapLayer* layer, bool visible = true, bool isInOverview = false );

void setVisible( bool visible );
void setInOverview( bool isInOverview );

bool isVisible() const;
bool isInOverview() const;

const QgsMapLayer* layer() const;
};


/** \ingroup gui
* Map canvas is a class for displaying all GIS data types on a canvas.
*/
Expand Down Expand Up @@ -52,16 +29,12 @@ class QgsMapCanvas : QGraphicsView
//! @note added in 2.16
double magnificationFactor() const;

void setLayerSet( QList<QgsMapCanvasLayer>& layers );
//! Set list of layers that should be shown in the canvas
//! @note added in 3.0
void setLayers( const QList<QgsMapLayer*>& layers );

void setCurrentLayer( QgsMapLayer* layer );

// ### QGIS 3: make QgsMapCanvas independent from overview
void updateOverview();

// ### QGIS 3: make QgsMapCanvas independent from overview
void enableOverviewMode( QgsMapOverviewCanvas* overview );

//! Get access to properties used for map rendering
//! @note added in 2.4
const QgsMapSettings& mapSettings() const /KeepReference/;
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -2968,7 +2968,7 @@ void QgisApp::createOverview()
// add to the Panel submenu
mPanelMenu->addAction( mOverviewDock->toggleViewAction() );

mMapCanvas->enableOverviewMode( mOverviewCanvas );
mLayerTreeCanvasBridge->setOvervewCanvas( mOverviewCanvas );

// moved here to set anti aliasing to both map canvas and overview
QSettings mySettings;
Expand Down Expand Up @@ -9622,9 +9622,9 @@ void QgisApp::closeProject()
removeAnnotationItems();
// clear out any stuff from project
mMapCanvas->freeze( true );
QList<QgsMapCanvasLayer> emptyList;
mMapCanvas->setLayerSet( emptyList );
mMapCanvas->setLayers( QList<QgsMapLayer*>() );
mMapCanvas->clearCache();
mOverviewCanvas->setLayers( QList<QgsMapLayer*>() );
removeAllLayers();
}

Expand Down
7 changes: 2 additions & 5 deletions src/browser/qgsbrowser.cpp
Expand Up @@ -134,8 +134,7 @@ void QgsBrowser::itemClicked( const QModelIndex& index )
// clear the previous stuff
setLayer( nullptr );

QList<QgsMapCanvasLayer> nolayers;
mapCanvas->setLayerSet( nolayers );
mapCanvas->setLayers( QList<QgsMapLayer*>() );
metaTextBrowser->clear();
if ( mParamWidget )
{
Expand Down Expand Up @@ -431,9 +430,7 @@ void QgsBrowser::updateCurrentTab()
if ( mLayer && mLayer->isValid() )
{
// Create preview: add to map canvas
QList<QgsMapCanvasLayer> layers;
layers << QgsMapCanvasLayer( mLayer );
mapCanvas->setLayerSet( layers );
mapCanvas->setLayers( QList<QgsMapLayer*>() << mLayer );
QgsRectangle fullExtent = mLayer->extent();
fullExtent.scale( 1.05 ); // add some border
mapCanvas->setExtent( fullExtent );
Expand Down
26 changes: 19 additions & 7 deletions src/gui/layertree/qgslayertreemapcanvasbridge.cpp
Expand Up @@ -20,12 +20,14 @@
#include "qgsmaplayer.h"
#include "qgsvectorlayer.h"
#include "qgsmapcanvas.h"
#include "qgsmapoverviewcanvas.h"
#include "qgsproject.h"

QgsLayerTreeMapCanvasBridge::QgsLayerTreeMapCanvasBridge( QgsLayerTreeGroup *root, QgsMapCanvas *canvas, QObject* parent )
: QObject( parent )
, mRoot( root )
, mCanvas( canvas )
, mOverviewCanvas( nullptr )
, mPendingCanvasUpdate( false )
, mHasCustomLayerOrder( false )
, mAutoSetupOnFirstLayer( true )
Expand Down Expand Up @@ -116,19 +118,24 @@ void QgsLayerTreeMapCanvasBridge::setCustomLayerOrder( const QStringList& order

void QgsLayerTreeMapCanvasBridge::setCanvasLayers()
{
QList<QgsMapCanvasLayer> layers;
QList<QgsMapLayer*> canvasLayers, overviewLayers;

if ( mHasCustomLayerOrder )
{
Q_FOREACH ( const QString& layerId, mCustomLayerOrder )
{
QgsLayerTreeLayer* nodeLayer = mRoot->findLayer( layerId );
if ( nodeLayer )
layers << QgsMapCanvasLayer( nodeLayer->layer(), nodeLayer->isVisible() == Qt::Checked, nodeLayer->customProperty( QStringLiteral( "overview" ), 0 ).toInt() );
{
if ( nodeLayer->isVisible() == Qt::Checked )
canvasLayers << nodeLayer->layer();
if ( nodeLayer->customProperty( QStringLiteral( "overview" ), 0 ).toInt() )
overviewLayers << nodeLayer->layer();
}
}
}
else
setCanvasLayers( mRoot, layers );
setCanvasLayers( mRoot, canvasLayers, overviewLayers );

QList<QgsLayerTreeLayer*> layerNodes = mRoot->findLayers();
int currentLayerCount = layerNodes.count();
Expand All @@ -155,7 +162,9 @@ void QgsLayerTreeMapCanvasBridge::setCanvasLayers()
}
}

mCanvas->setLayerSet( layers );
mCanvas->setLayers( canvasLayers );
if ( mOverviewCanvas )
mOverviewCanvas->setLayers( overviewLayers );

if ( firstLayers )
{
Expand Down Expand Up @@ -248,16 +257,19 @@ void QgsLayerTreeMapCanvasBridge::writeProject( QDomDocument& doc )
doc.documentElement().appendChild( elem );
}

void QgsLayerTreeMapCanvasBridge::setCanvasLayers( QgsLayerTreeNode *node, QList<QgsMapCanvasLayer> &layers )
void QgsLayerTreeMapCanvasBridge::setCanvasLayers( QgsLayerTreeNode *node, QList<QgsMapLayer*> &canvasLayers, QList<QgsMapLayer*>& overviewLayers )
{
if ( QgsLayerTree::isLayer( node ) )
{
QgsLayerTreeLayer* nodeLayer = QgsLayerTree::toLayer( node );
layers << QgsMapCanvasLayer( nodeLayer->layer(), nodeLayer->isVisible() == Qt::Checked, nodeLayer->customProperty( QStringLiteral( "overview" ), 0 ).toInt() );
if ( nodeLayer->isVisible() == Qt::Checked )
canvasLayers << nodeLayer->layer();
if ( nodeLayer->customProperty( QStringLiteral( "overview" ), 0 ).toInt() )
overviewLayers << nodeLayer->layer();
}

Q_FOREACH ( QgsLayerTreeNode* child, node->children() )
setCanvasLayers( child, layers );
setCanvasLayers( child, canvasLayers, overviewLayers );
}

void QgsLayerTreeMapCanvasBridge::deferredSetCanvasLayers()
Expand Down
13 changes: 11 additions & 2 deletions src/gui/layertree/qgslayertreemapcanvasbridge.h
Expand Up @@ -22,7 +22,8 @@
#include "qgscoordinatereferencesystem.h"

class QgsMapCanvas;
class QgsMapCanvasLayer;
class QgsMapLayer;
class QgsMapOverviewCanvas;
class QgsLayerTreeGroup;
class QgsLayerTreeNode;

Expand Down Expand Up @@ -54,6 +55,13 @@ class GUI_EXPORT QgsLayerTreeMapCanvasBridge : public QObject
QgsLayerTreeGroup* rootGroup() const { return mRoot; }
QgsMapCanvas* mapCanvas() const { return mCanvas; }

//! Associates overview canvas with the bridge, so the overview will be updated whenever main canvas is updated
//! @note added in 3.0
void setOvervewCanvas( QgsMapOverviewCanvas* overviewCanvas ) { mOverviewCanvas = overviewCanvas; }
//! Returns associated overview canvas (may be null)
//! @note added in 3.0
QgsMapOverviewCanvas* overviewCanvas() const { return mOverviewCanvas; }

bool hasCustomLayerOrder() const { return mHasCustomLayerOrder; }
QStringList customLayerOrder() const { return mCustomLayerOrder; }

Expand Down Expand Up @@ -87,7 +95,7 @@ class GUI_EXPORT QgsLayerTreeMapCanvasBridge : public QObject

void defaultLayerOrder( QgsLayerTreeNode* node, QStringList& order ) const;

void setCanvasLayers( QgsLayerTreeNode* node, QList<QgsMapCanvasLayer>& layers );
void setCanvasLayers( QgsLayerTreeNode* node, QList<QgsMapLayer*> &canvasLayers, QList<QgsMapLayer*>& overviewLayers );

void deferredSetCanvasLayers();

Expand All @@ -100,6 +108,7 @@ class GUI_EXPORT QgsLayerTreeMapCanvasBridge : public QObject
protected:
QgsLayerTreeGroup* mRoot;
QgsMapCanvas* mCanvas;
QgsMapOverviewCanvas* mOverviewCanvas;

bool mPendingCanvasUpdate;

Expand Down

0 comments on commit 2c9f1ff

Please sign in to comment.