QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsprojectversion.cpp
Go to the documentation of this file.
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, const QString &name )
25 {
26  mMajor = major;
27  mMinor = minor;
28  mSub = sub;
29  mName = name;
30 }
31 
32 QgsProjectVersion::QgsProjectVersion( const QString &string )
33 {
34  QString pre = string.section( '-', 0, 0 );
35 
36  QStringList fileVersionParts = pre.section( '-', 0 ).split( '.' );
37 
38  mMinor = 0;
39  mSub = 0;
40  mMajor = fileVersionParts.at( 0 ).toInt();
41 
42  if ( fileVersionParts.size() > 1 )
43  {
44  mMinor = fileVersionParts.at( 1 ).toInt();
45  }
46  if ( fileVersionParts.size() > 2 )
47  {
48  mSub = fileVersionParts.at( 2 ).toInt();
49  }
50  mName = string.section( '-', 1 );
51 
52  QgsDebugMsgLevel( QStringLiteral( "Version is set to " ) + text(), 4 );
53 }
54 
56 {
57  return ( ( mMajor == other.mMajor ) &&
58  ( mMinor == other.mMinor ) &&
59  ( mSub == other.mSub ) );
60 }
61 
63 {
64  return ( ( mMajor != other.mMajor ) ||
65  ( mMinor != other.mMinor ) ||
66  ( mSub != other.mSub ) );
67 }
68 
70 {
71  return ( *this == other ) || ( *this > other );
72 }
73 
75 {
76  return ( ( mMajor > other.mMajor ) ||
77  ( ( mMajor == other.mMajor ) && ( mMinor > other.mMinor ) ) ||
78  ( ( mMajor == other.mMajor ) && ( mMinor == other.mMinor ) && ( mSub > other.mSub ) ) );
79 }
80 
82 {
83  if ( mName.isEmpty() )
84  {
85  return QStringLiteral( "%1.%2.%3" ).arg( mMajor ).arg( mMinor ).arg( mSub );
86  }
87  else
88  {
89  return QStringLiteral( "%1.%2.%3-%4" ).arg( mMajor ).arg( mMinor ).arg( mSub ).arg( mName );
90  }
91 }
92 
94 {
95  return mMajor == 0 && mMinor == 0 && mSub == 0;
96 }
QgsProjectVersion::operator>
bool operator>(const QgsProjectVersion &other) const
Boolean > operator.
Definition: qgsprojectversion.cpp:74
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
QgsProjectVersion::isNull
bool isNull() const
Returns true if this is a NULL project version.
Definition: qgsprojectversion.cpp:93
QgsProjectVersion::QgsProjectVersion
QgsProjectVersion()=default
Creates a new NULL version.
QgsProjectVersion::text
QString text()
Definition: qgsprojectversion.cpp:81
QgsProjectVersion::operator!=
bool operator!=(const QgsProjectVersion &other) const
Boolean not equal operator.
Definition: qgsprojectversion.cpp:62
QgsProjectVersion::operator>=
bool operator>=(const QgsProjectVersion &other) const
Boolean >= operator.
Definition: qgsprojectversion.cpp:69
QgsProjectVersion::operator==
bool operator==(const QgsProjectVersion &other) const
Boolean equal operator.
Definition: qgsprojectversion.cpp:55
qgslogger.h
qgsprojectversion.h
QgsProjectVersion
Definition: qgsprojectversion.h:32