-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
28443c4
commit 2413c57
Showing
6 changed files
with
141 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "logger.h" | ||
|
||
Logger::Logger(QObject *parent, QString fileName, QPlainTextEdit *editor) : QObject(parent) { | ||
|
||
m_editor = editor; | ||
m_showDate = false; | ||
if (!fileName.isEmpty()) { | ||
file = new QFile; | ||
file->setFileName(fileName); | ||
file->open(QIODevice::Append | QIODevice::Text); | ||
} | ||
} | ||
|
||
void Logger::write(const QString &value) { | ||
|
||
QString text = value + " "; | ||
if (m_showDate) | ||
text = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss ") + text; | ||
QTextStream out(file); | ||
out.setCodec("UTF-8"); | ||
if (file != 0) { | ||
out << text; | ||
} | ||
if (m_editor != 0) | ||
{ | ||
QTextCursor prev_cursor = m_editor->textCursor(); | ||
m_editor->moveCursor (QTextCursor::End); | ||
m_editor->insertPlainText (text); | ||
m_editor->setTextCursor(prev_cursor); | ||
} | ||
} | ||
|
||
void Logger::setShowDateTime(bool value) { | ||
|
||
m_showDate = value; | ||
} | ||
|
||
Logger::~Logger() { | ||
|
||
if (file != 0) | ||
file->close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef LOGGER_H | ||
#define LOGGER_H | ||
|
||
#include <QObject> | ||
#include <QPlainTextEdit> | ||
#include <QFile> | ||
#include <QTextStream> | ||
#include <QDateTime> | ||
|
||
class Logger : public QObject { | ||
|
||
Q_OBJECT | ||
public: | ||
|
||
explicit Logger(QObject *parent, QString fileName, QPlainTextEdit *editor = 0); | ||
~Logger(); | ||
void setShowDateTime(bool value); | ||
private: | ||
|
||
QFile *file; | ||
QPlainTextEdit *m_editor; | ||
bool m_showDate; | ||
signals: | ||
|
||
public slots: | ||
|
||
void write(const QString &value); | ||
}; | ||
|
||
#endif // LOGGER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters