-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelpers.h
More file actions
81 lines (58 loc) · 1.89 KB
/
Helpers.h
File metadata and controls
81 lines (58 loc) · 1.89 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
78
79
80
81
#ifndef HELPERS_H
#define HELPERS_H
#include<QJsonObject>
#include<QTableWidget>
#include<sstream>
#include<iostream>
#include<ctime>
#include<cmath>
class ctrader;
namespace Helper {
int ROW_COUNT = 10;
int COLUMN_COUNT = 6;
void print(Ui::ctrader* trader, QString msg) {
trader->textBrowser->append(msg);
}
void shiftRows(QTableWidget* table) {
table->removeRow(table->rowCount() - 1);
table->insertRow(0);
}
void readOnly(QTableWidgetItem* item) {
item->setFlags(item->flags() ^ Qt::ItemIsEditable);
item->setFlags(item->flags() ^ Qt::ItemIsSelectable);
}
std::string** processData(std::string& str) {
str = str.substr(1,str.size()-2);
std::string** array2 = new std::string*[ROW_COUNT];
std::istringstream str2(str);
std::string s;
int i = 0;
while(std::getline(str2, s, ']')) {
array2[i] = new std::string[12];
std::istringstream ss(i == 0 ? s.substr(1,s.size()) : s.substr(2,s.size())); //remove the [
std::string s2;
int j = 0;
while(std::getline(ss, s2, ',')) {
array2[i][j] = j != 0 ? s2.substr(1,s2.size()-2) : s2; //remove the " "
j++;
}
i++;
}
for(int i = 0; i < ROW_COUNT; ++i) {
long timeStamp = stol(array2[i][0])/1000;
std::time_t time = timeStamp;
array2[i][0] = ctime(&time);
std::istringstream ss(array2[i][0]);
std::string str;
int counter = 0;
while(std::getline(ss, str,' ')) {
if(counter == 3) { //get the third element when the string is splitted
array2[i][0] = str;
}
counter++;
}
}
return array2;
}
}
#endif // HELPERS_H