mirror of
https://github.com/huderlem/porymap.git
synced 2026-06-22 15:49:47 -05:00
Fix UIntSpinBox disallowing intermediate inputs outside of range
This commit is contained in:
parent
06b22e0c2e
commit
a2bb2efa3e
|
|
@ -113,11 +113,16 @@ void UIntSpinBox::onEditFinished() {
|
|||
// Valid input
|
||||
newValue = this->valueFromText(input);
|
||||
} else if (state == QValidator::Intermediate) {
|
||||
// User has deleted all the number text.
|
||||
// If they did this by selecting all text and then hitting delete
|
||||
// make sure to put the cursor back in front of the prefix.
|
||||
newValue = m_minimum;
|
||||
this->lineEdit()->setCursorPosition(m_prefix.length());
|
||||
if (input == m_prefix) {
|
||||
// User has deleted all the number text.
|
||||
// If they did this by selecting all text and then hitting delete
|
||||
// make sure to put the cursor back in front of the prefix.
|
||||
newValue = m_minimum;
|
||||
this->lineEdit()->setCursorPosition(m_prefix.length());
|
||||
} else {
|
||||
// Other intermediate inputs (values outside of acceptable range) should be ignored.
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (newValue != m_value) {
|
||||
m_value = newValue;
|
||||
|
|
@ -160,10 +165,14 @@ QValidator::State UIntSpinBox::validate(QString &input, int &pos) const {
|
|||
|
||||
bool ok;
|
||||
uint32_t num = copy.toUInt(&ok, m_displayIntegerBase);
|
||||
if (!ok || num < m_minimum || num > m_maximum)
|
||||
if (!ok)
|
||||
return QValidator::Invalid;
|
||||
|
||||
input += copy.toUpper();
|
||||
|
||||
if (num < m_minimum || num > m_maximum)
|
||||
return QValidator::Intermediate;
|
||||
|
||||
return QValidator::Acceptable;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user