LibrePCB Developers Documentation
qtcompat.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_CORE_QTCOMPAT_H
21#define LIBREPCB_CORE_QTCOMPAT_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include <QtCore>
27
28/*******************************************************************************
29 * Namespace / Forward Declarations
30 ******************************************************************************/
31namespace librepcb {
32
33/*******************************************************************************
34 * Class QtCompat
35 ******************************************************************************/
36
43class QtCompat final {
44public:
45 // Disable Instantiation
46 QtCompat() = delete;
47 QtCompat(const QtCompat& other) = delete;
48 ~QtCompat() = delete;
49 QtCompat& operator=(const QtCompat& rhs) = delete;
50
52
55#if QT_VERSION_MAJOR >= 6
56 using Hash = std::size_t;
57#else
58 using Hash = uint;
59#endif
61
63
68#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
69 static inline constexpr Qt::SplitBehavior keepEmptyParts() noexcept {
70 return Qt::KeepEmptyParts;
71 }
72 static inline constexpr Qt::SplitBehavior skipEmptyParts() noexcept {
73 return Qt::SkipEmptyParts;
74 }
75#else
76 static inline constexpr QString::SplitBehavior keepEmptyParts() noexcept {
77 return QString::KeepEmptyParts;
78 }
79 static inline constexpr QString::SplitBehavior skipEmptyParts() noexcept {
80 return QString::SkipEmptyParts;
81 }
82#endif
84
86
89#if QT_VERSION_MAJOR >= 6
90 static inline QStringView midRef(const QString& s, int pos,
91 int n = -1) noexcept {
92 // Note: QStringView exists since Qt 5.10, but the behavior of mid() was
93 // different!
94 return QStringView(s).mid(pos, n);
95 }
96#else
97 static inline QStringRef midRef(const QString& s, int pos,
98 int n = -1) noexcept {
99 return s.midRef(pos, n);
100 }
101#endif
103};
104
105/*******************************************************************************
106 * End of File
107 ******************************************************************************/
108
109} // namespace librepcb
110
111#endif
Qt compatibility helper class.
Definition: qtcompat.h:43
static QStringRef midRef(const QString &s, int pos, int n=-1) noexcept
Wrapper for QString::midRef()
Definition: qtcompat.h:97
uint Hash
Return type of Qt's qHash() function.
Definition: qtcompat.h:58
static constexpr Qt::SplitBehavior keepEmptyParts() noexcept
String split behavior.
Definition: qtcompat.h:69
static constexpr Qt::SplitBehavior skipEmptyParts() noexcept
Definition: qtcompat.h:72
QtCompat & operator=(const QtCompat &rhs)=delete
QtCompat(const QtCompat &other)=delete
Definition: occmodel.cpp:77