Skip to content

Commit 2c9f1ff

Browse files
committedDec 11, 2016
Make map canvas independent from overview canvas, simplify QgsMapCanvas API
1 parent 20cdd4f commit 2c9f1ff

14 files changed

+88
-216
lines changed
 

‎doc/api_break.dox

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinat
249249
- addLegendLayerActionForLayer() moved to QgisInterface::addCustomActionForLayer()
250250
- removeLegendLayerAction() moved to QgisInterface::removeCustomActionForLayerType()
251251
- QgsLegendModel was removed.
252+
- QgsMapCanvasLayer. Map canvas and overview canvas are updated separately with their own setLayers() calls.
252253
- QgsMapCanvasMap. It is an internal class used by map canvas.
253254
- QgsMapLayerRegistry. Its functionality has been moved to QgsProject.
254255
- 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().
10691070
QgsMapCanvas {#qgis_api_break_3_0_QgsMapCanvas}
10701071
------------
10711072

1073+
- setLayerSet() has been replaced by setLayers() which accepts list of QgsMapLayer objects instead of QgsMapCanvasLayer objects
10721074
- rotationEnabled() and enableRotation() have been removed, since map rotation is now always supported
10731075
- The "name" parameter has been removed from constructor. Use QObject::setObjectName() to set canvas name if necessary.
10741076
- map() has been removed because QgsMapCanvasMap is not available in API anymore.
@@ -1081,6 +1083,7 @@ QgsMapCanvas {#qgis_api_break_3_0_QgsMapCanvas}
10811083
- setWheelAction() and WheelAction enum have been removed. Custom wheel actions are not supported anymore.
10821084
- updateMap(), showError(), useImageToRender() have been removed. They did nothing since 2.4.
10831085
- setProgress() signal has been removed. It was not emitted since 2.0.
1086+
- 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.
10841087

10851088

10861089
QgsMapCanvasItem {#qgis_api_break_3_0_QgsMapCanvasItem}

‎python/gui/layertree/qgslayertreemapcanvasbridge.sip

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ class QgsLayerTreeMapCanvasBridge : QObject
2828
QgsLayerTreeGroup* rootGroup() const;
2929
QgsMapCanvas* mapCanvas() const;
3030

31+
//! Associates overview canvas with the bridge, so the overview will be updated whenever main canvas is updated
32+
//! @note added in 3.0
33+
void setOvervewCanvas( QgsMapOverviewCanvas* overviewCanvas );
34+
//! Returns associated overview canvas (may be null)
35+
//! @note added in 3.0
36+
QgsMapOverviewCanvas* overviewCanvas() const;
37+
3138
bool hasCustomLayerOrder() const;
3239
QStringList customLayerOrder() const;
3340

@@ -61,7 +68,7 @@ class QgsLayerTreeMapCanvasBridge : QObject
6168

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

64-
void setCanvasLayers( QgsLayerTreeNode* node, QList<QgsMapCanvasLayer>& layers );
71+
void setCanvasLayers( QgsLayerTreeNode* node, QList<QgsMapLayer*> &canvasLayers, QList<QgsMapLayer*>& overviewLayers );
6572

6673
void deferredSetCanvasLayers();
6774

‎python/gui/qgsmapcanvas.sip

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,5 @@
11
%Feature HAVE_TOUCH
22

3-
/** \ingroup gui
4-
* A class that stores visibility and presence in overview flags together
5-
* with pointer to the layer.
6-
*
7-
*/
8-
class QgsMapCanvasLayer
9-
{
10-
%TypeHeaderCode
11-
#include <qgsmapcanvas.h>
12-
%End
13-
public:
14-
QgsMapCanvasLayer( QgsMapLayer* layer, bool visible = true, bool isInOverview = false );
15-
16-
void setVisible( bool visible );
17-
void setInOverview( bool isInOverview );
18-
19-
bool isVisible() const;
20-
bool isInOverview() const;
21-
22-
const QgsMapLayer* layer() const;
23-
};
24-
25-
263
/** \ingroup gui
274
* Map canvas is a class for displaying all GIS data types on a canvas.
285
*/
@@ -52,16 +29,12 @@ class QgsMapCanvas : QGraphicsView
5229
//! @note added in 2.16
5330
double magnificationFactor() const;
5431

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

5736
void setCurrentLayer( QgsMapLayer* layer );
5837

59-
// ### QGIS 3: make QgsMapCanvas independent from overview
60-
void updateOverview();
61-
62-
// ### QGIS 3: make QgsMapCanvas independent from overview
63-
void enableOverviewMode( QgsMapOverviewCanvas* overview );
64-
6538
//! Get access to properties used for map rendering
6639
//! @note added in 2.4
6740
const QgsMapSettings& mapSettings() const /KeepReference/;

‎src/app/qgisapp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2968,7 +2968,7 @@ void QgisApp::createOverview()
29682968
// add to the Panel submenu
29692969
mPanelMenu->addAction( mOverviewDock->toggleViewAction() );
29702970

2971-
mMapCanvas->enableOverviewMode( mOverviewCanvas );
2971+
mLayerTreeCanvasBridge->setOvervewCanvas( mOverviewCanvas );
29722972

29732973
// moved here to set anti aliasing to both map canvas and overview
29742974
QSettings mySettings;
@@ -9622,9 +9622,9 @@ void QgisApp::closeProject()
96229622
removeAnnotationItems();
96239623
// clear out any stuff from project
96249624
mMapCanvas->freeze( true );
9625-
QList<QgsMapCanvasLayer> emptyList;
9626-
mMapCanvas->setLayerSet( emptyList );
9625+
mMapCanvas->setLayers( QList<QgsMapLayer*>() );
96279626
mMapCanvas->clearCache();
9627+
mOverviewCanvas->setLayers( QList<QgsMapLayer*>() );
96289628
removeAllLayers();
96299629
}
96309630

‎src/browser/qgsbrowser.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ void QgsBrowser::itemClicked( const QModelIndex& index )
134134
// clear the previous stuff
135135
setLayer( nullptr );
136136

137-
QList<QgsMapCanvasLayer> nolayers;
138-
mapCanvas->setLayerSet( nolayers );
137+
mapCanvas->setLayers( QList<QgsMapLayer*>() );
139138
metaTextBrowser->clear();
140139
if ( mParamWidget )
141140
{
@@ -431,9 +430,7 @@ void QgsBrowser::updateCurrentTab()
431430
if ( mLayer && mLayer->isValid() )
432431
{
433432
// Create preview: add to map canvas
434-
QList<QgsMapCanvasLayer> layers;
435-
layers << QgsMapCanvasLayer( mLayer );
436-
mapCanvas->setLayerSet( layers );
433+
mapCanvas->setLayers( QList<QgsMapLayer*>() << mLayer );
437434
QgsRectangle fullExtent = mLayer->extent();
438435
fullExtent.scale( 1.05 ); // add some border
439436
mapCanvas->setExtent( fullExtent );

‎src/gui/layertree/qgslayertreemapcanvasbridge.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
#include "qgsmaplayer.h"
2121
#include "qgsvectorlayer.h"
2222
#include "qgsmapcanvas.h"
23+
#include "qgsmapoverviewcanvas.h"
2324
#include "qgsproject.h"
2425

2526
QgsLayerTreeMapCanvasBridge::QgsLayerTreeMapCanvasBridge( QgsLayerTreeGroup *root, QgsMapCanvas *canvas, QObject* parent )
2627
: QObject( parent )
2728
, mRoot( root )
2829
, mCanvas( canvas )
30+
, mOverviewCanvas( nullptr )
2931
, mPendingCanvasUpdate( false )
3032
, mHasCustomLayerOrder( false )
3133
, mAutoSetupOnFirstLayer( true )
@@ -116,19 +118,24 @@ void QgsLayerTreeMapCanvasBridge::setCustomLayerOrder( const QStringList& order
116118

117119
void QgsLayerTreeMapCanvasBridge::setCanvasLayers()
118120
{
119-
QList<QgsMapCanvasLayer> layers;
121+
QList<QgsMapLayer*> canvasLayers, overviewLayers;
120122

121123
if ( mHasCustomLayerOrder )
122124
{
123125
Q_FOREACH ( const QString& layerId, mCustomLayerOrder )
124126
{
125127
QgsLayerTreeLayer* nodeLayer = mRoot->findLayer( layerId );
126128
if ( nodeLayer )
127-
layers << QgsMapCanvasLayer( nodeLayer->layer(), nodeLayer->isVisible() == Qt::Checked, nodeLayer->customProperty( QStringLiteral( "overview" ), 0 ).toInt() );
129+
{
130+
if ( nodeLayer->isVisible() == Qt::Checked )
131+
canvasLayers << nodeLayer->layer();
132+
if ( nodeLayer->customProperty( QStringLiteral( "overview" ), 0 ).toInt() )
133+
overviewLayers << nodeLayer->layer();
134+
}
128135
}
129136
}
130137
else
131-
setCanvasLayers( mRoot, layers );
138+
setCanvasLayers( mRoot, canvasLayers, overviewLayers );
132139

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

158-
mCanvas->setLayerSet( layers );
165+
mCanvas->setLayers( canvasLayers );
166+
if ( mOverviewCanvas )
167+
mOverviewCanvas->setLayers( overviewLayers );
159168

160169
if ( firstLayers )
161170
{
@@ -248,16 +257,19 @@ void QgsLayerTreeMapCanvasBridge::writeProject( QDomDocument& doc )
248257
doc.documentElement().appendChild( elem );
249258
}
250259

251-
void QgsLayerTreeMapCanvasBridge::setCanvasLayers( QgsLayerTreeNode *node, QList<QgsMapCanvasLayer> &layers )
260+
void QgsLayerTreeMapCanvasBridge::setCanvasLayers( QgsLayerTreeNode *node, QList<QgsMapLayer*> &canvasLayers, QList<QgsMapLayer*>& overviewLayers )
252261
{
253262
if ( QgsLayerTree::isLayer( node ) )
254263
{
255264
QgsLayerTreeLayer* nodeLayer = QgsLayerTree::toLayer( node );
256-
layers << QgsMapCanvasLayer( nodeLayer->layer(), nodeLayer->isVisible() == Qt::Checked, nodeLayer->customProperty( QStringLiteral( "overview" ), 0 ).toInt() );
265+
if ( nodeLayer->isVisible() == Qt::Checked )
266+
canvasLayers << nodeLayer->layer();
267+
if ( nodeLayer->customProperty( QStringLiteral( "overview" ), 0 ).toInt() )
268+
overviewLayers << nodeLayer->layer();
257269
}
258270

259271
Q_FOREACH ( QgsLayerTreeNode* child, node->children() )
260-
setCanvasLayers( child, layers );
272+
setCanvasLayers( child, canvasLayers, overviewLayers );
261273
}
262274

263275
void QgsLayerTreeMapCanvasBridge::deferredSetCanvasLayers()

‎src/gui/layertree/qgslayertreemapcanvasbridge.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
#include "qgscoordinatereferencesystem.h"
2323

2424
class QgsMapCanvas;
25-
class QgsMapCanvasLayer;
25+
class QgsMapLayer;
26+
class QgsMapOverviewCanvas;
2627
class QgsLayerTreeGroup;
2728
class QgsLayerTreeNode;
2829

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

58+
//! Associates overview canvas with the bridge, so the overview will be updated whenever main canvas is updated
59+
//! @note added in 3.0
60+
void setOvervewCanvas( QgsMapOverviewCanvas* overviewCanvas ) { mOverviewCanvas = overviewCanvas; }
61+
//! Returns associated overview canvas (may be null)
62+
//! @note added in 3.0
63+
QgsMapOverviewCanvas* overviewCanvas() const { return mOverviewCanvas; }
64+
5765
bool hasCustomLayerOrder() const { return mHasCustomLayerOrder; }
5866
QStringList customLayerOrder() const { return mCustomLayerOrder; }
5967

@@ -87,7 +95,7 @@ class GUI_EXPORT QgsLayerTreeMapCanvasBridge : public QObject
8795

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

90-
void setCanvasLayers( QgsLayerTreeNode* node, QList<QgsMapCanvasLayer>& layers );
98+
void setCanvasLayers( QgsLayerTreeNode* node, QList<QgsMapLayer*> &canvasLayers, QList<QgsMapLayer*>& overviewLayers );
9199

92100
void deferredSetCanvasLayers();
93101

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

104113
bool mPendingCanvasUpdate;
105114

0 commit comments

Comments
 (0)
Please sign in to comment.