@@ -3112,7 +3112,7 @@ QgsMapCanvas *QgisApp::mapCanvas()
3112
3112
return mMapCanvas ;
3113
3113
}
3114
3114
3115
- QgsMapCanvas *QgisApp::createNewMapCanvas ( const QString &name )
3115
+ QgsMapCanvas *QgisApp::createNewMapCanvas ( const QString &name, bool isFloating, const QRect &dockGeometry )
3116
3116
{
3117
3117
Q_FOREACH ( QgsMapCanvas *canvas, mapCanvases () )
3118
3118
{
@@ -3127,6 +3127,16 @@ QgsMapCanvas *QgisApp::createNewMapCanvas( const QString &name )
3127
3127
QgsMapCanvasDockWidget *mapCanvasWidget = new QgsMapCanvasDockWidget ( name, this );
3128
3128
mapCanvasWidget->setAllowedAreas ( Qt::AllDockWidgetAreas );
3129
3129
3130
+ mapCanvasWidget->setFloating ( isFloating );
3131
+ if ( dockGeometry.isEmpty () )
3132
+ {
3133
+ mapCanvasWidget->resize ( 400 , 400 );
3134
+ }
3135
+ else
3136
+ {
3137
+ mapCanvasWidget->setGeometry ( dockGeometry );
3138
+ }
3139
+
3130
3140
QgsMapCanvas *mapCanvas = mapCanvasWidget->mapCanvas ();
3131
3141
mapCanvas->freeze ( true );
3132
3142
mapCanvas->setObjectName ( name );
@@ -11686,10 +11696,26 @@ void QgisApp::writeProject( QDomDocument &doc )
11686
11696
QDomElement oldLegendElem = QgsLayerTreeUtils::writeOldLegend ( doc, QgsLayerTree::toGroup ( clonedRoot ),
11687
11697
mLayerTreeCanvasBridge ->hasCustomLayerOrder (), mLayerTreeCanvasBridge ->customLayerOrder () );
11688
11698
delete clonedRoot;
11689
- doc.firstChildElement ( QStringLiteral ( " qgis" ) ).appendChild ( oldLegendElem );
11699
+ QDomElement qgisNode = doc.firstChildElement ( QStringLiteral ( " qgis" ) );
11700
+ qgisNode.appendChild ( oldLegendElem );
11690
11701
11691
11702
QgsProject::instance ()->writeEntry ( QStringLiteral ( " Legend" ), QStringLiteral ( " filterByMap" ), static_cast < bool >( layerTreeView ()->layerTreeModel ()->legendFilterMapSettings () ) );
11692
11703
11704
+ // Save the position of the map view docks
11705
+ QDomElement mapViewNode = doc.createElement ( QStringLiteral ( " mapViewDocks" ) );
11706
+ Q_FOREACH ( QgsMapCanvasDockWidget *w, findChildren< QgsMapCanvasDockWidget * >() )
11707
+ {
11708
+ QDomElement node = doc.createElement ( QStringLiteral ( " view" ) );
11709
+ node.setAttribute ( QStringLiteral ( " name" ), w->mapCanvas ()->objectName () );
11710
+ node.setAttribute ( QStringLiteral ( " x" ), w->x () );
11711
+ node.setAttribute ( QStringLiteral ( " y" ), w->y () );
11712
+ node.setAttribute ( QStringLiteral ( " width" ), w->width () );
11713
+ node.setAttribute ( QStringLiteral ( " height" ), w->height () );
11714
+ node.setAttribute ( QStringLiteral ( " floating" ), w->isFloating () ? QStringLiteral ( " 1" ) : QStringLiteral ( " 0" ) );
11715
+ mapViewNode.appendChild ( node );
11716
+ }
11717
+ qgisNode.appendChild ( mapViewNode );
11718
+
11693
11719
projectChanged ( doc );
11694
11720
}
11695
11721
@@ -11705,6 +11731,26 @@ void QgisApp::readProject( const QDomDocument &doc )
11705
11731
11706
11732
if ( autoSetupOnFirstLayer )
11707
11733
mLayerTreeCanvasBridge ->setAutoSetupOnFirstLayer ( true );
11734
+
11735
+ QDomNodeList nodes = doc.elementsByTagName ( QStringLiteral ( " mapViewDocks" ) );
11736
+ if ( !nodes.isEmpty () )
11737
+ {
11738
+ QDomNode viewNode = nodes.at ( 0 );
11739
+ nodes = viewNode.childNodes ();
11740
+ for ( int i = 0 ; i < nodes.size (); ++i )
11741
+ {
11742
+ QDomElement elementNode = nodes.at ( i ).toElement ();
11743
+ QString mapName = elementNode.attribute ( QStringLiteral ( " name" ) );
11744
+ int x = elementNode.attribute ( QStringLiteral ( " x" ), QStringLiteral ( " 0" ) ).toInt ();
11745
+ int y = elementNode.attribute ( QStringLiteral ( " y" ), QStringLiteral ( " 0" ) ).toInt ();
11746
+ int w = elementNode.attribute ( QStringLiteral ( " width" ), QStringLiteral ( " 400" ) ).toInt ();
11747
+ int h = elementNode.attribute ( QStringLiteral ( " height" ), QStringLiteral ( " 400" ) ).toInt ();
11748
+ bool floating = elementNode.attribute ( QStringLiteral ( " floating" ), QStringLiteral ( " 0" ) ).toInt ();
11749
+
11750
+ QgsMapCanvas *mapCanvas = createNewMapCanvas ( mapName, floating, QRect ( x, y, w, h ) );
11751
+ mapCanvas->readProject ( doc );
11752
+ }
11753
+ }
11708
11754
}
11709
11755
11710
11756
void QgisApp::showLayerProperties ( QgsMapLayer *ml )
0 commit comments