dialog_select_ros_topics.cpp
Go to the documentation of this file.
1 #include <QFile>
2 #include <QTextStream>
3 #include <QSettings>
4 #include <QFileInfo>
5 #include <QDir>
6 #include <QFileDialog>
7 #include <QTableWidget>
8 #include <QTableWidgetItem>
9 #include <QHeaderView>
10 #include <QDebug>
11 #include <QMessageBox>
12 #include <QAbstractItemView>
13 
15 #include "rule_editing.h"
16 #include "ui_dialog_select_ros_topics.h"
17 
18 
19 DialogSelectRosTopics::DialogSelectRosTopics(const std::vector<std::pair<QString, QString>>& topic_list,
20  const Configuration &config,
21  QWidget *parent) :
22  QDialog(parent),
23  ui(new Ui::dialogSelectRosTopics),
24  _default_selected_topics(config.selected_topics),
25  _select_all(QKeySequence(Qt::CTRL + Qt::Key_A), this),
26  _deselect_all(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_A), this)
27 {
28 
29  auto flags = this->windowFlags();
30  this->setWindowFlags( flags | Qt::WindowStaysOnTopHint);
31 
32  ui->setupUi(this);
33 
34  ui->checkBoxEnableRules->setChecked( config.use_renaming_rules );
35  ui->spinBoxArraySize->setValue( config.max_array_size );
36  ui->checkBoxTimestamp->setChecked( config.use_header_stamp );
37 
38  if( config.discard_large_arrays )
39  {
40  ui->radioMaxDiscard->setChecked(true);
41  }
42  else{
43  ui->radioMaxClamp->setChecked(true);
44  }
45 
46  QStringList labels;
47  labels.push_back("Topic name");
48  labels.push_back("Datatype");
49 
50  ui->listRosTopics->setHorizontalHeaderLabels(labels);
51  ui->listRosTopics->verticalHeader()->setVisible(false);
52 
53  updateTopicList(topic_list);
54 
55  if( ui->listRosTopics->rowCount() == 1)
56  {
57  ui->listRosTopics->selectRow(0);
58  }
59  ui->listRosTopics->setFocus();
60 
61  _select_all.setContext(Qt::WindowShortcut);
62  _deselect_all.setContext(Qt::WindowShortcut);
63 
64  connect( &_select_all, &QShortcut::activated,
65  ui->listRosTopics, &QAbstractItemView::selectAll );
66 
67  connect( &_deselect_all, &QShortcut::activated,
68  ui->listRosTopics, &QAbstractItemView::clearSelection );
69 
70  on_spinBoxArraySize_valueChanged( ui->spinBoxArraySize->value() );
71 
72  QSettings settings;
73  restoreGeometry(settings.value("DialogSelectRosTopics.geometry").toByteArray());
74 
75 }
76 
77 void DialogSelectRosTopics::updateTopicList(std::vector<std::pair<QString, QString> > topic_list )
78 {
79  std::set<QString> newly_added;
80 
81  // add if not present
82  for (const auto& it: topic_list)
83  {
84  const QString& topic_name = it.first ;
85  const QString& type_name = it.second ;
86 
87  bool found = false;
88  for(int r=0; r < ui->listRosTopics->rowCount(); r++ )
89  {
90  const QTableWidgetItem *item = ui->listRosTopics->item(r,0);
91  if( item->text() == topic_name){
92  found = true;
93  break;
94  }
95  }
96 
97  if( !found )
98  {
99  int new_row = ui->listRosTopics->rowCount();
100  ui->listRosTopics->setRowCount( new_row+1 );
101 
102  // order IS important, don't change it
103  ui->listRosTopics->setItem(new_row, 1, new QTableWidgetItem( type_name ));
104  ui->listRosTopics->setItem(new_row, 0, new QTableWidgetItem( topic_name ));
105  newly_added.insert(topic_name);
106  }
107  }
108 
109  ui->listRosTopics->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
110  ui->listRosTopics->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
111  ui->listRosTopics->sortByColumn(0, Qt::AscendingOrder);
112  //----------------------------------------------
113 
114  QModelIndexList selection = ui->listRosTopics->selectionModel()->selectedRows();
115 
116  for(int row=0; row < ui->listRosTopics->rowCount(); row++ )
117  {
118  const QTableWidgetItem *item = ui->listRosTopics->item(row,0);
119  QString topic_name = item->text();
120 
121  if(newly_added.count(topic_name) && _default_selected_topics.contains( topic_name ) )
122  {
123  bool selected = false;
124  for (const auto& selected_item: selection)
125  {
126  if( selected_item.row() == row)
127  {
128  selected = true;
129  break;
130  }
131  }
132  if( !selected ){
133  ui->listRosTopics->selectRow(row);
134  }
135  }
136  }
137 
138 }
139 
140 
142 {
143  delete ui;
144 }
145 
147 {
148  Configuration config;
149  config.selected_topics = _topic_list;
150  config.max_array_size = ui->spinBoxArraySize->value();
151  config.use_header_stamp = ui->checkBoxTimestamp->isChecked();
152  config.discard_large_arrays = ui->radioMaxDiscard->isChecked();
153  config.use_renaming_rules = ui->checkBoxEnableRules->isChecked();
154  return config;
155 }
156 
157 
159 {
160  QModelIndexList selected_indexes = ui->listRosTopics->selectionModel()->selectedIndexes();
161  QString selected_topics;
162 
163  foreach(QModelIndex index, selected_indexes)
164  {
165  if(index.column() == 0){
166  _topic_list.push_back( index.data(Qt::DisplayRole).toString() );
167  selected_topics.append( _topic_list.back() ).append(" ");
168  }
169  }
170 }
171 
173 {
174  QModelIndexList indexes = ui->listRosTopics->selectionModel()->selectedIndexes();
175 
176  ui->buttonBox->setEnabled( indexes.size() > 0) ;
177 }
178 
179 
181 {
182  ui->pushButtonEditRules->setEnabled( checked );
183 }
184 
186 {
187  RuleEditing* rule_editing = new RuleEditing(this);
188  rule_editing->exec();
189 }
190 
191 void DialogSelectRosTopics::closeEvent(QCloseEvent *event)
192 {
193  QSettings settings;
194  settings.setValue("DialogSelectRosTopics.geometry", saveGeometry());
195 }
196 
198 {
199  for (const auto& it: flat_msg.value)
200  {
201  if( it.second.getTypeID() != RosIntrospection::TIME)
202  {
203  continue;
204  }
205  const RosIntrospection::StringTreeNode* leaf1 = it.first.node_ptr;
206  const RosIntrospection::StringTreeNode* leaf2 = leaf1->parent();
207  if( leaf2 && leaf2->value() == "header" && leaf1->value() == "stamp")
208  {
209  return it.second.convert<double>();
210  }
211  }
212  return nonstd::optional<double>();
213 }
214 
216 {
217  QMessageBox msgBox;
218  msgBox.setWindowTitle("Help");
219  msgBox.setText("Maximum Size of Arrays:\n\n"
220  "If the size of an Arrays is larger than this maximum value, the entire array is skipped.\n\n"
221  "This parameter is used to prevent the user from loading HUGE arrays, "
222  "such as images, pointclouds, maps, etc.\n"
223  "The term 'array' refers to the array in a message field,\n\n"
224  " See http://wiki.ros.org/msg.\n\n"
225  "This is NOT about the duration of a time series!\n\n"
226  "MOTIVATION: pretend that a user tries to load a RGB image, which probably contains "
227  "a few millions pixels.\n"
228  "Plotjuggler would naively create a single time series for each pixel of the image! "
229  "That makes no sense, of course, and it would probably freeze your system.\n"
230  );
231  msgBox.exec();
232 }
233 
235 {
236  int visible_count = 0;
237  bool updated = false;
238 
239  QStringList spaced_items = search_string.split(' ');
240 
241  for (int row=0; row < ui->listRosTopics->rowCount(); row++)
242  {
243  auto item = ui->listRosTopics->item(row,0);
244  QString name = item->text();
245  int pos = 0;
246  bool toHide = false;
247 
248  for (const auto& item: spaced_items)
249  {
250  if( !name.contains(item) )
251  {
252  toHide = true;
253  break;
254  }
255  }
256  ui->listRosTopics->setRowHidden(row, toHide );
257  }
258 }
259 
261 {
262  if( value > 1000 )
263  {
264  ui->spinBoxArraySize->setStyleSheet("QSpinBox { color: red; }");
265  }
266  else{
267  ui->spinBoxArraySize->setStyleSheet("QSpinBox { color: black; }");
268  }
269 }
270 
271 
272 
void updateTopicList(std::vector< std::pair< QString, QString >> topic_list)
void on_lineEditFilter_textChanged(const QString &search_string)
void closeEvent(QCloseEvent *event) override
const TreeNode * parent() const
void on_spinBoxArraySize_valueChanged(int value)
std::vector< std::pair< StringTreeLeaf, Variant > > value
Configuration getResult() const
void on_checkBoxEnableRules_toggled(bool checked)
char name[1]
Ui::dialogSelectRosTopics * ui
DialogSelectRosTopics(const std::vector< std::pair< QString, QString >> &topic_list, const Configuration &default_info, QWidget *parent=nullptr)
ROSCPP_DECL std::string append(const std::string &left, const std::string &right)
int flags
nonstd::optional< double > FlatContainerContainHeaderStamp(const RosIntrospection::FlatMessage &flat_msg)


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17