Skip to content
Permalink
Browse files

Restored reading/writing of canvas map settings

  • Loading branch information
wonder-sk committed Dec 4, 2013
1 parent 4493f51 commit 7194567a90e1c5088a96a31d533c2feb75cfa877
@@ -3146,7 +3146,6 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
QSettings settings;

closeProject();
mMapCanvas->clear();

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

const QgsMapSettings& ms = mMapCanvas->mapSettings();
bool wasProjected = ms.hasCrsTransformEnabled();
long oldCRSID = ms.destinationCrs().srsid();

// Display the modal dialog box.
pp->exec();

long newCRSID = ms.destinationCrs().srsid();
bool isProjected = ms.hasCrsTransformEnabled();

int myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorRedPart", 255 );
int myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorGreenPart", 255 );
int myBlueInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorBluePart", 255 );
@@ -3,6 +3,7 @@

SET(QGIS_CORE_SRCS

qgsxmlutils.cpp
qgsmapsettings.cpp
qgsmaprendererjob.cpp
qgsvectorlayerrenderer.cpp
@@ -228,21 +228,11 @@ class CORE_EXPORT QgsMapLayer : public QObject
void removeCustomProperty( const QString& key );


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

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

/** Get current status error. This error describes some principal problem
* for which layer cannot work and thus is not valid. It is not last error
@@ -25,6 +25,7 @@
#include "qgsmaptopixel.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsmapsettings.h"
#include "qgsdistancearea.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
@@ -957,149 +958,31 @@ QStringList& QgsMapRenderer::layerSet()
return mLayerSet;
}


bool QgsMapRenderer::readXML( QDomNode & theNode )
{
QDomNode myNode = theNode.namedItem( "units" );
QDomElement element = myNode.toElement();

// set units
QGis::UnitType units;
if ( "meters" == element.text() )
{
units = QGis::Meters;
}
else if ( "feet" == element.text() )
{
units = QGis::Feet;
}
else if ( "nautical miles" == element.text() )
{
units = QGis::NauticalMiles;
}
else if ( "degrees" == element.text() )
{
units = QGis::Degrees;
}
else if ( "unknown" == element.text() )
{
units = QGis::UnknownUnit;
}
else
{
QgsDebugMsg( "Unknown map unit type " + element.text() );
units = QGis::Degrees;
}
setMapUnits( units );

// set projections flag
QDomNode projNode = theNode.namedItem( "projections" );
element = projNode.toElement();
setProjectionsEnabled( element.text().toInt() );

// set destination CRS
QgsCoordinateReferenceSystem srs;
QDomNode srsNode = theNode.namedItem( "destinationsrs" );
srs.readXML( srsNode );
setDestinationCrs( srs );

// set extent
QgsRectangle aoi;
QDomNode extentNode = theNode.namedItem( "extent" );

QDomNode xminNode = extentNode.namedItem( "xmin" );
QDomNode yminNode = extentNode.namedItem( "ymin" );
QDomNode xmaxNode = extentNode.namedItem( "xmax" );
QDomNode ymaxNode = extentNode.namedItem( "ymax" );

QDomElement exElement = xminNode.toElement();
double xmin = exElement.text().toDouble();
aoi.setXMinimum( xmin );

exElement = yminNode.toElement();
double ymin = exElement.text().toDouble();
aoi.setYMinimum( ymin );

exElement = xmaxNode.toElement();
double xmax = exElement.text().toDouble();
aoi.setXMaximum( xmax );
QgsMapSettings tmpSettings;
tmpSettings.readXML( theNode );

exElement = ymaxNode.toElement();
double ymax = exElement.text().toDouble();
aoi.setYMaximum( ymax );
setMapUnits( tmpSettings.mapUnits() );
setExtent( tmpSettings.extent() );
setProjectionsEnabled( tmpSettings.hasCrsTransformEnabled() );
setDestinationCrs( tmpSettings.destinationCrs() );

setExtent( aoi );
return true;
}

bool QgsMapRenderer::writeXML( QDomNode & theNode, QDomDocument & theDoc )
{
// units

QDomElement unitsNode = theDoc.createElement( "units" );
theNode.appendChild( unitsNode );

QString unitsString;

switch ( mapUnits() )
{
case QGis::Meters:
unitsString = "meters";
break;
case QGis::Feet:
unitsString = "feet";
break;
case QGis::NauticalMiles:
unitsString = "nautical miles";
break;
case QGis::Degrees:
unitsString = "degrees";
break;
case QGis::UnknownUnit:
default:
unitsString = "unknown";
break;
}
QDomText unitsText = theDoc.createTextNode( unitsString );
unitsNode.appendChild( unitsText );


// Write current view extents
QDomElement extentNode = theDoc.createElement( "extent" );
theNode.appendChild( extentNode );

QDomElement xMin = theDoc.createElement( "xmin" );
QDomElement yMin = theDoc.createElement( "ymin" );
QDomElement xMax = theDoc.createElement( "xmax" );
QDomElement yMax = theDoc.createElement( "ymax" );

QgsRectangle r = extent();
QDomText xMinText = theDoc.createTextNode( qgsDoubleToString( r.xMinimum() ) );
QDomText yMinText = theDoc.createTextNode( qgsDoubleToString( r.yMinimum() ) );
QDomText xMaxText = theDoc.createTextNode( qgsDoubleToString( r.xMaximum() ) );
QDomText yMaxText = theDoc.createTextNode( qgsDoubleToString( r.yMaximum() ) );

xMin.appendChild( xMinText );
yMin.appendChild( yMinText );
xMax.appendChild( xMaxText );
yMax.appendChild( yMaxText );

extentNode.appendChild( xMin );
extentNode.appendChild( yMin );
extentNode.appendChild( xMax );
extentNode.appendChild( yMax );

// projections enabled
QDomElement projNode = theDoc.createElement( "projections" );
theNode.appendChild( projNode );

QDomText projText = theDoc.createTextNode( QString::number( hasCrsTransformEnabled() ) );
projNode.appendChild( projText );

// destination CRS
QDomElement srsNode = theDoc.createElement( "destinationsrs" );
theNode.appendChild( srsNode );
destinationCrs().writeXML( srsNode, theDoc );

QgsMapSettings tmpSettings;
tmpSettings.setOutputDpi( outputDpi() );
tmpSettings.setOutputSize( outputSize() );
tmpSettings.setMapUnits( mapUnits() );
tmpSettings.setExtent( extent() );
tmpSettings.setProjectionsEnabled( hasCrsTransformEnabled() );
tmpSettings.setDestinationCrs( destinationCrs() );

tmpSettings.writeXML( theNode, theDoc );
return true;
}

@@ -10,6 +10,7 @@
#include "qgsmessagelog.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsxmlutils.h"


QgsMapSettings::QgsMapSettings()
@@ -461,3 +462,48 @@ QgsRectangle QgsMapSettings::fullExtent() const
QgsDebugMsg( "Full extent: " + fullExtent.toString() );
return fullExtent;
}


void QgsMapSettings::readXML( QDomNode& theNode )
{
// set units
QDomNode mapUnitsNode = theNode.namedItem( "units" );
QGis::UnitType units = QgsXmlUtils::readMapUnits( mapUnitsNode.toElement() );
setMapUnits( units );

// set projections flag
QDomNode projNode = theNode.namedItem( "projections" );
setProjectionsEnabled( projNode.toElement().text().toInt() );

// set destination CRS
QgsCoordinateReferenceSystem srs;
QDomNode srsNode = theNode.namedItem( "destinationsrs" );
srs.readXML( srsNode );
setDestinationCrs( srs );

// set extent
QDomNode extentNode = theNode.namedItem( "extent" );
QgsRectangle aoi = QgsXmlUtils::readRectangle( extentNode.toElement() );
setExtent( aoi );
}



void QgsMapSettings::writeXML( QDomNode& theNode, QDomDocument& theDoc )
{
// units
theNode.appendChild( QgsXmlUtils::writeMapUnits( mapUnits(), theDoc ) );

// Write current view extents
theNode.appendChild( QgsXmlUtils::writeRectangle( extent(), theDoc ) );

// projections enabled
QDomElement projNode = theDoc.createElement( "projections" );
projNode.appendChild( theDoc.createTextNode( QString::number( hasCrsTransformEnabled() ) ) );
theNode.appendChild( projNode );

// destination CRS
QDomElement srsNode = theDoc.createElement( "destinationsrs" );
theNode.appendChild( srsNode );
destinationCrs().writeXML( srsNode, theDoc );
}
@@ -126,6 +126,11 @@ class QgsMapSettings
//! returns current extent of layer set
QgsRectangle fullExtent() const;

/* serialization */

void readXML( QDomNode& theNode );

void writeXML( QDomNode& theNode, QDomDocument& theDoc );

protected:

0 comments on commit 7194567

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