Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Save extent sychronized state in project for views
  • Loading branch information
nyalldawson committed Mar 13, 2017
1 parent 73c09bf commit 40bb4e9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -3113,7 +3113,7 @@ QgsMapCanvas *QgisApp::mapCanvas()
return mMapCanvas;
}

QgsMapCanvas *QgisApp::createNewMapCanvas( const QString &name, bool isFloating, const QRect &dockGeometry )
QgsMapCanvas *QgisApp::createNewMapCanvas( const QString &name, bool isFloating, const QRect &dockGeometry, bool synced )
{
Q_FOREACH ( QgsMapCanvas *canvas, mapCanvases() )
{
Expand Down Expand Up @@ -3166,6 +3166,9 @@ QgsMapCanvas *QgisApp::createNewMapCanvas( const QString &name, bool isFloating,
markDirty();
connect( mapCanvasWidget, &QgsMapCanvasDockWidget::closed, this, &QgisApp::markDirty );
connect( mapCanvasWidget, &QgsMapCanvasDockWidget::renameTriggered, this, &QgisApp::renameView );

mapCanvasWidget->setViewExtentSynchronized( synced );

return mapCanvas;
}

Expand Down Expand Up @@ -11748,6 +11751,7 @@ void QgisApp::writeProject( QDomDocument &doc )
node.setAttribute( QStringLiteral( "width" ), w->width() );
node.setAttribute( QStringLiteral( "height" ), w->height() );
node.setAttribute( QStringLiteral( "floating" ), w->isFloating() ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
node.setAttribute( QStringLiteral( "synced" ), w->isViewExtentSynchronized() ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
mapViewNode.appendChild( node );
}
qgisNode.appendChild( mapViewNode );
Expand Down Expand Up @@ -11782,8 +11786,9 @@ void QgisApp::readProject( const QDomDocument &doc )
int w = elementNode.attribute( QStringLiteral( "width" ), QStringLiteral( "400" ) ).toInt();
int h = elementNode.attribute( QStringLiteral( "height" ), QStringLiteral( "400" ) ).toInt();
bool floating = elementNode.attribute( QStringLiteral( "floating" ), QStringLiteral( "0" ) ).toInt();
bool synced = elementNode.attribute( QStringLiteral( "synced" ), QStringLiteral( "0" ) ).toInt();

QgsMapCanvas *mapCanvas = createNewMapCanvas( mapName, floating, QRect( x, y, w, h ) );
QgsMapCanvas *mapCanvas = createNewMapCanvas( mapName, floating, QRect( x, y, w, h ), synced );
mapCanvas->readProject( doc );
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgisapp.h
Expand Up @@ -241,7 +241,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
* and \a dockGeometry arguments can be used to specify an initial floating state
* and widget geometry rect for the dock.
*/
QgsMapCanvas *createNewMapCanvas( const QString &name, bool isFloating = false, const QRect &dockGeometry = QRect() );
QgsMapCanvas *createNewMapCanvas( const QString &name, bool isFloating = false, const QRect &dockGeometry = QRect(),
bool synced = false );

/**
* Closes any additional map canvases. The main map canvas will not
Expand Down
10 changes: 10 additions & 0 deletions src/app/qgsmapcanvasdockwidget.cpp
Expand Up @@ -177,6 +177,16 @@ void QgsMapCanvasDockWidget::closeWithoutWarning()
close();
}

void QgsMapCanvasDockWidget::setViewExtentSynchronized( bool enabled )
{
mActionSyncView->setChecked( enabled );
}

bool QgsMapCanvasDockWidget::isViewExtentSynchronized() const
{
return mActionSyncView->isChecked();
}

void QgsMapCanvasDockWidget::closeEvent( QCloseEvent *event )
{
if ( mShowCloseWarning && mMapCanvas->layerCount() > 0
Expand Down
7 changes: 7 additions & 0 deletions src/app/qgsmapcanvasdockwidget.h
Expand Up @@ -54,6 +54,13 @@ class APP_EXPORT QgsMapCanvasDockWidget : public QgsDockWidget, private Ui::QgsM
*/
void closeWithoutWarning();

/**
* Sets whether the view extent should be synchronized with the main canvas extent.
*/
void setViewExtentSynchronized( bool enabled );

bool isViewExtentSynchronized() const;

signals:

void renameTriggered();
Expand Down

0 comments on commit 40bb4e9

Please sign in to comment.