diff --git a/framework/uicomponents/qml/Muse/UiComponents/tests/intinputvalidator_tests.cpp b/framework/uicomponents/qml/Muse/UiComponents/tests/intinputvalidator_tests.cpp index 277b20e73a..bd3d18a52a 100644 --- a/framework/uicomponents/qml/Muse/UiComponents/tests/intinputvalidator_tests.cpp +++ b/framework/uicomponents/qml/Muse/UiComponents/tests/intinputvalidator_tests.cpp @@ -112,10 +112,28 @@ TEST_F(IntInputValidatorTests, ValidateCommaLocale) { runInputTests({ { "0", QValidator::Invalid }, - { "", QValidator::Invalid }, + { "", QValidator::Intermediate, "1" }, { "1", QValidator::Acceptable } }); + m_validator->setTop(10); + m_validator->setBottom(5); + + runInputTests({ + { "1", QValidator::Intermediate, "5" }, + { "2", QValidator::Intermediate, "5" } + }); + + m_validator->setTop(-50); + m_validator->setBottom(-100); + + runInputTests({ + { "-5", QValidator::Intermediate, "-50" }, + { "-2", QValidator::Intermediate, "-50" }, + { "-75", QValidator::Acceptable }, + { "0", QValidator::Invalid } + }); + QLocale::setDefault(prev); } diff --git a/framework/uicomponents/qml/Muse/UiComponents/validators/intinputvalidator.cpp b/framework/uicomponents/qml/Muse/UiComponents/validators/intinputvalidator.cpp index f80c3ceaa9..db139ae8c5 100644 --- a/framework/uicomponents/qml/Muse/UiComponents/validators/intinputvalidator.cpp +++ b/framework/uicomponents/qml/Muse/UiComponents/validators/intinputvalidator.cpp @@ -21,6 +21,7 @@ */ #include "intinputvalidator.h" #include "global/realfn.h" +#include using namespace muse::uicomponents; @@ -89,16 +90,26 @@ QValidator::State IntInputValidator::validate(QString& inputStr, int& cursorPos) } else { state = Acceptable; } - } else if (digits.contains(QRegularExpression("^\\-?$"))) { - state = Intermediate; - } else { + } else if (digits.isEmpty()) { + return Intermediate; + } else if ((digits == "-")) { + if (m_bottom < 0) { + return Intermediate; + } + cursorPos = 0; return Invalid; } int val = digits.toInt(); - if (val > m_top || val < m_bottom) { - return Invalid; + if (val > m_top) { + // A negative value above the maximum may still be an in-progress prefix + return val < 0 ? Intermediate : Invalid; + } + + if (val < m_bottom) { + // Symmetrically, a positive not 0 value below the minimum may still be an in-progress + return val > 0 ? Intermediate : Invalid; } return state;