1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Designer of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include "qlonglongvalidator.h"
30
31QT_BEGIN_NAMESPACE
32
33using namespace qdesigner_internal;
34
35// ----------------------------------------------------------------------------
36QLongLongValidator::QLongLongValidator(QObject * parent)
37 : QValidator(parent),
38 b(Q_UINT64_C(0x8000000000000000)), t(Q_UINT64_C(0x7FFFFFFFFFFFFFFF))
39{
40}
41
42QLongLongValidator::QLongLongValidator(qlonglong minimum, qlonglong maximum,
43 QObject * parent)
44 : QValidator(parent), b(minimum), t(maximum)
45{
46}
47
48QLongLongValidator::~QLongLongValidator() = default;
49
50QValidator::State QLongLongValidator::validate(QString & input, int &) const
51{
52 if (input.contains(c: QLatin1Char(' ')))
53 return Invalid;
54 if (input.isEmpty() || (b < 0 && input == QString(QLatin1Char('-'))))
55 return Intermediate;
56 bool ok;
57 qlonglong entered = input.toLongLong(ok: &ok);
58 if (!ok || (entered < 0 && b >= 0))
59 return Invalid;
60 if (entered >= b && entered <= t)
61 return Acceptable;
62 if (entered >= 0)
63 return entered > t ? Invalid : Intermediate;
64 return entered < b ? Invalid : Intermediate;
65}
66
67void QLongLongValidator::setRange(qlonglong bottom, qlonglong top)
68{
69 b = bottom;
70 t = top;
71}
72
73void QLongLongValidator::setBottom(qlonglong bottom)
74{
75 setRange(bottom, top: top());
76}
77
78void QLongLongValidator::setTop(qlonglong top)
79{
80 setRange(bottom: bottom(), top);
81}
82
83
84// ----------------------------------------------------------------------------
85QULongLongValidator::QULongLongValidator(QObject * parent)
86 : QValidator(parent),
87 b(0), t(Q_UINT64_C(0xFFFFFFFFFFFFFFFF))
88{
89}
90
91QULongLongValidator::QULongLongValidator(qulonglong minimum, qulonglong maximum,
92 QObject * parent)
93 : QValidator(parent), b(minimum), t(maximum)
94{
95}
96
97QULongLongValidator::~QULongLongValidator() = default;
98
99QValidator::State QULongLongValidator::validate(QString & input, int &) const
100{
101 if (input.isEmpty())
102 return Intermediate;
103
104 bool ok;
105 qulonglong entered = input.toULongLong(ok: &ok);
106 if (input.contains(c: QLatin1Char(' ')) || input.contains(c: QLatin1Char('-')) || !ok)
107 return Invalid;
108
109 if (entered >= b && entered <= t)
110 return Acceptable;
111
112 return Invalid;
113}
114
115void QULongLongValidator::setRange(qulonglong bottom, qulonglong top)
116{
117 b = bottom;
118 t = top;
119}
120
121void QULongLongValidator::setBottom(qulonglong bottom)
122{
123 setRange(bottom, top: top());
124}
125
126void QULongLongValidator::setTop(qulonglong top)
127{
128 setRange(bottom: bottom(), top);
129}
130
131QT_END_NAMESPACE
132

source code of qttools/src/designer/src/components/propertyeditor/qlonglongvalidator.cpp