2016-08-18 20:31:37 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QString>
|
|
|
|
#include "MessageLevel.h"
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
class LogModel : public QAbstractListModel {
|
2016-08-18 20:31:37 +01:00
|
|
|
Q_OBJECT
|
2023-08-02 17:35:35 +01:00
|
|
|
public:
|
|
|
|
explicit LogModel(QObject* parent = 0);
|
2016-08-18 20:31:37 +01:00
|
|
|
|
2023-08-02 17:35:35 +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
|
|
|
|
|
|
|
void append(MessageLevel::Enum, QString line);
|
|
|
|
void clear();
|
2017-12-18 00:19:43 +00:00
|
|
|
|
2016-10-11 20:34:02 +01:00
|
|
|
void suspend(bool suspend);
|
2017-12-18 00:19:43 +00:00
|
|
|
bool suspended();
|
2016-08-18 20:31:37 +01:00
|
|
|
|
|
|
|
QString toPlainText();
|
|
|
|
|
2017-02-08 19:01:42 +00:00
|
|
|
int getMaxLines();
|
2016-08-18 20:31:37 +01:00
|
|
|
void setMaxLines(int maxLines);
|
|
|
|
void setStopOnOverflow(bool stop);
|
2023-08-02 17:35:35 +01:00
|
|
|
void setOverflowMessage(const QString& overflowMessage);
|
2016-08-18 20:31:37 +01:00
|
|
|
|
2017-12-18 00:19:43 +00:00
|
|
|
void setLineWrap(bool state);
|
|
|
|
bool wrapLines() const;
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
enum Roles { LevelRole = Qt::UserRole };
|
2016-08-18 20:31:37 +01:00
|
|
|
|
2023-08-23 12:46:23 +01:00
|
|
|
private /* types */:
|
2023-08-02 17:35:35 +01:00
|
|
|
struct entry {
|
2016-08-18 20:31:37 +01:00
|
|
|
MessageLevel::Enum level;
|
|
|
|
QString line;
|
|
|
|
};
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
private: /* data */
|
|
|
|
QVector<entry> m_content;
|
2016-08-18 20:31:37 +01:00
|
|
|
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";
|
2016-10-11 20:34:02 +01:00
|
|
|
bool m_suspended = false;
|
2017-12-18 00:19:43 +00:00
|
|
|
bool m_lineWrap = true;
|
2016-08-18 20:31:37 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
private:
|
2016-08-18 20:31:37 +01:00
|
|
|
Q_DISABLE_COPY(LogModel)
|
|
|
|
};
|