Skip to content

Make int input validator locale aware#64

Open
embarc-gabriel wants to merge 2 commits into
musescore:mainfrom
embarc-gabriel:make-input-validator-local-aware
Open

Make int input validator locale aware#64
embarc-gabriel wants to merge 2 commits into
musescore:mainfrom
embarc-gabriel:make-input-validator-local-aware

Conversation

@embarc-gabriel
Copy link
Copy Markdown
Contributor

Resolves: audacity/audacity#9949

Modify input validator to take group separator into account.

  • I signed the CLA
  • The title of the PR describes the problem it addresses
  • Each commit's message describes its purpose and effects, and references the issue it resolves
  • If changes are extensive, there is a sequence of easily reviewable commits
  • The code in the PR follows the coding rules
  • There are no unnecessary changes
  • The code compiles and runs on my machine, preferably after each commit individually
  • I created a unit test or vtest to verify the changes I made (if applicable)

Build configuration

audacity: audacity/audacity/master
audacity platforms: linux_x64
musescore: musescore/MuseScore/master
musescore platforms: linux_x64

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This pull request adds locale-aware integer input validation to the IntInputValidator class. The validate() method now recognizes and handles thousands separators based on the current QLocale, strips them before regex validation, and immediately returns Invalid for out-of-range values. The fixup() method reformats input using QLocale::toString to ensure consistent group separator formatting. A new test suite validates both en_US (comma) and ro_RO (dot) locale behaviors with comprehensive test cases covering valid inputs, boundaries, and fixup transformations.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Make int input validator locale aware' accurately and concisely describes the main change, which is making the integer input validator locale-aware to handle group separators correctly.
Description check ✅ Passed The PR description follows the template with all required sections completed: issue reference, motivation, and all checklist items marked as done including CLA, commit messages, code compliance, testing, and build configuration.
Linked Issues check ✅ Passed The code changes address the linked issue #9949 by making the integer input validator locale-aware to correctly handle group separators, allowing values like 1000+ to be entered and validated properly.
Out of Scope Changes check ✅ Passed All changes are directly related to the PR objective: CMakeLists.txt adds the test file, intinputvalidator_tests.cpp implements comprehensive locale-specific tests, and intinputvalidator.cpp implements the locale-aware validation and fixup logic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@framework/uicomponents/qml/Muse/UiComponents/tests/intinputvalidator_tests.cpp`:
- Around line 89-106: Add regression test cases in the intinputvalidator_tests
by extending the runInputTests calls to cover: (1) scenarios where the
validator's bottom bound > 0 and the input is "0" or "" to ensure fixup()
produces the bottom value (e.g., input "0" -> "1" when bottom==1) and validate()
returns Intermediate/Acceptable appropriately, and (2) near- and over-int-limit
cases (INT_MAX, INT_MAX+1, INT_MIN, INT_MIN-1) to assert validate() returns
Invalid for overflowed values and fixup() clamps to INT_MAX/INT_MIN where
appropriate; reference the existing test helper runInputTests and the
validator's validate()/fixup() behavior when adding these new entries similar to
the existing cases around the "0", "", and large-number examples.

In
`@framework/uicomponents/qml/Muse/UiComponents/validators/intinputvalidator.cpp`:
- Around line 46-48: In fixup(), remove the special-case that returns early when
val == 0 so zero is not bypassing clamping; change the logic that currently does
"if (!ok || val == 0) { string = "0"; return; }" to only treat parse failures
(e.g., "if (!ok) { ... }") and then run the existing clamp logic on val (using
the existing bottom/top bounds) before setting string so a parsed zero is
clamped into-range instead of returned as "0".
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2fba5062-e933-4eae-9300-1da812d3e1d5

📥 Commits

Reviewing files that changed from the base of the PR and between 751bd9c and ffda1ae.

📒 Files selected for processing (3)
  • framework/uicomponents/qml/Muse/UiComponents/tests/CMakeLists.txt
  • framework/uicomponents/qml/Muse/UiComponents/tests/intinputvalidator_tests.cpp
  • framework/uicomponents/qml/Muse/UiComponents/validators/intinputvalidator.cpp

Comment thread framework/uicomponents/qml/Muse/UiComponents/validators/intinputvalidator.cpp Outdated
@embarc-gabriel embarc-gabriel changed the title Make input validator locale aware Make int input validator locale aware May 29, 2026
@embarc-gabriel embarc-gabriel force-pushed the make-input-validator-local-aware branch from ffda1ae to 64e137c Compare May 29, 2026 08:35
Comment thread framework/uicomponents/qml/Muse/UiComponents/tests/intinputvalidator_tests.cpp Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@framework/uicomponents/qml/Muse/UiComponents/validators/intinputvalidator.cpp`:
- Around line 100-102: The current check in IntInputValidator that returns
Invalid when val > m_top || val < m_bottom is too strict; modify the validate
logic in IntInputValidator (the validate method that uses m_top and m_bottom) so
that you only return Invalid when the numeric input cannot possibly be completed
into [m_bottom, m_top] (e.g., value > m_top, or value < m_bottom AND the current
text cannot be extended/changed to reach m_bottom), otherwise return
Intermediate for in-progress prefixes; specifically, keep returning Invalid for
val > m_top, but for val < m_bottom detect prefix/partial cases (empty string,
just a sign, or a shorter numeric string that could grow by adding digits or a
sign to reach m_bottom) and return Intermediate for those, only returning
Invalid when the text is a complete number that is definitively below m_bottom
and cannot be changed by further typing into the same field to become valid.
Ensure you reference and use m_top and m_bottom and update the validate(...)
branch that currently contains if (val > m_top || val < m_bottom) { return
Invalid; } accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 96df75d8-71d5-4790-9f62-4e91d14fee90

📥 Commits

Reviewing files that changed from the base of the PR and between ffda1ae and 64e137c.

📒 Files selected for processing (3)
  • framework/uicomponents/qml/Muse/UiComponents/tests/CMakeLists.txt
  • framework/uicomponents/qml/Muse/UiComponents/tests/intinputvalidator_tests.cpp
  • framework/uicomponents/qml/Muse/UiComponents/validators/intinputvalidator.cpp

Comment on lines +100 to 102
if (val > m_top || val < m_bottom) {
return Invalid;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Usages of IntInputValidator and the bottom/top bounds configured around them
rg -nP -C3 'IntInputValidator' --iglob '*.qml' --iglob '*.cpp' --iglob '*.h'
# QML bottom bindings (likely on the validator instance)
rg -nP -C2 '\bbottom\s*:' --iglob '*.qml'
# C++ setBottom calls with their argument
rg -nP -C1 '\bsetBottom\s*\(' --iglob '*.cpp' --iglob '*.h'

Repository: musescore/muse_framework

Length of output: 50380


Fix IntInputValidator below-bottom behavior (don’t blanket-return Invalid).

IntInputValidator is used by IncrementalPropertyControl.qml with bottom: root.minValue, so real consumers can supply m_bottom > 1 (not just the bottom=1 case the unit tests cover). Returning QValidator::Invalid when val < m_bottom rejects valid in-progress prefixes that could still reach the allowed range, which should stay Intermediate instead.

Update the logic around the if (val > m_top || val < m_bottom) { return Invalid; } check to only return Invalid for inputs that can’t be completed into the range (and keep Intermediate when the partial value could still grow into [m_bottom, m_top], matching the behavior expected by QIntValidator/tests for bottom=1).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@framework/uicomponents/qml/Muse/UiComponents/validators/intinputvalidator.cpp`
around lines 100 - 102, The current check in IntInputValidator that returns
Invalid when val > m_top || val < m_bottom is too strict; modify the validate
logic in IntInputValidator (the validate method that uses m_top and m_bottom) so
that you only return Invalid when the numeric input cannot possibly be completed
into [m_bottom, m_top] (e.g., value > m_top, or value < m_bottom AND the current
text cannot be extended/changed to reach m_bottom), otherwise return
Intermediate for in-progress prefixes; specifically, keep returning Invalid for
val > m_top, but for val < m_bottom detect prefix/partial cases (empty string,
just a sign, or a shorter numeric string that could grow by adding digits or a
sign to reach m_bottom) and return Intermediate for those, only returning
Invalid when the text is a complete number that is definitively below m_bottom
and cannot be changed by further typing into the same field to become valid.
Ensure you reference and use m_top and m_bottom and update the validate(...)
branch that currently contains if (val > m_top || val < m_bottom) { return
Invalid; } accordingly.

@embarc-gabriel embarc-gabriel force-pushed the make-input-validator-local-aware branch from 64e137c to b2dbdef Compare May 29, 2026 11:29
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
framework/uicomponents/qml/Muse/UiComponents/tests/intinputvalidator_tests.cpp (1)

89-117: 🧹 Nitpick | 🔵 Trivial | 🏗️ Heavy lift

The previous review comment requesting additional regression cases is still unaddressed.

The test suite does not verify fixup() behavior for out-of-range inputs:

  1. Bottom-bound edge case (lines 113–117): When bottom = 1, inputs "0" and "" are marked Invalid, so fixup() is never called (due to the skip at line 69–71). The test should verify that fixup() clamps these to "1".

  2. Integer overflow edge case (lines 104–105): INT_MAX and INT_MIN are tested for Invalid state, but there's no verification that fixup() clamps overflowed values to the validator's [bottom, top] range.

Consider adding test cases where the expected state is Intermediate or Acceptable for boundary inputs, allowing fixup() to be exercised and its clamping behavior verified.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@framework/uicomponents/qml/Muse/UiComponents/tests/intinputvalidator_tests.cpp`
around lines 89 - 117, The tests currently never exercise
UiIntInputValidator::fixup for out-of-range inputs; update the test cases passed
to runInputTests so at least one out-of-range input yields Intermediate (or
Acceptable) rather than Invalid, then call fixup() and assert the edited string
is clamped to the set range; specifically add cases after
m_validator->setBottom(1)/setTop(10) where input "0" and "" are marked
Intermediate and expect fixup to produce "1" (use runInputTests or a dedicated
call to m_validator->fixup on the QString and check the result), and add cases
for INT_MAX/INT_MIN (e.g., "2147483647" and "-2147483648") that produce
Intermediate so fixup clamps them into [bottom, top]; reference runInputTests,
m_validator->setTop, m_validator->setBottom, and fixup when locating places to
add these assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In
`@framework/uicomponents/qml/Muse/UiComponents/tests/intinputvalidator_tests.cpp`:
- Around line 89-117: The tests currently never exercise
UiIntInputValidator::fixup for out-of-range inputs; update the test cases passed
to runInputTests so at least one out-of-range input yields Intermediate (or
Acceptable) rather than Invalid, then call fixup() and assert the edited string
is clamped to the set range; specifically add cases after
m_validator->setBottom(1)/setTop(10) where input "0" and "" are marked
Intermediate and expect fixup to produce "1" (use runInputTests or a dedicated
call to m_validator->fixup on the QString and check the result), and add cases
for INT_MAX/INT_MIN (e.g., "2147483647" and "-2147483648") that produce
Intermediate so fixup clamps them into [bottom, top]; reference runInputTests,
m_validator->setTop, m_validator->setBottom, and fixup when locating places to
add these assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 36431f2d-ae47-4633-867e-9c398a55fa5d

📥 Commits

Reviewing files that changed from the base of the PR and between 64e137c and b2dbdef.

📒 Files selected for processing (2)
  • framework/uicomponents/qml/Muse/UiComponents/tests/CMakeLists.txt
  • framework/uicomponents/qml/Muse/UiComponents/tests/intinputvalidator_tests.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EGAT: start/end frequency above 999 Hz cannot be entered

2 participants