-
Notifications
You must be signed in to change notification settings - Fork 1
/
manipulatormodel.cpp
116 lines (99 loc) · 2.84 KB
/
manipulatormodel.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
#include "manipulatormodel.h"
ManipulatorModel::ManipulatorModel(Manipulator *inp, QObject *parent)
: QAbstractTableModel(parent),
man(inp)
{}
QVariant ManipulatorModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal)
switch (section)
{
case 0:
return QString("Координата");
break;
case 1:
return QString("Значение");
break;
}
else
return QString("Звено %1").arg(section+1);
}
int ManipulatorModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
return man->links.size();
}
int ManipulatorModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
return 2;
}
QVariant ManipulatorModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (index.row() >= man->links.size() || index.row() < 0)
return QVariant();
if (index.column() >= 2 || index.column() < 0)
return QVariant();
if (role == Qt::DisplayRole || role == Qt::EditRole)
{
Link temp = man->links.at(index.row());
if (index.column())
{
if (temp.genCoorIndex != -1)
return temp.param[temp.genCoorIndex];
else
return QString("--");
}
else
{
if (temp.genCoorIndex != -1)
switch (temp.genCoorIndex)
{
case (0):
return QString("d%1").arg(index.row()+1);
break;
case (1):
return QString("a%1").arg(index.row()+1);
break;
case (2):
return QString("q%1").arg(index.row()+1);
break;
case (3):
return QString("alfa%1").arg(index.row()+1);
break;
}
else
return QString("--");
}
}
return QVariant();
}
bool ManipulatorModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
Link *temp = &man->links[index.row()];
if (index.isValid() && role == Qt::EditRole)
{
temp->set`Coor(value.toDouble(), temp->genCoorIndex);
man->updateRecentPosition();
emit dataChanged(index, index, QVector<int>() << role);
return true;
}
return false;
}
Qt::ItemFlags ManipulatorModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::NoItemFlags;
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
}
void ManipulatorModel::resetModel()
{
beginResetModel();
endResetModel();
}