Repository navigation
refactor: replace QDateTime/QDate/QSysInfo/QLocale with std::chrono - #8937
Conversation
…nd platform APIs Remove Qt dependencies from DateTime, Date, BuildInfo, DimMapper, and TOPPBase. DateTime and Date now use plain struct Fields with sscanf/snprintf for parsing and formatting instead of QDateTime/QDate via unique_ptr PImpl. BuildInfo uses platform APIs (RtlGetVersion, sysctlbyname, /etc/os-release) instead of QSysInfo. DimMapper uses a custom snprintf-based formatter with comma group separators instead of QLocale. TOPPBase uses DateTime::now().get() instead of QDateTime::currentDateTime(). All DateTime_test and Date_test cases pass unchanged (except removing the QDate constructor test from Date_test since that constructor was removed). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Guard toString() against invalid DateTime (return empty string) - Normalize millisecond parsing (sscanf %d ignores width, so ".4" was read as 4 instead of 400; now count fractional digits and scale) - Handle ISO datetime with milliseconds but no timezone in set() (e.g. "2011-08-05T15:32:07.468" was falling to the plain ISO branch) - Replace locale-dependent snprintf with std::to_chars in DimMapper formatWithGroupSeparators to avoid decimal comma on non-C locales Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
📝 WalkthroughWalkthroughReplaces Qt-based Date/DateTime storage and formatting with lightweight internal Fields structs, defaulted special members, custom parsing/validation, and std::chrono-based now/nowUTC; adds platform-aware OS version helper, removes several Qt locale/time dependencies, and updates related logging, formatting, and tests. Changes
Suggested reviewers
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 docstrings
🧪 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/DATASTRUCTURES/DateTime.cpp (1)
188-345: Complex but necessary parsing logic.Static analysis flagged this method as complex (188-346), which is accurate given the many date formats supported. The parsing handles:
- German, US, ISO formats
- ISO with/without milliseconds
- ISO with timezone suffixes (stripped)
- Legacy protXML formats
The millisecond normalization logic (lines 224-232, 249-257) is duplicated. Consider extracting to a helper:
♻️ Optional: Extract millisecond normalization
// Add helper function near other helpers: static int normalizeMilliseconds_(int millisecond, size_t frac_digits) { for (size_t i = frac_digits; i < 3; ++i) millisecond *= 10; return millisecond % 1000; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/DATASTRUCTURES/DateTime.cpp` around lines 188 - 345, The DateTime::set method contains duplicated millisecond-normalization logic in the ISO-with-timezone branch and the ISO-no-timezone branch; extract that logic into a new static helper (e.g., normalizeMilliseconds_(int millisecond, size_t frac_digits)) placed near other helpers (same translation unit), implement the normalization there (multiply until 3 digits then modulo 1000) and replace the duplicated loops in DateTime::set with calls to normalizeMilliseconds_, updating the code paths that compute frac_digits (keep computing frac_digits via find('.') and digit scan) and then assign fields_.millisecond from the helper result before setting fields_.valid.
🤖 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/DATASTRUCTURES/DateTime.cpp`:
- Around line 188-345: The DateTime::set method contains duplicated
millisecond-normalization logic in the ISO-with-timezone branch and the
ISO-no-timezone branch; extract that logic into a new static helper (e.g.,
normalizeMilliseconds_(int millisecond, size_t frac_digits)) placed near other
helpers (same translation unit), implement the normalization there (multiply
until 3 digits then modulo 1000) and replace the duplicated loops in
DateTime::set with calls to normalizeMilliseconds_, updating the code paths that
compute frac_digits (keep computing frac_digits via find('.') and digit scan)
and then assign fields_.millisecond from the helper result before setting
fields_.valid.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3a8684d4-d32c-45b1-a1b0-733ffda52108
📒 Files selected for processing (8)
src/openms/include/OpenMS/DATASTRUCTURES/Date.hsrc/openms/include/OpenMS/DATASTRUCTURES/DateTime.hsrc/openms/include/OpenMS/SYSTEM/BuildInfo.hsrc/openms/source/APPLICATIONS/TOPPBase.cppsrc/openms/source/DATASTRUCTURES/Date.cppsrc/openms/source/DATASTRUCTURES/DateTime.cppsrc/openms/source/KERNEL/DimMapper.cppsrc/tests/class_tests/openms/source/Date_test.cpp
Clang reports ambiguity between String and std::string operator+ when mixing const char* with std::string. Explicit std::string cast. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/openms/source/KERNEL/DimMapper.cpp (2)
14-15: Consider removing unused includes.
<cstdio>and<cstring>don't appear to be used in this file after the refactor. If they were previously needed for Qt interop and are now dead, consider removing them.🤖 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 14 - 15, Remove the unused C headers from DimMapper.cpp: delete the `#include` <cstdio> and `#include` <cstring> lines (they appear unused after the refactor in src/openms/source/KERNEL/DimMapper.cpp); after removing them, rebuild to ensure no missing symbols and, if the compiler complains, re-add only the specific header(s) actually required by functions referenced in this file.
58-58: UseSizeorSignedSizeinstead of(int)cast for.size().Per coding guidelines, STL
.size()values should useSize/SignedSizetypes rather than rawint.♻️ Proposed fix
- int len = (int)integer_part.size(); + SignedSize len = static_cast<SignedSize>(integer_part.size());Note: You'll also need to adjust the loop variable
ion line 65 accordingly, or useSize(unsigned) if negative indices aren't needed.As per coding guidelines: "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` at line 58, Change the type of len from int to the appropriate OpenMS size type (Size or SignedSize) when assigning from integer_part.size(), i.e. replace the cast "(int)integer_part.size()" with a Size/SignedSize variable; also update the loop index variable used later (the loop using i around the code referencing len) to match the chosen signedness (use SignedSize if the loop uses negative values or subtraction, otherwise use Size) so types are consistent with integer_part.size().
🤖 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/openms/source/KERNEL/DimMapper.cpp`:
- Around line 36-39: The call to std::to_chars stores an error code in ec but
never checks it; validate ec after std::to_chars (check ec != std::errc() or ec
== std::errc::value_too_large) and handle failures before using ptr or
constructing result. On error, provide a safe fallback (e.g., format with
snprintf/ostringstream, or set a sentinel string like "nan"/"inf" or log/throw),
using the same variables (buf, ptr, ec, result) so you don't build result from
an indeterminate buffer.
---
Nitpick comments:
In `@src/openms/source/KERNEL/DimMapper.cpp`:
- Around line 14-15: Remove the unused C headers from DimMapper.cpp: delete the
`#include` <cstdio> and `#include` <cstring> lines (they appear unused after the
refactor in src/openms/source/KERNEL/DimMapper.cpp); after removing them,
rebuild to ensure no missing symbols and, if the compiler complains, re-add only
the specific header(s) actually required by functions referenced in this file.
- Line 58: Change the type of len from int to the appropriate OpenMS size type
(Size or SignedSize) when assigning from integer_part.size(), i.e. replace the
cast "(int)integer_part.size()" with a Size/SignedSize variable; also update the
loop index variable used later (the loop using i around the code referencing
len) to match the chosen signedness (use SignedSize if the loop uses negative
values or subtraction, otherwise use Size) so types are consistent with
integer_part.size().
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: fadc9dd4-dc40-4824-ab1d-26bcf7f76f8e
📒 Files selected for processing (1)
src/openms/source/KERNEL/DimMapper.cpp
Wrap formatWithGroupSeparators() return value in String() to avoid Clang ambiguity between OpenMS::String and std::string operator+. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
🧹 Nitpick comments (3)
src/openms/source/KERNEL/DimMapper.cpp (3)
63-63: Single-line if statement should use braces.As per coding guidelines, use braces even for single-line blocks in C++.
♻️ Proposed fix
- if (first_group == 0) first_group = 3; + if (first_group == 0) + { + first_group = 3; + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/KERNEL/DimMapper.cpp` at line 63, Replace the single-line if statement that sets first_group with a braced block: locate the statement "if (first_group == 0) first_group = 3;" in DimMapper.cpp and rewrite it to use braces around the assignment (i.e., if (first_group == 0) { first_group = 3; }) so it follows the project's C++ coding guideline for using braces even for single-line blocks.
14-15: Unused includes.
<cstdio>and<cstring>are included but not used in the current implementation. If these were intended for fallback error handling (as suggested in past reviews), they can be removed if not implementing that path, or kept if you plan to add the error handling.♻️ Proposed cleanup
`#include` <charconv> -#include <cstdio> -#include <cstring> `#include` <string>🤖 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 14 - 15, The includes <cstdio> and <cstring> in DimMapper.cpp are unused; remove these two headers from the top of src/openms/source/KERNEL/DimMapper.cpp (leave any other existing includes) or reintroduce them only if you will add fallback error handling that requires C stdio/string functions; specifically update the include block in the DimMapper.cpp file so only the actually used headers remain (remove the lines with `#include` <cstdio> and `#include` <cstring>).
58-58: Consider usingSignedSizefor.size()result.Per coding guidelines, prefer
Size/SignedSizefor STL.size()values. Whileintworks fine here given the bounded string length, usingSignedSizewould be more consistent with the codebase style.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/KERNEL/DimMapper.cpp` at line 58, Replace the use of a plain int for the length with the project's SignedSize type: change the declaration "int len = (int)integer_part.size();" to use SignedSize (e.g. "SignedSize len = static_cast<SignedSize>(integer_part.size());") so the variable type matches the codebase convention for .size() results; locate this change in DimMapper.cpp where the integer_part and len variables are used.
🤖 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`:
- Line 63: Replace the single-line if statement that sets first_group with a
braced block: locate the statement "if (first_group == 0) first_group = 3;" in
DimMapper.cpp and rewrite it to use braces around the assignment (i.e., if
(first_group == 0) { first_group = 3; }) so it follows the project's C++ coding
guideline for using braces even for single-line blocks.
- Around line 14-15: The includes <cstdio> and <cstring> in DimMapper.cpp are
unused; remove these two headers from the top of
src/openms/source/KERNEL/DimMapper.cpp (leave any other existing includes) or
reintroduce them only if you will add fallback error handling that requires C
stdio/string functions; specifically update the include block in the
DimMapper.cpp file so only the actually used headers remain (remove the lines
with `#include` <cstdio> and `#include` <cstring>).
- Line 58: Replace the use of a plain int for the length with the project's
SignedSize type: change the declaration "int len = (int)integer_part.size();" to
use SignedSize (e.g. "SignedSize len =
static_cast<SignedSize>(integer_part.size());") so the variable type matches the
codebase convention for .size() results; locate this change in DimMapper.cpp
where the integer_part and len variables are used.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2fa6c472-d7e2-4171-ba82-2a6ef167e5b9
📒 Files selected for processing (1)
src/openms/source/KERNEL/DimMapper.cpp
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
…rs (#8947) 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 #8937. https://claude.ai/code/session_015odPaUy23pSDYFufRXv4Rr Co-authored-by: Claude <[email protected]>
Add changelog entries for three Qt-removal refactors merged since the last sync (2026-03-19): - #8937: QDateTime/QDate/QSysInfo/QLocale replaced with std::chrono (BREAKING: QDate constructor removed from Date class) - #8938: QDir/QFile/QFileInfo replaced with std::filesystem (BREAKING: copyDirRecursively/removeDir signatures, ToolHandler return type) - #8939: QProcess/QObject replaced with boost::process (BREAKING: ExternalProcess/TOPPBase/RWrapper APIs; boost-process added) Co-authored-by: Copilot <[email protected]>
Document the incremental Qt removal from libOpenMS core library: - QDateTime/QDate/QSysInfo/QLocale replaced by std::chrono (#8937) - QDir/QFile/QFileInfo replaced by std::filesystem (#8938) - QProcess/QObject replaced by boost::process (#8939) - QJsonDocument/QJsonObject replaced by nlohmann/json (#8936) These changes landed after the 2026-03-19 changelog sync and represent significant steps toward making Qt6 optional for the core library. Co-authored-by: Copilot <[email protected]>
Add changelog entries for three Qt-removal refactors merged since the last sync (2026-03-19): - #8937: QDateTime/QDate/QSysInfo/QLocale replaced with std::chrono (BREAKING: QDate constructor removed from Date class) - #8938: QDir/QFile/QFileInfo replaced with std::filesystem (BREAKING: copyDirRecursively/removeDir signatures, ToolHandler return type) - #8939: QProcess/QObject replaced with boost::process (BREAKING: ExternalProcess/TOPPBase/RWrapper APIs; boost-process added) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <[email protected]>
Document the incremental Qt removal from libOpenMS core library: - QDateTime/QDate/QSysInfo/QLocale replaced by std::chrono (#8937) - QDir/QFile/QFileInfo replaced by std::filesystem (#8938) - QProcess/QObject replaced by boost::process (#8939) - QJsonDocument/QJsonObject replaced by nlohmann/json (#8936) These changes landed after the 2026-03-19 changelog sync and represent significant steps toward making Qt6 optional for the core library. Co-authored-by: GitHub Copilot <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Timo Sachsenberg <[email protected]>
After the Qt removal refactoring (#8937-#8940, #8965), Qt6::Core is no longer a dependency of libOpenMS itself. Update AGENTS.md to reflect that Qt6 is required only for TOPP tools and GUI (openms_gui) builds, and is optional when building only the core library or pyOpenMS. Co-authored-by: Copilot <[email protected]>
…8977) After the Qt removal refactoring (#8937-#8940, #8965), Qt6::Core is no longer a dependency of libOpenMS itself. Update AGENTS.md to reflect that Qt6 is required only for TOPP tools and GUI (openms_gui) builds, and is optional when building only the core library or pyOpenMS. Co-authored-by: GitHub Copilot <[email protected]> Co-authored-by: Copilot <[email protected]>
Summary
unique_ptr<QDateTime/QDate>pimpl to plain structTest plan
🤖 Generated with Claude Code
Summary by CodeRabbit
Refactor
Tests