summaryrefslogtreecommitdiffstats
path: root/api/logic/launch/LogModel.h
blob: bccceaeffb5acaf6af52b41ba83ff59531c7ec63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once

#include <QAbstractListModel>
#include <QString>
#include "MessageLevel.h"

#include <multimc_logic_export.h>

class MULTIMC_LOGIC_EXPORT LogModel : public QAbstractListModel
{
    Q_OBJECT
public:
    explicit LogModel(QObject *parent = 0);

    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    QVariant data(const QModelIndex &index, int role) const;

    void append(MessageLevel::Enum, QString line);
    void clear();

    void suspend(bool suspend);
    bool suspended();

    QString toPlainText();

    int getMaxLines();
    void setMaxLines(int maxLines);
    void setStopOnOverflow(bool stop);
    void setOverflowMessage(const QString & overflowMessage);

    void setLineWrap(bool state);
    bool wrapLines() const;

    enum Roles
    {
        LevelRole = Qt::UserRole
    };

private /* types */:
    struct entry
    {
        MessageLevel::Enum level;
        QString line;
    };

private: /* data */
    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;

private:
    Q_DISABLE_COPY(LogModel)
};