Skip to content

Commit ae437a8

Browse files
author
homann
committedJan 10, 2008

13 files changed

+524
-55
lines changed
 

‎src/app/legend/qgslegend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ bool QgsLegend::readXML(QDomNode& legendnode)
988988

989989
//set the checkbox of the legend layer to the right state
990990
blockSignals(true);
991-
QString checked = childelem.attribute("checked");
991+
QString checked = childelem.attribute("checked", "Qt::Checked"); // Default is to show
992992
if(checked == "Qt::Checked")
993993
{
994994
theLayer->setCheckState(0, Qt::Checked);
@@ -1030,7 +1030,7 @@ bool QgsLegend::readXML(QDomNode& legendnode)
10301030
QgsLegendLayerFile* theLegendLayerFile = new QgsLegendLayerFile(lastLayerFileGroup, QgsLegendLayerFile::nameFromLayer(theMapLayer), theMapLayer);
10311031

10321032
// load layer's visibility and 'show in overview' flag
1033-
theLegendLayerFile->setVisible(atoi(childelem.attribute("visible")));
1033+
theLegendLayerFile->setVisible(atoi(childelem.attribute("visible", "1"))); //Default is visible
10341034
theLegendLayerFile->setInOverview(atoi(childelem.attribute("inOverview")));
10351035

10361036
// set the check state

‎src/app/qgisapp.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,11 @@ void QgisApp::setupConnections()
12361236
connect(mMapCanvas, SIGNAL(scaleChanged(double)), this, SLOT(updateMouseCoordinatePrecision()));
12371237

12381238
connect(mRenderSuppressionCBox, SIGNAL(toggled(bool )), mMapCanvas, SLOT(setRenderFlag(bool)));
1239+
1240+
// Connect warning dialog from project reading
1241+
connect(QgsProject::instance(), SIGNAL(warnOlderProjectVersion(QString)),
1242+
this, SLOT(warnOlderProjectVersion(QString)));
1243+
12391244
}
12401245
void QgisApp::createCanvas()
12411246
{
@@ -5394,3 +5399,37 @@ void QgisApp::setToolbarVisibility(bool visibility)
53945399
mPluginToolBar->setVisible(visibility);
53955400
mHelpToolBar->setVisible(visibility);
53965401
}
5402+
5403+
// Slot that gets called when the project file was saved with an older
5404+
// version of QGIS
5405+
5406+
void QgisApp::warnOlderProjectVersion(QString oldVersion)
5407+
{
5408+
QSettings settings;
5409+
5410+
if ( settings.value("/qgis/warnOldProjectVersion", QVariant(true)).toBool() )
5411+
{
5412+
QMessageBox::warning(NULL, tr("Project file is older"),
5413+
tr("<p>This project file was saved by an older version "
5414+
"of QGIS. When saving this project file, "
5415+
"QGIS will update it to the latest version, "
5416+
"possibly rendering it useless for older versions of QGIS."
5417+
"<p>Even though QGIS developers try to maintain backwards "
5418+
"compatibility, some of the information from the old project "
5419+
"file might be lost. To improve the quality of QGIS, we appreciate "
5420+
"if you file a bug report at "
5421+
"<a href=http://svn.qgis.org/trac/wiki>http://svn.qgis.org/trac/wiki</a> "
5422+
"Be sure to include the old project file, and state the version of "
5423+
"QGIS you used to discover the error."
5424+
"<p>To remove this warning when opening an older project file, "
5425+
"check the box 'Warn me when opening a project file saved with an "
5426+
"older verision of QGIS' "
5427+
"in the <tt>Settings:Options:General</tt> menu. "
5428+
"<p>Version of the project file: %1<br>"
5429+
"Current version of QGIS: %2")
5430+
.arg(oldVersion)
5431+
.arg(QGis::qgisVersion));
5432+
5433+
}
5434+
return;
5435+
}

‎src/app/qgisapp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ public slots:
376376
*/
377377
void editPaste(QgsMapLayer * destinationLayer = 0);
378378

379+
//! Shows a warning when an old project file is read.
380+
void warnOlderProjectVersion(QString);
379381

380382
signals:
381383
/** emitted when a key is pressed and we want non widget sublasses to be able

‎src/app/qgsoptions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ QgsOptions::QgsOptions(QWidget *parent, Qt::WFlags fl) :
136136
capitaliseCheckBox->setChecked(settings.value("qgis/capitaliseLayerName", QVariant(false)).toBool());
137137

138138
chbAskToSaveProjectChanges->setChecked(settings.value("qgis/askToSaveProjectChanges", QVariant(true)).toBool());
139+
chbWarnOldProjectVersion->setChecked(settings.value("/qgis/warnOldProjectVersion", QVariant(true)).toBool());
139140

140141
cmbWheelAction->setCurrentIndex(settings.value("/qgis/wheel_action", 0).toInt());
141142
spinZoomFactor->setValue(settings.value("/qgis/zoom_factor", 2).toDouble());
@@ -230,6 +231,7 @@ void QgsOptions::saveOptions()
230231
settings.writeEntry("/qgis/use_qimage_to_render", !(chkUseQPixmap->isChecked()));
231232
settings.setValue("qgis/capitaliseLayerName", capitaliseCheckBox->isChecked());
232233
settings.setValue("qgis/askToSaveProjectChanges", chbAskToSaveProjectChanges->isChecked());
234+
settings.setValue("qgis/warnOldProjectVersion", chbWarnOldProjectVersion->isChecked());
233235

234236
if(cmbTheme->currentText().length() == 0)
235237
{

‎src/core/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ qgsmaptopixel.cpp
2828
qgsmessageoutput.cpp
2929
qgspoint.cpp
3030
qgsproject.cpp
31+
qgsprojectfiletransform.cpp
32+
qgsprojectversion.cpp
3133
qgsprojectproperty.cpp
3234
qgsprovidercountcalcevent.cpp
3335
qgsproviderextentcalcevent.cpp
@@ -202,6 +204,7 @@ qgsmaptopixel.h
202204
qgsmessageoutput.h
203205
qgspoint.h
204206
qgsproject.h
207+
qgsprojectfiletransform.h
205208
qgsprojectproperty.h
206209
qgsprovidercountcalcevent.h
207210
qgsproviderextentcalcevent.h

‎src/core/qgsproject.cpp

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "qgsexception.h"
3131
#include "qgsprojectproperty.h"
3232
#include "qgslogger.h"
33+
#include "qgsprojectfiletransform.h"
34+
#include "qgsprojectversion.h"
3335

3436
#include <QApplication>
3537
#include <QFileInfo>
@@ -576,21 +578,21 @@ static void _getTitle(QDomDocument const &doc, QString & title)
576578
577579
@returns the version string or an empty string if none found
578580
*/
579-
static QString _getVersion(QDomDocument const &doc)
581+
static QgsProjectVersion _getVersion(QDomDocument const &doc)
580582
{
581-
QDomNodeList nl = doc.elementsByTagName("qgis");
582-
583-
if (!nl.count())
584-
{
585-
QgsDebugMsg(" unable to find qgis element in project file");
586-
return "";
587-
}
588-
589-
QDomNode qgisNode = nl.item(0); // there should only be one, so zeroth element ok
583+
QDomNodeList nl = doc.elementsByTagName("qgis");
584+
585+
if (!nl.count())
586+
{
587+
QgsDebugMsg(" unable to find qgis element in project file");
588+
return QgsProjectVersion(0, 0, 0, QString(""));
589+
}
590590

591-
QDomElement qgisElement = qgisNode.toElement(); // qgis node should be element
591+
QDomNode qgisNode = nl.item(0); // there should only be one, so zeroth element ok
592592

593-
return qgisElement.attribute("version");
593+
QDomElement qgisElement = qgisNode.toElement(); // qgis node should be element
594+
QgsProjectVersion projectVersion(qgisElement.attribute("version"));
595+
return projectVersion;
594596
} // _getVersion
595597

596598

@@ -782,6 +784,32 @@ bool QgsProject::read()
782784

783785

784786
QgsDebugMsg("Opened document " + imp_->file.name());
787+
QgsDebugMsg("Project title: " + imp_->title);
788+
789+
// get project version string, if any
790+
QgsProjectVersion fileVersion = _getVersion(*doc);
791+
QgsProjectVersion thisVersion(QGis::qgisVersion);
792+
793+
if (thisVersion > fileVersion)
794+
{
795+
QgsLogger::warning("Loading a file that was saved with an older "
796+
"version of qgis (saved in " + fileVersion.text() +
797+
", loaded in " + QGis::qgisVersion +
798+
"). Problems may occur.");
799+
800+
QgsProjectFileTransform projectFile(*doc, fileVersion);
801+
802+
//! Shows a warning when an old project file is read.
803+
emit warnOlderProjectVersion(fileVersion.text());
804+
QgsDebugMsg("Emitting warnOlderProjectVersion(oldVersion).");
805+
806+
projectFile.dump();
807+
808+
projectFile.updateRevision(thisVersion);
809+
810+
projectFile.dump();
811+
812+
}
785813

786814
// before we start loading everything, let's clear out the current set of
787815
// properties first so that we don't have the properties from the previous
@@ -802,44 +830,6 @@ bool QgsProject::read()
802830
// now get project title
803831
_getTitle(*doc, imp_->title);
804832

805-
// get project version string, if any
806-
QString fileVersion = _getVersion(*doc);
807-
808-
if ( fileVersion.isNull() )
809-
{
810-
QgsDebugMsg( "project file has no version string" );
811-
}
812-
else
813-
{
814-
QgsDebugMsg( "project file has version " + QString(fileVersion) );
815-
}
816-
817-
QStringList fileVersionParts = fileVersion.split(".");
818-
QStringList qgisVersionParts = QString(QGis::qgisVersion).split(".");
819-
820-
QgsDebugMsg("Project title: " + imp_->title);
821-
822-
bool older = false;
823-
824-
if (fileVersionParts.size() != 3 || qgisVersionParts.size() != 3)
825-
older = false; // probably an older version
826-
else
827-
{
828-
if (fileVersionParts.at(0) < qgisVersionParts.at(0))
829-
older = true;
830-
else if (fileVersionParts.at(1) < qgisVersionParts.at(1))
831-
older = true;
832-
else if (fileVersionParts.at(2) < qgisVersionParts.at(2))
833-
older = true;
834-
}
835-
836-
if (older)
837-
{
838-
QgsLogger::warning("Loading a file that was saved with an older "
839-
"version of qgis (saved in " + fileVersion +
840-
", loaded in " + QGis::qgisVersion +
841-
"). Problems may occur.");
842-
}
843833

844834
// get the map layers
845835
std::pair< bool, std::list<QDomNode> > getMapLayersResults = _getMapLayers(*doc);

‎src/core/qgsproject.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define QGSPROJECT_H
2424

2525
#include <memory>
26+
#include "qgsprojectversion.h"
2627
#include <QObject>
2728

2829
//#include <QDomDocument>
@@ -261,6 +262,9 @@ class CORE_EXPORT QgsProject : public QObject
261262
//! emitted when project is being written
262263
void writeProject(QDomDocument &);
263264

265+
//! emitted when an old project file is read.
266+
void warnOlderProjectVersion(QString);
267+
264268
private:
265269

266270
QgsProject(); // private 'cause it's a singleton

‎src/core/qgsprojectfiletransform.cpp

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
/***************************************************************************
2+
qgsprojectfiletransform.cpp - description
3+
-------------------
4+
begin : Sun 15 dec 2007
5+
copyright : (C) 2007 by Magnus Homann
6+
email : magnus at homann.se
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
/* $Id: $ */
18+
19+
20+
#include "qgsprojectfiletransform.h"
21+
#include "qgsprojectversion.h"
22+
#include "qgslogger.h"
23+
#include <QTextStream>
24+
#include <QDomDocument>
25+
26+
typedef QgsProjectVersion PFV;
27+
28+
29+
QgsProjectFileTransform::transform QgsProjectFileTransform::transformers[] = {
30+
{PFV(0,8,1), PFV(0,9,0), &QgsProjectFileTransform::transform081to090},
31+
{PFV(0,9,0), PFV(0,9,1), &QgsProjectFileTransform::transform090to091},
32+
{PFV(0,9,1), PFV(0,9,2), &QgsProjectFileTransform::transformNull}
33+
};
34+
35+
bool QgsProjectFileTransform::updateRevision(QgsProjectVersion newVersion)
36+
{
37+
bool returnValue = false;
38+
39+
if ( ! mDom.isNull() )
40+
{
41+
for (int i = 0; i < sizeof(transformers)/sizeof(transform); i++)
42+
{
43+
if ( transformers[i].from == mCurrentVersion)
44+
{
45+
// Run the transformer, and update the revision in every case
46+
(this->*(transformers[i].transformFunc))();
47+
mCurrentVersion = transformers[i].to;
48+
returnValue = true;
49+
}
50+
}
51+
}
52+
return returnValue;
53+
};
54+
55+
void QgsProjectFileTransform::dump()
56+
{
57+
QgsDebugMsg(QString("Current project file version is %1.%2.%3\n")
58+
.arg(mCurrentVersion.major())
59+
.arg(mCurrentVersion.minor())
60+
.arg(mCurrentVersion.sub()));
61+
#ifdef QGISDEBUG
62+
// Using QgsDebugMsg() didn't print the entire mDom...
63+
std::cout << mDom.toString(2).toLatin1().constData();
64+
#endif
65+
}
66+
67+
/*
68+
* Transformers below!
69+
*/
70+
71+
void QgsProjectFileTransform::transform081to090()
72+
{
73+
QgsDebugMsg("Entering...");
74+
if ( ! mDom.isNull() )
75+
{
76+
// Start with inserting a mapcanvas element and populate it
77+
78+
QDomElement mapCanvas; // A null element.
79+
80+
// there should only be one <qgis>
81+
QDomNode qgis = mDom.firstChildElement("qgis");
82+
if ( ! qgis.isNull() )
83+
{
84+
QgsDebugMsg("Populating new mapcanvas");
85+
86+
// Create a mapcanvas
87+
mapCanvas = mDom.createElement("mapcanvas");
88+
// Append mapcanvas to parent 'qgis'.
89+
qgis.appendChild(mapCanvas);
90+
// Re-parent units
91+
mapCanvas.appendChild(qgis.namedItem("units"));
92+
// Re-parent extent
93+
mapCanvas.appendChild(qgis.namedItem("extent"));
94+
95+
// See if we can find if projection is on.
96+
97+
QDomElement properties = qgis.firstChildElement("properties");
98+
QDomElement spatial = properties.firstChildElement("SpatialRefSys");
99+
QDomElement projectionsEnabled = spatial.firstChildElement("ProjectionsEnabled");
100+
// Type is 'int', and '1' if on.
101+
// Create an element
102+
QDomElement projection = mDom.createElement("projections");
103+
QgsDebugMsg(QString("Projection flag: ") + projectionsEnabled.text());
104+
// Set flag from ProjectionsEnabled
105+
projection.appendChild(mDom.createTextNode(projectionsEnabled.text()));
106+
// Set new element as child of <mapcanvas>
107+
mapCanvas.appendChild(projection);
108+
109+
}
110+
111+
112+
// Transforming coordinate-transforms
113+
// Create a list of all map layers
114+
QDomNodeList mapLayers = mDom.elementsByTagName("maplayer");
115+
bool doneDestination = false;
116+
for (int i = 0; i < mapLayers.count(); i++)
117+
{
118+
QDomNode mapLayer = mapLayers.item(i);
119+
// Find the coordinatetransform
120+
QDomNode coordinateTransform = mapLayer.namedItem("coordinatetransform");
121+
// Find the sourcesrs
122+
QDomNode sourceSRS = coordinateTransform.namedItem("sourcesrs");
123+
// Rename to srs
124+
sourceSRS.toElement().setTagName("srs");
125+
// Re-parent to maplayer
126+
mapLayer.appendChild(sourceSRS);
127+
// Re-move coordinatetransform
128+
// Take the destination SRS of the first layer and use for mapcanvas projection
129+
if (! doneDestination)
130+
{
131+
// Use destination SRS from the last layer
132+
QDomNode destinationSRS = coordinateTransform.namedItem("destinationsrs");
133+
// Re-parent the destination SRS to the mapcanvas
134+
// If mapcanvas wasn't set, nothing will happen.
135+
mapCanvas.appendChild(destinationSRS);
136+
// Only do this once
137+
doneDestination = true;
138+
}
139+
mapLayer.removeChild(coordinateTransform);
140+
//QDomNode id = mapLayer.namedItem("id");
141+
//QgsDebugMsg(QString("Found maplayer ") + id.toElement().text());
142+
143+
}
144+
145+
// Set the flag 'visible' to match the status of 'checked'
146+
QDomNodeList legendLayerFiles = mDom.elementsByTagName("legendlayerfile");
147+
QgsDebugMsg(QString("Legend layer file entrie: ") + QString::number(legendLayerFiles.count()));
148+
for (int i = 0; i < mapLayers.count(); i++)
149+
{
150+
// Get one maplayer element from list
151+
QDomElement mapLayer = mapLayers.item(i).toElement();
152+
// Find it's id.
153+
QString id = mapLayer.firstChildElement("id").text();
154+
QgsDebugMsg(QString("Handling layer " + id));
155+
// Now, look it up in legend
156+
for (int j = 0; j < legendLayerFiles.count(); j++)
157+
{
158+
QDomElement legendLayerFile = legendLayerFiles.item(j).toElement();
159+
if (id == legendLayerFile.attribute("layerid") )
160+
{
161+
// Found a the legend layer that matches the maplayer
162+
QgsDebugMsg("Found matching id");
163+
164+
// Set visible flag from maplayer to legendlayer
165+
legendLayerFile.setAttribute("visible", mapLayer.attribute("visible"));
166+
167+
// Set overview flag from maplayer to legendlayer
168+
legendLayerFile.setAttribute("inOverview", mapLayer.attribute("showInOverviewFlag"));
169+
}
170+
}
171+
}
172+
}
173+
return;
174+
175+
};
176+
177+
void QgsProjectFileTransform::transform090to091()
178+
{
179+
QgsDebugMsg("entering");
180+
if ( ! mDom.isNull() )
181+
{
182+
}
183+
return;
184+
185+
};
186+

‎src/core/qgsprojectfiletransform.h

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/***************************************************************************
2+
qgsprojectfiletransform.h - description
3+
-------------------
4+
begin : Sun 15 dec 2007
5+
copyright : (C) 2007 by Magnus Homann
6+
email : magnus at homann.se
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
/*
19+
* This class provides possibility to store a project file as a QDomDocument,
20+
* and provides the ability to specify version of the project file, and
21+
* perform upgrades to a more recent version
22+
*/
23+
24+
/* $Id: $ */
25+
26+
#ifndef QGSPROJECTFILETRANSFORM_H
27+
#define QGSPROJECTFILETRANSFORM_H
28+
29+
#include <QString>
30+
#include <QDomDocument>
31+
#include <vector>
32+
#include "qgsprojectversion.h"
33+
34+
class QgsProjectFileTransform
35+
{
36+
public:
37+
//Default constructor
38+
//QgsProjectfiletransform() {}
39+
~QgsProjectFileTransform() {}
40+
41+
/*! Create an instance from a DOM and a supplied version
42+
* @param domDocument The DOM document to use as content
43+
* @param version Version number
44+
*/
45+
QgsProjectFileTransform(QDomDocument & domDocument,
46+
QgsProjectVersion version)
47+
{
48+
mDom = domDocument;
49+
mCurrentVersion = version;
50+
}
51+
52+
53+
bool updateRevision(QgsProjectVersion version);
54+
55+
/*! Prints the contents via QgsDebugMsg()
56+
*/
57+
void dump();
58+
59+
60+
private:
61+
62+
typedef struct {
63+
QgsProjectVersion from;
64+
QgsProjectVersion to;
65+
void (QgsProjectFileTransform::* transformFunc)();
66+
} transform;
67+
68+
static transform transformers[];;
69+
70+
QDomDocument mDom;
71+
QgsProjectVersion mCurrentVersion;
72+
73+
// Transformer functions below. Declare functions here,
74+
// define them in qgsprojectfiletransform.cpp and add them
75+
// to the transformArray with proper version number
76+
void transformNull() {}; // Do absolutely nothing
77+
void transform081to090();
78+
void transform090to091();
79+
};
80+
81+
82+
#endif //QGSPROJECTFILETRANSFORM_H
83+

‎src/core/qgsprojectversion.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/***************************************************************************
2+
qgsprojectfile.h - description
3+
-------------------
4+
begin : Sun 15 dec 2007
5+
copyright : (C) 2007 by Magnus Homann
6+
email : magnus at homann.se
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include <QString>
19+
#include <QStringList>
20+
21+
#include "qgslogger.h"
22+
#include "qgsprojectversion.h"
23+
24+
QgsProjectVersion::QgsProjectVersion(int major, int minor, int sub, QString name)
25+
{
26+
mMajor = major;
27+
mMinor = minor;
28+
mSub = sub;
29+
mName = name;
30+
}
31+
32+
QgsProjectVersion::QgsProjectVersion(QString string)
33+
{
34+
QString pre = string.section('-', 0, 0);
35+
36+
QStringList fileVersionParts = pre.section("-", 0).split(".");
37+
38+
mMajor = fileVersionParts.at(0).toInt();
39+
mMinor = fileVersionParts.at(1).toInt();
40+
mSub = fileVersionParts.at(2).toInt();
41+
mName = string.section('-', 1);
42+
43+
QgsDebugMsg(QString("Version is set to ") + text());
44+
45+
}
46+
47+
/*! Boolean equal operator
48+
*/
49+
bool QgsProjectVersion::operator==(const QgsProjectVersion &other)
50+
{
51+
return ((mMajor == other.mMajor) &&
52+
(mMinor == other.mMinor) &&
53+
(mSub == other.mSub));
54+
};
55+
56+
/*! Boolean >= operator
57+
*/
58+
bool QgsProjectVersion::operator>=(const QgsProjectVersion &other)
59+
{
60+
return ( (mMajor >= other.mMajor) ||
61+
((mMajor == other.mMajor) && (mMinor >= other.mMinor)) ||
62+
((mMajor == other.mMajor) && (mMinor == other.mMinor) && (mSub >= other.mSub)));
63+
};
64+
65+
/*! Boolean > operator
66+
*/
67+
bool QgsProjectVersion::operator>(const QgsProjectVersion &other)
68+
{
69+
return ( (mMajor > other.mMajor) ||
70+
((mMajor == other.mMajor) && (mMinor > other.mMinor)) ||
71+
((mMajor == other.mMajor) && (mMinor == other.mMinor) && (mSub > other.mSub)));
72+
};
73+
74+
QString QgsProjectVersion::text()
75+
{
76+
if (mName.isNull())
77+
{
78+
return QString("%1.%2.%3").arg(mMajor).arg(mMinor).arg(mSub);
79+
}
80+
else
81+
{
82+
return QString("%1.%2.%3-%4").arg(mMajor).arg(mMinor).arg(mSub).arg(mName);
83+
}
84+
}

‎src/core/qgsprojectversion.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/***************************************************************************
2+
qgsprojectfile.h - description
3+
-------------------
4+
begin : Sun 15 dec 2007
5+
copyright : (C) 2007 by Magnus Homann
6+
email : magnus at homann.se
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSPROJECTVERSION_H
19+
#define QGSPROJECTVERSION_H
20+
21+
#include <QString>
22+
#include <QStringList>
23+
24+
class QgsProjectVersion
25+
{
26+
27+
public:
28+
29+
QgsProjectVersion() {}
30+
31+
QgsProjectVersion(int major, int minor, int sub, QString name = "");
32+
33+
QgsProjectVersion(QString string);
34+
35+
~QgsProjectVersion() {}
36+
37+
int major() { return mMajor;};
38+
int minor() { return mMinor;};
39+
int sub() { return mSub;};
40+
41+
QString text();
42+
43+
/*! Boolean equal operator
44+
*/
45+
bool operator==(const QgsProjectVersion &other);
46+
47+
48+
/*! Boolean >= operator
49+
*/
50+
bool operator>=(const QgsProjectVersion &other);
51+
52+
/*! Boolean > operator
53+
*/
54+
bool operator>(const QgsProjectVersion &other);
55+
56+
private:
57+
int mMajor;
58+
int mMinor;
59+
int mSub;
60+
QString mName;
61+
};
62+
63+
#endif // QGSPROJECTVERSION_H

‎src/core/qgsspatialrefsys.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,8 @@ bool QgsSpatialRefSys::readXML( QDomNode & theNode )
11791179
QgsDebugMsg("Reading Spatial Ref Sys from xml ------------------------!");
11801180
QDomNode srsNode = theNode.namedItem( "spatialrefsys" );
11811181

1182+
if ( ! srsNode.isNull() )
1183+
{
11821184
QDomNode myNode = srsNode.namedItem("proj4");
11831185
QDomElement myElement = myNode.toElement();
11841186
setProj4String(myElement.text());
@@ -1218,13 +1220,17 @@ bool QgsSpatialRefSys::readXML( QDomNode & theNode )
12181220
setGeographicFlag(false);
12191221
}
12201222
//make sure the map units have been set
1221-
12221223
setMapUnits();
12231224

12241225
//@TODO this srs needs to be validated!!!
12251226
mIsValidFlag=true;//shamelessly hard coded for now
1226-
1227-
return true;
1227+
}
1228+
else
1229+
{
1230+
// Return default SRS if none was found in the XML.
1231+
createFromSrsId(GEOSRS_ID);
1232+
}
1233+
return true;
12281234
}
12291235

12301236
bool QgsSpatialRefSys::writeXML( QDomNode & theNode, QDomDocument & theDoc ) const

‎src/ui/qgsoptionsbase.ui

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@
6363
</property>
6464
</widget>
6565
</item>
66+
<item>
67+
<widget class="QCheckBox" name="chbWarnOldProjectVersion" >
68+
<property name="text" >
69+
<string>Warn me when opening a project file saved with an older verision of QGIS</string>
70+
</property>
71+
</widget>
72+
</item>
6673
</layout>
6774
</widget>
6875
</item>

0 commit comments

Comments
 (0)
Please sign in to comment.