File indexing completed on 2024-11-17 04:49:34
0001 /* 0002 * Copyright (c) 2019 Alexander Potashev <aspotashev@gmail.com> 0003 * 0004 * This program is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU General Public License as 0006 * published by the Free Software Foundation; either version 2 of 0007 * the License or (at your option) version 3 or any later version 0008 * accepted by the membership of KDE e.V. (or its successor approved 0009 * by the membership of KDE e.V.), which shall act as a proxy 0010 * defined in Section 14 of version 3 of the license. 0011 * 0012 * This program is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 * GNU General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU General Public License 0018 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 #ifndef KTIMETRACKER_TASKSMODEL_H 0022 #define KTIMETRACKER_TASKSMODEL_H 0023 0024 #include <QAbstractItemModel> 0025 0026 QT_BEGIN_NAMESPACE 0027 class QMovie; 0028 QT_END_NAMESPACE 0029 0030 class TasksModelItem; 0031 class Task; 0032 0033 class TasksModel : public QAbstractItemModel 0034 { 0035 Q_OBJECT 0036 0037 friend class TasksModelItem; 0038 0039 public: 0040 TasksModel(); 0041 ~TasksModel() override = default; 0042 0043 // Clears the tree widget by removing all of its items and selections. 0044 void clear(); 0045 0046 int topLevelItemCount() const; 0047 int indexOfTopLevelItem(TasksModelItem *item) const; 0048 TasksModelItem *topLevelItem(int index) const; 0049 0050 TasksModelItem *takeTopLevelItem(int index); 0051 0052 QModelIndex index(int row, int column, const QModelIndex &parent) const override; 0053 QModelIndex index(TasksModelItem *item, int column) const; 0054 QModelIndex parent(const QModelIndex &child) const override; 0055 0056 int rowCount(const QModelIndex &parent) const override; 0057 int columnCount(const QModelIndex &parent) const override; 0058 0059 QVariant data(const QModelIndex &index, int role) const override; 0060 0061 QVariant headerData(int section, Qt::Orientation orientation, int role) const override; 0062 0063 TasksModelItem *item(const QModelIndex &index) const; 0064 0065 QList<TasksModelItem *> getAllItems(); 0066 QList<Task *> getAllTasks(); 0067 0068 QList<Task *> getActiveTasks(); 0069 0070 void addChild(TasksModelItem *item); 0071 0072 Qt::DropActions supportedDropActions() const override; 0073 bool canDropMimeData(const QMimeData *data, 0074 Qt::DropAction action, 0075 int row, 0076 int column, 0077 const QModelIndex &parent) const override; 0078 bool 0079 dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; 0080 QMimeData *mimeData(const QModelIndexList &indexes) const override; 0081 0082 Qt::ItemFlags flags(const QModelIndex &index) const override; 0083 0084 /** return the task with the given UID */ 0085 Task *taskByUID(const QString &uid); 0086 0087 /* 0088 * Reset session time to zero for all tasks. 0089 * 0090 * This procedure starts a new session. We speak of session times, 0091 * overalltimes (comprising all sessions) and total times (comprising all subtasks). 0092 * That is why there is also a total session time. 0093 */ 0094 void startNewSession(); 0095 0096 /** 0097 * Add time delta to all active tasks. 0098 * Does not modify events model. 0099 */ 0100 void addTimeToActiveTasks(int64_t minutes); 0101 0102 public Q_SLOTS: 0103 void setActiveIcon(int frameNumber); 0104 0105 Q_SIGNALS: 0106 void taskCompleted(Task *task); 0107 void taskDropped(); 0108 0109 private: 0110 TasksModelItem *m_rootItem; 0111 QStringList m_headerLabels; 0112 QMovie *m_clockAnimation; 0113 mutable QString m_dragCutTaskId; 0114 }; 0115 0116 #endif // KTIMETRACKER_TASKSMODEL_H