-
Notifications
You must be signed in to change notification settings - Fork 0
/
logwindow.cpp
60 lines (51 loc) · 1.5 KB
/
logwindow.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
#include "logwindow.h"
#include <QGridLayout>
#include <QScrollBar>
#include <QTextStream>
#include <QFont>
#include <QDebug>
LogWindow::LogWindow(QWidget *parent)
: QDialog(parent),
m_logFile(new QFile("Saved Messages")),
m_logMessages(new QPlainTextEdit(tr("Log Messages")))
{
setStyleSheet("QPlainTextEdit {font: 10pt 'Times'}");
auto mainLayout = new QGridLayout;
m_logMessages->setReadOnly(true);
mainLayout->addWidget(m_logMessages);
setLayout(mainLayout);
setBaseSize(QSize(100, 100));
setWindowTitle(tr("Comm Messages"));
// connect();
}
void LogWindow::addCOMConnected()
{
addLog("COM connected");
}
void LogWindow::addCOMDisconnected()
{
addLog("COM disconnected");
}
void LogWindow::addSuccessfulMemAlloc() {
addLog("Successful Memory Allocation");
}
void LogWindow::addUnsuccessfulMemAlloc() {
addLog("Unsuccessful Memory Allocation");
}
void LogWindow::addLog(const QString& text)
{
m_logFile->open(QIODevice::WriteOnly);
if (!m_logFile->isOpen()) {
qDebug() << "Could not load file";
return;
}
QTextStream stream(m_logFile);
stream << text;
m_logMessages->appendPlainText(text); // Adds the message to the widget
m_logMessages->verticalScrollBar()->setValue(m_logMessages->verticalScrollBar()->maximum());
m_logFile->close();
// optional if you want to see the changes
// after appendPlainText() immediately
// useful if you use this->appendMessage() in a loop
// QDialog::processEvents();
}