From 70999431a527d25f69a7d2c9400a3b3790d29d15 Mon Sep 17 00:00:00 2001 From: pascal Date: Sun, 8 Dec 2024 18:51:16 +0100 Subject: [PATCH] find_open_intervals is a member of IntervalModel --- src/intervalmodel.cpp | 7 +++++++ src/intervalmodel.h | 1 + src/mainwindow.cpp | 10 ++-------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/intervalmodel.cpp b/src/intervalmodel.cpp index d4ee04a..22ac863 100644 --- a/src/intervalmodel.cpp +++ b/src/intervalmodel.cpp @@ -187,6 +187,13 @@ const Interval* IntervalModel::interval(const std::size_t index) const return m_intervals.at(index).get(); } +std::vector IntervalModel::open_intervals() const +{ + auto view = m_intervals | std::views::filter([](const auto& interval) { return !interval->end().isValid(); }) + | std::views::transform(&std::unique_ptr::get); + return std::vector(view.begin(), view.end()); +} + std::chrono::minutes IntervalModel::minutes(const std::optional& period, const std::optional& name) const { diff --git a/src/intervalmodel.h b/src/intervalmodel.h index 6df3634..2954473 100644 --- a/src/intervalmodel.h +++ b/src/intervalmodel.h @@ -40,6 +40,7 @@ class IntervalModel final : public QAbstractTableModel [[nodiscard]] std::vector intervals() const; [[nodiscard]] std::vector intervals(const Period& period) const; [[nodiscard]] const Interval* interval(std::size_t index) const; + [[nodiscard]] std::vector open_intervals() const; Q_SIGNALS: void data_changed(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 006e87b..e56f3a8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -30,12 +30,6 @@ constexpr auto extension = ".ts"; return QObject::tr("Time Sheets (*%1)").arg(extension); } -auto find_open_intervals(const std::vector& intervals) -{ - auto view = intervals | std::views::filter([](const auto* const interval) { return !interval->end().isValid(); }); - return std::vector(view.begin(), view.end()); -} - } // namespace MainWindow::MainWindow(QWidget* parent) @@ -129,7 +123,7 @@ void MainWindow::set_filename(std::filesystem::path filename) void MainWindow::end_task() { auto& interval_model = m_time_sheet->interval_model(); - const auto open_intervals = ::find_open_intervals(interval_model.intervals()); + const auto open_intervals = interval_model.open_intervals(); if (const auto n = open_intervals.size(); n != 1) { QMessageBox::warning( this, QApplication::applicationDisplayName(), @@ -145,7 +139,7 @@ void MainWindow::end_task() void MainWindow::switch_task() { auto& interval_model = m_time_sheet->interval_model(); - const auto open_intervals = ::find_open_intervals(interval_model.intervals()); + const auto open_intervals = interval_model.open_intervals(); if (const auto n = open_intervals.size(); n > 1) { QMessageBox::warning( this, QApplication::applicationDisplayName(),