Skip to content
Permalink
Browse files

Prevent synced view scale from going to 0 when resizing synced docks

  • Loading branch information
nyalldawson committed Mar 14, 2017
1 parent 48df5dd commit 946a9d0e8575d77a4ef48e8b6ddb9065c79af2fb
Showing with 25 additions and 2 deletions.
  1. +18 −2 src/app/qgsmapcanvasdockwidget.cpp
  2. +7 −0 src/app/qgsmapcanvasdockwidget.h
@@ -163,6 +163,13 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa
mBlockMagnificationUpdate = false;
}
} );

mResizeTimer.setSingleShot( true );
connect( &mResizeTimer, &QTimer::timeout, this, [ = ]
{
mBlockExtentSync = false;
syncViewExtent( mMainCanvas );
} );
}

QgsMapCanvas *QgsMapCanvasDockWidget::mapCanvas()
@@ -180,6 +187,12 @@ bool QgsMapCanvasDockWidget::isViewExtentSynchronized() const
return mActionSyncView->isChecked();
}

void QgsMapCanvasDockWidget::resizeEvent( QResizeEvent * )
{
mBlockExtentSync = true;
mResizeTimer.start( 500 );
}

void QgsMapCanvasDockWidget::setMapCrs()
{
QgsProjectionSelectionDialog dlg;
@@ -209,7 +222,7 @@ void QgsMapCanvasDockWidget::syncView( bool enabled )
void QgsMapCanvasDockWidget::syncViewExtent( QgsMapCanvas *sourceCanvas )
{
// avoid infinite recursion
syncView( false );
mBlockExtentSync = true;

QgsMapCanvas *destCanvas = sourceCanvas == mMapCanvas ? mMainCanvas : mMapCanvas;

@@ -226,11 +239,14 @@ void QgsMapCanvasDockWidget::syncViewExtent( QgsMapCanvas *sourceCanvas )
}
destCanvas->refresh();

syncView( true );
mBlockExtentSync = false;
}

void QgsMapCanvasDockWidget::mapExtentChanged()
{
if ( mBlockExtentSync )
return;

QgsMapCanvas *sourceCanvas = qobject_cast< QgsMapCanvas * >( sender() );
if ( !sourceCanvas )
return;
@@ -20,6 +20,7 @@
#include "qgsdockwidget.h"
#include "qgis_app.h"
#include <QWidgetAction>
#include <QTimer>
#include <memory>

class QgsMapCanvas;
@@ -60,6 +61,10 @@ class APP_EXPORT QgsMapCanvasDockWidget : public QgsDockWidget, private Ui::QgsM

void renameTriggered();

protected:

void resizeEvent( QResizeEvent *e ) override;

private slots:

void setMapCrs();
@@ -81,7 +86,9 @@ class APP_EXPORT QgsMapCanvasDockWidget : public QgsDockWidget, private Ui::QgsM
bool mBlockScaleUpdate = false;
bool mBlockRotationUpdate = false;
bool mBlockMagnificationUpdate = false;
bool mBlockExtentSync = false;
QgsMapToolPan *mPanTool = nullptr;
QTimer mResizeTimer;
void syncViewExtent( QgsMapCanvas *sourceCanvas );
};

0 comments on commit 946a9d0

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