1 | // Copyright (C) 2018 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QQMLSOURCECOORDINATE_P_H |
5 | #define QQMLSOURCECOORDINATE_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtCore/private/qglobal_p.h> |
19 | |
20 | #include <limits> |
21 | |
22 | QT_BEGIN_NAMESPACE |
23 | |
24 | // These methods are needed because in some public methods we historically interpret -1 as the |
25 | // invalid line or column, even though all the lines and columns are 1-based. Also, the different |
26 | // integer ranges may turn certain large values into invalid ones on conversion. |
27 | |
28 | template<typename From, typename To> |
29 | To qmlConvertSourceCoordinate(From n); |
30 | |
31 | template<> |
32 | inline quint16 qmlConvertSourceCoordinate<int, quint16>(int n) |
33 | { |
34 | return (n > 0 && n <= int(std::numeric_limits<quint16>::max())) ? quint16(n) : 0; |
35 | } |
36 | |
37 | template<> |
38 | inline quint32 qmlConvertSourceCoordinate<int, quint32>(int n) |
39 | { |
40 | return n > 0 ? quint32(n) : 0u; |
41 | } |
42 | |
43 | // TODO: In Qt6, change behavior and make the invalid coordinate 0 for the following two methods. |
44 | |
45 | template<> |
46 | inline int qmlConvertSourceCoordinate<quint16, int>(quint16 n) |
47 | { |
48 | return (n == 0u) ? -1 : int(n); |
49 | } |
50 | |
51 | template<> |
52 | inline int qmlConvertSourceCoordinate<quint32, int>(quint32 n) |
53 | { |
54 | return (n == 0u || n > quint32(std::numeric_limits<int>::max())) ? -1 : int(n); |
55 | } |
56 | |
57 | QT_END_NAMESPACE |
58 | |
59 | #endif // QQMLSOURCECOORDINATE_P_H |
60 | |