MCPcopy Create free account
hub / github.com/WarmUpTill/SceneSwitcher / SetValues

Method SetValues

plugins/mqtt/topic-selection.cpp:45–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45void MqttTopicListWidget::SetValues(const std::vector<std::string> &topics,
46 const std::vector<int> &qos)
47{
48 assert(topics.size() == qos.size());
49 if (topics.size() != qos.size()) {
50 blog(LOG_WARNING, "%s topics and qos size mismatch", __func__);
51 return;
52 }
53
54 _table->setRowCount(0);
55 _topicSet.clear();
56
57 std::vector<std::pair<QString, int>> entries;
58 for (size_t i = 0; i < topics.size(); ++i) {
59 auto topic = QString::fromStdString(topics[i]).trimmed();
60 int qos_ = qos[i];
61 if (topic.isEmpty()) {
62 blog(LOG_INFO, "%s ignoring empty topic entry",
63 __func__);
64 continue;
65 }
66 if (_topicSet.contains(topic)) {
67 blog(LOG_INFO, "%s discarding duplicate topic \"%s\"",
68 __func__, topics[i].c_str());
69 continue;
70 }
71 if (qos_ < 0 || qos_ > 2) {
72 blog(LOG_INFO,
73 "%s discard invalid QoS level \"%d\" and set to \"1\"",
74 __func__, qos[i]);
75 qos_ = 1;
76 }
77 entries.emplace_back(topic, qos_);
78 _topicSet.insert(topic);
79 }
80
81 for (const auto &entry : entries) {
82 int row = _table->rowCount();
83 _table->insertRow(row);
84 _table->setItem(row, 0, new QTableWidgetItem(entry.first));
85 _table->setItem(
86 row, 1,
87 new QTableWidgetItem(QString::number(entry.second)));
88 }
89
90 SortTable();
91}
92
93std::vector<std::string> MqttTopicListWidget::GetTopics()
94{

Callers 1

Calls 3

sizeMethod · 0.80
rowCountMethod · 0.80
c_strMethod · 0.45

Tested by

no test coverage detected