File indexing completed on 2025-01-19 04:56:39
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Kevin Ottens <ervin@kde.org> 0003 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 0007 0008 #ifndef PRESENTATION_EDITORMODEL_H 0009 #define PRESENTATION_EDITORMODEL_H 0010 0011 #include <QDate> 0012 #include <QObject> 0013 0014 #include <functional> 0015 0016 #include "domain/task.h" 0017 0018 #include "presentation/errorhandlingmodelbase.h" 0019 0020 class QAbstractItemModel; 0021 class QTimer; 0022 0023 namespace Presentation { 0024 0025 class AttachmentModel; 0026 0027 class EditorModel : public QObject, public ErrorHandlingModelBase 0028 { 0029 Q_OBJECT 0030 Q_PROPERTY(Domain::Task::Ptr task READ task WRITE setTask NOTIFY taskChanged) 0031 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) 0032 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) 0033 Q_PROPERTY(bool done READ isDone WRITE setDone NOTIFY doneChanged) 0034 Q_PROPERTY(QDate startDate READ startDate WRITE setStartDate NOTIFY startDateChanged) 0035 Q_PROPERTY(QDate dueDate READ dueDate WRITE setDueDate NOTIFY dueDateChanged) 0036 Q_PROPERTY(Domain::Task::Recurrence recurrence READ recurrence WRITE setRecurrence NOTIFY recurrenceChanged) 0037 Q_PROPERTY(QAbstractItemModel* attachmentModel READ attachmentModel CONSTANT) 0038 Q_PROPERTY(bool editingInProgress READ editingInProgress WRITE setEditingInProgress) 0039 0040 public: 0041 typedef std::function<KJob*(const Domain::Task::Ptr &)> SaveFunction; 0042 0043 explicit EditorModel(QObject *parent = nullptr); 0044 ~EditorModel(); 0045 0046 Domain::Task::Ptr task() const; 0047 void setTask(const Domain::Task::Ptr &task); 0048 0049 bool hasSaveFunction() const; 0050 void setSaveFunction(const SaveFunction &function); 0051 0052 QString text() const; 0053 QString title() const; 0054 bool isDone() const; 0055 QDate startDate() const; 0056 QDate dueDate() const; 0057 Domain::Task::Recurrence recurrence() const; 0058 QAbstractItemModel *attachmentModel() const; 0059 0060 static int autoSaveDelay(); 0061 static void setAutoSaveDelay(int delay); 0062 0063 bool editingInProgress() const; 0064 0065 public slots: 0066 void setText(const QString &text); 0067 void setTitle(const QString &title); 0068 void setDone(bool done); 0069 void setStartDate(const QDate &start); 0070 void setDueDate(const QDate &due); 0071 void setRecurrence(Domain::Task::Recurrence recurrence); 0072 0073 void addAttachment(const QString &fileName); 0074 void removeAttachment(const QModelIndex &index); 0075 void openAttachment(const QModelIndex &index); 0076 0077 void setEditingInProgress(bool editingInProgress); 0078 0079 signals: 0080 void taskChanged(const Domain::Task::Ptr &task); 0081 void textChanged(const QString &text); 0082 void titleChanged(const QString &title); 0083 void doneChanged(bool done); 0084 void startDateChanged(const QDate &date); 0085 void dueDateChanged(const QDate &due); 0086 void recurrenceChanged(Domain::Task::Recurrence recurrence); 0087 0088 private slots: 0089 void onTextChanged(const QString &text); 0090 void onTitleChanged(const QString &title); 0091 void onDoneChanged(bool done); 0092 void onStartDateChanged(const QDate &start); 0093 void onDueDateChanged(const QDate &due); 0094 void onRecurrenceChanged(Domain::Task::Recurrence recurrence); 0095 0096 void save(); 0097 0098 private: 0099 void setSaveNeeded(bool needed); 0100 bool isSaveNeeded() const; 0101 void applyNewText(const QString &text); 0102 void applyNewTitle(const QString &title); 0103 void applyNewDone(bool done); 0104 void applyNewStartDate(const QDate &start); 0105 void applyNewDueDate(const QDate &due); 0106 void applyNewRecurrence(Domain::Task::Recurrence recurrence); 0107 0108 Domain::Task::Ptr m_task; 0109 SaveFunction m_saveFunction; 0110 0111 QString m_text; 0112 QString m_title; 0113 bool m_done; 0114 QDate m_start; 0115 QDate m_due; 0116 Domain::Task::Recurrence m_recurrence; 0117 AttachmentModel *m_attachmentModel; 0118 0119 QTimer *m_saveTimer; 0120 bool m_saveNeeded; 0121 bool m_editingInProgress; 0122 }; 0123 0124 } 0125 0126 #endif // PRESENTATION_EDITORMODEL_H