-
Notifications
You must be signed in to change notification settings - Fork 1
/
ordertablemodel.cpp
111 lines (102 loc) · 2.89 KB
/
ordertablemodel.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
#include "ordertablemodel.h"
OrderTableModel::OrderTableModel(QObject *parent)
: QAbstractTableModel(parent)
{
results.clear();
buySound = new QMediaPlayer;
buySound->setMedia(QUrl("qrc:/resources/sound/buy.mp3"));
sellSound = new QMediaPlayer;
sellSound->setMedia(QUrl("qrc:/resources/sound/sell.mp3"));
}
QVariant OrderTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(role == Qt::DisplayRole && orientation == Qt::Horizontal){
switch (section) {
case 0:
return QString("#");
case 1:
return QString("ID");
case 2:
return QString("Start Time");
case 3:
return QString("End Time");
case 4:
return QString("Elapsed(ms)");
case 5:
return QString("Action");
case 6:
return QString("Status");
case 7:
return QString("Trigger Size");
case 8:
return QString("Code");
case 9:
return QString("Name");
case 10:
return QString("Price");
case 11:
return QString("Qty");
case 12:
return QString("Message");
}
}
return QVariant();
}
int OrderTableModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
return results.size();
}
int OrderTableModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
return 13;
}
QVariant OrderTableModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if(role == Qt::DisplayRole){
OrderResult result = results[index.row()];
switch (index.column()) {
case 0:
return index.row();
case 1:
return result.id;
case 2:
return result.startTime.toString("hh:mm:ss.zzz");
case 3:
return result.endTime.toString("hh:mm:ss.zzz");
case 4:
return result.startTime.msecsTo(result.endTime);
case 5:
return result.action;
case 6:
if(result.status == 1) return "SUCCESS";
else if(result.status == 2) return "FAILED";
return "ERROR";
case 7:
return QLocale(QLocale::English).toString(result.triggerSize);
case 8:
return result.code;
case 9:
return result.name;
case 10:
return QString::number(result.price, 'f', 3);
case 11:
return result.qty;
case 12:
return result.response;
}
}
return QVariant();
}
void OrderTableModel::addRow(OrderResult result){
beginInsertRows(QModelIndex(), rowCount(), rowCount());
results.push_back(result);
endInsertRows();
if(result.action == "buy") buySound->play();
else sellSound->play();
}