-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvetodelegate.cpp
141 lines (110 loc) · 3.68 KB
/
vetodelegate.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "vetodelegate.h"
#include"animal.h"
#include"owner.h"
#include"algorithm"
#include<cassert>
#include<QtWidgets>
VetoDelegate::VetoDelegate(QList<Animal*> animal, QObject *parent): QStyledItemDelegate(parent)
{
VetoDelegate::m_animal= animal;
}
VetoDelegate::VetoDelegate(QObject *parent) : QStyledItemDelegate(parent)
{}
QWidget *VetoDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
// QDialog *splitter = new QDialog(parent);
// return splitter;
Q_UNUSED(index);
Q_UNUSED(option);
Q_UNUSED(parent);
}
void VetoDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
/*auto it = std::find_if(std::begin(VetoDelegate::m_animal), std::end(VetoDelegate::m_animal), [&index](Animal *animal )
{ return animal->getName() == index.data().toString(); } );
assert( it != std::end(VetoDelegate::m_animal) );
Animal *p = *it;
assert( p != nullptr );
QLabel *label = new QLabel(p->getName());
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(label);
// editor->setLayout(layout);
emit sendData(p->getName());*/
Q_UNUSED(index);
Q_UNUSED(editor);
}
void VetoDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
Q_UNUSED(model);
Q_UNUSED(index);
Q_UNUSED(editor);
}
void VetoDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex & index) const
{
Q_UNUSED(option);
Q_UNUSED(index);
editor->setGeometry(60, 40, 300, 150);
}
QList<Animal*> VetoDelegate::getListAnimal()
{
return VetoDelegate::m_animal;
}
QList<Owner *> VetoDelegate::getListOwner()
{
return VetoDelegate::m_owner;
}
void VetoDelegate::setListAnimal(QList<Animal*> animal)
{
VetoDelegate::m_animal=animal;
}
QList<Animal*> VetoDelegate::m_animal;
QList<Owner*> VetoDelegate::m_owner;
ModelTest::ModelTest(QObject *parent) : QStyledItemDelegate(parent)
{
}
QWidget *ModelTest::createEditor(QWidget *parent, const QStyleOptionViewItem &/*option*/, const QModelIndex &/*index*/) const
{
QDialog *splitter = new QDialog(parent);
// QComboBox *combox = new QComboBox(parent);
return splitter;
// return combox;
}
void ModelTest::setEditorData(QWidget *editor, const QModelIndex &/*index*/) const
{
QStringList list;
QStringList list2;
list<< "cameroun" << "tchad" << "congo";
list2 << "ivoire" << "argent" << "pain";
QStandardItemModel *model = new QStandardItemModel;
QStandardItem *parent1 = new QStandardItem("Pays");
for(int row =0; row<3; ++row)
{
parent1->appendRow(new QStandardItem(static_cast<QString>(list.at(row))));
}
QStandardItem *parent2 = new QStandardItem("Monnaie");
for(int row =0; row<3; ++row)
{
parent2->appendRow(new QStandardItem(static_cast<QString>(list2.at(row))));
}
model->setItem(0, 0, parent1);
model->setItem(1, 0, parent2);
QTreeView *tree = new QTreeView();
QHBoxLayout *hlayout = new QHBoxLayout;
QVBoxLayout * vlayout = new QVBoxLayout;
QPushButton *fermer = new QPushButton("Fermer");
hlayout->addWidget(new QPushButton("Valider"));
hlayout->addWidget(fermer);
vlayout->addWidget(tree);
vlayout->addLayout(hlayout);
vlayout->addWidget(new QLabel("JACK"));
editor->setLayout(vlayout);
tree->setModel(model);
}
void ModelTest::setModelData(QWidget */*editor*/, QAbstractItemModel */*model*/, const QModelIndex &/*index*/) const
{
}
void ModelTest::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex & /*index*/ ) const
{
Q_UNUSED(option);
editor->setGeometry(60, 40, 300, 150);
}