8 qRegisterMetaType<QMessageBox::Icon>();
13 connect(
this, SIGNAL(
displayMessageBox(
const QString,
const QString,
const QString,
const QMessageBox::Icon)),
this,
17 QWidget *scroll_widget =
new QWidget;
18 scroll_widget->setLayout(
layout_);
19 QScrollArea *scroll_area =
new QScrollArea;
20 scroll_area->setWidget(scroll_widget);
21 scroll_area->setWidgetResizable(
true);
22 scroll_area->setFrameShape(QFrame::NoFrame);
23 QVBoxLayout* main_layout =
new QVBoxLayout(
this);
24 main_layout->addWidget(scroll_area);
26 QPushButton *
configure =
new QPushButton(
"Configure");
27 configure->setIcon(QIcon::fromTheme(
"preferences-system"));
28 connect(configure, SIGNAL(clicked()),
this, SLOT(
configure()));
35 labels.push_back(
"Topic");
36 labels.push_back(
"Value");
37 table_->setHorizontalHeaderLabels(labels);
38 table_->setShowGrid(
false);
40 Q_EMIT setEnabled(
true);
42 connect(
table_->horizontalHeader(), SIGNAL(sectionResized(
int,
int,
int)),
this, SIGNAL(
configChanged()));
43 connect(
table_->verticalHeader(), SIGNAL(sectionResized(
int,
int,
int)),
this, SIGNAL(
configChanged()));
61 if (!config.
mapGetString(
"topic_" + QString::number(i) +
"_name", &topic_name))
64 if (!config.
mapGetString(
"topic_" + QString::number(i) +
"_type", &topic_type))
67 displayed_topics_.insert(std::pair<std::string, std::string>(topic_name.toStdString(), topic_type.toStdString()));
74 QString table_header_state_str;
75 if (config.
mapGetString(
"horizontal_table_header", &table_header_state_str))
77 table_->horizontalHeader()->restoreState(QByteArray::fromHex(qPrintable(table_header_state_str)));
80 if (config.
mapGetString(
"vertical_table_header", &table_header_state_str))
82 table_->verticalHeader()->restoreState(QByteArray::fromHex(qPrintable(table_header_state_str)));
92 config.
mapSetValue(
"topic_" + QString::number(i) +
"_name", QString::fromStdString(topic.first));
93 config.
mapSetValue(
"topic_" + QString::number(i) +
"_type", QString::fromStdString(topic.second));
97 QByteArray table_header_state(
table_->horizontalHeader()->saveState());
99 config.
mapSetValue(
"horizontal_table_header", table_header_state.toHex());
101 table_header_state =
table_->verticalHeader()->saveState();
103 config.
mapSetValue(
"vertical_table_header", table_header_state.toHex());
108 Q_EMIT setEnabled(
false);
113 Q_EMIT
displayMessageBox(
"Error getting topics",
"Could not retrieve the topics names.",
"",
114 QMessageBox::Icon::Critical);
115 Q_EMIT setEnabled(
true);
120 for (
auto topic : topics)
122 if (topic.datatype ==
"std_msgs/Bool" ||
123 topic.datatype ==
"std_msgs/Int8" ||
124 topic.datatype ==
"std_msgs/UInt8" ||
125 topic.datatype ==
"std_msgs/Int16" ||
126 topic.datatype ==
"std_msgs/UInt16" ||
127 topic.datatype ==
"std_msgs/Int32" ||
128 topic.datatype ==
"std_msgs/UInt32" ||
129 topic.datatype ==
"std_msgs/Int64" ||
130 topic.datatype ==
"std_msgs/UInt64" ||
131 topic.datatype ==
"std_msgs/Float32" ||
132 topic.datatype ==
"std_msgs/Float64" ||
133 topic.datatype ==
"std_msgs/String" ||
134 topic.datatype ==
"std_msgs/Time" ||
135 topic.datatype ==
"std_msgs/Duration")
136 supported_topics.push_back(topic);
139 if (supported_topics.empty())
141 Q_EMIT setEnabled(
false);
143 QDialog *no_topics_dialog =
new QDialog(
this);
144 no_topics_dialog->setWindowTitle(
"No supported topic");
145 QVBoxLayout *layout =
new QVBoxLayout;
146 no_topics_dialog->setLayout(layout);
148 new QLabel(
"Error with topics, no supported topics found.\n" 149 "- Ok will clear the topics displayed\n- Cancel will not change the displayed topics"));
151 QDialogButtonBox *button_box =
new QDialogButtonBox(QDialogButtonBox::Ok
152 | QDialogButtonBox::Cancel);
153 no_topics_dialog->layout()->addWidget(button_box);
155 connect(button_box, &QDialogButtonBox::accepted, no_topics_dialog, &QDialog::accept);
156 connect(button_box, &QDialogButtonBox::rejected, no_topics_dialog, &QDialog::reject);
158 if (!no_topics_dialog->exec())
160 Q_EMIT setEnabled(
true);
167 Q_EMIT setEnabled(
true);
171 QDialog *pick_topics_dialog =
new QDialog(
this);
172 pick_topics_dialog->setWindowTitle(
"Pick displayed topics");
173 QVBoxLayout *layout =
new QVBoxLayout;
174 pick_topics_dialog->setLayout(layout);
175 layout->addWidget(
new QLabel(
"Only supported built-in types are displayed"));
177 std::vector<QCheckBox *> topic_buttons;
178 for (
auto topic : supported_topics)
180 QCheckBox *radio_button =
new QCheckBox;
183 radio_button->setChecked(
true);
185 topic_buttons.push_back(radio_button);
186 radio_button->setText(QString::fromStdString(topic.name));
187 radio_button->setToolTip(QString::fromStdString(topic.datatype));
188 pick_topics_dialog->layout()->addWidget(radio_button);
191 QDialogButtonBox *button_box =
new QDialogButtonBox(QDialogButtonBox::Ok
192 | QDialogButtonBox::Cancel);
193 pick_topics_dialog->layout()->addWidget(button_box);
195 connect(button_box, &QDialogButtonBox::accepted, pick_topics_dialog, &QDialog::accept);
196 connect(button_box, &QDialogButtonBox::rejected, pick_topics_dialog, &QDialog::reject);
198 if (!pick_topics_dialog->exec())
200 Q_EMIT setEnabled(
true);
207 for (
auto button : topic_buttons)
209 if (!button->isChecked())
212 displayed_topics_.insert(std::pair<std::string, std::string>(button->text().toStdString(),
213 button->toolTip().toStdString()));
217 Q_EMIT setEnabled(
true);
228 std::shared_ptr<TopicInfo> topic_info(
new TopicInfo(topic.first, topic.second));
235 table_->setCellWidget(i, 0, topic_info->label_.get());
236 table_->setCellWidget(i, 1, topic_info->display_.get());
242 const QString message,
243 const QString info_msg,
244 const QMessageBox::Icon icon)
246 const bool old(isEnabled());
247 Q_EMIT setEnabled(
false);
249 msg_box.setWindowTitle(title);
250 msg_box.setText(message);
251 msg_box.setInformativeText(info_msg);
252 msg_box.setIcon(icon);
253 msg_box.setStandardButtons(QMessageBox::Ok);
255 Q_EMIT setEnabled(old);
void updateTopicsDisplayed()
void displayMessageBoxHandler(const QString title, const QString message, const QString info_msg="", const QMessageBox::Icon icon=QMessageBox::Icon::Information)
ROSCPP_DECL bool getTopics(V_TopicInfo &topics)
std::vector< std::shared_ptr< TopicInfo > > topic_infos_
std::vector< TopicInfo > V_TopicInfo
virtual void save(rviz::Config config) const
bool mapGetString(const QString &key, QString *value_out) const
void mapSetValue(const QString &key, QVariant value)
virtual void setName(const QString &name)
virtual void load(const rviz::Config &config)
std::map< std::string, std::string > displayed_topics_
virtual QString getName() const
DisplayTopics(QWidget *parent=NULL)
void displayMessageBox(const QString, const QString, const QString, const QMessageBox::Icon)
virtual void save(Config config) const
virtual void load(const Config &config)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)