33 #include <QListWidget> 35 #include <QVBoxLayout> 36 #include <QHBoxLayout> 37 #include <QPushButton> 39 #include <QTimerEvent> 44 const std::string &datatype,
47 std::vector<std::string> datatypes;
48 datatypes.push_back(datatype);
53 const std::string &datatype1,
54 const std::string &datatype2,
57 std::vector<std::string> datatypes;
58 datatypes.push_back(datatype1);
59 datatypes.push_back(datatype2);
64 const std::vector<std::string> &datatypes,
70 if (dialog.exec() == QDialog::Accepted) {
78 const std::string &datatype,
81 std::vector<std::string> datatypes;
82 datatypes.push_back(datatype);
87 const std::string &datatype1,
88 const std::string &datatype2,
91 std::vector<std::string> datatypes;
92 datatypes.push_back(datatype1);
93 datatypes.push_back(datatype2);
98 const std::vector<std::string> &datatypes,
104 if (dialog.exec() == QDialog::Accepted) {
107 return std::vector<ros::master::TopicInfo>();
118 QHBoxLayout *filter_box =
new QHBoxLayout();
119 filter_box->addWidget(
new QLabel(
"Filter:"));
122 QHBoxLayout *button_box =
new QHBoxLayout();
123 button_box->addStretch(1);
127 QVBoxLayout *vbox =
new QVBoxLayout();
129 vbox->addLayout(filter_box);
130 vbox->addLayout(button_box);
134 this, SLOT(accept()));
136 this, SLOT(reject()));
137 connect(
name_filter_, SIGNAL(textChanged(
const QString &)),
143 setWindowTitle(
"Select topics...");
160 QDialog::closeEvent(event);
167 list_widget_->setSelectionMode(QAbstractItemView::MultiSelection);
169 list_widget_->setSelectionMode(QAbstractItemView::SingleSelection);
174 const std::vector<std::string> &datatypes)
177 for (
size_t i = 0; i < datatypes.size(); i++) {
186 if (selection.empty()) {
189 return selection.front();
195 QModelIndexList qt_selection =
list_widget_->selectionModel()->selectedIndexes();
197 std::vector<ros::master::TopicInfo> selection;
198 selection.resize(qt_selection.size());
199 for (
int i = 0; i < qt_selection.size(); i++) {
200 if (!qt_selection[i].isValid()) {
204 int row = qt_selection[i].row();
229 const std::vector<ros::master::TopicInfo> &topics)
const 232 std::vector<ros::master::TopicInfo> filtered;
234 for (
size_t i = 0; i < topics.size(); i++) {
240 QString topic_name = QString::fromStdString(topics[i].
name);
241 if (!topic_filter.isEmpty() &&
242 !topic_name.contains(topic_filter, Qt::CaseInsensitive)) {
246 filtered.push_back(topics[i]);
261 std::set<std::string> prev_names;
266 std::set<std::string> next_names;
267 for (
size_t i = 0; i < next_displayed_topics.size(); i++) {
268 next_names.insert(next_displayed_topics[i].
name);
271 std::set<std::string> added_names;
272 std::set_difference(next_names.begin(), next_names.end(),
273 prev_names.begin(), prev_names.end(),
274 std::inserter(added_names, added_names.end()));
276 std::set<std::string> removed_names;
277 std::set_difference(prev_names.begin(), prev_names.end(),
278 next_names.begin(), next_names.end(),
279 std::inserter(removed_names, removed_names.end()));
288 QListWidgetItem *item =
list_widget_->takeItem(i - removed);
294 for (
size_t i = 0; i < next_displayed_topics.size(); i++) {
295 if (added_names.count(next_displayed_topics[i].name) == 0) {
299 list_widget_->insertItem(i, QString::fromStdString(next_displayed_topics[i].
name));
void closeEvent(QCloseEvent *)
std::set< std::string > allowed_datatypes_
static ros::master::TopicInfo selectTopic(const std::string &datatype, QWidget *parent=0)
void setDatatypeFilter(const std::vector< std::string > &datatypes)
ros::master::TopicInfo selectedTopic() const
std::vector< ros::master::TopicInfo > filterTopics(const std::vector< ros::master::TopicInfo > &) const
QListWidget * list_widget_
ROSCPP_DECL bool getTopics(V_TopicInfo &topics)
void updateDisplayedTopics()
QPushButton * cancel_button_
std::vector< ros::master::TopicInfo > known_topics_
static bool topicSort(const ros::master::TopicInfo &info1, const ros::master::TopicInfo &info2)
void allowMultipleTopics(bool allow)
int fetch_topics_timer_id_
std::vector< ros::master::TopicInfo > displayed_topics_
SelectTopicDialog(QWidget *parent=0)
std::vector< ros::master::TopicInfo > selectedTopics() const
static std::vector< ros::master::TopicInfo > selectTopics(const std::string &datatype, QWidget *parent=0)
void timerEvent(QTimerEvent *)