Skip to content
Permalink
Browse files

Make map canvas independent from overview canvas, simplify QgsMapCanv…

…as API
  • Loading branch information
wonder-sk committed Dec 11, 2016
1 parent 20cdd4f commit 2c9f1ff579c79f99090869a247ad5a314cb261a3
@@ -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.
@@ -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.
@@ -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}
@@ -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;

@@ -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();

@@ -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.
*/
@@ -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/;
@@ -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;
@@ -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();
}

@@ -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 )
{
@@ -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 );
@@ -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 )
@@ -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();
@@ -155,7 +162,9 @@ void QgsLayerTreeMapCanvasBridge::setCanvasLayers()
}
}

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

if ( firstLayers )
{
@@ -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()
@@ -22,7 +22,8 @@
#include "qgscoordinatereferencesystem.h"

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

@@ -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; }

@@ -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();

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

bool mPendingCanvasUpdate;

0 comments on commit 2c9f1ff

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