Skip to content
Permalink
Browse files
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
  • Loading branch information
homann committed Jan 10, 2008
1 parent 15a5c1f commit ae437a8d7308576c76e94a82715fc416fe23b5a0
@@ -988,7 +988,7 @@ bool QgsLegend::readXML(QDomNode& legendnode)

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

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

// set the check state
@@ -1236,6 +1236,11 @@ void QgisApp::setupConnections()
connect(mMapCanvas, SIGNAL(scaleChanged(double)), this, SLOT(updateMouseCoordinatePrecision()));

connect(mRenderSuppressionCBox, SIGNAL(toggled(bool )), mMapCanvas, SLOT(setRenderFlag(bool)));

// Connect warning dialog from project reading
connect(QgsProject::instance(), SIGNAL(warnOlderProjectVersion(QString)),
this, SLOT(warnOlderProjectVersion(QString)));

}
void QgisApp::createCanvas()
{
@@ -5394,3 +5399,37 @@ void QgisApp::setToolbarVisibility(bool visibility)
mPluginToolBar->setVisible(visibility);
mHelpToolBar->setVisible(visibility);
}

// Slot that gets called when the project file was saved with an older
// version of QGIS

void QgisApp::warnOlderProjectVersion(QString oldVersion)
{
QSettings settings;

if ( settings.value("/qgis/warnOldProjectVersion", QVariant(true)).toBool() )
{
QMessageBox::warning(NULL, tr("Project file is older"),
tr("<p>This project file was saved by an older version "
"of QGIS. When saving this project file, "
"QGIS will update it to the latest version, "
"possibly rendering it useless for older versions of QGIS."
"<p>Even though QGIS developers try to maintain backwards "
"compatibility, some of the information from the old project "
"file might be lost. To improve the quality of QGIS, we appreciate "
"if you file a bug report at "
"<a href=http://svn.qgis.org/trac/wiki>http://svn.qgis.org/trac/wiki</a> "
"Be sure to include the old project file, and state the version of "
"QGIS you used to discover the error."
"<p>To remove this warning when opening an older project file, "
"check the box 'Warn me when opening a project file saved with an "
"older verision of QGIS' "
"in the <tt>Settings:Options:General</tt> menu. "
"<p>Version of the project file: %1<br>"
"Current version of QGIS: %2")
.arg(oldVersion)
.arg(QGis::qgisVersion));

}
return;
}
@@ -376,6 +376,8 @@ public slots:
*/
void editPaste(QgsMapLayer * destinationLayer = 0);

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

signals:
/** emitted when a key is pressed and we want non widget sublasses to be able
@@ -136,6 +136,7 @@ QgsOptions::QgsOptions(QWidget *parent, Qt::WFlags fl) :
capitaliseCheckBox->setChecked(settings.value("qgis/capitaliseLayerName", QVariant(false)).toBool());

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

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

if(cmbTheme->currentText().length() == 0)
{
@@ -28,6 +28,8 @@ qgsmaptopixel.cpp
qgsmessageoutput.cpp
qgspoint.cpp
qgsproject.cpp
qgsprojectfiletransform.cpp
qgsprojectversion.cpp
qgsprojectproperty.cpp
qgsprovidercountcalcevent.cpp
qgsproviderextentcalcevent.cpp
@@ -202,6 +204,7 @@ qgsmaptopixel.h
qgsmessageoutput.h
qgspoint.h
qgsproject.h
qgsprojectfiletransform.h
qgsprojectproperty.h
qgsprovidercountcalcevent.h
qgsproviderextentcalcevent.h
@@ -30,6 +30,8 @@
#include "qgsexception.h"
#include "qgsprojectproperty.h"
#include "qgslogger.h"
#include "qgsprojectfiletransform.h"
#include "qgsprojectversion.h"

#include <QApplication>
#include <QFileInfo>
@@ -576,21 +578,21 @@ static void _getTitle(QDomDocument const &doc, QString & title)
@returns the version string or an empty string if none found
*/
static QString _getVersion(QDomDocument const &doc)
static QgsProjectVersion _getVersion(QDomDocument const &doc)
{
QDomNodeList nl = doc.elementsByTagName("qgis");

if (!nl.count())
{
QgsDebugMsg(" unable to find qgis element in project file");
return "";
}

QDomNode qgisNode = nl.item(0); // there should only be one, so zeroth element ok
QDomNodeList nl = doc.elementsByTagName("qgis");

if (!nl.count())
{
QgsDebugMsg(" unable to find qgis element in project file");
return QgsProjectVersion(0, 0, 0, QString(""));
}

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

return qgisElement.attribute("version");
QDomElement qgisElement = qgisNode.toElement(); // qgis node should be element
QgsProjectVersion projectVersion(qgisElement.attribute("version"));
return projectVersion;
} // _getVersion


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


QgsDebugMsg("Opened document " + imp_->file.name());
QgsDebugMsg("Project title: " + imp_->title);

// get project version string, if any
QgsProjectVersion fileVersion = _getVersion(*doc);
QgsProjectVersion thisVersion(QGis::qgisVersion);

if (thisVersion > fileVersion)
{
QgsLogger::warning("Loading a file that was saved with an older "
"version of qgis (saved in " + fileVersion.text() +
", loaded in " + QGis::qgisVersion +
"). Problems may occur.");

QgsProjectFileTransform projectFile(*doc, fileVersion);

//! Shows a warning when an old project file is read.
emit warnOlderProjectVersion(fileVersion.text());
QgsDebugMsg("Emitting warnOlderProjectVersion(oldVersion).");

projectFile.dump();

projectFile.updateRevision(thisVersion);

projectFile.dump();

}

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

// get project version string, if any
QString fileVersion = _getVersion(*doc);

if ( fileVersion.isNull() )
{
QgsDebugMsg( "project file has no version string" );
}
else
{
QgsDebugMsg( "project file has version " + QString(fileVersion) );
}

QStringList fileVersionParts = fileVersion.split(".");
QStringList qgisVersionParts = QString(QGis::qgisVersion).split(".");

QgsDebugMsg("Project title: " + imp_->title);

bool older = false;

if (fileVersionParts.size() != 3 || qgisVersionParts.size() != 3)
older = false; // probably an older version
else
{
if (fileVersionParts.at(0) < qgisVersionParts.at(0))
older = true;
else if (fileVersionParts.at(1) < qgisVersionParts.at(1))
older = true;
else if (fileVersionParts.at(2) < qgisVersionParts.at(2))
older = true;
}

if (older)
{
QgsLogger::warning("Loading a file that was saved with an older "
"version of qgis (saved in " + fileVersion +
", loaded in " + QGis::qgisVersion +
"). Problems may occur.");
}

// get the map layers
std::pair< bool, std::list<QDomNode> > getMapLayersResults = _getMapLayers(*doc);
@@ -23,6 +23,7 @@
#define QGSPROJECT_H

#include <memory>
#include "qgsprojectversion.h"
#include <QObject>

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

//! emitted when an old project file is read.
void warnOlderProjectVersion(QString);

private:

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

0 comments on commit ae437a8

Please sign in to comment.