-
Notifications
You must be signed in to change notification settings - Fork 0
/
todolist.cpp
68 lines (58 loc) · 2.01 KB
/
todolist.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "todolist.h"
ToDoList::ToDoList(QObject *parent)
: QObject{parent}
{
// for debug testing
m_items.append({true, QStringLiteral("this is Task1")});
m_items.append({true, QStringLiteral("Buy Milk")});
m_items.append({true, QStringLiteral("Wash The Car")});
m_items.append({true, QStringLiteral("Do Homework")});
m_items.append({true, QStringLiteral("Commit Last changes")});
m_items.append({true, QStringLiteral("Create new Repo")});
m_items.append({true, QStringLiteral("this is Task1")});
m_items.append({true, QStringLiteral("Buy Milk")});
m_items.append({true, QStringLiteral("Wash The Car")});
m_items.append({true, QStringLiteral("Do Homework")});
m_items.append({true, QStringLiteral("Commit Last changes")});
m_items.append({true, QStringLiteral("Create new Repo")});
m_items.append({true, QStringLiteral("this is Task1")});
m_items.append({true, QStringLiteral("Buy Milk")});
m_items.append({true, QStringLiteral("Wash The Car")});
m_items.append({true, QStringLiteral("Do Homework")});
m_items.append({true, QStringLiteral("Commit Last changes")});
m_items.append({true, QStringLiteral("Create new Repo")});
}
QVector<ToDoItem> ToDoList::items() const
{
return m_items;
}
bool ToDoList::setItemAt(int index, const ToDoItem &item)
{
if (index < 0 || index >= m_items.size())
return false;
const ToDoItem &oldItem = m_items.at(index);
if (item.done == oldItem.done && item.title == oldItem.title)
return false;
m_items[index] = item;
return true; // true means model changed
}
void ToDoList::appendItem()
{
emit preItemAppended();
ToDoItem item;
item.done = false;
m_items.append(item);
emit postItemAppended();
}
void ToDoList::removeCompletedItems()
{
for (int i = 0; i < m_items.size();) {
if (m_items.at(i).done) {
emit preItemRemoved(i);
m_items.removeAt(i);
emit postItemRemoved();
} else {
i++;
}
}
}