-
Notifications
You must be signed in to change notification settings - Fork 6
/
providerconnectionview.cpp
64 lines (55 loc) · 2.53 KB
/
providerconnectionview.cpp
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
#include "providerconnectionview.h"
#include "ui_providerconnectionview.h"
ProviderConnectionView::ProviderConnectionView(QWidget *parent) :
QWidget(parent),
ui(new Ui::ProviderConnectionView)
{
ui->setupUi(this);
ui->statusTable->setColumnCount(5);
ui->statusTable->setHorizontalHeaderLabels(QStringList()
<< QStringLiteral("Direction")
<< QStringLiteral("Type")
<< QStringLiteral("Topic")
<< QStringLiteral("ID")
<< QStringLiteral("Content"));
}
ProviderConnectionView::~ProviderConnectionView()
{
delete ui;
}
void ProviderConnectionView::setProviderConnection(ProviderConnectionBase *p)
{
m_connection = p;
if (p ==nullptr)
return;
const auto publishTopic = p->defaultPublishTopic();
ui->publishTopicEdit->setText(publishTopic);
ui->publishTopicEdit->setPlaceholderText(publishTopic);
const auto subTopic = p->defaultSubscriptionTopic();
ui->subscriptionTopicEdit->setText(subTopic);
ui->subscriptionTopicEdit->setPlaceholderText(subTopic);
// Connections for updating / inserting into the table
connect(ui->publishButton, &QPushButton::clicked, this, [this] () {
const QString topic = ui->publishTopicEdit->text();
const QByteArray payload = ui->publishPayloadEdit->toPlainText().toLocal8Bit();
m_connection->publish(topic, payload);
});
connect(ui->subscriptionButton, &QPushButton::clicked, this, [this] () {
m_connection->subscribe(ui->subscriptionTopicEdit->text(), 1);
});
connect(m_connection, &ProviderConnectionBase::statusUpdate, this, &ProviderConnectionView::insertStatus);
setWindowTitle(m_connection->windowTitle());
}
void ProviderConnectionView::insertStatus(const QString &direction,
const QString &type,
const QString &topic,
const QString &id,
const QString &content)
{
ui->statusTable->insertRow(0);
ui->statusTable->setItem(0, 0, new QTableWidgetItem(direction));
ui->statusTable->setItem(0, 1, new QTableWidgetItem(type));
ui->statusTable->setItem(0, 2, new QTableWidgetItem(topic));
ui->statusTable->setItem(0, 3, new QTableWidgetItem(id));
ui->statusTable->setItem(0, 4, new QTableWidgetItem(content));
}