1 // Copyright (C) 2012-2019 The VPaint Developers.
2 // See the COPYRIGHT file at the top-level directory of this distribution
3 // and at https://github.com/dalboris/vpaint/blob/master/COPYRIGHT
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #include "Version.h"
18 
19 #include <QStringList>
20 
Version(const QString & str)21 Version::Version(const QString & str)
22 {
23     major_ = minor_ = patch_ = 0;
24 
25     if(str.trimmed().isEmpty()) return;
26 
27     QStringList split = str.split(".");
28     if(split.size() > 0)
29     {
30         major_ = split.at(0).toShort();
31     }
32     if(split.size() > 1)
33     {
34         minor_ = split.at(1).toShort();
35     }
36     if(split.size() > 2)
37     {
38         patch_ = split.at(2).toShort();
39     }
40 }
41 
getMajor() const42 short Version::getMajor() const
43 {
44     return major_;
45 }
46 
setMajor(short val)47 void Version::setMajor(short val)
48 {
49     major_ = val;
50 }
51 
getMinor() const52 short Version::getMinor() const
53 {
54     return minor_;
55 }
56 
setMinor(short val)57 void Version::setMinor(short val)
58 {
59     minor_ = val;
60 }
61 
getPatch() const62 short Version::getPatch() const
63 {
64     return patch_;
65 }
66 
setPatch(short val)67 void Version::setPatch(short val)
68 {
69     patch_ = val;
70 }
71 
operator <(const Version & other) const72 bool Version::operator< (const Version& other) const
73 {
74     if(getMajor() > other.getMajor()) return false;
75     if(getMajor() < other.getMajor()) return true;
76 
77     if(getMinor() > other.getMinor()) return false;
78     if(getMinor() < other.getMinor()) return true;
79 
80     if(getPatch() > other.getPatch()) return false;
81     if(getPatch() < other.getPatch()) return true;
82 
83     return false;
84 }
85 
toString(bool ignorePatch)86 QString Version::toString(bool ignorePatch)
87 {
88     if (ignorePatch || getPatch() == 0)
89     {
90         return QString("%1.%2").arg(getMajor()).arg(getMinor());
91     }
92     else
93     {
94         return QString("%1.%2.%3").arg(getMajor()).arg(getMinor()).arg(getPatch());
95     }
96 }
97