Skip to content

Remove Qt dependency from DimMapper formatting - #8947

Merged
timosachsenberg merged 2 commits into
OpenMS:developfrom
enetz:claude/review-nan-handling-bz4og
Mar 18, 2026
Merged

timosachsenberg merged 2 commits into
OpenMS:developfrom
enetz:claude/review-nan-handling-bz4og

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

Replace Qt's QLocale::c().toString() with a standard C++ implementation using <charconv> and <cmath>. This removes a Qt dependency from the DimMapper formatting code while maintaining identical behavior for number formatting with group separators.

The new formatWithGroupSeparators() function:

  • Uses std::to_chars() for efficient double-to-string conversion
  • Handles special floating-point values (NaN, infinity) matching Qt's behavior
  • Inserts comma separators every 3 digits in the integer part (C locale convention)
  • Preserves the original precision and formatting semantics

Checklist

  • Make sure that you are listed in the AUTHORS file
  • Add relevant changes and new features to the CHANGELOG file
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes
  • Updated or added python bindings for changed or new classes (Tick if no updates were necessary.)

Testing

The formatting behavior is functionally equivalent to the previous Qt-based implementation. Existing unit tests for DimBase::formattedValue() should verify the change produces identical output.

https://claude.ai/code/session_015odPaUy23pSDYFufRXv4Rr

Summary by CodeRabbit

  • Refactor
    • Updated numeric formatting implementation for displayed values with thousands separators and improved handling of special numeric values (NaN, infinity, negative numbers).

claude and others added 2 commits March 18, 2026 18:58
Replace QLocale::c().toString with std::to_chars-based formatting that
matches Qt behavior: NaN returns "nan", Inf returns "inf"/"-inf".
Check std::to_chars error code to avoid UB on buffer overflow, and
use a 512-byte buffer sufficient for any fixed-format double.

Addresses CodeRabbit review concern on PR OpenMS#8937.

https://claude.ai/code/session_015odPaUy23pSDYFufRXv4Rr
@coderabbitai

coderabbitai Bot commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This change refactors numeric formatting in DimMapper.cpp by replacing Qt's QLocale-based formatting with an internal helper function that formats doubles with thousands separators, handling special cases like NaN and negative values without Qt dependencies.

Changes

Cohort / File(s) Summary
Numeric Formatting Refactoring
src/openms/source/KERNEL/DimMapper.cpp
Introduced internal helper function formatWithGroupSeparators to replace QLocale-based numeric formatting; added <charconv> and <cmath> includes; removed Qt QLocale dependency from DimBase::formattedValue.

Poem

🐰 Numbers dance in comma rows,
A new formatter gently flows,
No Qt needed anymore,
Digits grouped and cleanly scored,
Thousands separated with care—
Formatting magic fills the air! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Remove Qt dependency from DimMapper formatting' accurately summarizes the main change: replacing Qt's QLocale-based formatting with standard C++ implementation in DimMapper.cpp.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/openms/source/KERNEL/DimMapper.cpp (1)

29-76: Well-structured implementation with correct handling of edge cases.

The algorithm correctly handles NaN/Inf, negative values, and group separator insertion. A few minor observations:

  1. Line 59: Uses int instead of Size/SignedSize for .size(). This is acceptable here since the value is bounded by the digit count of a double (~309 max), but consider using SignedSize for consistency with coding guidelines.

  2. Line 41: The fallback std::to_string(value) won't include group separators, but the 512-byte buffer makes this effectively unreachable.

♻️ Optional: Use OpenMS types for stricter guideline compliance
-      int len = static_cast<int>(integer_part.size());
+      SignedSize len = static_cast<SignedSize>(integer_part.size());
       if (len > 3)
       {
         std::string formatted;
-        int first_group = len % 3;
+        SignedSize first_group = len % 3;
         if (first_group == 0)
           first_group = 3;
-        formatted = integer_part.substr(0, first_group);
-        for (int i = first_group; i < len; i += 3)
+        formatted = integer_part.substr(0, static_cast<size_t>(first_group));
+        for (SignedSize i = first_group; i < len; i += 3)
         {
           formatted += ',';
-          formatted += integer_part.substr(i, 3);
+          formatted += integer_part.substr(static_cast<size_t>(i), 3);
         }

Based on learnings: "use Size/SignedSize for STL .size() values in C++".

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

In `@src/openms/source/KERNEL/DimMapper.cpp` around lines 29 - 76, The function
formatWithGroupSeparators currently uses a plain int for the integer-part
length; change that to the OpenMS signed size alias (SignedSize) to match
project guidelines and avoid implicit narrowing — update the variable
declaration for len and any related arithmetic to use SignedSize, keeping the
rest of the logic identical; also optionally replace any other plain int loop
indices in this function (e.g., the loop variable i) with SignedSize to maintain
consistency with OpenMS container sizing conventions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/openms/source/KERNEL/DimMapper.cpp`:
- Around line 29-76: The function formatWithGroupSeparators currently uses a
plain int for the integer-part length; change that to the OpenMS signed size
alias (SignedSize) to match project guidelines and avoid implicit narrowing —
update the variable declaration for len and any related arithmetic to use
SignedSize, keeping the rest of the logic identical; also optionally replace any
other plain int loop indices in this function (e.g., the loop variable i) with
SignedSize to maintain consistency with OpenMS container sizing conventions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1afd0389-815f-457a-b36e-a3b3860281cc

📥 Commits

Reviewing files that changed from the base of the PR and between 1ff4dd0 and 6c6d940.

📒 Files selected for processing (1)
  • src/openms/source/KERNEL/DimMapper.cpp

@timosachsenberg
timosachsenberg merged commit 9eba1a9 into OpenMS:develop Mar 18, 2026
16 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