/
consolemodel.h
48 lines (37 loc) · 1.24 KB
/
consolemodel.h
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
#ifndef CONSOLEMODEL_H
#define CONSOLEMODEL_H
#include <QAbstractListModel>
#include <QStringList>
#include <QProcess>
/**
* @brief The ConsoleModel class holds a list of strings for a QML list model.
*/
class ConsoleModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(QStringList lines READ lines() WRITE setLines(QString) NOTIFY linesChanged())
public:
explicit ConsoleModel(QObject *parent = 0);
~ConsoleModel();
// methods needed by ListView
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QHash<int, QByteArray> roleNames() const;
// property accessors
QStringList lines() const { return m_lines; }
void setLines(QStringList lines);
void setLines(QString lines);
void appendLine(QString line);
Q_INVOKABLE bool executeCommand(QString command, QStringList arguments);
signals:
void linesChanged();
void processExited(int exitCode);
private slots:
void readProcessChannels();
void handleProcessFinish(int exitCode, QProcess::ExitStatus status);
void handleProcessError(QProcess::ProcessError error);
private:
QProcess *m_process;
QStringList m_lines;
};
#endif // CONSOLEMODEL_H