Skip to content

Commit

Permalink
implement TimeRangeEditor pb_begin_to_last_end
Browse files Browse the repository at this point in the history
  • Loading branch information
pasbi committed Dec 8, 2024
1 parent 7099943 commit 3c1f0b6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
21 changes: 16 additions & 5 deletions src/timerangeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,37 @@

#include "application.h"
#include "datetimeselector.h"
#include "intervalmodel.h"
#include "ui_timerangeeditor.h"

#include <QMessageBox>

TimeRangeEditor::TimeRangeEditor(QWidget* const parent)
TimeRangeEditor::TimeRangeEditor(const IntervalModel& interval_model, QWidget* const parent)
: QDialog(parent), m_ui(std::make_unique<Ui::TimeRangeEditor>())
{
m_ui->setupUi(this);
connect(m_ui->cb_has_end, &QCheckBox::toggled, this, &TimeRangeEditor::update_enabledness);
connect(m_ui->pb_begin_to_last_end, &QPushButton::clicked, this, []() {});
connect(m_ui->pb_begin_to_last_end, &QPushButton::clicked, this, [&interval_model, this]() {
auto ends_view =
interval_model.intervals() | std::views::transform(&Interval::end) | std::views::filter(&QDateTime::isValid);
if (const std::vector ends(ends_view.begin(), ends_view.end()); ends.empty()) {
QMessageBox::critical(this, "Error", "No end intervals were found");
} else {
const auto end = std::ranges::max_element(ends);
m_ui->de_begin->setDate(end->date());
m_ui->te_begin->setTime(end->time());
}
});
connect(m_ui->pb_begin_to_now, &QPushButton::clicked, this, [this]() {
m_ui->te_begin->setDate(Application::current_date_time().date());
m_ui->de_begin->setTime(Application::current_date_time().time());
m_ui->te_begin->setTime(Application::current_date_time().time());
m_ui->de_begin->setDate(Application::current_date_time().date());
});
connect(m_ui->pb_end_to_begin, &QPushButton::clicked, this, [this]() {
m_ui->te_end->setTime(m_ui->te_begin->time());
m_ui->sp_end_offset->setValue(0);
});
connect(m_ui->pb_end_to_now, &QPushButton::clicked, this, [this]() {
const auto offset = m_ui->te_begin->date().daysTo(Application::current_date_time().date());
const auto offset = m_ui->de_begin->date().daysTo(Application::current_date_time().date());
m_ui->sp_end_offset->setValue(offset);
m_ui->te_end->setTime(Application::current_date_time().time());
});
Expand Down
3 changes: 2 additions & 1 deletion src/timerangeeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QDateTime>
#include <QDialog>

class IntervalModel;
namespace Ui
{
class TimeRangeEditor;
Expand All @@ -13,7 +14,7 @@ class TimeRangeEditor : public QDialog
Q_OBJECT

public:
explicit TimeRangeEditor(QWidget* parent = nullptr);
explicit TimeRangeEditor(const IntervalModel& interval_model, QWidget* parent = nullptr);
~TimeRangeEditor() override;

void set_range(const QDateTime& begin, const QDateTime& end);
Expand Down
2 changes: 1 addition & 1 deletion src/views/perioddetailview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void PeriodDetailView::show_table_context_menu(const QPoint& pos)

void PeriodDetailView::edit_date_time(const QModelIndex& index) const
{
TimeRangeEditor e;
TimeRangeEditor e{time_sheet()->interval_model()};
auto& interval = *time_sheet()->interval_model().intervals().at(index.row());
e.set_range(interval.begin(), interval.end());
if (e.exec() == QDialog::Accepted) {
Expand Down

0 comments on commit 3c1f0b6

Please sign in to comment.