Skip to content

Commit ae437a8

Browse files
author
homann
committed
Merged rev-up branch to trunk. Rev-up is now closed
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7917 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 15a5c1f commit ae437a8

13 files changed

+524
-55
lines changed

src/app/legend/qgslegend.cpp

+2-2
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

+39
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

+2
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

+2
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

+3
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

+40-50
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

+4
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

0 commit comments

Comments
 (0)