| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#ifndef LOGRECORDER_H |
| 19 |
#define LOGRECORDER_H |
| 20 |
|
| 21 |
#include <QObject> |
| 22 |
#include <QmlObjectListModel.h> |
| 23 |
|
| 24 |
#include <QtQuick> |
| 25 |
#include <QQmlEngine> |
| 26 |
#include <QJSEngine> |
| 27 |
|
| 28 |
class LogMessage : public QObject |
| 29 |
{ |
| 30 |
Q_OBJECT |
| 31 |
Q_PROPERTY(QString message READ message WRITE setMessage NOTIFY messageChanged) |
| 32 |
QString m_message; |
| 33 |
|
| 34 |
public: |
| 35 |
explicit LogMessage(QObject *parent = 0) : QObject(parent){} |
| 36 |
QString message() const |
| 37 |
{ |
| 38 |
return m_message; |
| 39 |
} |
| 40 |
public slots: |
| 41 |
void setMessage(QString message) |
| 42 |
{ |
| 43 |
if (m_message == message) |
| 44 |
return; |
| 45 |
|
| 46 |
m_message = message; |
| 47 |
emit messageChanged(message); |
| 48 |
} |
| 49 |
signals: |
| 50 |
void messageChanged(QString message); |
| 51 |
}; |
| 52 |
|
| 53 |
class LogRecorder : public QObject |
| 54 |
{ |
| 55 |
Q_OBJECT |
| 56 |
Q_PROPERTY(QObject *model READ model NOTIFY modelChanged) |
| 57 |
Q_ENUMS(Type) |
| 58 |
public: |
| 59 |
explicit LogRecorder(QObject *parent = 0); |
| 60 |
enum Type { |
| 61 |
INFO, |
| 62 |
STATUS, |
| 63 |
WARNING, |
| 64 |
ERROR |
| 65 |
}; |
| 66 |
QObject *model() { return m_model; } |
| 67 |
static QObject *factory(QQmlEngine *engine, QJSEngine *scriptEngine); |
| 68 |
|
| 69 |
signals: |
| 70 |
void modelChanged(); |
| 71 |
|
| 72 |
public slots: |
| 73 |
void logMessage(const QString &location, const int &type, const QString &message); |
| 74 |
|
| 75 |
private: |
| 76 |
QString formatMessage(const QString &location, const int &type, const QString &message); |
| 77 |
QQmlObjectListModel<LogMessage> *m_model; |
| 78 |
}; |
| 79 |
|
| 80 |
#endif |