MCPcopy Create free account
hub / github.com/KDE/labplot / mqttMessageReceived

Method mqttMessageReceived

src/frontend/datasources/ImportFileWidget.cpp:2762–2852  ·  view source on GitHub ↗

! *\brief called when the client receives a message * if the message arrived from a new topic, the topic is put in twTopics */

Source from the content-addressed store, hash-verified

2760 * if the message arrived from a new topic, the topic is put in twTopics
2761 */
2762void ImportFileWidget::mqttMessageReceived(const QByteArray& /*message*/, const QMqttTopicName& topic) {
2763 // qDebug()<<"received " << topic.name();
2764 if (m_addedTopics.contains(topic.name()))
2765 return;
2766
2767 m_addedTopics.push_back(topic.name());
2768 m_subscriptionWidget->setTopicTreeText(i18n("Available (%1)", m_addedTopics.size()));
2769 QStringList name;
2770 QString rootName;
2771 const QChar sep = QLatin1Char('/');
2772
2773 if (topic.name().contains(sep)) {
2774 const QStringList& list = topic.name().split(sep, Qt::SkipEmptyParts);
2775
2776 if (!list.isEmpty()) {
2777 rootName = list.at(0);
2778 name.append(list.at(0));
2779 int topItemIdx = -1;
2780 // check whether the first level of the topic can be found in twTopics
2781 for (int i = 0; i < m_subscriptionWidget->topicCount(); ++i) {
2782 if (m_subscriptionWidget->topLevelTopic(i)->text(0) == list.at(0)) {
2783 topItemIdx = i;
2784 break;
2785 }
2786 }
2787
2788 // if not we simply add every level of the topic to the tree
2789 if (topItemIdx < 0) {
2790 auto* currentItem = new QTreeWidgetItem(name);
2791 m_subscriptionWidget->addTopic(currentItem);
2792 for (int i = 1; i < list.size(); ++i) {
2793 name.clear();
2794 name.append(list.at(i));
2795 currentItem->addChild(new QTreeWidgetItem(name));
2796 currentItem = currentItem->child(0);
2797 }
2798 }
2799 // otherwise we search for the first level that isn't part of the tree,
2800 // then add every level of the topic to the tree from that certain level
2801 else {
2802 QTreeWidgetItem* currentItem = m_subscriptionWidget->topLevelTopic(topItemIdx);
2803 int listIdx = 1;
2804 for (; listIdx < list.size(); ++listIdx) {
2805 QTreeWidgetItem* childItem = nullptr;
2806 bool found = false;
2807 for (int j = 0; j < currentItem->childCount(); ++j) {
2808 childItem = currentItem->child(j);
2809 if (childItem->text(0) == list.at(listIdx)) {
2810 found = true;
2811 currentItem = childItem;
2812 break;
2813 }
2814 }
2815 if (!found) {
2816 // this is the level that isn't present in the tree
2817 break;
2818 }
2819 }

Callers

nothing calls this directly

Calls 15

setTopicTreeTextMethod · 0.80
splitMethod · 0.80
appendMethod · 0.80
topicCountMethod · 0.80
topLevelTopicMethod · 0.80
addTopicMethod · 0.80
subscriptionCountMethod · 0.80
topLevelSubscriptionMethod · 0.80
containsMethod · 0.45
nameMethod · 0.45
sizeMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected