-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget_precond.cpp
77 lines (66 loc) · 2.28 KB
/
widget_precond.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
#include "widget_precond.h"
widget_precond::widget_precond(FirstWindow * fw, QWidget *parent) :
QWidget(parent)
{
FirstW = fw;
QVBoxLayout * mainlayout = new QVBoxLayout();
this->setLayout(mainlayout);
QLabel * explications = new QLabel();
explications->setWordWrap(true);
explications->setText("Indiquez quelles tâches devront être effectuées avant cette nouvelle tâche. Il est possible d'en spécifier plusieurs.");
explications->setAlignment(Qt::AlignJustify);
mainlayout->addWidget(explications);
tree = new QTreeWidget();
QHeaderView * header = tree->header();
header->setResizeMode(QHeaderView::ResizeToContents);
header->setResizeMode(0,QHeaderView::Stretch);
header->setResizeMode(3,QHeaderView::Fixed);
header->setResizeMode(4,QHeaderView::Fixed);
header->setStretchLastSection(false);
tree->setHeaderHidden(true);
tree->setMouseTracking(true);
tree->setStyleSheet("font-weight : bold; font-size : 18px; ");
for(int i=0 ; i<FirstW->arbo->topLevelItemCount() ; i++){
QTreeWidgetItem * itemCourant = FirstW->arbo->topLevelItem(i);
QTreeWidgetItem * toAdd = itemCourant->clone();
toAdd->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
tree->addTopLevelItem(toAdd);
}
mainlayout->addWidget(tree);
QObject::connect(tree,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(itemChecked(QTreeWidgetItem*,int)));
}
widget_precond::~widget_precond()
{
}
vector<Tache> widget_precond::getPreconditions()
{
vector<Tache> preconditions;
for (vector<QTreeWidgetItem*>::iterator it = itemschecked.begin() ; it != itemschecked.end() ; ++it)
{
Tache t(*it,false);
preconditions.push_back(t);
}
return preconditions;
}
// SLOTS
void widget_precond::itemChecked(QTreeWidgetItem* item,int n)
{
if (n == 0)
{
if (item->checkState(0)==Qt::Checked)
{
itemschecked.push_back(item);
}
else
{
for (vector<QTreeWidgetItem*>::iterator it = itemschecked.begin() ; it != itemschecked.end() ; ++it)
{
if (*it == item)
{
itemschecked.erase(it);
break;
}
}
}
}
}