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
22QT_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
28template<typename From, typename To>
29To qmlConvertSourceCoordinate(From n);
30
31template<>
32inline quint16 qmlConvertSourceCoordinate<int, quint16>(int n)
33{
34 return (n > 0 && n <= int(std::numeric_limits<quint16>::max())) ? quint16(n) : 0;
35}
36
37template<>
38inline 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
45template<>
46inline int qmlConvertSourceCoordinate<quint16, int>(quint16 n)
47{
48 return (n == 0u) ? -1 : int(n);
49}
50
51template<>
52inline int qmlConvertSourceCoordinate<quint32, int>(quint32 n)
53{
54 return (n == 0u || n > quint32(std::numeric_limits<int>::max())) ? -1 : int(n);
55}
56
57QT_END_NAMESPACE
58
59#endif // QQMLSOURCECOORDINATE_P_H
60

source code of qtdeclarative/src/qml/qml/qqmlsourcecoordinate_p.h