forked from alphaonex86/Ultracopier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DebugModel.cpp
executable file
·158 lines (142 loc) · 3.94 KB
/
DebugModel.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "DebugEngine.h"
#include <QColor>
#ifdef ULTRACOPIER_DEBUG
#define COLUMN_COUNT 5
// Model
DebugModel::DebugModel()
{
displayed = false;
inWaitOfDisplay = false;
updateDisplayTimer = NULL;
}
DebugModel::~DebugModel()
{
if(updateDisplayTimer!=NULL)
delete updateDisplayTimer;
}
int DebugModel::columnCount( const QModelIndex& parent ) const
{
return parent == QModelIndex() ? COLUMN_COUNT : 0;
}
QVariant DebugModel::data( const QModelIndex& index, int role ) const
{
int row,column;
row=index.row();
column=index.column();
if(index.parent()!=QModelIndex() || row < 0 || row >= (int)list.size() || column < 0 || column >= COLUMN_COUNT)
return QVariant();
const DebugItem& item = list.at(row);
if(role==Qt::UserRole)
return row;
else if(role==Qt::DisplayRole)
{
switch(column)
{
case 0:
return item.time;
break;
case 1:
return QString::fromStdString(item.file);
break;
case 2:
return QString::fromStdString(item.function);
break;
case 3:
return QString::fromStdString(item.location);
break;
case 4:
return QString::fromStdString(item.text);
break;
default:
return QVariant();
}
}
else if(role==Qt::DecorationRole)
return QVariant();
else if(role==Qt::ForegroundRole)
{
switch(item.level)
{
case DebugLevel_custom_Information:
return QColor(94,165,255);
break;
case DebugLevel_custom_Critical:
return QColor(255,0,0);
break;
case DebugLevel_custom_Warning:
return QColor(255,178,0);
break;
case DebugLevel_custom_Notice:
return QColor(128,128,128);
break;
case DebugLevel_custom_UserNote:
return QColor(0,0,0);
break;
}
return QVariant();
}
return QVariant();
}
int DebugModel::rowCount( const QModelIndex& parent ) const
{
return parent == QModelIndex() ? list.size() : 0;
}
QVariant DebugModel::headerData( int section, Qt::Orientation orientation, int role ) const
{
if ( role == Qt::DisplayRole && orientation == Qt::Horizontal && section >= 0 && section < COLUMN_COUNT ) {
switch ( section ) {
case 0:
return QStringLiteral("Time");
case 1:
return QStringLiteral("File");
case 2:
return QStringLiteral("Function");
case 3:
return QStringLiteral("Location");
case 4:
return QStringLiteral("Text");
}
}
return QAbstractTableModel::headerData( section, orientation, role );
}
bool DebugModel::setData( const QModelIndex&, const QVariant&, int)
{
return false;
}
void DebugModel::addDebugInformation(const int &time, const DebugLevel_custom &level, const std::string &function, const std::string &text, const std::string &file, const unsigned int& ligne, const std::string &location)
{
DebugItem item;
item.time=time;
item.level=level;
item.function=function;
item.text=text;
item.file=file+":"+std::to_string(ligne);
item.location=location;
list.push_back(item);
if(!displayed)
{
displayed=true;
emit layoutChanged();
}
else
inWaitOfDisplay=true;
}
void DebugModel::setupTheTimer()
{
if(updateDisplayTimer!=NULL)
return;
updateDisplayTimer=new QTimer();
connect(updateDisplayTimer,&QTimer::timeout,this,&DebugModel::updateDisplay);
updateDisplayTimer->start(100);
}
void DebugModel::updateDisplay()
{
displayed=false;
if(!inWaitOfDisplay)
{
inWaitOfDisplay=false;
displayed=true;
emit layoutChanged();
}
}
#endif