! * \brief Reparents the given MQTTTopic to the given MQTTSubscription * * \param topic, the name of the MQTTTopic * \param parent, the name of the MQTTSubscription */
| 515 | * \param parent, the name of the MQTTSubscription |
| 516 | */ |
| 517 | void MQTTClient::reparentTopic(const QString& topicName, const QString& parentTopicName) { |
| 518 | // We can only reparent if the parent contained the topic |
| 519 | if (m_subscriptions.contains(parentTopicName) && m_topicNames.contains(topicName)) { |
| 520 | // qDebug() << "Reparent " << topicName << " to " << parentTopicName; |
| 521 | // search for the parent MQTTSubscription |
| 522 | bool found = false; |
| 523 | MQTTSubscription* superiorSubscription = nullptr; |
| 524 | for (auto* subscription : m_MQTTSubscriptions) { |
| 525 | if (subscription->subscriptionName() == parentTopicName) { |
| 526 | found = true; |
| 527 | superiorSubscription = subscription; |
| 528 | break; |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | if (found) { |
| 533 | // get every topic of the MQTTClient |
| 534 | QVector<MQTTTopic*> topics = children<MQTTTopic>(AbstractAspect::ChildIndexFlag::Recursive); |
| 535 | // Search for the given topic among the MQTTTopics |
| 536 | for (auto* topic : topics) { |
| 537 | if (topicName == topic->topicName()) { |
| 538 | // if found, it is reparented to the parent MQTTSubscription |
| 539 | topic->reparent(superiorSubscription); |
| 540 | break; |
| 541 | } |
| 542 | } |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | /*! |
| 548 | *\brief Checks if a topic contains another one |
nothing calls this directly
no test coverage detected