-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodelclass.cpp
90 lines (65 loc) · 2.04 KB
/
modelclass.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
#include "modelclass.h"
#include "google/protobuf/descriptor.pb.h"
#include <string.h>
#include <qdebug>
using namespace std;
namespace fantasybit_bx {
ModelClass::ModelClass()
{
}
void ModelClass::init() {
qDebug() << BlockMeta::descriptor()->file()->DebugString().data();
google::protobuf::FileDescriptorProto fdp;
BlockMeta::descriptor()->file()->CopyTo(&fdp);
for ( auto db : fdp.message_type()) {
qDebug() << db.DebugString().data();
}
bc.init();
if ( !bc.Valid() )
qDebug() << "invalid";
else {
bc.SeekToFirst();
//bc.Next();
if ( !bc.Valid() )
qDebug() << "invalid";
else
first = bc.GetCurrentBlock().signedhead().head().num();
}
//setProperty("blockheight",bc.GetBlockHeight());
}
qint32 ModelClass::firstblock() {
return first;
}
qint32 ModelClass::blockheight() {
return bc.GetBlockHeight();
}
int ModelClass::rowCount(const QModelIndex &parent) const {
//qInfo() << " 0test " << bc.GetBlockHeight();
return bc.GetBlockHeight();// - first;
}
QVariant ModelClass::data(const QModelIndex & index, int role) const {
//qInfo() << " 1test " << index;
int row = bc.GetBlockHeight() - index.row();// + 1 + first;
if (index.isValid()) {
bc.Seek(row);
if (bc.Valid()) {
if (role == BlockNum) {
//qInfo() << " BlockNum " << bc.GetCurrentBlock().DebugString().data();
return QVariant(bc.GetCurrentBlock().signedhead().head().num());
}
else if (role == CreationTime) {
//qInfo() << " CreationTime " << bc.GetCurrentBlock().DebugString().data();
return QVariant(bc.GetCurrentBlock().signedhead().head().timestamp());
// bc.GetCurrentBlock().signedhead().head().
}
}
}
return QVariant();
}
QHash<int, QByteArray> ModelClass::roleNames() const {
QHash<int, QByteArray> roles;
roles[BlockNum] = "blocknum";
roles[CreationTime] = "time";
return roles;
}
}