Skip to content

Commit

Permalink
Prevent synced view scale from going to 0 when resizing synced docks
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 14, 2017
1 parent 48df5dd commit 946a9d0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/app/qgsmapcanvasdockwidget.cpp
Expand Up @@ -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()
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/app/qgsmapcanvasdockwidget.h
Expand Up @@ -20,6 +20,7 @@
#include "qgsdockwidget.h"
#include "qgis_app.h"
#include <QWidgetAction>
#include <QTimer>
#include <memory>

class QgsMapCanvas;
Expand Down Expand Up @@ -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();
Expand All @@ -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 );
};

Expand Down

0 comments on commit 946a9d0

Please sign in to comment.