-
Notifications
You must be signed in to change notification settings - Fork 7
/
SC_vectorlistmodel.cpp
130 lines (108 loc) · 3.48 KB
/
SC_vectorlistmodel.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
#include "SC_vectorlistmodel.h"
#include "CL_classes.h"
vectorListModel::vectorListModel(QObject *parent) :
QAbstractTableModel(parent)
{
this->selectedData = -1;
}
int vectorListModel::rowCount(const QModelIndex & /*parent = QModelIndex()*/) const
{
if (this->list.size() > 0) {
return this->list[0].size();
}
return 0;
}
int vectorListModel::columnCount(const QModelIndex &/*parent = QModelIndex()*/) const
{
return this->list.size();
}
double vectorListModel::data(int row, int col) {
return this->data(this->createIndex(row,col), Qt::DisplayRole).toFloat();
}
QVariant vectorListModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole)
{
if (index.column() > list.size()-1) {
return "#Err";
}
if (index.row() > list[index.column()].size()-1) {
return "#Err";
}
return list[index.column()][index.row()];
}
if (role == Qt::ForegroundRole) {
if (index.row() == selectedData) {
return QBrush(QColor::fromRgb(255,0,0));
}
return QBrush(QColor::fromRgb(0,0,0));
}
return QVariant();
}
void vectorListModel::emitDataChanged() {
QModelIndex index = this->createIndex(0,0);
emit dataChanged(index, index);
}
QVariant vectorListModel::headerData(int section, Qt::Orientation orientation, int role) const {
if (role == Qt::DisplayRole)
{
if (orientation == Qt::Horizontal) {
if (section > this->destinations.size()-1) {
return "#Err";
}
if (this->destinations[section] == NULL) {
return "#ErrNull";
}
return this->destinations[section]->name;
}
if (orientation == Qt::Vertical) {
return section;
}
}
//if (role == Qt::)
return QVariant();
}
void vectorListModel::setData(int row, int col, double data) {
// create and index and prod the real method
QModelIndex index = this->createIndex(row,col);
this->setData(index, data, Qt::EditRole);
}
bool vectorListModel::setData(const QModelIndex & index, const QVariant & value, int role)
{
if (role == Qt::EditRole)
{
if (index.column() < list.size()) {
if (index.row() < list[index.column()].size()) {
// modify existing experimental set
list[index.column()][index.row()] = value.toDouble();
return true;
} else if (index.row() == list[index.column()].size()) {
// add a new experimental set
beginInsertRows(this->createIndex(list[index.column()].size()-1, 0).parent(),list[index.column()].size(),list[index.column()].size());
// add extra indices onto all the lists
for (int i = 0; i < list.size(); ++i) {
list[i].push_back(0);
}
endInsertRows();
return true;
}
}
}
return false;
}
void vectorListModel::moveIndex(int row) {
// copy the corresponding data row to the experiment
if (this->list.size() == 0) {
return;
}
if (row < this->list[0].size()) {
for (int i = 0; i < this->list.size(); ++i) {
// copy
this->destinations[i]->value[0] = this->list[i][row];
}
}
}
Qt::ItemFlags vectorListModel::flags(const QModelIndex & /*index*/) const
{
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled ;
}