32 #include <boost/filesystem.hpp>
40 #include <QTextBrowser>
41 #include <QVBoxLayout>
42 #include <QDialogButtonBox>
43 #include <QPushButton>
47 #include <QHeaderView>
80 bool isSubtopic(
const std::string& base,
const std::string& topic)
94 std::string query = topic;
120 QList<PluginGroup>* groups,
121 QList<ros::master::TopicInfo>* unvisualizable)
126 ros::master::V_TopicInfo::iterator topic_it;
128 for (topic_it = all_topics.begin(); topic_it != all_topics.end(); ++topic_it)
130 QString topic = QString::fromStdString(topic_it->name);
131 QString
datatype = QString::fromStdString(topic_it->datatype);
133 if (datatype_plugins.contains(
datatype))
135 if (groups->empty() || !
isSubtopic(groups->back().base_topic.toStdString(), topic.toStdString()))
143 QString topic_suffix(
"raw");
147 topic_suffix = topic.right(topic.size() - group.
base_topic.size() - 1);
150 const QList<QString>& plugin_names = datatype_plugins.values(
datatype);
151 for (
int i = 0; i < plugin_names.size(); ++i)
153 const QString& name = plugin_names[i];
161 unvisualizable->append(*topic_it);
169 const QStringList& disallowed_display_names,
170 const QStringList& disallowed_class_lookup_names,
171 QString* lookup_name_output,
172 QString* display_name_output,
173 QString* topic_output,
174 QString* datatype_output,
178 , disallowed_display_names_(disallowed_display_names)
179 , disallowed_class_lookup_names_(disallowed_class_lookup_names)
180 , lookup_name_output_(lookup_name_output)
181 , display_name_output_(display_name_output)
182 , topic_output_(topic_output)
183 , datatype_output_(datatype_output)
188 QGroupBox* type_box =
new QGroupBox(
"Create visualization");
190 QLabel* description_label =
new QLabel(
"Description:");
199 topic_widget->
fill(factory);
205 QVBoxLayout* type_layout =
new QVBoxLayout;
207 type_layout->addWidget(description_label);
210 type_box->setLayout(type_layout);
213 QGroupBox* name_box =
nullptr;
216 name_box =
new QGroupBox(
"Display Name");
218 QVBoxLayout* name_layout =
new QVBoxLayout;
220 name_box->setLayout(name_layout);
224 button_box_ =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal);
226 QVBoxLayout* main_layout =
new QVBoxLayout;
227 main_layout->addWidget(type_box);
230 main_layout->addWidget(name_box);
233 setLayout(main_layout);
243 connect(
button_box_, &QDialogButtonBox::rejected,
this, &AddDisplayDialog::reject);
256 return (QSize(500, 660));
293 QString html =
"<html><body>" + data->
whats_this +
"</body></html>";
318 if (display_name.size() == 0)
320 setError(
"Enter a name for the display.");
325 setError(
"Name in use. Display names must be unique.");
335 button_box_->button(QDialogButtonBox::Ok)->setToolTip(error_text);
358 setHeaderHidden(
true);
366 if (curr->parent() !=
nullptr)
370 sd.
lookup_name = curr->data(0, Qt::UserRole).toString();
378 QIcon default_package_icon =
loadPixmap(
"package://rviz/icons/default_package_icon.png");
384 std::map<QString, QTreeWidgetItem*> package_items;
386 for (
int i = 0; i < classes.size(); i++)
388 QString lookup_name = classes[i];
389 QString
package = factory->getClassPackage(lookup_name);
393 QTreeWidgetItem* package_item;
395 std::map<QString, QTreeWidgetItem*>::iterator mi;
396 mi = package_items.find(
package);
397 if (mi == package_items.end())
399 package_item =
new QTreeWidgetItem(
this);
400 package_item->setText(0,
package);
401 package_item->setIcon(0, default_package_icon);
403 package_item->setExpanded(
true);
404 package_items[
package] = package_item;
408 package_item = (*mi).second;
410 QTreeWidgetItem* class_item =
new QTreeWidgetItem(package_item);
412 class_item->setIcon(0, factory->
getIcon(lookup_name));
414 class_item->setText(0, name);
417 class_item->setData(0, Qt::UserRole, lookup_name);
423 tree_ =
new QTreeWidget;
424 tree_->setHeaderHidden(
true);
425 tree_->setColumnCount(2);
427 tree_->header()->setStretchLastSection(
false);
428 tree_->header()->setSectionResizeMode(0, QHeaderView::Stretch);
430 enable_hidden_box_ =
new QCheckBox(
"Show unvisualizable topics");
431 enable_hidden_box_->setCheckState(Qt::Unchecked);
433 QVBoxLayout* layout =
new QVBoxLayout;
434 layout->setContentsMargins(QMargins(0, 0, 0, 0));
436 layout->addWidget(tree_);
437 layout->addWidget(enable_hidden_box_);
453 if (curr->data(1, Qt::UserRole).isValid())
455 QTreeWidgetItem* parent = curr->parent();
458 sd.
topic = parent->data(0, Qt::UserRole).toString();
459 sd.
lookup_name = curr->data(0, Qt::UserRole).toString();
462 QComboBox* combo = qobject_cast<QComboBox*>(tree_->itemWidget(curr, 1));
463 if (combo !=
nullptr)
465 QString combo_text = combo->currentText();
466 if (combo_text !=
"raw")
468 sd.
topic +=
"/" + combo_text;
470 sd.
datatype = combo->itemData(combo->currentIndex()).toString();
474 sd.
datatype = curr->data(1, Qt::UserRole).toString();
482 tree_->setCurrentItem(curr);
487 bool hide_disabled = state == Qt::Unchecked;
488 QTreeWidgetItemIterator it(tree_, QTreeWidgetItemIterator::Disabled);
491 QTreeWidgetItem* item = *it;
492 item->setHidden(hide_disabled);
498 findPlugins(factory);
500 QList<PluginGroup> groups;
501 QList<ros::master::TopicInfo> unvisualizable;
505 QList<PluginGroup>::const_iterator pg_it;
506 for (pg_it = groups.begin(); pg_it < groups.end(); ++pg_it)
510 QTreeWidgetItem* item = insertItem(pg.
base_topic,
false);
511 item->setData(0, Qt::UserRole, pg.
base_topic);
513 QMap<QString, PluginGroup::Info>::const_iterator it;
516 const QString& plugin_name = it.key();
518 QTreeWidgetItem* row =
new QTreeWidgetItem(item);
521 row->setIcon(0, factory->
getIcon(plugin_name));
523 row->setData(0, Qt::UserRole, plugin_name);
524 row->setData(1, Qt::UserRole, info.
datatypes[0]);
534 tree_->setItemWidget(row, 1, box);
535 tree_->setColumnWidth(1, std::max(tree_->columnWidth(1), box->width()));
541 for (
int i = 0; i < unvisualizable.size(); ++i)
544 insertItem(QString::fromStdString(ti.
name),
true);
548 stateChanged(enable_hidden_box_->isChecked());
556 QStringList::iterator it;
557 for (it = lookup_names.begin(); it != lookup_names.end(); ++it)
559 const QString& lookup_name = *it;
563 Q_FOREACH (QString topic_type, topic_types)
566 datatype_plugins_.insert(topic_type, lookup_name);
573 QTreeWidgetItem* current = tree_->invisibleRootItem();
575 QStringList parts = topic.split(
"/");
577 for (
int part_ind = 1; part_ind < parts.size(); ++part_ind)
579 QString part =
"/" + parts[part_ind];
582 for (
int c = 0; c < current->childCount(); ++c)
584 QTreeWidgetItem* child = current->child(c);
585 if (child->text(0) == part && !child->data(1, Qt::UserRole).isValid())
595 QTreeWidgetItem* new_child =
new QTreeWidgetItem(current);
597 new_child->setExpanded(3 > part_ind);
598 new_child->setText(0, part);
599 new_child->setDisabled(disabled);