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