30
30
#include " qgsexception.h"
31
31
#include " qgsprojectproperty.h"
32
32
#include " qgslogger.h"
33
+ #include " qgsprojectfiletransform.h"
34
+ #include " qgsprojectversion.h"
33
35
34
36
#include < QApplication>
35
37
#include < QFileInfo>
@@ -576,21 +578,21 @@ static void _getTitle(QDomDocument const &doc, QString & title)
576
578
577
579
@returns the version string or an empty string if none found
578
580
*/
579
- static QString _getVersion (QDomDocument const &doc)
581
+ static QgsProjectVersion _getVersion (QDomDocument const &doc)
580
582
{
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
+ }
590
590
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
592
592
593
- return qgisElement.attribute (" version" );
593
+ QDomElement qgisElement = qgisNode.toElement (); // qgis node should be element
594
+ QgsProjectVersion projectVersion (qgisElement.attribute (" version" ));
595
+ return projectVersion;
594
596
} // _getVersion
595
597
596
598
@@ -782,6 +784,32 @@ bool QgsProject::read()
782
784
783
785
784
786
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
+ }
785
813
786
814
// before we start loading everything, let's clear out the current set of
787
815
// properties first so that we don't have the properties from the previous
@@ -802,44 +830,6 @@ bool QgsProject::read()
802
830
// now get project title
803
831
_getTitle (*doc, imp_->title );
804
832
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
- }
843
833
844
834
// get the map layers
845
835
std::pair< bool , std::list<QDomNode> > getMapLayersResults = _getMapLayers (*doc);
0 commit comments