@@ -719,9 +719,10 @@ static QString _getVersion(QDomDocument const &doc)
719
719
/* *
720
720
locate a qgsMapCanvas object
721
721
*/
722
- static QgsMapCanvas * _findMapCanvas (QString const &canonicalMapCanvasName )
722
+ static QgsMapCanvas * _findMapCanvas ()
723
723
{
724
724
QgsMapCanvas * theMapCanvas = 0x0 ;
725
+ QString canonicalMapCanvasName = " theMapCanvas" ;
725
726
726
727
QWidgetList wlist = QApplication::topLevelWidgets ();
727
728
foreach (QWidget *widget, QApplication::topLevelWidgets ())
@@ -739,7 +740,7 @@ static QgsMapCanvas * _findMapCanvas(QString const &canonicalMapCanvasName)
739
740
}
740
741
else
741
742
{
742
- qDebug (( " Unable to find canvas widget " + canonicalMapCanvasName). toLocal8Bit (). data () );
743
+ qDebug (" Unable to find the map canvas widget with name " + canonicalMapCanvasName);
743
744
744
745
return 0x0 ; // XXX some sort of error value? Exception?
745
746
}
@@ -901,14 +902,11 @@ static pair< bool, list<QDomNode> > _getMapLayers(QDomDocument const &doc)
901
902
/* *
902
903
Sets the given canvas' extents
903
904
904
- @param canonicalName will be "theMapCanvas" or "theOverviewCanvas"; these
905
- are set when those are created in qgisapp ctor
906
905
*/
907
- static void _setCanvasExtent (QString const &canonicalMapCanvasName,
908
- QgsRect const &newExtent)
906
+ static void _setCanvasExtent (QgsRect const &newExtent)
909
907
{
910
908
// first find the canonical map canvas
911
- QgsMapCanvas *theMapCanvas = _findMapCanvas (canonicalMapCanvasName );
909
+ QgsMapCanvas *theMapCanvas = _findMapCanvas ();
912
910
913
911
if (!theMapCanvas)
914
912
{
@@ -937,28 +935,24 @@ static void _setCanvasExtent(QString const &canonicalMapCanvasName,
937
935
set the overview canvas to that instead of stupidly setting the overview
938
936
canvas to the *same* extent that's in the main map canvas.
939
937
940
- @param canonicalMapCanvasName will be "theMapCanvas" or "theOverviewCanvas"; these
941
- are set when those are created in qgisapp ctor
942
-
943
938
*/
944
- static QgsRect _getFullExtent (QString const &canonicalMapCanvasName )
939
+ static QgsRect _getFullExtent ()
945
940
{
946
941
// XXX since this is a cut-n-paste from above, maybe generalize to a
947
942
// XXX separate function?
948
943
// first find the canonical map canvas
949
- QgsMapCanvas *theMapCanvas = _findMapCanvas (canonicalMapCanvasName );
944
+ QgsMapCanvas *theMapCanvas = _findMapCanvas ();
950
945
951
946
if (!theMapCanvas)
952
947
{
953
- qDebug ((" Unable to find canvas widget " + canonicalMapCanvasName).toLocal8Bit ().data ());
954
-
948
+ // _findMapCanvas() will produce an error if the map canvas wasn't found
955
949
return QgsRect (); // XXX some sort of error value? Exception?
956
950
}
957
951
958
952
959
953
return theMapCanvas->fullExtent ();
960
954
961
- } // _getFullExtent( QString const & canonicalMapCanvasName )
955
+ } // _getFullExtent( )
962
956
963
957
964
958
@@ -972,28 +966,24 @@ static QgsRect _getFullExtent(QString const &canonicalMapCanvasName)
972
966
set the overview canvas to that instead of stupidly setting the overview
973
967
canvas to the *same* extent that's in the main map canvas.
974
968
975
- @param canonicalMapCanvasName will be "theMapCanvas" or "theOverviewCanvas"; these
976
- are set when those are created in qgisapp ctor
977
-
978
969
*/
979
- static QgsRect _getExtent (QString const &canonicalMapCanvasName )
970
+ static QgsRect _getExtent ()
980
971
{
981
972
// XXX since this is a cut-n-paste from above, maybe generalize to a
982
973
// XXX separate function?
983
974
// first find the canonical map canvas
984
- QgsMapCanvas *theMapCanvas = _findMapCanvas (canonicalMapCanvasName );
975
+ QgsMapCanvas *theMapCanvas = _findMapCanvas ();
985
976
986
977
if (!theMapCanvas)
987
978
{
988
- qDebug ((" Unable to find canvas widget " + canonicalMapCanvasName).toLocal8Bit ().data ());
989
-
979
+ // _findMapCanvas will produce an error if the map canvas wasn't found
990
980
return QgsRect (); // XXX some sort of error value? Exception?
991
981
}
992
982
993
983
994
984
return theMapCanvas->extent ();
995
985
996
- } // _getExtent( QString const & canonicalMapCanvasName )
986
+ } // _getExtent( )
997
987
998
988
999
989
@@ -1101,7 +1091,9 @@ bool QgsProject::read()
1101
1091
1102
1092
// now set the map units; note, alters QgsProject::instance().
1103
1093
_getMapUnits (*doc);
1104
- _findMapCanvas (" theMapCanvas" )->setMapUnits (mapUnits ());
1094
+ QgsMapCanvas* canvas = _findMapCanvas ();
1095
+ if (canvas)
1096
+ canvas->setMapUnits (mapUnits ());
1105
1097
1106
1098
// get the map layers
1107
1099
pair< bool , list<QDomNode> > getMapLayersResults = _getMapLayers (*doc);
@@ -1123,12 +1115,6 @@ bool QgsProject::read()
1123
1115
// return false;
1124
1116
}
1125
1117
1126
- // ensure that overview map canvas is set to *entire* extent
1127
- QgsRect mapCanvasFullExtent = _getFullExtent (" theMapCanvas" );
1128
- _setCanvasExtent (" theOverviewCanvas" , mapCanvasFullExtent);
1129
- // now restore the extent for the main canvas
1130
- _setCanvasExtent (" theMapCanvas" , savedExtent);
1131
-
1132
1118
if ( ! getMapLayersResults.first )
1133
1119
{
1134
1120
#ifdef QGISDEBUG
@@ -1309,13 +1295,10 @@ bool QgsProject::write()
1309
1295
1310
1296
// extents and layers info are written by the map canvas
1311
1297
// find the canonical map canvas
1312
- QgsMapCanvas *theMapCanvas = _findMapCanvas (" theMapCanvas " );
1298
+ QgsMapCanvas *theMapCanvas = _findMapCanvas ();
1313
1299
1314
1300
if (!theMapCanvas)
1315
1301
{
1316
- qDebug (" Unable to find canvas widget theMapCanvas" );
1317
-
1318
-
1319
1302
// Actually this might be run from the test harness, and therefore
1320
1303
// there won't be a GUI, so no map canvas. Just blithely continue on.
1321
1304
}
0 commit comments