Skip to content

Commit 40bb4e9

Browse files
committed
Save extent sychronized state in project for views
1 parent 73c09bf commit 40bb4e9

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

src/app/qgisapp.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -3113,7 +3113,7 @@ QgsMapCanvas *QgisApp::mapCanvas()
31133113
return mMapCanvas;
31143114
}
31153115

3116-
QgsMapCanvas *QgisApp::createNewMapCanvas( const QString &name, bool isFloating, const QRect &dockGeometry )
3116+
QgsMapCanvas *QgisApp::createNewMapCanvas( const QString &name, bool isFloating, const QRect &dockGeometry, bool synced )
31173117
{
31183118
Q_FOREACH ( QgsMapCanvas *canvas, mapCanvases() )
31193119
{
@@ -3166,6 +3166,9 @@ QgsMapCanvas *QgisApp::createNewMapCanvas( const QString &name, bool isFloating,
31663166
markDirty();
31673167
connect( mapCanvasWidget, &QgsMapCanvasDockWidget::closed, this, &QgisApp::markDirty );
31683168
connect( mapCanvasWidget, &QgsMapCanvasDockWidget::renameTriggered, this, &QgisApp::renameView );
3169+
3170+
mapCanvasWidget->setViewExtentSynchronized( synced );
3171+
31693172
return mapCanvas;
31703173
}
31713174

@@ -11748,6 +11751,7 @@ void QgisApp::writeProject( QDomDocument &doc )
1174811751
node.setAttribute( QStringLiteral( "width" ), w->width() );
1174911752
node.setAttribute( QStringLiteral( "height" ), w->height() );
1175011753
node.setAttribute( QStringLiteral( "floating" ), w->isFloating() ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
11754+
node.setAttribute( QStringLiteral( "synced" ), w->isViewExtentSynchronized() ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
1175111755
mapViewNode.appendChild( node );
1175211756
}
1175311757
qgisNode.appendChild( mapViewNode );
@@ -11782,8 +11786,9 @@ void QgisApp::readProject( const QDomDocument &doc )
1178211786
int w = elementNode.attribute( QStringLiteral( "width" ), QStringLiteral( "400" ) ).toInt();
1178311787
int h = elementNode.attribute( QStringLiteral( "height" ), QStringLiteral( "400" ) ).toInt();
1178411788
bool floating = elementNode.attribute( QStringLiteral( "floating" ), QStringLiteral( "0" ) ).toInt();
11789+
bool synced = elementNode.attribute( QStringLiteral( "synced" ), QStringLiteral( "0" ) ).toInt();
1178511790

11786-
QgsMapCanvas *mapCanvas = createNewMapCanvas( mapName, floating, QRect( x, y, w, h ) );
11791+
QgsMapCanvas *mapCanvas = createNewMapCanvas( mapName, floating, QRect( x, y, w, h ), synced );
1178711792
mapCanvas->readProject( doc );
1178811793
}
1178911794
}

src/app/qgisapp.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
241241
* and \a dockGeometry arguments can be used to specify an initial floating state
242242
* and widget geometry rect for the dock.
243243
*/
244-
QgsMapCanvas *createNewMapCanvas( const QString &name, bool isFloating = false, const QRect &dockGeometry = QRect() );
244+
QgsMapCanvas *createNewMapCanvas( const QString &name, bool isFloating = false, const QRect &dockGeometry = QRect(),
245+
bool synced = false );
245246

246247
/**
247248
* Closes any additional map canvases. The main map canvas will not

src/app/qgsmapcanvasdockwidget.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@ void QgsMapCanvasDockWidget::closeWithoutWarning()
177177
close();
178178
}
179179

180+
void QgsMapCanvasDockWidget::setViewExtentSynchronized( bool enabled )
181+
{
182+
mActionSyncView->setChecked( enabled );
183+
}
184+
185+
bool QgsMapCanvasDockWidget::isViewExtentSynchronized() const
186+
{
187+
return mActionSyncView->isChecked();
188+
}
189+
180190
void QgsMapCanvasDockWidget::closeEvent( QCloseEvent *event )
181191
{
182192
if ( mShowCloseWarning && mMapCanvas->layerCount() > 0

src/app/qgsmapcanvasdockwidget.h

+7
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ class APP_EXPORT QgsMapCanvasDockWidget : public QgsDockWidget, private Ui::QgsM
5454
*/
5555
void closeWithoutWarning();
5656

57+
/**
58+
* Sets whether the view extent should be synchronized with the main canvas extent.
59+
*/
60+
void setViewExtentSynchronized( bool enabled );
61+
62+
bool isViewExtentSynchronized() const;
63+
5764
signals:
5865

5966
void renameTriggered();

0 commit comments

Comments
 (0)