Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Flip QgsMapCanvas connects to new style
Also remove unneeded duplicate signal
  • Loading branch information
nyalldawson committed Feb 28, 2017
1 parent 555d104 commit b681b7b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 68 deletions.
2 changes: 1 addition & 1 deletion doc/api_break.dox
Expand Up @@ -1314,7 +1314,7 @@ QgsMapCanvas {#qgis_api_break_3_0_QgsMapCanvas}
- 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.

- the duplicate mapToolSet signal with a single QgsMapTool argument has been removed. Use the signal with arguments for new and old map tool instead.

QgsMapCanvasItem {#qgis_api_break_3_0_QgsMapCanvasItem}
----------------
Expand Down
6 changes: 0 additions & 6 deletions python/gui/qgsmapcanvas.sip
Expand Up @@ -442,12 +442,6 @@ class QgsMapCanvas : QGraphicsView
//! Emit key release event
void keyReleased( QKeyEvent * e );

//! Emit map tool changed event
void mapToolSet( QgsMapTool *tool );

/** Emit map tool changed with the old tool
* @note added in 2.3
*/
void mapToolSet( QgsMapTool *newTool, QgsMapTool* oldTool );

// ### QGIS 3: remove the signal
Expand Down
90 changes: 42 additions & 48 deletions src/app/qgisapp.cpp
Expand Up @@ -692,8 +692,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
startProfile( QStringLiteral( "Creating map canvas" ) );
mMapCanvas = new QgsMapCanvas( centralWidget );
mMapCanvas->setObjectName( QStringLiteral( "theMapCanvas" ) );
connect( mMapCanvas, SIGNAL( messageEmitted( const QString&, const QString&, QgsMessageBar::MessageLevel ) ),
this, SLOT( displayMessage( const QString&, const QString&, QgsMessageBar::MessageLevel ) ) );
connect( mMapCanvas, &QgsMapCanvas::messageEmitted, this, &QgisApp::displayMessage );
mMapCanvas->setWhatsThis( tr( "Map canvas. This is where raster and vector "
"layers are displayed when added to the map" ) );

Expand All @@ -718,7 +717,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh

centralLayout->addWidget( mCentralContainer, 0, 0, 2, 1 );

connect( mMapCanvas, SIGNAL( layersChanged() ), this, SLOT( showMapCanvas() ) );
connect( mMapCanvas, &QgsMapCanvas::layersChanged, this, &QgisApp::showMapCanvas );

mCentralContainer->setCurrentIndex( mProjOpen ? 0 : 1 );

Expand Down Expand Up @@ -1076,15 +1075,15 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
mLastComposerId = 0;

QShortcut* zoomInShortCut = new QShortcut( QKeySequence( tr( "Ctrl++" ) ), this );
connect( zoomInShortCut, SIGNAL( activated() ), mMapCanvas, SLOT( zoomIn() ) );
connect( zoomInShortCut, &QShortcut::activated, mMapCanvas, &QgsMapCanvas::zoomIn );
zoomInShortCut->setObjectName( QStringLiteral( "ZoomInToCanvas" ) );
zoomInShortCut->setWhatsThis( QStringLiteral( "Zoom in to canvas" ) );
QShortcut* zoomShortCut2 = new QShortcut( QKeySequence( tr( "Ctrl+=" ) ), this );
connect( zoomShortCut2, SIGNAL( activated() ), mMapCanvas, SLOT( zoomIn() ) );
connect( zoomShortCut2, &QShortcut::activated, mMapCanvas, &QgsMapCanvas::zoomIn );
zoomShortCut2->setObjectName( QStringLiteral( "ZoomInToCanvas2" ) );
zoomShortCut2->setWhatsThis( QStringLiteral( "Zoom in to canvas (secondary)" ) );
QShortcut* zoomOutShortCut = new QShortcut( QKeySequence( tr( "Ctrl+-" ) ), this );
connect( zoomOutShortCut, SIGNAL( activated() ), mMapCanvas, SLOT( zoomOut() ) );
connect( zoomOutShortCut, &QShortcut::activated, mMapCanvas, &QgsMapCanvas::zoomOut );
zoomOutShortCut->setObjectName( QStringLiteral( "ZoomOutOfCanvas" ) );
zoomOutShortCut->setWhatsThis( QStringLiteral( "Zoom out of canvas" ) );

Expand Down Expand Up @@ -1258,8 +1257,7 @@ QgisApp::QgisApp()
setupUi( this );
mInternalClipboard = new QgsClipboard;
mMapCanvas = new QgsMapCanvas();
connect( mMapCanvas, SIGNAL( messageEmitted( const QString&, const QString&, QgsMessageBar::MessageLevel ) ),
this, SLOT( displayMessage( const QString&, const QString&, QgsMessageBar::MessageLevel ) ) );
connect( mMapCanvas, &QgsMapCanvas::messageEmitted, this, &QgisApp::displayMessage );
mMapCanvas->freeze();
mLayerTreeView = new QgsLayerTreeView( this );
mUndoWidget = new QgsUndoWidget( nullptr, mMapCanvas );
Expand Down Expand Up @@ -2434,8 +2432,8 @@ void QgisApp::createStatusBar()
"of rendering layers and other time-intensive operations" ) );
statusBar()->addPermanentWidget( mProgressBar, 1 );

connect( mMapCanvas, SIGNAL( renderStarting() ), this, SLOT( canvasRefreshStarted() ) );
connect( mMapCanvas, SIGNAL( mapCanvasRefreshed() ), this, SLOT( canvasRefreshFinished() ) );
connect( mMapCanvas, &QgsMapCanvas::renderStarting, this, &QgisApp::canvasRefreshStarted );
connect( mMapCanvas, &QgsMapCanvas::mapCanvasRefreshed, this, &QgisApp::canvasRefreshFinished );

mTaskManagerWidget = new QgsTaskManagerStatusBarWidget( QgsApplication::taskManager(), statusBar() );
statusBar()->addPermanentWidget( mTaskManagerWidget, 0 );
Expand Down Expand Up @@ -2463,8 +2461,8 @@ void QgisApp::createStatusBar()
mMagnifierWidget = new QgsStatusBarMagnifierWidget( statusBar() );
mMagnifierWidget->setObjectName( QStringLiteral( "mMagnifierWidget" ) );
mMagnifierWidget->setFont( myFont );
connect( mMapCanvas, SIGNAL( magnificationChanged( double ) ), mMagnifierWidget, SLOT( updateMagnification( double ) ) );
connect( mMagnifierWidget, SIGNAL( magnificationChanged( double ) ), mMapCanvas, SLOT( setMagnificationFactor( double ) ) );
connect( mMapCanvas, &QgsMapCanvas::magnificationChanged, mMagnifierWidget, &QgsStatusBarMagnifierWidget::updateMagnification );
connect( mMagnifierWidget, &QgsStatusBarMagnifierWidget::magnificationChanged, mMapCanvas, &QgsMapCanvas::setMagnificationFactor );
mMagnifierWidget->updateMagnification( QSettings().value( QStringLiteral( "/qgis/magnifier_factor_default" ), 1.0 ).toDouble() );
statusBar()->addPermanentWidget( mMagnifierWidget, 0 );

Expand Down Expand Up @@ -2768,44 +2766,40 @@ void QgisApp::setupConnections()
connect( qApp, SIGNAL( aboutToQuit() ), this, SLOT( saveWindowState() ) );

// signal when mouse moved over window (coords display in status bar)
connect( mMapCanvas, SIGNAL( xyCoordinates( const QgsPoint & ) ),
this, SLOT( saveLastMousePosition( const QgsPoint & ) ) );
connect( mMapCanvas, SIGNAL( extentsChanged() ),
this, SLOT( extentChanged() ) );
connect( mMapCanvas, SIGNAL( scaleChanged( double ) ),
this, SLOT( showScale( double ) ) );
connect( mMapCanvas, SIGNAL( rotationChanged( double ) ),
this, SLOT( showRotation() ) );
connect( mMapCanvas, SIGNAL( scaleChanged( double ) ),
this, SLOT( updateMouseCoordinatePrecision() ) );
connect( mMapCanvas, SIGNAL( mapToolSet( QgsMapTool *, QgsMapTool * ) ),
this, SLOT( mapToolChanged( QgsMapTool *, QgsMapTool * ) ) );
connect( mMapCanvas, SIGNAL( selectionChanged( QgsMapLayer * ) ),
this, SLOT( selectionChanged( QgsMapLayer * ) ) );
connect( mMapCanvas, SIGNAL( extentsChanged() ),
this, SLOT( markDirty() ) );
connect( mMapCanvas, SIGNAL( layersChanged() ),
this, SLOT( markDirty() ) );

connect( mMapCanvas, SIGNAL( zoomLastStatusChanged( bool ) ),
mActionZoomLast, SLOT( setEnabled( bool ) ) );
connect( mMapCanvas, SIGNAL( zoomNextStatusChanged( bool ) ),
mActionZoomNext, SLOT( setEnabled( bool ) ) );
connect( mRenderSuppressionCBox, SIGNAL( toggled( bool ) ),
mMapCanvas, SLOT( setRenderFlag( bool ) ) );

connect( mMapCanvas, SIGNAL( destinationCrsChanged() ),
this, SLOT( reprojectAnnotations() ) );
connect( mMapCanvas, &QgsMapCanvas::xyCoordinates, this, &QgisApp::saveLastMousePosition );
connect( mMapCanvas, &QgsMapCanvas::extentsChanged, this, &QgisApp::extentChanged );
connect( mMapCanvas, &QgsMapCanvas::scaleChanged, this, &QgisApp::showScale );
connect( mMapCanvas, &QgsMapCanvas::rotationChanged, this, &QgisApp::showRotation );
connect( mMapCanvas, &QgsMapCanvas::scaleChanged,
this, &QgisApp::updateMouseCoordinatePrecision );
connect( mMapCanvas, &QgsMapCanvas::mapToolSet,
this, &QgisApp::mapToolChanged );
connect( mMapCanvas, &QgsMapCanvas::selectionChanged,
this, &QgisApp::selectionChanged );
connect( mMapCanvas, &QgsMapCanvas::extentsChanged,
this, &QgisApp::markDirty );
connect( mMapCanvas, &QgsMapCanvas::layersChanged,
this, &QgisApp::markDirty );

connect( mMapCanvas, &QgsMapCanvas::zoomLastStatusChanged,
mActionZoomLast, &QAction::setEnabled );
connect( mMapCanvas, &QgsMapCanvas::zoomNextStatusChanged,
mActionZoomNext, &QAction::setEnabled );
connect( mRenderSuppressionCBox, &QAbstractButton::toggled,
mMapCanvas, &QgsMapCanvas::setRenderFlag );

connect( mMapCanvas, &QgsMapCanvas::destinationCrsChanged,
this, &QgisApp::reprojectAnnotations );

// connect MapCanvas keyPress event so we can check if selected feature collection must be deleted
connect( mMapCanvas, SIGNAL( keyPressed( QKeyEvent * ) ),
this, SLOT( mapCanvas_keyPressed( QKeyEvent * ) ) );
connect( mMapCanvas, &QgsMapCanvas::keyPressed,
this, &QgisApp::mapCanvas_keyPressed );

// connect renderer
connect( mMapCanvas, SIGNAL( hasCrsTransformEnabledChanged( bool ) ),
this, SLOT( hasCrsTransformEnabled( bool ) ) );
connect( mMapCanvas, SIGNAL( destinationCrsChanged() ),
this, SLOT( destinationCrsChanged() ) );
connect( mMapCanvas, &QgsMapCanvas::hasCrsTransformEnabledChanged,
this, &QgisApp::hasCrsTransformEnabled );
connect( mMapCanvas, &QgsMapCanvas::destinationCrsChanged,
this, &QgisApp::destinationCrsChanged );

// connect legend signals
connect( mLayerTreeView, SIGNAL( currentLayerChanged( QgsMapLayer * ) ),
Expand Down Expand Up @@ -3209,7 +3203,7 @@ void QgisApp::initLayerTreeView()
addDockWidget( Qt::LeftDockWidgetArea, mLayerOrderDock );
mLayerOrderDock->hide();

connect( mMapCanvas, SIGNAL( mapCanvasRefreshed() ), this, SLOT( updateFilterLegend() ) );
connect( mMapCanvas, &QgsMapCanvas::mapCanvasRefreshed, this, &QgisApp::updateFilterLegend );
}

void QgisApp::setupLayerTreeViewFromSettings()
Expand Down Expand Up @@ -3304,7 +3298,7 @@ void QgisApp::createDecorations()
addDecorationItem( mDecorationCopyright );
addDecorationItem( mDecorationNorthArrow );
addDecorationItem( mDecorationScaleBar );
connect( mMapCanvas, SIGNAL( renderComplete( QPainter * ) ), this, SLOT( renderDecorationItems( QPainter * ) ) );
connect( mMapCanvas, &QgsMapCanvas::renderComplete, this, &QgisApp::renderDecorationItems );
connect( this, SIGNAL( newProject() ), this, SLOT( projectReadDecorationItems() ) );
connect( this, SIGNAL( projectRead() ), this, SLOT( projectReadDecorationItems() ) );
}
Expand Down
18 changes: 8 additions & 10 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -129,16 +129,16 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent )

mResizeTimer = new QTimer( this );
mResizeTimer->setSingleShot( true );
connect( mResizeTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) );
connect( mResizeTimer, &QTimer::timeout, this, &QgsMapCanvas::refresh );

// create map canvas item which will show the map
mMap = new QgsMapCanvasMap( this );

// project handling
connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ),
this, SLOT( readProject( const QDomDocument & ) ) );
connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ),
this, SLOT( writeProject( QDomDocument & ) ) );
connect( QgsProject::instance(), &QgsProject::readProject,
this, &QgsMapCanvas::readProject );
connect( QgsProject::instance(), &QgsProject::writeProject,
this, &QgsMapCanvas::writeProject );

mSettings.setFlag( QgsMapSettings::DrawEditingInfo );
mSettings.setFlag( QgsMapSettings::UseRenderingOptimization );
Expand Down Expand Up @@ -504,7 +504,7 @@ void QgsMapCanvas::refreshMap()
mJob = new QgsMapRendererParallelJob( mSettings );
else
mJob = new QgsMapRendererSequentialJob( mSettings );
connect( mJob, SIGNAL( finished() ), SLOT( rendererJobFinished() ) );
connect( mJob, &QgsMapRendererJob::finished, this, &QgsMapCanvas::rendererJobFinished );
mJob->setCache( mCache );

QStringList layersForGeometryCache;
Expand Down Expand Up @@ -1473,7 +1473,7 @@ void QgsMapCanvas::setMapTool( QgsMapTool* tool )

if ( mMapTool )
{
disconnect( mMapTool, SIGNAL( destroyed() ), this, SLOT( mapToolDestroyed() ) );
disconnect( mMapTool, &QObject::destroyed, this, &QgsMapCanvas::mapToolDestroyed );
mMapTool->deactivate();
}

Expand All @@ -1496,11 +1496,10 @@ void QgsMapCanvas::setMapTool( QgsMapTool* tool )
mMapTool = tool;
if ( mMapTool )
{
connect( mMapTool, SIGNAL( destroyed() ), this, SLOT( mapToolDestroyed() ) );
connect( mMapTool, &QObject::destroyed, this, &QgsMapCanvas::mapToolDestroyed );
mMapTool->activate();
}

emit mapToolSet( mMapTool );
emit mapToolSet( mMapTool, oldTool );
} // setMapTool

Expand All @@ -1510,7 +1509,6 @@ void QgsMapCanvas::unsetMapTool( QgsMapTool* tool )
{
mMapTool->deactivate();
mMapTool = nullptr;
emit mapToolSet( nullptr );
emit mapToolSet( nullptr, mMapTool );
setCursor( Qt::ArrowCursor );
}
Expand Down
3 changes: 0 additions & 3 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -511,9 +511,6 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! Emit key release event
void keyReleased( QKeyEvent * e );

//! Emit map tool changed event
void mapToolSet( QgsMapTool *tool );

/** Emit map tool changed with the old tool
* @note added in 2.3
*/
Expand Down

0 comments on commit b681b7b

Please sign in to comment.