2016-08-18 20:31:37 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QString>
|
|
|
|
#include "MessageLevel.h"
|
|
|
|
|
2021-07-25 18:11:59 +01:00
|
|
|
class LogModel : public QAbstractListModel
|
2016-08-18 20:31:37 +01:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
Q_OBJECT
|
2016-08-18 20:31:37 +01:00
|
|
|
public:
|
2018-07-15 13:51:05 +01:00
|
|
|
explicit LogModel(QObject *parent = 0);
|
2016-08-18 20:31:37 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
QVariant data(const QModelIndex &index, int role) const;
|
2016-08-18 20:31:37 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
void append(MessageLevel::Enum, QString line);
|
|
|
|
void clear();
|
2017-12-18 00:19:43 +00:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
void suspend(bool suspend);
|
|
|
|
bool suspended();
|
2016-08-18 20:31:37 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
QString toPlainText();
|
2016-08-18 20:31:37 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
int getMaxLines();
|
|
|
|
void setMaxLines(int maxLines);
|
|
|
|
void setStopOnOverflow(bool stop);
|
|
|
|
void setOverflowMessage(const QString & overflowMessage);
|
2016-08-18 20:31:37 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
void setLineWrap(bool state);
|
|
|
|
bool wrapLines() const;
|
2017-12-18 00:19:43 +00:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
enum Roles
|
|
|
|
{
|
|
|
|
LevelRole = Qt::UserRole
|
|
|
|
};
|
2016-08-18 20:31:37 +01:00
|
|
|
|
|
|
|
private /* types */:
|
2018-07-15 13:51:05 +01:00
|
|
|
struct entry
|
|
|
|
{
|
|
|
|
MessageLevel::Enum level;
|
|
|
|
QString line;
|
|
|
|
};
|
2016-08-18 20:31:37 +01:00
|
|
|
|
|
|
|
private: /* data */
|
2018-07-15 13:51:05 +01:00
|
|
|
QVector <entry> m_content;
|
|
|
|
int m_maxLines = 1000;
|
|
|
|
// first line in the circular buffer
|
|
|
|
int m_firstLine = 0;
|
|
|
|
// number of lines occupied in the circular buffer
|
|
|
|
int m_numLines = 0;
|
|
|
|
bool m_stopOnOverflow = false;
|
|
|
|
QString m_overflowMessage = "OVERFLOW";
|
|
|
|
bool m_suspended = false;
|
|
|
|
bool m_lineWrap = true;
|
2016-08-18 20:31:37 +01:00
|
|
|
|
|
|
|
private:
|
2018-07-15 13:51:05 +01:00
|
|
|
Q_DISABLE_COPY(LogModel)
|
2016-08-18 20:31:37 +01:00
|
|
|
};
|