forked from twiniars/RESpecTa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subtaskWidget.cpp
105 lines (86 loc) · 2.88 KB
/
subtaskWidget.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "subtaskWidget.h"
SubtaskWidget::SubtaskWidget(QWidget * parent,Model * mod): QWidget(parent)
{
model = mod;
QGridLayout * mainLayout = new QGridLayout;
subtaskList = new QListWidget();
mainLayout->addWidget(subtaskList,0,0,6,2);
QLabel * Name = new QLabel ("Name");
mainLayout->addWidget(Name, 6,0, 1, 2);
changeNameButton = new QPushButton("Change Name");
connect(changeNameButton, SIGNAL(clicked()), this, SLOT(ChangeClicked()));
mainLayout->addWidget(changeNameButton, 8,0);
QPushButton * DeleteButton = new QPushButton("Delete");
connect(DeleteButton, SIGNAL(clicked()), this, SLOT(DeleteClicked()));
mainLayout->addWidget(DeleteButton, 8,1);
AddButton = new QPushButton("Add");
connect(AddButton, SIGNAL(clicked()), this, SLOT(AddClicked()));
mainLayout->addWidget(AddButton, 9,0);
QPushButton * CleanButton = new QPushButton("Clean");
connect(CleanButton, SIGNAL(clicked()), this, SLOT(CleanClicked()));
mainLayout->addWidget(CleanButton, 9, 1);
nameEdit = new QLineEdit();
nameEdit->setValidator(new QRegExpValidator(QRegExp("^[\\w\\s\\-]*$"), nameEdit));
mainLayout->addWidget(nameEdit, 7,0, 1, 2);
connect(nameEdit, SIGNAL(textChanged(QString)), this, SLOT(LengthChanged(QString)));
changeNameButton->setDisabled(true);
AddButton->setDisabled(true);
setLayout(mainLayout);
}
void SubtaskWidget::CleanClicked()
{
QStringList list = model->getTasksNameLists();
model->CleanTask(list[subtaskList->currentIndex().row()]);
//TODO: emit uncheck me
emit UncheckTasksAction();
}
void SubtaskWidget::refreshData()
{
subtaskList->clear();
subtaskList->addItems(model->getTasksNameLists());
subtaskList->setCurrentRow(0);
}
void SubtaskWidget::ChangeClicked()
{
if((subtaskList->findItems(nameEdit->text(),Qt::MatchExactly)).size()!=0)
{
emit reportError(QString("This subtask name is already taken"));
return;
}
QStringList list = model->getTasksNameLists();
if(list[subtaskList->currentIndex().row()]!= nameEdit->text())
{
emit changed(list[subtaskList->currentIndex().row()], nameEdit->text());
refreshData();
}
}
void SubtaskWidget::AddClicked()
{
if(model->checkSubtaskExists(nameEdit->text()))
{
emit reportError(QString("Subtask with that name already exists"));
return;
}
else
{
emit added(nameEdit->text());
refreshData();
}
}
void SubtaskWidget::DeleteClicked()
{
QStringList list = model->getTasksNameLists();
emit removed(list[subtaskList->currentIndex().row()]);
refreshData();
}
void SubtaskWidget::LengthChanged(QString newString)
{
if(newString.size()>0)
{ changeNameButton->setDisabled(false);
AddButton->setDisabled(false);
}
else
{ changeNameButton->setDisabled(true);
AddButton->setDisabled(true);
}
}