Commit 6f859a64 authored by Glen Ditchfield's avatar Glen Ditchfield 🐛
Browse files

Edit start dates in the Todo view

Let the user edit start dates by right-clicking in the start date
column.  If the new start date is later than a pre-existing due date,
the due date is adjusted.

Note:  to preserve TodoView's ABI, I put the new popup menu in TodoViewView.
parent 6a6d7327
Pipeline #175213 skipped
......@@ -384,6 +384,7 @@ TodoView::TodoView(const EventViews::PrefsPtr &prefs, bool sidebarView, QWidget
mMovePopupMenu->setTitle(i18nc("@title:menu", "&Move To"));
connect(mMovePopupMenu, &CalendarSupport::KDatePickerPopup::dateChanged, this, &TodoView::setNewDate);
connect(mView->startPopupMenu(), &CalendarSupport::KDatePickerPopup::dateChanged, this, &TodoView::setStartDate);
connect(mMovePopupMenu, &CalendarSupport::KDatePickerPopup::dateChanged, mItemPopupMenu, &QMenu::hide);
......@@ -708,6 +709,8 @@ void TodoView::contextMenu(QPoint pos)
mPercentageCompletedPopupMenu->popup(mView->viewport()->mapToGlobal(pos));
break;
case TodoModel::StartDateColumn:
mView->startPopupMenu()->popup(mView->viewport()->mapToGlobal(pos));
break;
case TodoModel::DueDateColumn:
mMovePopupMenu->popup(mView->viewport()->mapToGlobal(pos));
break;
......@@ -922,6 +925,37 @@ void TodoView::setNewDate(QDate date)
}
}
void TodoView::setStartDate(QDate date)
{
QModelIndexList selection = mView->selectionModel()->selectedRows();
if (selection.size() != 1) {
return;
}
const auto todoItem = selection[0].data(TodoModel::TodoRole).value<Akonadi::Item>();
KCalendarCore::Todo::Ptr todo = CalendarSupport::todo(todoItem);
Q_ASSERT(todo);
if (calendar()->hasRight(todoItem, Akonadi::Collection::CanChangeItem)) {
KCalendarCore::Todo::Ptr oldTodo(todo->clone());
QDateTime dt(date.startOfDay());
if (!todo->allDay()) {
dt.setTime(todo->dtStart().time());
}
if (todo->hasDueDate() && dt > todo->dtDue()) {
todo->setDtDue(dt);
}
todo->setDtStart(dt);
changer()->modifyIncidence(todoItem, oldTodo, this);
} else {
qCDebug(CALENDARVIEW_LOG) << "Item is readOnly";
}
}
void TodoView::setNewPercentage(QAction *action)
{
QModelIndexList selection = mView->selectionModel()->selectedRows();
......
......@@ -120,6 +120,7 @@ private Q_SLOTS:
void resizeColumns();
void itemDoubleClicked(const QModelIndex &index);
void setNewDate(QDate date);
void setStartDate(QDate date);
void setNewPercentage(QAction *action);
void setNewPriority(QAction *action);
void changedCategories(QAction *action);
......
......@@ -8,6 +8,8 @@
#include "todoviewview.h"
#include <CalendarSupport/KDatePickerPopup>
#include <KLocalizedString>
#include <QMenu>
......@@ -28,6 +30,9 @@ TodoViewView::TodoViewView(QWidget *parent)
connect(&mExpandTimer, &QTimer::timeout, this, &TodoViewView::expandParent);
mExpandTimer.setInterval(1s);
header()->setStretchLastSection(false);
mStartPopupMenu = new CalendarSupport::KDatePickerPopup(
CalendarSupport::KDatePickerPopup::NoDate | CalendarSupport::KDatePickerPopup::DatePicker | CalendarSupport::KDatePickerPopup::Words,
QDate::currentDate(), this);
}
bool TodoViewView::isEditing(const QModelIndex &index) const
......@@ -67,6 +72,11 @@ bool TodoViewView::eventFilter(QObject *watched, QEvent *event)
return false;
}
CalendarSupport::KDatePickerPopup *TodoViewView::startPopupMenu()
{
return mStartPopupMenu;
}
void TodoViewView::toggleColumnHidden(QAction *action)
{
if (action->isChecked()) {
......
......@@ -13,6 +13,11 @@
class QMenu;
namespace CalendarSupport
{
class KDatePickerPopup;
}
class TodoViewView : public QTreeView
{
Q_OBJECT
......@@ -23,6 +28,7 @@ public:
Q_REQUIRED_RESULT bool isEditing(const QModelIndex &index) const;
Q_REQUIRED_RESULT bool eventFilter(QObject *watched, QEvent *event) override;
Q_REQUIRED_RESULT CalendarSupport::KDatePickerPopup *startPopupMenu();
protected:
QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
......@@ -38,6 +44,9 @@ private:
QTimer mExpandTimer;
bool mIgnoreNextMouseRelease = false;
// TODO KF6: move this next to TodoView::mMovePopupMenu.
CalendarSupport::KDatePickerPopup *mStartPopupMenu = nullptr;
Q_SIGNALS:
void visibleColumnCountChanged();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment