Skip to content

Commit

Permalink
force topic list to use actual displayed list of topics
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-alton committed Jan 2, 2025
1 parent 67b1ee4 commit c75216f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions mapviz_plugins/src/topic_select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,19 @@ std::vector<std::string> SelectTopicDialog::filterTopics(
void SelectTopicDialog::updateDisplayedTopics()
{
std::vector<std::string> next_displayed_topics = filterTopics(known_topics_);

// It's a lot more work to keep track of the additions/removals like
// this compared to resetting the QListWidget's items each time, but
// it allows Qt to properly track the selection and current items
// across updates, which results in much less frustration for the user.

displayed_topics_.clear();
std::set<std::string> prev_names;
for (const auto & displayed_topic : displayed_topics_) {
prev_names.insert(displayed_topic);
}

for (int i = 0; i < ui_->topicList->count(); i++)
{
prev_names.insert(ui_->topicList->item(i)->text().toStdString());
displayed_topics_.push_back(ui_->topicList->item(i)->text().toStdString());
}
std::set<std::string> next_names;
for (const auto & next_displayed_topic : next_displayed_topics) {
next_names.insert(next_displayed_topic);
Expand Down Expand Up @@ -375,6 +377,7 @@ void SelectTopicDialog::updateDisplayedTopics()
}

// Now we can add the new items.

for (size_t i = 0; i < next_displayed_topics.size(); i++) {
if (added_names.count(next_displayed_topics[i]) == 0) {
continue;
Expand Down

0 comments on commit c75216f

Please sign in to comment.