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

Method addTopicToTree

src/frontend/dockwidgets/LiveDataDock.cpp:683–762  ·  view source on GitHub ↗

! *\brief Adds topicName to twTopics * * \param topicName the name of the topic, which will be added to the tree widget */

Source from the content-addressed store, hash-verified

681 * \param topicName the name of the topic, which will be added to the tree widget
682 */
683void LiveDataDock::addTopicToTree(const QString& topicName) {
684 QStringList name;
685 QChar sep = QLatin1Char('/');
686 QString rootName;
687 if (topicName.contains(sep)) {
688 QStringList list = topicName.split(sep, Qt::SkipEmptyParts);
689
690 if (!list.isEmpty()) {
691 rootName = list.at(0);
692 name.append(list.at(0));
693 QTreeWidgetItem* currentItem;
694 // check whether the first level of the topic can be found in twTopics
695 int topItemIdx = -1;
696 for (int i = 0; i < m_subscriptionWidget->topicCount(); ++i) {
697 if (m_subscriptionWidget->topLevelTopic(i)->text(0) == list.at(0)) {
698 topItemIdx = i;
699 break;
700 }
701 }
702 // if not we simply add every level of the topic to the tree
703 if (topItemIdx < 0) {
704 currentItem = new QTreeWidgetItem(name);
705 m_subscriptionWidget->addTopic(currentItem);
706 for (int i = 1; i < list.size(); ++i) {
707 name.clear();
708 name.append(list.at(i));
709 currentItem->addChild(new QTreeWidgetItem(name));
710 currentItem = currentItem->child(0);
711 }
712 }
713 // otherwise we search for the first level that isn't part of the tree,
714 // then add every level of the topic to the tree from that certain level
715 else {
716 currentItem = m_subscriptionWidget->topLevelTopic(topItemIdx);
717 int listIdx = 1;
718 for (; listIdx < list.size(); ++listIdx) {
719 QTreeWidgetItem* childItem = nullptr;
720 bool found = false;
721 for (int j = 0; j < currentItem->childCount(); ++j) {
722 childItem = currentItem->child(j);
723 if (childItem->text(0) == list.at(listIdx)) {
724 found = true;
725 currentItem = childItem;
726 break;
727 }
728 }
729 if (!found) {
730 // this is the level that isn't present in the tree
731 break;
732 }
733 }
734
735 // add every level to the tree starting with the first level that isn't part of the tree
736 for (; listIdx < list.size(); ++listIdx) {
737 name.clear();
738 name.append(list.at(listIdx));
739 currentItem->addChild(new QTreeWidgetItem(name));
740 currentItem = currentItem->child(currentItem->childCount() - 1);

Callers

nothing calls this directly

Calls 15

splitMethod · 0.80
appendMethod · 0.80
topicCountMethod · 0.80
topLevelTopicMethod · 0.80
addTopicMethod · 0.80
subscriptionCountMethod · 0.80
topLevelSubscriptionMethod · 0.80
MQTTSubscriptionsMethod · 0.80
containsMethod · 0.45
isEmptyMethod · 0.45
textMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected