Quantum GIS API Documentation  1.8
src/core/qgsprojectversion.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           qgsprojectfile.h  -  description
00003                              -------------------
00004     begin                : Sun 15 dec 2007
00005     copyright            : (C) 2007 by Magnus Homann
00006     email                : magnus at homann.se
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include <QString>
00019 #include <QStringList>
00020 
00021 #include "qgslogger.h"
00022 #include "qgsprojectversion.h"
00023 
00024 QgsProjectVersion::QgsProjectVersion( int major, int minor, int sub, QString name )
00025 {
00026   mMajor = major;
00027   mMinor = minor;
00028   mSub   = sub;
00029   mName  = name;
00030 }
00031 
00032 QgsProjectVersion::QgsProjectVersion( QString string )
00033 {
00034   QString pre = string.section( '-', 0, 0 );
00035 
00036   QStringList fileVersionParts = pre.section( "-", 0 ).split( "." );
00037 
00038   mMinor = 0;
00039   mSub   = 0;
00040   mName  = "";
00041   mMajor = fileVersionParts.at( 0 ).toInt();
00042 
00043   if ( fileVersionParts.size() > 1 )
00044   {
00045     mMinor = fileVersionParts.at( 1 ).toInt();
00046   }
00047   if ( fileVersionParts.size() > 2 )
00048   {
00049     mSub   = fileVersionParts.at( 2 ).toInt();
00050   }
00051   mName  = string.section( '-', 1 );
00052 
00053   QgsDebugMsg( QString( "Version is set to " ) + text() );
00054 
00055 }
00056 
00059 bool QgsProjectVersion::operator==( const QgsProjectVersion &other )
00060 {
00061   return (( mMajor == other.mMajor ) &&
00062           ( mMinor == other.mMinor ) &&
00063           ( mSub == other.mSub ) );
00064 }
00065 
00068 bool QgsProjectVersion::operator>=( const QgsProjectVersion &other )
00069 {
00070   return (( mMajor >= other.mMajor ) ||
00071           (( mMajor == other.mMajor ) && ( mMinor >= other.mMinor ) ) ||
00072           (( mMajor == other.mMajor ) && ( mMinor == other.mMinor ) && ( mSub >= other.mSub ) ) );
00073 }
00074 
00077 bool QgsProjectVersion::operator>( const QgsProjectVersion &other )
00078 {
00079   return (( mMajor > other.mMajor ) ||
00080           (( mMajor == other.mMajor ) && ( mMinor > other.mMinor ) ) ||
00081           (( mMajor == other.mMajor ) && ( mMinor == other.mMinor ) && ( mSub > other.mSub ) ) );
00082 }
00083 
00084 QString QgsProjectVersion::text()
00085 {
00086   if ( mName.isNull() )
00087   {
00088     return QString( "%1.%2.%3" ).arg( mMajor ).arg( mMinor ).arg( mSub );
00089   }
00090   else
00091   {
00092     return QString( "%1.%2.%3-%4" ).arg( mMajor ).arg( mMinor ).arg( mSub ).arg( mName );
00093   }
00094 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines