-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tag_modif.cpp
69 lines (59 loc) · 1.93 KB
/
Tag_modif.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
#include "Tag_modif.h"
#include "ui_Tag_modif.h"
Tag_modif::Tag_modif(NM::Note *n, QWidget *parent) :
note(n),
QDialog(parent),
ui(new Ui::Tag_modif)
{
ui->setupUi(this);
ui->label_name->setText(n->getTitle());
create_listTags();
connect(ui->button_addTag, SIGNAL(pressed()), this, SLOT(create_tag()));
connect(ui->save_button, SIGNAL(pressed()), this, SLOT(saveAndQuit()));
connect(ui->save_button, SIGNAL(pressed()), MainWindow::getInstance(), SLOT(createListTags()));
}
Tag_modif::~Tag_modif()
{
delete ui;
MainWindow::getInstance()->createListTags();
}
void Tag_modif::create_listTags() {
if(ui->group_tags->layout()) {
QLayoutItem *child;
while( (child = ui->group_tags->layout()->takeAt(0)) ) {
ui->group_tags->layout()->removeItem( child );
delete child->widget();
delete child;
}
} else {
QVBoxLayout *lay = new QVBoxLayout();
ui->group_tags->setLayout(lay);
}
NM::TagManager::Iterator it = NM::TagManager::getInstance()->getIterator();
while (it.hasNext()) {
it.next();
QCheckBox *cb = new QCheckBox(it.getTagLabel());
if (NM::TagManager::getInstance()->isLinked(it.getTagLabel(), note))
cb->setChecked(true);
ui->group_tags->layout()->addWidget(cb);
}
}
void Tag_modif::create_tag() {
if(!ui->line_newTag->text().isEmpty())
NM::TagManager::getInstance()->addTag(ui->line_newTag->text());
ui->line_newTag->clear();
create_listTags();
}
void Tag_modif::saveAndQuit() {
NM::TagManager *tm = NM::TagManager::getInstance();
QLayoutItem *child;
while( (child = ui->group_tags->layout()->takeAt(0)) ) {
QCheckBox *ch = dynamic_cast<QCheckBox*>(child->widget());
if (ch->isChecked()) {
tm->addLink(ch->text(), note);
} else {
tm->removeLink(ch->text(), note);
}
}
this->close();
}