QVersionNumber was introduced in 5.6.0; for compatibility with older versions this class provides a rudimentary implementation if necessary
| 72 | // QVersionNumber was introduced in 5.6.0; for compatibility with older versions |
| 73 | // this class provides a rudimentary implementation if necessary |
| 74 | class VersionNumber { |
| 75 | QVector<int> m_segments; |
| 76 | public: |
| 77 | VersionNumber() = default; |
| 78 | VersionNumber(int maj, int min, int mic) { m_segments << maj << min << mic; } |
| 79 | static VersionNumber fromString(const QString & string) { |
| 80 | VersionNumber rv; |
| 81 | Q_FOREACH(const QString & s, string.split(QChar('.'))) { |
| 82 | bool ok; |
| 83 | int i = s.toInt(&ok); |
| 84 | if (!ok) return {}; |
| 85 | rv.m_segments.append(i); |
| 86 | } |
| 87 | return rv; |
| 88 | } |
| 89 | static int compare(const VersionNumber & v1, const VersionNumber & v2) { |
| 90 | for (int i = 0; i < qMax(v1.m_segments.size(), v2.m_segments.size()); ++i) { |
| 91 | int a = (i < v1.m_segments.size() ? v1.m_segments[i] : 0); |
| 92 | int b = (i < v2.m_segments.size() ? v2.m_segments[i] : 0); |
| 93 | if (a < b) |
| 94 | return -1; |
| 95 | else if (a > b) |
| 96 | return 1; |
| 97 | } |
| 98 | return 0; |
| 99 | } |
| 100 | bool operator==(const VersionNumber & rhs) const { return compare(*this, rhs) == 0; } |
| 101 | bool operator!=(const VersionNumber & rhs) const { return compare(*this, rhs) != 0; } |
| 102 | bool operator<(const VersionNumber & rhs) const { return compare(*this, rhs) < 0; } |
| 103 | bool operator<=(const VersionNumber & rhs) const { return compare(*this, rhs) <= 0; } |
| 104 | bool operator>(const VersionNumber & rhs) const { return compare(*this, rhs) > 0; } |
| 105 | bool operator>=(const VersionNumber & rhs) const { return compare(*this, rhs) >= 0; } |
| 106 | }; |
| 107 | #else |
| 108 | using VersionNumber = QVersionNumber; |
| 109 | #endif |
no outgoing calls