-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathNegotiationModel.cpp
More file actions
77 lines (69 loc) · 1.76 KB
/
NegotiationModel.cpp
File metadata and controls
77 lines (69 loc) · 1.76 KB
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 "NegotiationModel.hpp"
NegotiationModel::NegotiationModel(QTableWidget* widget)
{
_negotiation_view = widget;
}
void NegotiationModel::add_negotiation(
uint64_t negotiation_id,
const std::vector<uint64_t>& participants)
{
_model[negotiation_id] = participants;
render();
}
void NegotiationModel::remove(uint64_t neg_id)
{
_model.erase(neg_id);
render();
}
void NegotiationModel::get_selected_id(std::vector<uint64_t>& negotiations)
{
QItemSelectionModel* select = _negotiation_view->selectionModel();
if (select->hasSelection())
{
auto indices = select->selectedRows();
for (auto i: indices)
{
auto neg_id = get_negotiation_id(i.row());
negotiations.push_back(neg_id);
}
}
}
void NegotiationModel::render()
{
QStringList table_header;
_negotiation_view->clearContents();
_negotiation_view->setRowCount(_model.size());
auto _current_row = _model.begin();
for (std::size_t i = 0; i < _model.size(); i++)
{
QTableWidgetItem* item = new QTableWidgetItem;
item->setText(QString::number(_current_row->first));
_negotiation_view->setItem(i, 0, item);
QTableWidgetItem* participants = new QTableWidgetItem;
participants->setText(render_participants(_current_row->first));
_negotiation_view->setItem(i, 1, participants);
_current_row++;
}
}
uint64_t NegotiationModel::get_negotiation_id(std::size_t n)
{
auto _current_row = _model.begin();
for (std::size_t i = 0; i < _model.size(); i++)
{
if (i == n)
{
return _current_row->first;
}
_current_row++;
}
return 0;
}
QString NegotiationModel::render_participants(uint64_t conflict_version)
{
QString res("");
for (auto& item: _model[conflict_version])
{
res += QString::number(item) + " ";
}
return res;
}