77 lines
1.8 KiB
C++
77 lines
1.8 KiB
C++
#ifndef SESSIONMODEL_H
|
|
#define SESSIONMODEL_H
|
|
|
|
#include <QAbstractListModel>
|
|
#include <QHash>
|
|
#include <QVariantList>
|
|
#include <QSet>
|
|
#include <QString>
|
|
|
|
class Ollie9pClient;
|
|
|
|
class SessionModel : public QAbstractListModel
|
|
{
|
|
Q_OBJECT
|
|
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
|
public:
|
|
enum Roles {
|
|
TypeRole = Qt::UserRole + 1,
|
|
IdRole,
|
|
ParentIdRole,
|
|
AgentIdRole,
|
|
LevelRole,
|
|
ExpandedRole,
|
|
ParentExpandedRole,
|
|
StateRole,
|
|
ModelRole,
|
|
DisplayNameRole,
|
|
BaseNameRole,
|
|
ConnectionColorRole,
|
|
PausedRole
|
|
};
|
|
|
|
explicit SessionModel(Ollie9pClient *client, QObject *parent = nullptr);
|
|
|
|
int rowCount(const QModelIndex &parent = {}) const override;
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
Q_INVOKABLE QVariantMap get(int index) const;
|
|
Q_INVOKABLE void setExpanded(int index, bool expanded);
|
|
Q_INVOKABLE QString firstAgentId(const QString &sessionId) const;
|
|
|
|
signals:
|
|
void countChanged();
|
|
|
|
private slots:
|
|
void rebuild();
|
|
void updateAgentState(const QString &sessionId, const QString &agentId, const QString &state);
|
|
|
|
private:
|
|
struct Row {
|
|
QString type;
|
|
QString id;
|
|
QString parentId;
|
|
QString agentId;
|
|
int level = 0;
|
|
bool expanded = true;
|
|
bool parentExpanded = true;
|
|
QString state;
|
|
QString model;
|
|
QString displayName;
|
|
QString baseName;
|
|
QString connectionColor;
|
|
bool paused = false;
|
|
};
|
|
|
|
static QString connectionColor(const QVariantMap &session);
|
|
void appendSession(const QVariantMap &session);
|
|
void updateVisibility();
|
|
|
|
Ollie9pClient *m_client;
|
|
QList<Row> m_rows;
|
|
QHash<QString, bool> m_expanded;
|
|
};
|
|
|
|
#endif
|