Skip to content

Fix doubleinputvalidator for large values (10⁴ and more)#33087

Merged
igorkorsukov merged 3 commits intomusescore:masterfrom
saintmatthieu:double-input-validator-fix-for-large-values
Apr 24, 2026
Merged

Fix doubleinputvalidator for large values (10⁴ and more)#33087
igorkorsukov merged 3 commits intomusescore:masterfrom
saintmatthieu:double-input-validator-fix-for-large-values

Conversation

@saintmatthieu
Copy link
Copy Markdown
Contributor

Needed for audacity/audacity#10745

Generalizes the double input validator (used e.g. by IncrementalPropertyControl) to handle arbitrarily large numbers. At the moment it correctly handles up to three integers.

  • 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)

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

📝 Walkthrough

Walkthrough

The validator now computes the maximum integer-digit count from configured m_top/m_bottom via a new internal helper. fixup() and validate() build regular expressions and intermediate-input checks using that dynamic integer-digit limit together with the configured decimal-digit limit. Zero and negative-zero normalization and invalid-zero detection were adjusted to use the computed digit range instead of fixed digit counts. Tests were updated for larger boundaries, a new small-range test was added, and a GoogleTest printer for QString was introduced.

🚥 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 clearly describes the main fix: making the double input validator handle large values (10⁴ and above), which is the core purpose of the changeset.
Description check ✅ Passed The description follows the template with all required sections completed: issue reference, change motivation, all checklist items marked as done, and appropriate external context provided.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/framework/uicomponents/qml/Muse/UiComponents/validators/doubleinputvalidator.cpp`:
- Around line 88-93: Add a unit/vtest for the new large-value handling in
doubleinputvalidator by testing maxIntegerDigits behavior and boundary overflow:
create tests that instantiate the validator (or call maxIntegerDigits) with
m_top=99999 (and appropriate m_bottom) and assert that input "12345" is accepted
while values exceeding the top are rejected; also include a test for the edge
case when maxIntDigits == 1 (e.g., very small range) to ensure intPart
normalization to "0" or "-0" still behaves correctly. Reference the
maxIntegerDigits(m_top, m_bottom) logic and the code paths that normalize
intPart (the branches using QRegularExpression and QString("0")/QString("-0"))
when writing the tests so future regressions are caught.
- Line 145: Fix the uncrustify style violation by running the project's
codestyle formatter and applying its suggested formatting to the
DoubleInputValidator implementation (the method containing the assignment "state
= Acceptable;"). Run the uncrustify script used by CI, stage the modified
doubleinputvalidator.cpp, and amend the commit so the formatter-corrected
whitespace/indentation around the validate() logic (or the function that sets
state = Acceptable) matches the project's codestyle.
- Line 133: The quantifier in invalidZeroRegex can become invalid when
maxIntDigits == 1 (producing {2,1}); change the upper bound passed into the
regex to be at least 2 by clamping maxIntDigits (e.g., use qMax(2, maxIntDigits)
or similar) before constructing QRegularExpression in doubleinputvalidator.cpp
where invalidZeroRegex is defined so the pattern becomes valid for small ranges;
keep the rest of the regex logic unchanged.
🪄 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: 1943edee-d3b3-45ce-8fc0-14c1574b6a64

📥 Commits

Reviewing files that changed from the base of the PR and between be437ff and d37453c.

📒 Files selected for processing (1)
  • src/framework/uicomponents/qml/Muse/UiComponents/validators/doubleinputvalidator.cpp

@saintmatthieu saintmatthieu force-pushed the double-input-validator-fix-for-large-values branch from d37453c to 1a61b4e Compare April 22, 2026 10:25
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)
src/framework/uicomponents/qml/Muse/UiComponents/validators/doubleinputvalidator.cpp (1)

145-145: ⚠️ Potential issue | 🟡 Minor

Fix the remaining Uncrustify violation.

Check: Codestyle still fails for this file at Line 145. Please run tools/codestyle/uncrustify_run_file.sh src/framework/uicomponents/qml/Muse/UiComponents/validators/doubleinputvalidator.cpp and amend the commit.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/framework/uicomponents/qml/Muse/UiComponents/validators/doubleinputvalidator.cpp`
at line 145, There is a remaining Uncrustify codestyle violation at the
assignment `state = Acceptable;` in doubleinputvalidator.cpp; run the formatter
script (tools/codestyle/uncrustify_run_file.sh
src/framework/uicomponents/qml/Muse/UiComponents/validators/doubleinputvalidator.cpp),
accept the produced changes (which will adjust spacing/indentation around the
`state` assignment and nearby lines), then amend the commit so Codestyle passes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In
`@src/framework/uicomponents/qml/Muse/UiComponents/validators/doubleinputvalidator.cpp`:
- Line 145: There is a remaining Uncrustify codestyle violation at the
assignment `state = Acceptable;` in doubleinputvalidator.cpp; run the formatter
script (tools/codestyle/uncrustify_run_file.sh
src/framework/uicomponents/qml/Muse/UiComponents/validators/doubleinputvalidator.cpp),
accept the produced changes (which will adjust spacing/indentation around the
`state` assignment and nearby lines), then amend the commit so Codestyle passes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9e69f397-39e6-4ee7-aa65-c62008494756

📥 Commits

Reviewing files that changed from the base of the PR and between d37453c and 1a61b4e.

📒 Files selected for processing (1)
  • src/framework/uicomponents/qml/Muse/UiComponents/validators/doubleinputvalidator.cpp

@saintmatthieu saintmatthieu force-pushed the double-input-validator-fix-for-large-values branch from 1a61b4e to 23b7cca Compare April 22, 2026 14:52
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 the current code and only fix it if needed.

Inline comments:
In
`@src/framework/uicomponents/qml/Muse/UiComponents/validators/doubleinputvalidator.cpp`:
- Around line 29-38: The maxIntegerDigits function currently uses std::log10
which can misround for exact powers of ten; replace that with an integer-only
digit count: if maxAbs < 1.0 return 1, otherwise take uint64_t n =
static_cast<uint64_t>(std::floor(maxAbs)); count digits by repeatedly dividing n
by 10 (incrementing a counter) until n == 0 and return the counter; ensure
negatives are handled via std::llabs or std::fabs before casting and use the
function name maxIntegerDigits to locate and update the implementation
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: ec6ed8ee-6b05-4d63-8463-582d0d9ff163

📥 Commits

Reviewing files that changed from the base of the PR and between 1a61b4e and 23b7cca.

📒 Files selected for processing (2)
  • src/framework/uicomponents/qml/Muse/UiComponents/tests/doubleinputvalidator_tests.cpp
  • src/framework/uicomponents/qml/Muse/UiComponents/validators/doubleinputvalidator.cpp

@saintmatthieu saintmatthieu force-pushed the double-input-validator-fix-for-large-values branch from 23b7cca to 2355789 Compare April 22, 2026 15:17
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

♻️ Duplicate comments (1)
src/framework/uicomponents/qml/Muse/UiComponents/validators/doubleinputvalidator.cpp (1)

94-99: ⚠️ Potential issue | 🟡 Minor

Preserve leading-zero handling for small ranges.

For maxIntDigits == 1, inputs such as 00.5 are now rejected before invalidZeroRegex can classify them, and fixup() no longer normalizes the 00 integer part. Consider using a separate zero-normalization limit, at least the old fixed width, and checking leading-zero cases before the strict digit-count regex rejects them.

Possible direction
     const int maxIntDigits = maxIntegerDigits(m_top, m_bottom);
-    if (intPart.contains(QRegularExpression(QString("^0{1,%1}$").arg(maxIntDigits)))) {
+    const int maxZeroDigits = std::max(maxIntDigits, 3);
+    if (intPart.contains(QRegularExpression(QString("^0{1,%1}$").arg(maxZeroDigits)))) {
         intPart = QString("0");
-    } else if (intPart.contains(QRegularExpression(QString("^\\-0{0,%1}$").arg(maxIntDigits)))) {
+    } else if (intPart.contains(QRegularExpression(QString("^\\-0{0,%1}$").arg(maxZeroDigits)))) {
         intPart = QString("-0");
     }

Then mirror that separate zero-specific allowance in validate() before the strict \d{1,maxIntDigits} path.

Also applies to: 135-155

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/framework/uicomponents/qml/Muse/UiComponents/validators/doubleinputvalidator.cpp`
around lines 94 - 99, The current integer-part normalization uses maxIntDigits
(from maxIntegerDigits(m_top, m_bottom)) which can be 1 and causes inputs like
"00.5" to be rejected before zero-normalization runs; change the logic to use a
separate zero-normalization limit (e.g., zeroNormWidth) that preserves the
previous fixed-width allowance for leading-zero normalization, perform the
leading-zero checks (the two QRegularExpression branches that set intPart to "0"
or "-0") using that zeroNormWidth before any strict max-digit regex is applied,
and mirror the same zero-specific allowance in the validate() path (the
corresponding validation code around lines 135-155) so leading-zero cases are
accepted for normalization even when maxIntDigits == 1; reference
maxIntegerDigits(m_top,m_bottom), intPart variable, the QRegularExpression
checks, and validate() to locate the spots to update.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/framework/uicomponents/qml/Muse/UiComponents/validators/doubleinputvalidator.cpp`:
- Around line 25-32: The code uses std::max in the helper function
maxIntegerDigits (and elsewhere in the validator regex logic) but relies on a
transitive include; add a direct include of <algorithm> at the top of
doubleinputvalidator.cpp so std::max is guaranteed available (update the include
list near the existing <cmath> and other headers and rebuild to ensure no
transitive dependency remains).

---

Duplicate comments:
In
`@src/framework/uicomponents/qml/Muse/UiComponents/validators/doubleinputvalidator.cpp`:
- Around line 94-99: The current integer-part normalization uses maxIntDigits
(from maxIntegerDigits(m_top, m_bottom)) which can be 1 and causes inputs like
"00.5" to be rejected before zero-normalization runs; change the logic to use a
separate zero-normalization limit (e.g., zeroNormWidth) that preserves the
previous fixed-width allowance for leading-zero normalization, perform the
leading-zero checks (the two QRegularExpression branches that set intPart to "0"
or "-0") using that zeroNormWidth before any strict max-digit regex is applied,
and mirror the same zero-specific allowance in the validate() path (the
corresponding validation code around lines 135-155) so leading-zero cases are
accepted for normalization even when maxIntDigits == 1; reference
maxIntegerDigits(m_top,m_bottom), intPart variable, the QRegularExpression
checks, and validate() to locate the spots to update.
🪄 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: ff3f4aac-f48a-4ff6-ad24-53b9348fb724

📥 Commits

Reviewing files that changed from the base of the PR and between 23b7cca and 2355789.

📒 Files selected for processing (1)
  • src/framework/uicomponents/qml/Muse/UiComponents/validators/doubleinputvalidator.cpp

@igorkorsukov igorkorsukov merged commit dbaa95a into musescore:master Apr 24, 2026
13 checks passed
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.

2 participants