|
26 | 26 | #include <algorithm> // for any_of, find_if |
27 | 27 | #include <filesystem> // for exists |
28 | 28 | #include <future> |
29 | | -#include <ranges> // for ranges::* |
30 | | -#include <span> // for span |
31 | | -#include <thread> // for this_thread |
| 29 | +#include <ranges> // for ranges::* |
| 30 | +#include <span> // for span |
| 31 | +#include <string_view> // for string_view |
| 32 | +#include <thread> // for this_thread |
32 | 33 |
|
33 | 34 | #include <fmt/core.h> |
34 | 35 |
|
@@ -87,7 +88,7 @@ bool is_kernels_change_state(alpm_handle_t* handle, std::span<std::string_view> |
87 | 88 |
|
88 | 89 | void init_kernels_tree_widget(QTreeWidget* tree_kernels, std::span<Kernel> kernels) noexcept { |
89 | 90 | for (auto& kernel : kernels) { |
90 | | - auto* widget_item = new QTreeWidgetItem(tree_kernels); |
| 91 | + auto* widget_item = new KernelTreeWidgetItem(tree_kernels); |
91 | 92 | widget_item->setCheckState(TreeCol::Check, Qt::Unchecked); |
92 | 93 | widget_item->setText(TreeCol::PkgName, kernel.get_raw()); |
93 | 94 | widget_item->setText(TreeCol::Version, QString::fromStdString(kernel.version())); |
@@ -386,4 +387,27 @@ void MainWindow::on_schedext_config() noexcept { |
386 | 387 | m_sched_window->show(); |
387 | 388 | } |
388 | 389 |
|
| 390 | +bool KernelTreeWidgetItem::operator<(const QTreeWidgetItem& other) const { |
| 391 | + const auto sort_col = treeWidget()->sortColumn(); |
| 392 | + if (sort_col != TreeCol::Version) { |
| 393 | + return QTreeWidgetItem::operator<(other); |
| 394 | + } |
| 395 | + |
| 396 | + auto get_comparable_version = [](QString&& version_string) { |
| 397 | + using namespace std::string_view_literals; |
| 398 | + auto std_str = std::move(version_string).toStdString(); |
| 399 | + for (auto&& prefix : {"∨"sv, "∧"sv}) { |
| 400 | + if (std_str.starts_with(prefix)) { |
| 401 | + return std_str.substr(prefix.size()); |
| 402 | + } |
| 403 | + } |
| 404 | + return std_str; |
| 405 | + }; |
| 406 | + |
| 407 | + const auto& version_a = get_comparable_version(text(sort_col)); |
| 408 | + const auto& version_b = get_comparable_version(other.text(sort_col)); |
| 409 | + |
| 410 | + return alpm_pkg_vercmp(version_a.c_str(), version_b.c_str()) < 0; |
| 411 | +} |
| 412 | + |
389 | 413 | // NOLINTEND(bugprone-unhandled-exception-at-new) |
0 commit comments