diff options
| author | Dave Hibberd <hibby@debian.org> | 2026-10-20 22:35:06 +0100 |
|---|---|---|
| committer | Dave Hibberd <hibby@debian.org> | 2026-10-20 22:35:06 +0100 |
| commit | 82ebb1ed1af30cee4dfbb1c628431d32885a00e0 (patch) | |
| tree | 1a1f782d3e576b758be0bc61171574a7cd8f2376 /qt_helpers.cpp | |
| parent | 061658210acb6425517733ea012dda803a7f72a1 (diff) | |
| parent | 61d684922b0f1c8455cc60eb3d123df058c9e1f5 (diff) | |
Merge tag 'debian/3.3.0_beta2+dfsg-1' into hibbian/trixie-backports
tagging wsjtx 3.3.0~beta2+dfsg-1
Diffstat (limited to 'qt_helpers.cpp')
| -rw-r--r-- | qt_helpers.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/qt_helpers.cpp b/qt_helpers.cpp index a9e5b14d..7f4ceaf8 100644 --- a/qt_helpers.cpp +++ b/qt_helpers.cpp @@ -18,6 +18,33 @@ #include "wsjtx_config.h" #endif +bool serial_port_name_less (QString const& lhs, QString const& rhs) +{ + auto suffix_start = [] (QString const& name) { + auto pos = name.size (); + while (pos && name.at (pos - 1) >= QLatin1Char {'0'} + && name.at (pos - 1) <= QLatin1Char {'9'}) --pos; + return pos; + }; + auto const lhs_start = suffix_start (lhs); + auto const rhs_start = suffix_start (rhs); + auto const prefix_order = lhs.leftRef (lhs_start).compare (rhs.leftRef (rhs_start)); + if (prefix_order) return prefix_order < 0; + if (lhs_start == lhs.size () || rhs_start == rhs.size ()) return lhs < rhs; + + auto significant_digits = [] (QString const& name, int pos) { + while (pos < name.size () && name.at (pos) == QLatin1Char {'0'}) ++pos; + return name.midRef (pos); + }; + auto const lhs_number = significant_digits (lhs, lhs_start); + auto const rhs_number = significant_digits (rhs, rhs_start); + // Comparing digits avoids overflow for long device identifiers. + if (lhs_number.size () != rhs_number.size ()) return lhs_number.size () < rhs_number.size (); + auto const number_order = lhs_number.compare (rhs_number); + if (number_order) return number_order < 0; + return lhs < rhs; +} + QString font_as_stylesheet (QFont const& font) { QString font_weight; |
