|
2 | 2 |
|
3 | 3 | #include <QDebug> |
4 | 4 | #include <QDialog> |
5 | | -#include <QFormLayout> |
6 | | -#include <QCheckBox> |
7 | | -#include <QLabel> |
8 | | -#include <QLineEdit> |
9 | | -#include <QHBoxLayout> |
10 | | -#include <QVBoxLayout> |
11 | | -#include <QDialogButtonBox> |
12 | | -#include <QScrollArea> |
| 5 | +#include <QTableWidget> |
| 6 | +#include <QTableWidgetItem> |
| 7 | +#include <QAbstractItemView> |
13 | 8 | #include <QPushButton> |
14 | | -#include <QSettings> |
15 | | -#include <QRadioButton> |
16 | | -#include <unordered_map> |
17 | 9 | #include <algorithm> |
18 | | -#include <QMessageBox> |
19 | 10 | #include <tf2_ros/qos.hpp> |
20 | 11 | #include <rosbag2_cpp/types.hpp> |
21 | 12 | #include <rmw/rmw.h> |
@@ -155,48 +146,56 @@ void TopicPublisherROS2::filterDialog() |
155 | 146 |
|
156 | 147 | std::map<std::string, QCheckBox*> checkbox; |
157 | 148 |
|
158 | | - std::map<std::string, QCheckBox *> checkbox; |
159 | | - std::map<std::string, std::pair<QLabel *, QCheckBox *>> topic_widgets; |
| 149 | + dialog->ui()->listTopics->setRowCount(sorted_topics.size()); |
160 | 150 |
|
161 | | - for (const TopicInfo &info : sorted_topics) |
| 151 | + for (size_t i = 0; i < sorted_topics.size(); i++) |
162 | 152 | { |
163 | | - const std::string topic_name = info.topic_name; |
164 | | - auto cb = new QCheckBox(dialog); |
| 153 | + const std::string topic_name = sorted_topics[i].topic_name; |
| 154 | + auto item = new QTableWidgetItem(QString::fromStdString(topic_name)); |
| 155 | + item->setFlags(item->flags() & ~Qt::ItemIsEditable); |
| 156 | + dialog->ui()->listTopics->setItem(i, 0, item); |
| 157 | + |
165 | 158 | auto filter_it = _topics_to_publish.find(topic_name); |
166 | | - if (filter_it == _topics_to_publish.end()) |
| 159 | + if (filter_it == _topics_to_publish.end() || filter_it->second) |
167 | 160 | { |
168 | | - cb->setChecked(true); |
| 161 | + dialog->ui()->listTopics->selectRow(i); |
169 | 162 | } |
170 | | - else |
171 | | - { |
172 | | - cb->setChecked(filter_it->second); |
173 | | - } |
174 | | - cb->setFocusPolicy(Qt::NoFocus); |
175 | | - auto label = new QLabel(); |
176 | | - label->setTextFormat(Qt::RichText); |
177 | | - label->setText(QString("<a href=\"#\">%1</a>").arg(QString::fromStdString(topic_name))); |
178 | | - label->setOpenExternalLinks(false); |
179 | | - dialog->ui()->formLayout->addRow(label, cb); |
180 | | - checkbox.insert(std::make_pair(topic_name, cb)); |
181 | | - topic_widgets.insert(std::make_pair(topic_name, std::make_pair(label, cb))); |
182 | | - connect(label, &QLabel::linkActivated, [cb]() |
183 | | - { cb->toggle(); }); |
184 | | - connect(dialog->ui()->pushButtonSelect, &QPushButton::pressed, [cb]() |
185 | | - { cb->setChecked(true); }); |
186 | | - connect(dialog->ui()->pushButtonDeselect, &QPushButton::pressed, [cb]() |
187 | | - { cb->setChecked(false); }); |
188 | 163 | } |
189 | 164 |
|
190 | | - dialog->setTopicWidgets(topic_widgets); |
| 165 | + dialog->ui()->listTopics->sortByColumn(0, Qt::AscendingOrder); |
| 166 | + |
| 167 | + connect(dialog->ui()->pushButtonSelect, &QPushButton::pressed, [dialog]() |
| 168 | + { |
| 169 | + for (int row = 0; row < dialog->ui()->listTopics->rowCount(); row++) |
| 170 | + { |
| 171 | + if (!dialog->ui()->listTopics->isRowHidden(row)) |
| 172 | + { |
| 173 | + dialog->ui()->listTopics->selectRow(row); |
| 174 | + } |
| 175 | + } |
| 176 | + }); |
| 177 | + connect(dialog->ui()->pushButtonDeselect, &QPushButton::pressed, dialog->ui()->listTopics, |
| 178 | + &QAbstractItemView::clearSelection); |
191 | 179 |
|
192 | 180 | dialog->exec(); |
193 | 181 |
|
194 | 182 | if (dialog->result() == QDialog::Accepted) |
195 | 183 | { |
196 | 184 | _topics_to_publish.clear(); |
197 | | - for (const auto &it : checkbox) |
| 185 | + QModelIndexList selected_indexes = dialog->ui()->listTopics->selectionModel()->selectedIndexes(); |
| 186 | + |
| 187 | + for (const auto &info : sorted_topics) |
198 | 188 | { |
199 | | - _topics_to_publish.insert({it.first, it.second->isChecked()}); |
| 189 | + _topics_to_publish.insert({info.topic_name, false}); |
| 190 | + } |
| 191 | + |
| 192 | + foreach (QModelIndex index, selected_indexes) |
| 193 | + { |
| 194 | + if (index.column() == 0) |
| 195 | + { |
| 196 | + std::string topic_name = index.data(Qt::DisplayRole).toString().toStdString(); |
| 197 | + _topics_to_publish[topic_name] = true; |
| 198 | + } |
200 | 199 | } |
201 | 200 |
|
202 | 201 | updatePublishers(); |
|
0 commit comments