selection_topics.cpp
Go to the documentation of this file.
2 
3 namespace graph_rviz_plugin
4 {
5 
6 SelectionTopics::SelectionTopics(std::shared_ptr<ros::NodeHandle> nh,
7  std::deque<std::shared_ptr<TopicData>> already_displayed_topics,
8  const std::vector<std::string> allowed_types,
9  const bool single_choice,
10  QDialog *) :
11  nh_(nh),
12  already_displayed_topics_(already_displayed_topics),
13  allowed_types_(allowed_types),
14  single_choice_(single_choice)
15 {
16  setWindowTitle("Topics selection");
17  QVBoxLayout *main_layout = new QVBoxLayout;
18  setLayout(main_layout);
19  QVBoxLayout *scroll_widget_layout = new QVBoxLayout;
20  QWidget *scroll_widget = new QWidget;
21  scroll_widget->setLayout(scroll_widget_layout);
22  QScrollArea *scroll_area = new QScrollArea;
23  scroll_area->setWidget(scroll_widget);
24  scroll_area->setWidgetResizable(true);
25  scroll_area->setFrameShape(QFrame::NoFrame);
26  detectTopics();
27 
29  return a.name < b.name;
30  });
31 
32  for (auto topic : supported_topics_)
33  {
34  QAbstractButton *button;
35  if (single_choice_)
36  button = new QRadioButton;
37  else
38  button = new QCheckBox;
39 
40  topic_buttons_.push_back(button);
41  button->setText(QString::fromStdString(topic.name));
42  button->setObjectName(QString::fromStdString(topic.name));
43  button->setToolTip(QString::fromStdString(topic.datatype));
44 
45  for (std::size_t i(0); i < already_displayed_topics_.size(); ++i)
46  {
47  if (!already_displayed_topics_.at(i))
48  continue;
49 
50  if (already_displayed_topics_.at(i)->topic_name_ == topic.name)
51  button->setChecked(true);
52  }
53 
54  scroll_widget_layout->addWidget(button);
55  }
56 
57  main_layout->addWidget(scroll_area);
58  QDialogButtonBox *button_box = new QDialogButtonBox(QDialogButtonBox::Ok
59  | QDialogButtonBox::Cancel);
60  main_layout->addWidget(button_box);
61 
62  connect(button_box, &QDialogButtonBox::accepted, this, &SelectionTopics::okClicked);
63  connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
65 }
66 
68 {
69 }
70 
72 {
74 
75  if (!ros::master::getTopics(topics))
76  {
77  Q_EMIT displayMessageBox("Error getting topics", "Could not retrieve the topics names.", "",
78  QMessageBox::Icon::Critical);
79  return;
80  }
81 
82  for (auto topic : topics)
83  {
84  for (auto type : allowed_types_)
85  {
86  if (topic.datatype == type)
87  {
88  supported_topics_.push_back(topic);
89  break;
90  }
91  }
92  }
93 }
94 
96  const QString text,
97  const QString info,
98  const QMessageBox::Icon icon)
99 {
100  const bool old_state(isEnabled());
101  setEnabled(false);
102  QMessageBox msg_box;
103  msg_box.setWindowTitle(title);
104  msg_box.setText(text);
105  msg_box.setInformativeText(info);
106  msg_box.setIcon(icon);
107  msg_box.setStandardButtons(QMessageBox::Ok);
108  msg_box.exec();
109  setEnabled(old_state);
110 }
111 
113 {
114  displayed_topics_.clear();
115  for (auto button : topic_buttons_)
116  {
117  if (!button->isChecked())
118  continue;
119 
120  std::shared_ptr<TopicData> topic_data =
121  std::make_shared<TopicData>(button->objectName().toStdString(), button->toolTip().toStdString(), nh_);
122  displayed_topics_.push_back(topic_data);
123  }
124 
125  accept();
126 }
127 
128 }
std::deque< std::shared_ptr< TopicData > > displayed_topics_
ROSCPP_DECL bool getTopics(V_TopicInfo &topics)
std::vector< TopicInfo > V_TopicInfo
std::deque< std::shared_ptr< TopicData > > already_displayed_topics_
std::vector< QAbstractButton * > topic_buttons_
const std::vector< std::string > allowed_types_
void displayMessageBoxHandler(const QString title, const QString text, const QString info="", const QMessageBox::Icon icon=QMessageBox::Icon::Information)
SelectionTopics(std::shared_ptr< ros::NodeHandle > nh, std::deque< std::shared_ptr< TopicData >> already_displayed_topics, const std::vector< std::string > allowed_types, const bool single_choice, QDialog *parent=0)
ros::master::V_TopicInfo supported_topics_
void displayMessageBox(const QString, const QString, const QString, const QMessageBox::Icon)
std::shared_ptr< ros::NodeHandle > nh_


graph_rviz_plugin
Author(s): Édouard Pronier, Victor Lamoine - Institut Maupertuis
autogenerated on Mon Feb 28 2022 22:27:30