Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
CaptureListModel.h
Go to the documentation of this file.
1#pragma once
2#include <QAbstractListModel>
3#include <QMenu>
4#include <iostream>
6#include <misc/global.h>
7
8namespace sf
9{
10
14class _MISC_CLASS CaptureListModel : public QAbstractListModel
15{
16 Q_OBJECT
17
18 public:
22 explicit CaptureListModel(QObject* parent = nullptr);
23
28
32 bool append(const QString& str);
33
37 enum StreamSource : unsigned
38 {
40 ssCout = 1u << 0u,
42 ssClog = 1u << 1u,
44 ssCerr = 1u << 2u
45 };
46
50 unsigned setSource(unsigned ss);
51
55 [[nodiscard]] unsigned source() const;
56
60 [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role /* = Qt::DisplayRole*/) const override;
61
65 [[nodiscard]] int rowCount(const QModelIndex& parent /* = QModelIndex()*/) const override;
66
70 [[nodiscard]] QVariant data(const QModelIndex& index, int role) const override;
71
72 private Q_SLOTS:
73
77 void onClear();
78
79 private:
80 // Holds the stream source
81 unsigned _source{0};
82 // Pointer to own stream buffer.
83 LineBuffer* _streamBuf{nullptr};
84 // Pointers to saved stream buffers of the standard streams.
85 static std::streambuf* _coutSaved;
86 static std::streambuf* _clogSaved;
87 static std::streambuf* _cerrSaved;
88 // Holds the context menu.
89 QMenu* _contextMenu{nullptr};
90
91 void handleNewLine(LineBuffer* sender, const QString& line);
92
93 void contextMenuRequested(QPoint);
94};
95
96}// namespace sf
List model implementation on captured output stream data.
Definition CaptureListModel.h:15
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Overridden from base class.
unsigned setSource(unsigned ss)
bool append(const QString &str)
Append string to the end of the list.
CaptureListModel(QObject *parent=nullptr)
Constructor.
StreamSource
Stream sources to capture.
Definition CaptureListModel.h:38
int rowCount(const QModelIndex &parent) const override
Overridden from base class.
QVariant data(const QModelIndex &index, int role) const override
Overridden from base class.
~CaptureListModel() override
Destructor.
unsigned source() const
Reports the stream being captured.
Special std::streambuf class for capturing lines.
Definition LineBuffer.h:14
#define _MISC_CLASS
Definition misc/global.h:40
Definition Application.h:10