|
|
|
@ -1,36 +1,36 @@
|
|
|
|
|
#include "TaskModel.h"
|
|
|
|
|
#include "ObservableTaskList.h"
|
|
|
|
|
|
|
|
|
|
TaskModel::TaskModel(QObject *parent)
|
|
|
|
|
ObservableTaskList::ObservableTaskList(QObject *parent)
|
|
|
|
|
: QAbstractListModel(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskModel::addTask(Task* task)
|
|
|
|
|
void ObservableTaskList::addTask(Task* task)
|
|
|
|
|
{
|
|
|
|
|
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
|
|
|
|
m_tasks << task;
|
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskModel::removeTask(int index)
|
|
|
|
|
void ObservableTaskList::removeTask(int index)
|
|
|
|
|
{
|
|
|
|
|
beginRemoveRows(QModelIndex(), index, index);
|
|
|
|
|
m_tasks.removeAt(index);
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskModel::updateTask(int index, Task* task)
|
|
|
|
|
void ObservableTaskList::updateTask(int index, Task* task)
|
|
|
|
|
{
|
|
|
|
|
m_tasks[index] = task;
|
|
|
|
|
emit dataChanged(this->index(index), this->index(index), {TitleRole, DescriptionRole, PriorityRole});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TaskModel::rowCount(const QModelIndex &) const
|
|
|
|
|
int ObservableTaskList::rowCount(const QModelIndex &) const
|
|
|
|
|
{
|
|
|
|
|
return m_tasks.count();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant TaskModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
QVariant ObservableTaskList::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
if (index.row() < 0 || index.row() >= m_tasks.count())
|
|
|
|
|
return QVariant();
|
|
|
|
@ -46,7 +46,7 @@ QVariant TaskModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TaskModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
|
|
|
bool ObservableTaskList::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
|
|
|
{
|
|
|
|
|
if (index.row() < 0 || index.row() >= m_tasks.count())
|
|
|
|
|
return false;
|
|
|
|
@ -66,7 +66,7 @@ bool TaskModel::setData(const QModelIndex &index, const QVariant &value, int rol
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags TaskModel::flags(const QModelIndex& index) const
|
|
|
|
|
Qt::ItemFlags ObservableTaskList::flags(const QModelIndex& index) const
|
|
|
|
|
{
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
return Qt::NoItemFlags;
|
|
|
|
@ -74,23 +74,25 @@ Qt::ItemFlags TaskModel::flags(const QModelIndex& index) const
|
|
|
|
|
return Qt::ItemIsEditable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TaskModel::insertRows(int row, int count, const QModelIndex &parent)
|
|
|
|
|
bool ObservableTaskList::insertRows(int row, int count, const QModelIndex &parent)
|
|
|
|
|
{
|
|
|
|
|
beginInsertRows(parent, row, row + count-1);
|
|
|
|
|
beginInsertRows(parent, row, row + count - 1);
|
|
|
|
|
for (int nb = 0; nb < count; ++nb) {
|
|
|
|
|
m_tasks.insert(row, new Task("no title", "no description", 3));
|
|
|
|
|
Task* newTask = new Task("no title", "no description", 3);
|
|
|
|
|
m_tasks.insert(row, newTask);
|
|
|
|
|
}
|
|
|
|
|
endInsertRows();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TaskModel::removeRows(int row, int count, const QModelIndex &parent)
|
|
|
|
|
|
|
|
|
|
bool ObservableTaskList::removeRows(int row, int count, const QModelIndex &parent)
|
|
|
|
|
{
|
|
|
|
|
if (row < 0 || row+count >= m_tasks.count())
|
|
|
|
|
if (row < 0 || row + count > m_tasks.count())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
beginRemoveRows(parent, row, row + count-1);
|
|
|
|
|
beginRemoveRows(parent, row, row + count - 1);
|
|
|
|
|
for (int nb = 0; nb < count; ++nb) {
|
|
|
|
|
m_tasks.removeAt(row);
|
|
|
|
|
}
|
|
|
|
@ -99,7 +101,7 @@ bool TaskModel::removeRows(int row, int count, const QModelIndex &parent)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QHash<int, QByteArray> TaskModel::roleNames() const
|
|
|
|
|
QHash<int, QByteArray> ObservableTaskList::roleNames() const
|
|
|
|
|
{
|
|
|
|
|
QHash<int, QByteArray> roles;
|
|
|
|
|
roles[TitleRole] = "title";
|