Repository navigation
Remove Qt dependency from DimMapper formatting - #8947
Conversation
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
📝 WalkthroughWalkthroughThis 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
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
There was a problem hiding this comment.
🧹 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:
Line 59: Uses
intinstead ofSize/SignedSizefor.size(). This is acceptable here since the value is bounded by the digit count of a double (~309 max), but consider usingSignedSizefor consistency with coding guidelines.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/SignedSizefor 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
📒 Files selected for processing (1)
src/openms/source/KERNEL/DimMapper.cpp
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:std::to_chars()for efficient double-to-string conversionChecklist
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