refactor: rename unsigned integer parsing function
Make the name for unsigned integer parsing (counter validator) fit better with the new custom datetime validator.master
parent
63033b568d
commit
668a969d4f
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* SPDX-FileCopyrightText: 2019 Johan Ouwerkerk <jm.ouwerkerk@gmail.com>
|
* SPDX-FileCopyrightText: 2019-2020 Johan Ouwerkerk <jm.ouwerkerk@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "validators/countervalidator.h"
|
#include "validators/countervalidator.h"
|
||||||
|
@ -17,16 +17,16 @@ class UnsignedLongParsingSamplesTest: public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void testParsea(void);
|
void testParseUnsignedInteger(void);
|
||||||
void testParsea_data(void);
|
void testParseUnsignedInteger_data(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void UnsignedLongParsingSamplesTest::testParsea(void)
|
void UnsignedLongParsingSamplesTest::testParseUnsignedInteger(void)
|
||||||
{
|
{
|
||||||
QFETCH(QString, input);
|
QFETCH(QString, input);
|
||||||
QFETCH(QLocale, locale);
|
QFETCH(QLocale, locale);
|
||||||
QTEST(validators::parse(input, locale), "result");
|
QTEST(validators::parseUnsignedInteger(input, locale), "result");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void define_test_case(const QString &input, const QLocale &locale, const std::optional<qulonglong> &result)
|
static void define_test_case(const QString &input, const QLocale &locale, const std::optional<qulonglong> &result)
|
||||||
|
@ -34,7 +34,7 @@ static void define_test_case(const QString &input, const QLocale &locale, const
|
||||||
QTest::newRow(qPrintable(input)) << input << locale << result;
|
QTest::newRow(qPrintable(input)) << input << locale << result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnsignedLongParsingSamplesTest::testParsea_data(void)
|
void UnsignedLongParsingSamplesTest::testParseUnsignedInteger_data(void)
|
||||||
{
|
{
|
||||||
QTest::addColumn<QString>("input");
|
QTest::addColumn<QString>("input");
|
||||||
QTest::addColumn<QLocale>("locale");
|
QTest::addColumn<QLocale>("locale");
|
||||||
|
|
|
@ -187,7 +187,7 @@ namespace model
|
||||||
|
|
||||||
if (m_counter != counter) {
|
if (m_counter != counter) {
|
||||||
m_counter = counter;
|
m_counter = counter;
|
||||||
m_counterValue = validators::parse(counter, validator->locale()).value_or(0ULL);
|
m_counterValue = validators::parseUnsignedInteger(counter, validator->locale()).value_or(0ULL);
|
||||||
Q_EMIT counterChanged();
|
Q_EMIT counterChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
namespace validators
|
namespace validators
|
||||||
{
|
{
|
||||||
std::optional<qulonglong> parse(const QString &input, const QLocale &locale)
|
std::optional<qulonglong> parseUnsignedInteger(const QString &input, const QLocale &locale)
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ namespace validators
|
||||||
* This may also involve switching from Latin script (C locale) to
|
* This may also involve switching from Latin script (C locale) to
|
||||||
* whatever script the configured locale uses natively.
|
* whatever script the configured locale uses natively.
|
||||||
*/
|
*/
|
||||||
const auto v = parse(fixed, l);
|
const auto v = parseUnsignedInteger(fixed, l);
|
||||||
if (v) {
|
if (v) {
|
||||||
fixed = l.toString(v.value());
|
fixed = l.toString(v.value());
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ namespace validators
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
const QLocale l = locale();
|
const QLocale l = locale();
|
||||||
const auto parsed = parse(input, l);
|
const auto parsed = parseUnsignedInteger(input, l);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The actual value is a don't care at this point.
|
* The actual value is a don't care at this point.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* SPDX-FileCopyrightText: 2019 Johan Ouwerkerk <jm.ouwerkerk@gmail.com>
|
* SPDX-FileCopyrightText: 2019-2020 Johan Ouwerkerk <jm.ouwerkerk@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef COUNTER_VALIDATOR_H
|
#ifndef COUNTER_VALIDATOR_H
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
namespace validators
|
namespace validators
|
||||||
{
|
{
|
||||||
std::optional<qulonglong> parse(const QString &input, const QLocale &locale = QLocale::system());
|
std::optional<qulonglong> parseUnsignedInteger(const QString &input, const QLocale &locale = QLocale::system());
|
||||||
|
|
||||||
class UnsignedLongValidator: public QValidator
|
class UnsignedLongValidator: public QValidator
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue