-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_cluster_model.h
76 lines (62 loc) · 2.17 KB
/
test_cluster_model.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* (C) Copyright 2014, MongoDB, Inc. */
#pragma once
#include <QAbstractItemModel>
#include <QProcess>
#include "host_types.h"
class TestClusterModel : public QAbstractItemModel {
Q_OBJECT
public:
TestClusterModel(QObject* parent = nullptr);
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
virtual QModelIndex parent(const QModelIndex& index) const;
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
void addHost(HostType type, int port, const QString& dbPath, const QString& replicaSet, const QString& configDB);
void startHost(const QModelIndex& index);
void stopHost(const QModelIndex& index);
void removeHost(const QModelIndex& index);
void updateHosts();
int hostPort(const QModelIndex& index) const;
QString hostReplicaSet(const QModelIndex& index) const;
QString hostConsoleOutput(const QModelIndex& index) const;
bool hostRunning(const QModelIndex& index) const;
bool anyStarted() const;
bool anyStopped() const;
bool isDirty() const;
bool hasFileName() const;
void startAllHosts();
void stopAllHosts();
void clearCluster();
void saveToFile();
void saveToFile(const QString& fileName);
bool loadFromFile(const QString& fileName);
signals:
void consoleOutputChanged(int row);
private:
enum Column {
COLUMN_TYPE,
COLUMN_PORT,
COLUMN_DBPATH,
COLUMN_REPLICASET,
COLUMN_STATE,
COLUMN_MAX
};
struct HostInfo {
HostType type;
int port;
QString dbPath;
QString replicaSet;
QString configDB;
QProcess* process;
QProcess::ProcessState state;
QString consoleOutput;
};
static const QString _columnHeaders[COLUMN_MAX];
QList<HostInfo> _hosts;
bool _anyStarted;
bool _anyStopped;
bool _dirty;
QString _fileName;
};