Skip to content

Commit 946a9d0

Browse files
committedMar 14, 2017
Prevent synced view scale from going to 0 when resizing synced docks
1 parent 48df5dd commit 946a9d0

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed
 

‎src/app/qgsmapcanvasdockwidget.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa
163163
mBlockMagnificationUpdate = false;
164164
}
165165
} );
166+
167+
mResizeTimer.setSingleShot( true );
168+
connect( &mResizeTimer, &QTimer::timeout, this, [ = ]
169+
{
170+
mBlockExtentSync = false;
171+
syncViewExtent( mMainCanvas );
172+
} );
166173
}
167174

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

190+
void QgsMapCanvasDockWidget::resizeEvent( QResizeEvent * )
191+
{
192+
mBlockExtentSync = true;
193+
mResizeTimer.start( 500 );
194+
}
195+
183196
void QgsMapCanvasDockWidget::setMapCrs()
184197
{
185198
QgsProjectionSelectionDialog dlg;
@@ -209,7 +222,7 @@ void QgsMapCanvasDockWidget::syncView( bool enabled )
209222
void QgsMapCanvasDockWidget::syncViewExtent( QgsMapCanvas *sourceCanvas )
210223
{
211224
// avoid infinite recursion
212-
syncView( false );
225+
mBlockExtentSync = true;
213226

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

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

229-
syncView( true );
242+
mBlockExtentSync = false;
230243
}
231244

232245
void QgsMapCanvasDockWidget::mapExtentChanged()
233246
{
247+
if ( mBlockExtentSync )
248+
return;
249+
234250
QgsMapCanvas *sourceCanvas = qobject_cast< QgsMapCanvas * >( sender() );
235251
if ( !sourceCanvas )
236252
return;

‎src/app/qgsmapcanvasdockwidget.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "qgsdockwidget.h"
2121
#include "qgis_app.h"
2222
#include <QWidgetAction>
23+
#include <QTimer>
2324
#include <memory>
2425

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

6162
void renameTriggered();
6263

64+
protected:
65+
66+
void resizeEvent( QResizeEvent *e ) override;
67+
6368
private slots:
6469

6570
void setMapCrs();
@@ -81,7 +86,9 @@ class APP_EXPORT QgsMapCanvasDockWidget : public QgsDockWidget, private Ui::QgsM
8186
bool mBlockScaleUpdate = false;
8287
bool mBlockRotationUpdate = false;
8388
bool mBlockMagnificationUpdate = false;
89+
bool mBlockExtentSync = false;
8490
QgsMapToolPan *mPanTool = nullptr;
91+
QTimer mResizeTimer;
8592
void syncViewExtent( QgsMapCanvas *sourceCanvas );
8693
};
8794

0 commit comments

Comments
 (0)
Please sign in to comment.