-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog_view.cpp
More file actions
executable file
·47 lines (38 loc) · 1.42 KB
/
log_view.cpp
File metadata and controls
executable file
·47 lines (38 loc) · 1.42 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
#include "log_view.hpp"
LogView::LogView():file(QCoreApplication::applicationDirPath() + "/Resources/Log.txt"), stream(&file) {
// Initialize text View and file
textView = new QPlainTextEdit();
textView->setReadOnly(true);
file.open(QIODevice::Append | QIODevice::Text);
logButton = new QPushButton("Preview Log File");
QObject::connect(logButton, &QPushButton::clicked, this, &LogView::logButtonClicked);
// Record section time
auto time = QDateTime::currentDateTime().toString();
textView->appendPlainText(time + "\nStart Logging...");
stream << time << endl;
// Layout
QGridLayout *layout = new QGridLayout();
layout->addWidget(textView, 0, 0, 10, 10);
layout->addWidget(logButton, 11, 9);
setLayout(layout);
}
void LogView::write(QString content) {
// Log file existence check.
if(!file.exists()){
file.close();
file.open(QIODevice::Append | QIODevice::Text);
stream << QDateTime::currentDateTime().toString() << endl;
stream << "Warning: lose log file when program is running. New log file is now created." << endl;
}
// Write to widget and file
textView->appendPlainText(" " + content);
stream << " " << content << endl;
}
void LogView::clear() {
textView->clear();
}
void LogView::logButtonClicked() {
QFileInfo info(file);
LogPreview msgbox(info.absoluteFilePath());
msgbox.exec();
}