CurveAxisConfigWidget.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2015 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
19 #include <ros/package.h>
20 
21 #include <ui_CurveAxisConfigWidget.h>
22 
24 
25 namespace rqt_multiplot {
26 
27 /*****************************************************************************/
28 /* Constructors and Destructor */
29 /*****************************************************************************/
30 
32  QWidget(parent),
33  ui_(new Ui::CurveAxisConfigWidget()),
34  config_(0) {
35  ui_->setupUi(this);
36 
37  QPixmap pixmapOkay = QPixmap(QString::fromStdString(ros::package::getPath(
38  "rqt_multiplot").append("/resource/22x22/okay.png")));
39  QPixmap pixmapError = QPixmap(QString::fromStdString(ros::package::getPath(
40  "rqt_multiplot").append("/resource/22x22/error.png")));
41  QPixmap pixmapBusy = QPixmap(QString::fromStdString(ros::package::getPath(
42  "rqt_multiplot").append("/resource/22x22/busy.png")));
43 
44  ui_->statusWidgetTopic->setIcon(StatusWidget::Okay, pixmapOkay);
45  ui_->statusWidgetTopic->setIcon(StatusWidget::Error, pixmapError);
46  ui_->statusWidgetTopic->setFrames(StatusWidget::Busy, pixmapBusy, 8);
47 
48  ui_->statusWidgetType->setIcon(StatusWidget::Okay, pixmapOkay);
49  ui_->statusWidgetType->setIcon(StatusWidget::Error, pixmapError);
50  ui_->statusWidgetType->setFrames(StatusWidget::Busy, pixmapBusy, 8);
51 
52  ui_->statusWidgetField->setIcon(StatusWidget::Okay, pixmapOkay);
53  ui_->statusWidgetField->setIcon(StatusWidget::Error, pixmapError);
54  ui_->statusWidgetField->setFrames(StatusWidget::Busy, pixmapBusy, 8);
55 
56  ui_->statusWidgetScale->setIcon(StatusWidget::Okay, pixmapOkay);
57  ui_->statusWidgetScale->setIcon(StatusWidget::Error, pixmapError);
58  ui_->statusWidgetScale->setFrames(StatusWidget::Busy, pixmapBusy, 8);
59 
60  connect(ui_->comboBoxTopic, SIGNAL(updateStarted()), this,
62  connect(ui_->comboBoxTopic, SIGNAL(updateFinished()), this,
64  connect(ui_->comboBoxTopic, SIGNAL(currentTopicChanged(const QString&)),
65  this, SLOT(comboBoxTopicCurrentTopicChanged(const QString&)));
66 
67  connect(ui_->comboBoxType, SIGNAL(updateStarted()), this,
69  connect(ui_->comboBoxType, SIGNAL(updateFinished()), this,
71  connect(ui_->comboBoxType, SIGNAL(currentTypeChanged(const QString&)),
72  this, SLOT(comboBoxTypeCurrentTypeChanged(const QString&)));
73 
74  connect(ui_->widgetField, SIGNAL(loadingStarted()), this,
76  connect(ui_->widgetField, SIGNAL(loadingFinished()), this,
78  connect(ui_->widgetField, SIGNAL(loadingFailed(const QString&)),
79  this, SLOT(widgetFieldLoadingFailed(const QString&)));
80  connect(ui_->widgetField, SIGNAL(connecting(const QString&)), this,
81  SLOT(widgetFieldConnecting(const QString&)));
82  connect(ui_->widgetField, SIGNAL(connected(const QString&)), this,
83  SLOT(widgetFieldConnected(const QString&)));
84  connect(ui_->widgetField, SIGNAL(connectionTimeout(const QString&,
85  double)), this, SLOT(widgetFieldConnectionTimeout(const QString&,
86  double)));
87  connect(ui_->widgetField, SIGNAL(currentFieldChanged(const QString&)),
88  this, SLOT(widgetFieldCurrentFieldChanged(const QString&)));
89 
90  connect(ui_->checkBoxFieldReceiptTime, SIGNAL(stateChanged(int)), this,
92 
93  if (ui_->comboBoxTopic->isUpdating())
95  else
97 
98  if (ui_->comboBoxType->isUpdating())
100  else
102 }
103 
105  delete ui_;
106 }
107 
108 /*****************************************************************************/
109 /* Accessors */
110 /*****************************************************************************/
111 
113  if (config_ != config) {
114  if (config_) {
115  disconnect(config_, SIGNAL(topicChanged(const QString&)), this,
116  SLOT(configTopicChanged(const QString&)));
117  disconnect(config_, SIGNAL(typeChanged(const QString&)), this,
118  SLOT(configTypeChanged(const QString&)));
119  disconnect(config_, SIGNAL(fieldTypeChanged(int)), this,
120  SLOT(configFieldTypeChanged(int)));
121  disconnect(config_, SIGNAL(fieldChanged(const QString&)), this,
122  SLOT(configFieldChanged(const QString&)));
123  disconnect(config_->getScaleConfig(), SIGNAL(changed()), this,
124  SLOT(configScaleConfigChanged()));
125  }
126 
127  config_ = config;
128 
129  if (config) {
130  ui_->widgetScale->setConfig(config->getScaleConfig());
131 
132  connect(config, SIGNAL(topicChanged(const QString&)), this,
133  SLOT(configTopicChanged(const QString&)));
134  connect(config, SIGNAL(typeChanged(const QString&)), this,
135  SLOT(configTypeChanged(const QString&)));
136  connect(config, SIGNAL(fieldTypeChanged(int)), this,
137  SLOT(configFieldTypeChanged(int)));
138  connect(config, SIGNAL(fieldChanged(const QString&)), this,
139  SLOT(configFieldChanged(const QString&)));
140  connect(config->getScaleConfig(), SIGNAL(changed()), this,
141  SLOT(configScaleConfigChanged()));
142 
143  configTopicChanged(config->getTopic());
144  configTypeChanged(config->getType());
146  configFieldChanged(config->getField());
148  }
149  else {
150  ui_->widgetScale->setConfig(0);
151  }
152  }
153 }
154 
156  return config_;
157 }
158 
159 /*****************************************************************************/
160 /* Methods */
161 /*****************************************************************************/
162 
164  ui_->comboBoxTopic->updateTopics();
165 }
166 
168  ui_->comboBoxType->updateTypes();
169 }
170 
172  if (config_)
173  ui_->widgetField->loadFields(config_->getType());
174 }
175 
177  if (!config_ || ui_->comboBoxTopic->isUpdating())
178  return false;
179 
180  if (config_->getTopic().isEmpty()) {
181  ui_->statusWidgetTopic->setCurrentRole(StatusWidget::Error,
182  "No topic selected");
183 
184  return false;
185  }
186 
187  if (ui_->comboBoxTopic->isCurrentTopicRegistered()) {
188  ui_->statusWidgetTopic->setCurrentRole(StatusWidget::Okay,
189  "Topic okay");
190 
191  return true;
192  }
193  else {
194  ui_->statusWidgetTopic->setCurrentRole(StatusWidget::Error,
195  "Topic ["+config_->getTopic()+"] not advertised");
196 
197  return false;
198  }
199 }
200 
202  if (!config_ || ui_->comboBoxType->isUpdating())
203  return false;
204 
205  if (config_->getType().isEmpty()) {
206  ui_->statusWidgetType->setCurrentRole(StatusWidget::Error,
207  "No message type selected");
208 
209  return false;
210  }
211 
212  if (!ui_->comboBoxTopic->isCurrentTopicRegistered()) {
213  if (ui_->comboBoxType->isCurrentTypeRegistered()) {
214  ui_->statusWidgetType->setCurrentRole(StatusWidget::Okay,
215  "Message type okay");
216 
217  return true;
218  }
219  else {
220  ui_->statusWidgetType->setCurrentRole(StatusWidget::Error,
221  "Message type ["+config_->getType()+"] not found in package path");
222 
223  return false;
224  }
225  }
226  else {
227  if (ui_->comboBoxTopic->getCurrentTopicType() == config_->getType()) {
228  ui_->statusWidgetType->setCurrentRole(StatusWidget::Okay,
229  "Message type okay");
230 
231  return true;
232  }
233  else {
234  ui_->statusWidgetType->setCurrentRole(StatusWidget::Error,
235  "Message type ["+config_->getType()+
236  "] mismatches advertised message type ["
237  +ui_->comboBoxTopic->getCurrentTopicType()+"] for topic ["+
238  config_->getTopic()+"]");
239 
240  return false;
241  }
242  }
243 }
244 
246  if (!config_ || ui_->widgetField->isLoading())
247  return false;
248 
250  ui_->statusWidgetField->setCurrentRole(StatusWidget::Okay,
251  "Message field okay");
252 
253  return true;
254  }
255 
256  if (config_->getField().isEmpty()) {
257  ui_->statusWidgetField->setCurrentRole(StatusWidget::Error,
258  "No message field selected");
259 
260  return false;
261  }
262 
263  variant_topic_tools::DataType fieldType = ui_->widgetField->
264  getCurrentFieldDataType();
265 
266  if (fieldType.isValid()) {
267  if (fieldType.isBuiltin() && variant_topic_tools::
268  BuiltinDataType(fieldType).isNumeric()) {
269  ui_->statusWidgetField->setCurrentRole(StatusWidget::Okay,
270  "Message field okay");
271 
272  return true;
273  }
274  else {
275  ui_->statusWidgetField->setCurrentRole(StatusWidget::Error,
276  "Message field ["+config_->getField()+"] is not numeric");
277 
278  return false;
279  }
280  }
281  else {
282  ui_->statusWidgetField->setCurrentRole(StatusWidget::Error,
283  "No such message field ["+config_->getField()+"]");
284 
285  return false;
286  }
287 }
288 
290  if (!config_)
291  return false;
292 
293  if (!config_->getScaleConfig()->isValid()) {
294  ui_->statusWidgetScale->setCurrentRole(StatusWidget::Error,
295  "Axis scale invalid");
296 
297  return false;
298  }
299  else {
300  ui_->statusWidgetScale->setCurrentRole(StatusWidget::Okay,
301  "Axis scale okay");
302 
303  return true;
304  }
305 }
306 
307 /*****************************************************************************/
308 /* Slots */
309 /*****************************************************************************/
310 
311 void CurveAxisConfigWidget::configTopicChanged(const QString& topic) {
312  ui_->comboBoxTopic->setCurrentTopic(topic);
313 
314  validateTopic();
315 }
316 
317 void CurveAxisConfigWidget::configTypeChanged(const QString& type) {
318  ui_->comboBoxType->setCurrentType(type);
319 
320  validateType();
321 }
322 
324  ui_->checkBoxFieldReceiptTime->setCheckState(
325  (fieldType == CurveAxisConfig::MessageReceiptTime) ?
326  Qt::Checked : Qt::Unchecked);
327 
328  validateType();
329 }
330 
331 void CurveAxisConfigWidget::configFieldChanged(const QString& field) {
332  ui_->widgetField->setCurrentField(field);
333 
334  validateField();
335 }
336 
338  validateScale();
339 }
340 
342  ui_->statusWidgetTopic->pushCurrentRole();
343  ui_->statusWidgetTopic->setCurrentRole(StatusWidget::Busy,
344  "Updating topics...");
345 }
346 
348  ui_->statusWidgetTopic->popCurrentRole();
349 
350  validateTopic();
351 }
352 
354  topic) {
355  if (config_) {
356  config_->setTopic(topic);
357 
358  if (ui_->comboBoxTopic->isCurrentTopicRegistered())
359  config_->setType(ui_->comboBoxTopic->getCurrentTopicType());
360  }
361 
362  validateTopic();
363 }
364 
366  ui_->statusWidgetType->pushCurrentRole();
367  ui_->statusWidgetType->setCurrentRole(StatusWidget::Busy,
368  "Updating message types...");
369 }
370 
372  ui_->statusWidgetType->popCurrentRole();
373 
374  validateType();
375 }
376 
378  type) {
379  if (config_)
380  config_->setType(type);
381 
382  validateType();
383  updateFields();
384 }
385 
387  ui_->widgetField->setEnabled(false);
388 
389  ui_->statusWidgetField->pushCurrentRole();
390  ui_->statusWidgetField->setCurrentRole(StatusWidget::Busy,
391  "Loading message definition...");
392 }
393 
395  ui_->widgetField->setEnabled(ui_->checkBoxFieldReceiptTime->
396  checkState() != Qt::Checked);
397  ui_->statusWidgetField->popCurrentRole();
398 
399  validateField();
400 }
401 
403  error) {
404  ui_->statusWidgetField->popCurrentRole();
405 
406  if (config_ && (ui_->comboBoxTopic->getCurrentTopicType() == config_->
407  getType()))
408  ui_->widgetField->connectTopic(config_->getTopic());
409  else
410  validateField();
411 }
412 
414  ui_->widgetField->setEnabled(false);
415 
416  ui_->statusWidgetField->pushCurrentRole();
417  ui_->statusWidgetField->setCurrentRole(StatusWidget::Busy,
418  "Waiting for connnection on topic ["+topic+"]...");
419 }
420 
422  ui_->widgetField->setEnabled(ui_->checkBoxFieldReceiptTime->
423  checkState() != Qt::Checked);
424  ui_->statusWidgetField->popCurrentRole();
425 
426  validateField();
427 }
428 
430  topic, double timeout) {
431  ui_->statusWidgetField->popCurrentRole();
432 
433  validateField();
434 }
435 
437  field) {
438  if (config_)
439  config_->setField(field);
440 
441  validateField();
442 }
443 
445  ui_->widgetField->setEnabled(state != Qt::Checked);
446 
447  if (config_)
448  config_->setFieldType((state == Qt::Checked) ?
450 
451  validateField();
452 }
453 
454 }
void setConfig(CurveAxisConfig *config)
const QString & getTopic() const
void comboBoxTypeCurrentTypeChanged(const QString &type)
void widgetFieldConnectionTimeout(const QString &topic, double timeout)
void widgetFieldConnecting(const QString &topic)
CurveAxisScaleConfig * getScaleConfig() const
const QString & getType() const
void setField(const QString &field)
void configFieldChanged(const QString &field)
void widgetFieldLoadingFailed(const QString &error)
void setTopic(const QString &topic)
const QString & getField() const
void setType(const QString &type)
void comboBoxTopicCurrentTopicChanged(const QString &topic)
void widgetFieldCurrentFieldChanged(const QString &field)
ROSLIB_DECL std::string getPath(const std::string &package_name)
ROSCPP_DECL std::string append(const std::string &left, const std::string &right)
void widgetFieldConnected(const QString &topic)
void setFieldType(FieldType fieldType)
void configTopicChanged(const QString &topic)


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Wed Jul 10 2019 03:49:44