-
Notifications
You must be signed in to change notification settings - Fork 2
/
AddToDocDialog.cpp
60 lines (53 loc) · 1.81 KB
/
AddToDocDialog.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
#include "AddToDocDialog.h"
#include "NotesManager.h"
#include "Note.h"
#include "ui_AddToDocDialog.h"
#include <QListWidgetItem>
AddToDocDialog::AddToDocDialog(Note *n, QWidget *parent) :
QDialog(parent),
ui(new Ui::AddToDocDialog)
{
ui->setupUi(this);
nm = &NotesManager::getInstance();
activatedDocuments = new QSet<Document*>();
for(QSet<Document*>::const_iterator it=nm->beginDocumentContainer(); it!=nm->endDocumentContainer(); ++it){
if((*it)==n || (*it)->isDeleted())
continue;
QListWidgetItem* item = new QListWidgetItemWithpDocument((*it)->getTitle(), *it, ui->docListWidget);
item->setData(0, (*it)->getTitle());
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
if(n->belongs(*it)){
item->setCheckState(Qt::Checked);
activatedDocuments->insert(*it);
}
else
item->setCheckState(Qt::Unchecked);
}
QObject::connect(ui->docListWidget, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(STOCK_ACTIVATED_DOC(QListWidgetItem*)));
}
void AddToDocDialog::STOCK_ACTIVATED_DOC(QListWidgetItem* item){
if(item->checkState()==Qt::Checked){
qDebug()<<"Getting "<< item->data(0) << "checked";
activatedDocuments->insert(static_cast<QListWidgetItemWithpDocument*>(item)->getRessource());
}
else{
qDebug()<<"Getting "<< item->data(0) << "unchecked";
activatedDocuments->remove(static_cast<QListWidgetItemWithpDocument*>(item)->getRessource());
}
}
AddToDocDialog::~AddToDocDialog()
{
delete ui;
}
QSet<Document *> *AddToDocDialog::getDocuments()
{
return activatedDocuments;
}
Document *QListWidgetItemWithpDocument::getRessource() const
{
return ressource;
}
void QListWidgetItemWithpDocument::setRessource(Document *value)
{
ressource = value;
}