Skip to content
Permalink
Browse files

Save/restore extra map views in project

  • Loading branch information
nyalldawson committed Mar 13, 2017
1 parent ee969df commit e4469c89256c7469284c6eeab563c9951d21735a
Showing with 54 additions and 4 deletions.
  1. +48 −2 src/app/qgisapp.cpp
  2. +6 −2 src/app/qgisapp.h
@@ -3112,7 +3112,7 @@ QgsMapCanvas *QgisApp::mapCanvas()
return mMapCanvas;
}

QgsMapCanvas *QgisApp::createNewMapCanvas( const QString &name )
QgsMapCanvas *QgisApp::createNewMapCanvas( const QString &name, bool isFloating, const QRect &dockGeometry )
{
Q_FOREACH ( QgsMapCanvas *canvas, mapCanvases() )
{
@@ -3127,6 +3127,16 @@ QgsMapCanvas *QgisApp::createNewMapCanvas( const QString &name )
QgsMapCanvasDockWidget *mapCanvasWidget = new QgsMapCanvasDockWidget( name, this );
mapCanvasWidget->setAllowedAreas( Qt::AllDockWidgetAreas );

mapCanvasWidget->setFloating( isFloating );
if ( dockGeometry.isEmpty() )
{
mapCanvasWidget->resize( 400, 400 );
}
else
{
mapCanvasWidget->setGeometry( dockGeometry );
}

QgsMapCanvas *mapCanvas = mapCanvasWidget->mapCanvas();
mapCanvas->freeze( true );
mapCanvas->setObjectName( name );
@@ -11686,10 +11696,26 @@ void QgisApp::writeProject( QDomDocument &doc )
QDomElement oldLegendElem = QgsLayerTreeUtils::writeOldLegend( doc, QgsLayerTree::toGroup( clonedRoot ),
mLayerTreeCanvasBridge->hasCustomLayerOrder(), mLayerTreeCanvasBridge->customLayerOrder() );
delete clonedRoot;
doc.firstChildElement( QStringLiteral( "qgis" ) ).appendChild( oldLegendElem );
QDomElement qgisNode = doc.firstChildElement( QStringLiteral( "qgis" ) );
qgisNode.appendChild( oldLegendElem );

QgsProject::instance()->writeEntry( QStringLiteral( "Legend" ), QStringLiteral( "filterByMap" ), static_cast< bool >( layerTreeView()->layerTreeModel()->legendFilterMapSettings() ) );

// Save the position of the map view docks
QDomElement mapViewNode = doc.createElement( QStringLiteral( "mapViewDocks" ) );
Q_FOREACH ( QgsMapCanvasDockWidget *w, findChildren< QgsMapCanvasDockWidget * >() )
{
QDomElement node = doc.createElement( QStringLiteral( "view" ) );
node.setAttribute( QStringLiteral( "name" ), w->mapCanvas()->objectName() );
node.setAttribute( QStringLiteral( "x" ), w->x() );
node.setAttribute( QStringLiteral( "y" ), w->y() );
node.setAttribute( QStringLiteral( "width" ), w->width() );
node.setAttribute( QStringLiteral( "height" ), w->height() );
node.setAttribute( QStringLiteral( "floating" ), w->isFloating() ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
mapViewNode.appendChild( node );
}
qgisNode.appendChild( mapViewNode );

projectChanged( doc );
}

@@ -11705,6 +11731,26 @@ void QgisApp::readProject( const QDomDocument &doc )

if ( autoSetupOnFirstLayer )
mLayerTreeCanvasBridge->setAutoSetupOnFirstLayer( true );

QDomNodeList nodes = doc.elementsByTagName( QStringLiteral( "mapViewDocks" ) );
if ( !nodes.isEmpty() )
{
QDomNode viewNode = nodes.at( 0 );
nodes = viewNode.childNodes();
for ( int i = 0; i < nodes.size(); ++i )
{
QDomElement elementNode = nodes.at( i ).toElement();
QString mapName = elementNode.attribute( QStringLiteral( "name" ) );
int x = elementNode.attribute( QStringLiteral( "x" ), QStringLiteral( "0" ) ).toInt();
int y = elementNode.attribute( QStringLiteral( "y" ), QStringLiteral( "0" ) ).toInt();
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();

QgsMapCanvas *mapCanvas = createNewMapCanvas( mapName, floating, QRect( x, y, w, h ) );
mapCanvas->readProject( doc );
}
}
}

void QgisApp::showLayerProperties( QgsMapLayer *ml )
@@ -236,8 +236,12 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
*/
QList< QgsMapCanvas * > mapCanvases();

//! Create a new map canvas with the specified unique \a name
QgsMapCanvas *createNewMapCanvas( const QString &name );
/**
* Create a new map canvas with the specified unique \a name. The \a isFloating
* 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() );

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

0 comments on commit e4469c8

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