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
23class _MISC_CLASS CaptureListModel final : public QAbstractListModel
24{
25 Q_OBJECT
26
27 public:
31 explicit CaptureListModel(QObject* parent = nullptr);
32
37
41 bool append(const QString& str);
42
47 std::streambuf* getStreamBuffer() const;
48
52 enum StreamSource : unsigned
53 {
55 ssStdCout = 1u << 0u,
57 ssStdClog = 1u << 1u,
59 ssStdCerr = 1u << 2u
60 };
61
65 unsigned setSource(unsigned ss);
66
70 unsigned source() const;
71
75 QVariant headerData(int section, Qt::Orientation orientation, int role /* = Qt::DisplayRole*/) const override;
76
80 int rowCount(const QModelIndex& parent /* = QModelIndex()*/) const override;
81
85 QVariant data(const QModelIndex& index, int role) const override;
86
87 private Q_SLOTS:
91 void clear();
92
93 private:
97 void contextMenuRequested(QPoint);
98
104 void handleNewLine(LineBuffer* sender, const QString& line);
105
106 unsigned _source;
107 LineBuffer* _streamBuf;
108 static std::streambuf* _stdCoutSaved;
109 static std::streambuf* _stdClogSaved;
110 static std::streambuf* _stdCerrSaved;
111 QMenu* _contextMenu;
112};
113
114}// namespace sf
List model implementation which can capture output streams from std::cout, std::clog and std::cerr by...
Definition CaptureListModel.h:24
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:53
int rowCount(const QModelIndex &parent) const override
Overridden from base class.
std::streambuf * getStreamBuffer() const
Gets the internal stream buffer. Used for attaching to a std::ostream instance.
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:15
#define _MISC_CLASS
Definition misc/global.h:40
Definition Application.h:10