Skip to content

Commit 7194567

Browse files
committed
Restored reading/writing of canvas map settings
1 parent 4493f51 commit 7194567

15 files changed

+256
-206
lines changed

src/app/qgisapp.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -3146,7 +3146,6 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
31463146
QSettings settings;
31473147

31483148
closeProject();
3149-
mMapCanvas->clear();
31503149

31513150
QgsProject* prj = QgsProject::instance();
31523151
prj->title( QString::null );
@@ -7863,16 +7862,9 @@ void QgisApp::projectProperties()
78637862
// It is needed to refresh scale bar after changing display units.
78647863
connect( pp, SIGNAL( refresh() ), mMapCanvas, SLOT( refresh() ) );
78657864

7866-
const QgsMapSettings& ms = mMapCanvas->mapSettings();
7867-
bool wasProjected = ms.hasCrsTransformEnabled();
7868-
long oldCRSID = ms.destinationCrs().srsid();
7869-
78707865
// Display the modal dialog box.
78717866
pp->exec();
78727867

7873-
long newCRSID = ms.destinationCrs().srsid();
7874-
bool isProjected = ms.hasCrsTransformEnabled();
7875-
78767868
int myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorRedPart", 255 );
78777869
int myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorGreenPart", 255 );
78787870
int myBlueInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorBluePart", 255 );

src/core/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
SET(QGIS_CORE_SRCS
55

6+
qgsxmlutils.cpp
67
qgsmapsettings.cpp
78
qgsmaprendererjob.cpp
89
qgsvectorlayerrenderer.cpp

src/core/qgsmaplayer.h

+4-14
Original file line numberDiff line numberDiff line change
@@ -228,21 +228,11 @@ class CORE_EXPORT QgsMapLayer : public QObject
228228
void removeCustomProperty( const QString& key );
229229

230230

231-
/**
232-
* If an operation returns 0 (e.g. draw()), this function
233-
* returns the text of the error associated with the failure.
234-
* Interactive users of this provider can then, for example,
235-
* call a QMessageBox to display the contents.
236-
*/
237-
virtual QString lastErrorTitle();
231+
//! @deprecated since 2.1 - returns empty string
232+
Q_DECL_DEPRECATED virtual QString lastErrorTitle();
238233

239-
/**
240-
* If an operation returns 0 (e.g. draw()), this function
241-
* returns the text of the error associated with the failure.
242-
* Interactive users of this provider can then, for example,
243-
* call a QMessageBox to display the contents.
244-
*/
245-
virtual QString lastError();
234+
//! @deprecated since 2.1 - returns empty string
235+
Q_DECL_DEPRECATED virtual QString lastError();
246236

247237
/** Get current status error. This error describes some principal problem
248238
* for which layer cannot work and thus is not valid. It is not last error

src/core/qgsmaprenderer.cpp

+17-134
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "qgsmaptopixel.h"
2626
#include "qgsmaplayer.h"
2727
#include "qgsmaplayerregistry.h"
28+
#include "qgsmapsettings.h"
2829
#include "qgsdistancearea.h"
2930
#include "qgsproject.h"
3031
#include "qgsvectorlayer.h"
@@ -957,149 +958,31 @@ QStringList& QgsMapRenderer::layerSet()
957958
return mLayerSet;
958959
}
959960

961+
960962
bool QgsMapRenderer::readXML( QDomNode & theNode )
961963
{
962-
QDomNode myNode = theNode.namedItem( "units" );
963-
QDomElement element = myNode.toElement();
964-
965-
// set units
966-
QGis::UnitType units;
967-
if ( "meters" == element.text() )
968-
{
969-
units = QGis::Meters;
970-
}
971-
else if ( "feet" == element.text() )
972-
{
973-
units = QGis::Feet;
974-
}
975-
else if ( "nautical miles" == element.text() )
976-
{
977-
units = QGis::NauticalMiles;
978-
}
979-
else if ( "degrees" == element.text() )
980-
{
981-
units = QGis::Degrees;
982-
}
983-
else if ( "unknown" == element.text() )
984-
{
985-
units = QGis::UnknownUnit;
986-
}
987-
else
988-
{
989-
QgsDebugMsg( "Unknown map unit type " + element.text() );
990-
units = QGis::Degrees;
991-
}
992-
setMapUnits( units );
993-
994-
// set projections flag
995-
QDomNode projNode = theNode.namedItem( "projections" );
996-
element = projNode.toElement();
997-
setProjectionsEnabled( element.text().toInt() );
998-
999-
// set destination CRS
1000-
QgsCoordinateReferenceSystem srs;
1001-
QDomNode srsNode = theNode.namedItem( "destinationsrs" );
1002-
srs.readXML( srsNode );
1003-
setDestinationCrs( srs );
1004-
1005-
// set extent
1006-
QgsRectangle aoi;
1007-
QDomNode extentNode = theNode.namedItem( "extent" );
1008-
1009-
QDomNode xminNode = extentNode.namedItem( "xmin" );
1010-
QDomNode yminNode = extentNode.namedItem( "ymin" );
1011-
QDomNode xmaxNode = extentNode.namedItem( "xmax" );
1012-
QDomNode ymaxNode = extentNode.namedItem( "ymax" );
1013-
1014-
QDomElement exElement = xminNode.toElement();
1015-
double xmin = exElement.text().toDouble();
1016-
aoi.setXMinimum( xmin );
1017-
1018-
exElement = yminNode.toElement();
1019-
double ymin = exElement.text().toDouble();
1020-
aoi.setYMinimum( ymin );
1021-
1022-
exElement = xmaxNode.toElement();
1023-
double xmax = exElement.text().toDouble();
1024-
aoi.setXMaximum( xmax );
964+
QgsMapSettings tmpSettings;
965+
tmpSettings.readXML( theNode );
1025966

1026-
exElement = ymaxNode.toElement();
1027-
double ymax = exElement.text().toDouble();
1028-
aoi.setYMaximum( ymax );
967+
setMapUnits( tmpSettings.mapUnits() );
968+
setExtent( tmpSettings.extent() );
969+
setProjectionsEnabled( tmpSettings.hasCrsTransformEnabled() );
970+
setDestinationCrs( tmpSettings.destinationCrs() );
1029971

1030-
setExtent( aoi );
1031972
return true;
1032973
}
1033974

1034975
bool QgsMapRenderer::writeXML( QDomNode & theNode, QDomDocument & theDoc )
1035976
{
1036-
// units
1037-
1038-
QDomElement unitsNode = theDoc.createElement( "units" );
1039-
theNode.appendChild( unitsNode );
1040-
1041-
QString unitsString;
1042-
1043-
switch ( mapUnits() )
1044-
{
1045-
case QGis::Meters:
1046-
unitsString = "meters";
1047-
break;
1048-
case QGis::Feet:
1049-
unitsString = "feet";
1050-
break;
1051-
case QGis::NauticalMiles:
1052-
unitsString = "nautical miles";
1053-
break;
1054-
case QGis::Degrees:
1055-
unitsString = "degrees";
1056-
break;
1057-
case QGis::UnknownUnit:
1058-
default:
1059-
unitsString = "unknown";
1060-
break;
1061-
}
1062-
QDomText unitsText = theDoc.createTextNode( unitsString );
1063-
unitsNode.appendChild( unitsText );
1064-
1065-
1066-
// Write current view extents
1067-
QDomElement extentNode = theDoc.createElement( "extent" );
1068-
theNode.appendChild( extentNode );
1069-
1070-
QDomElement xMin = theDoc.createElement( "xmin" );
1071-
QDomElement yMin = theDoc.createElement( "ymin" );
1072-
QDomElement xMax = theDoc.createElement( "xmax" );
1073-
QDomElement yMax = theDoc.createElement( "ymax" );
1074-
1075-
QgsRectangle r = extent();
1076-
QDomText xMinText = theDoc.createTextNode( qgsDoubleToString( r.xMinimum() ) );
1077-
QDomText yMinText = theDoc.createTextNode( qgsDoubleToString( r.yMinimum() ) );
1078-
QDomText xMaxText = theDoc.createTextNode( qgsDoubleToString( r.xMaximum() ) );
1079-
QDomText yMaxText = theDoc.createTextNode( qgsDoubleToString( r.yMaximum() ) );
1080-
1081-
xMin.appendChild( xMinText );
1082-
yMin.appendChild( yMinText );
1083-
xMax.appendChild( xMaxText );
1084-
yMax.appendChild( yMaxText );
1085-
1086-
extentNode.appendChild( xMin );
1087-
extentNode.appendChild( yMin );
1088-
extentNode.appendChild( xMax );
1089-
extentNode.appendChild( yMax );
1090-
1091-
// projections enabled
1092-
QDomElement projNode = theDoc.createElement( "projections" );
1093-
theNode.appendChild( projNode );
1094-
1095-
QDomText projText = theDoc.createTextNode( QString::number( hasCrsTransformEnabled() ) );
1096-
projNode.appendChild( projText );
1097-
1098-
// destination CRS
1099-
QDomElement srsNode = theDoc.createElement( "destinationsrs" );
1100-
theNode.appendChild( srsNode );
1101-
destinationCrs().writeXML( srsNode, theDoc );
1102-
977+
QgsMapSettings tmpSettings;
978+
tmpSettings.setOutputDpi( outputDpi() );
979+
tmpSettings.setOutputSize( outputSize() );
980+
tmpSettings.setMapUnits( mapUnits() );
981+
tmpSettings.setExtent( extent() );
982+
tmpSettings.setProjectionsEnabled( hasCrsTransformEnabled() );
983+
tmpSettings.setDestinationCrs( destinationCrs() );
984+
985+
tmpSettings.writeXML( theNode, theDoc );
1103986
return true;
1104987
}
1105988

src/core/qgsmapsettings.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "qgsmessagelog.h"
1111
#include "qgsmaplayer.h"
1212
#include "qgsmaplayerregistry.h"
13+
#include "qgsxmlutils.h"
1314

1415

1516
QgsMapSettings::QgsMapSettings()
@@ -461,3 +462,48 @@ QgsRectangle QgsMapSettings::fullExtent() const
461462
QgsDebugMsg( "Full extent: " + fullExtent.toString() );
462463
return fullExtent;
463464
}
465+
466+
467+
void QgsMapSettings::readXML( QDomNode& theNode )
468+
{
469+
// set units
470+
QDomNode mapUnitsNode = theNode.namedItem( "units" );
471+
QGis::UnitType units = QgsXmlUtils::readMapUnits( mapUnitsNode.toElement() );
472+
setMapUnits( units );
473+
474+
// set projections flag
475+
QDomNode projNode = theNode.namedItem( "projections" );
476+
setProjectionsEnabled( projNode.toElement().text().toInt() );
477+
478+
// set destination CRS
479+
QgsCoordinateReferenceSystem srs;
480+
QDomNode srsNode = theNode.namedItem( "destinationsrs" );
481+
srs.readXML( srsNode );
482+
setDestinationCrs( srs );
483+
484+
// set extent
485+
QDomNode extentNode = theNode.namedItem( "extent" );
486+
QgsRectangle aoi = QgsXmlUtils::readRectangle( extentNode.toElement() );
487+
setExtent( aoi );
488+
}
489+
490+
491+
492+
void QgsMapSettings::writeXML( QDomNode& theNode, QDomDocument& theDoc )
493+
{
494+
// units
495+
theNode.appendChild( QgsXmlUtils::writeMapUnits( mapUnits(), theDoc ) );
496+
497+
// Write current view extents
498+
theNode.appendChild( QgsXmlUtils::writeRectangle( extent(), theDoc ) );
499+
500+
// projections enabled
501+
QDomElement projNode = theDoc.createElement( "projections" );
502+
projNode.appendChild( theDoc.createTextNode( QString::number( hasCrsTransformEnabled() ) ) );
503+
theNode.appendChild( projNode );
504+
505+
// destination CRS
506+
QDomElement srsNode = theDoc.createElement( "destinationsrs" );
507+
theNode.appendChild( srsNode );
508+
destinationCrs().writeXML( srsNode, theDoc );
509+
}

src/core/qgsmapsettings.h

+5
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ class QgsMapSettings
126126
//! returns current extent of layer set
127127
QgsRectangle fullExtent() const;
128128

129+
/* serialization */
130+
131+
void readXML( QDomNode& theNode );
132+
133+
void writeXML( QDomNode& theNode, QDomDocument& theDoc );
129134

130135
protected:
131136

0 commit comments

Comments
 (0)