capsqt.cpp
1 //------------------------------------------------------------------------------
2 // capsqt.cpp
3 //------------------------------------------------------------------------------
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 //
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 // 02110-1301 USA
18 //------------------------------------------------------------------------------
19 // Copyright (C) 2023 "Zalewa" <zalewapl@gmail.com>
20 //------------------------------------------------------------------------------
21 #include "capsqt.h"
22 
23 #include <QtGlobal>
24 #include <QString>
25 #include <QStringList>
26 
27 // Fix "error: does not have any field named 'gnu_dev_major'"
28 // https://bugzilla.redhat.com/show_bug.cgi?id=130601
29 #undef major
30 #undef minor
31 
32 namespace
33 {
34 struct VersionNumber
35 {
36  int major;
37  int minor;
38 
39  VersionNumber(int major = 0, int minor = 0) : major(major), minor(minor) {}
40 
47  int compare(const VersionNumber &other) const
48  {
49  int major = this->major - other.major;
50  if (major != 0)
51  return major;
52  return this->minor - other.minor;
53  }
54 };
55 }
56 
57 static const VersionNumber &runtimeQtVersion()
58 {
59  static const VersionNumber version = [](){
60  QString versionQt = qVersion();
61  QStringList tokens = versionQt.split(".");
62  VersionNumber version;
63  if (tokens.size() >= 1)
64  {
65  version.major = tokens[0].toInt();
66  }
67  if (tokens.size() >= 2)
68  {
69  version.minor = tokens[1].toInt();
70  }
71  return version;
72  }();
73  return version;
74 }
75 
76 bool CapsQt::canCssCellBorders()
77 {
78  static const VersionNumber minVersion(5, 14);
79  static bool can = runtimeQtVersion().compare(minVersion) >= 0;
80  return can;
81 }