-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMainWindowTrace.cpp
More file actions
79 lines (67 loc) · 2.29 KB
/
MainWindowTrace.cpp
File metadata and controls
79 lines (67 loc) · 2.29 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
#include <QDockWidget>
#include <QTextBrowser>
#include <QDateTime>
#include "MainWindow.h"
#include "ui_MainWindow.h"
void MainWindow::createTraceWindow(bool showWindow, int traceSize)
{
QDockWidget *dock = new QDockWidget(tr("Trace"), this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
trace = new QTextBrowser(dock);
trace->document()->setMaximumBlockCount(traceSize);
//int rows = trace->document()->blockCount();
addTrace("Application Start");
dock->setWidget(trace);
// dock->resize(600,300);
addDockWidget(Qt::BottomDockWidgetArea, dock);
ui->menuTools->addAction(dock->toggleViewAction());
//resize Qt buck
dock->setFloating(true);
dock->hide();
dock->setFloating(false);
if(showWindow)
dock->show();
}
void MainWindow::closeTrace()
{
addTrace("Application Closed");
}
void MainWindow::addTrace(QString text, QColor color)
{
if(trace!=nullptr)
{
QDateTime dt = QDateTime::currentDateTime();
//trace->append(dt.toString("[yyyy-MM-dd hh:mm:ss.zzz] ") + text);
text.remove("\n");
trace->append(dt.toString("[hh:mm:ss.zzz] ") + text);
ui->statusBar->showMessage(dt.toString("[hh:mm:ss.zzz] ") + text);
if(traceErrorsToFile)
{
//log to file: error, exception
if(text.contains("error", Qt::CaseInsensitive)
|| text.contains("exception", Qt::CaseInsensitive)
|| text.contains("application", Qt::CaseInsensitive))
{
QString filePathLog(QCoreApplication::applicationDirPath() + "/" + "trace.txt");
QFile log(filePathLog);
if(log.open(QIODevice::WriteOnly | QIODevice::Append))
{
QTextStream txt(&log);
txt << dt.toString("[yyyy-MM-dd hh:mm:ss] ");
txt << text;
if(!text.contains("\n"))
txt << "\n";
log.close();
}
}
}
}
}
void MainWindow::clearTrace(QString text)
{
if(trace!=nullptr)
{
trace->clear();
trace->append(text);
}
}