2016-08-19 01:01:37 +05:30
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QString>
|
|
|
|
#include "MessageLevel.h"
|
|
|
|
|
2021-07-25 22:41:59 +05:30
|
|
|
class LogModel : public QAbstractListModel
|
2016-08-19 01:01:37 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
Q_OBJECT
|
2016-08-19 01:01:37 +05:30
|
|
|
public:
|
2018-07-15 18:21:05 +05:30
|
|
|
explicit LogModel(QObject *parent = 0);
|
2016-08-19 01:01:37 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
QVariant data(const QModelIndex &index, int role) const;
|
2016-08-19 01:01:37 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
void append(MessageLevel::Enum, QString line);
|
|
|
|
void clear();
|
2017-12-18 05:49:43 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
void suspend(bool suspend);
|
|
|
|
bool suspended();
|
2016-08-19 01:01:37 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
QString toPlainText();
|
2016-08-19 01:01:37 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
int getMaxLines();
|
|
|
|
void setMaxLines(int maxLines);
|
|
|
|
void setStopOnOverflow(bool stop);
|
|
|
|
void setOverflowMessage(const QString & overflowMessage);
|
2016-08-19 01:01:37 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
void setLineWrap(bool state);
|
|
|
|
bool wrapLines() const;
|
2017-12-18 05:49:43 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
enum Roles
|
|
|
|
{
|
|
|
|
LevelRole = Qt::UserRole
|
|
|
|
};
|
2016-08-19 01:01:37 +05:30
|
|
|
|
|
|
|
private /* types */:
|
2018-07-15 18:21:05 +05:30
|
|
|
struct entry
|
|
|
|
{
|
|
|
|
MessageLevel::Enum level;
|
|
|
|
QString line;
|
|
|
|
};
|
2016-08-19 01:01:37 +05:30
|
|
|
|
|
|
|
private: /* data */
|
2018-07-15 18:21:05 +05:30
|
|
|
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-19 01:01:37 +05:30
|
|
|
|
|
|
|
private:
|
2018-07-15 18:21:05 +05:30
|
|
|
Q_DISABLE_COPY(LogModel)
|
2016-08-19 01:01:37 +05:30
|
|
|
};
|