PlotTableConfigWidget.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 <QColorDialog>
20 #include <QFileDialog>
21 
22 #include <ros/package.h>
23 
26 
27 #include <ui_PlotTableConfigWidget.h>
28 
30 
31 namespace rqt_multiplot {
32 
33 /*****************************************************************************/
34 /* Constructors and Destructor */
35 /*****************************************************************************/
36 
38  QWidget(parent),
39  ui_(new Ui::PlotTableConfigWidget()),
40  menuImportExport_(new QMenu(this)),
41  config_(0),
42  plotTable_(0) {
43  ui_->setupUi(this);
44 
45  ui_->labelBackgroundColor->setAutoFillBackground(true);
46  ui_->labelForegroundColor->setAutoFillBackground(true);
47 
48  ui_->widgetProgress->setEnabled(false);
49 
50  ui_->pushButtonRun->setIcon(
51  QIcon(QString::fromStdString(ros::package::getPath("rqt_multiplot").
52  append("/resource/16x16/run.png"))));
53  ui_->pushButtonPause->setIcon(
54  QIcon(QString::fromStdString(ros::package::getPath("rqt_multiplot").
55  append("/resource/16x16/pause.png"))));
56  ui_->pushButtonClear->setIcon(
57  QIcon(QString::fromStdString(ros::package::getPath("rqt_multiplot").
58  append("/resource/16x16/clear.png"))));
59  ui_->pushButtonImportExport->setIcon(
60  QIcon(QString::fromStdString(ros::package::getPath("rqt_multiplot").
61  append("/resource/16x16/eject.png"))));
62 
63  ui_->pushButtonPause->setEnabled(false);
64 
65  menuImportExport_->addAction("Import from bag file...", this,
67  menuImportExport_->addSeparator();
68  menuImportExport_->addAction("Export to image file...", this,
70  menuImportExport_->addAction("Export to text file...", this,
72 
73  connect(ui_->spinBoxRows, SIGNAL(valueChanged(int)), this,
74  SLOT(spinBoxRowsValueChanged(int)));
75  connect(ui_->spinBoxColumns, SIGNAL(valueChanged(int)), this,
76  SLOT(spinBoxColumnsValueChanged(int)));
77 
78  connect(ui_->checkBoxLinkScale, SIGNAL(stateChanged(int)), this,
80  connect(ui_->checkBoxLinkCursor, SIGNAL(stateChanged(int)), this,
82  connect(ui_->checkBoxTrackPoints, SIGNAL(stateChanged(int)), this,
84 
85  connect(ui_->pushButtonRun, SIGNAL(clicked()), this,
86  SLOT(pushButtonRunClicked()));
87  connect(ui_->pushButtonPause, SIGNAL(clicked()), this,
88  SLOT(pushButtonPauseClicked()));
89  connect(ui_->pushButtonClear, SIGNAL(clicked()), this,
90  SLOT(pushButtonClearClicked()));
91  connect(ui_->pushButtonImportExport, SIGNAL(clicked()), this,
93 
94  ui_->labelBackgroundColor->installEventFilter(this);
95  ui_->labelForegroundColor->installEventFilter(this);
96 }
97 
99  delete ui_;
100 }
101 
102 /*****************************************************************************/
103 /* Accessors */
104 /*****************************************************************************/
105 
107  if (config != config_) {
108  if (config_) {
109  disconnect(config_, SIGNAL(backgroundColorChanged(const QColor&)),
110  this, SLOT(configBackgroundColorChanged(const QColor&)));
111  disconnect(config_, SIGNAL(foregroundColorChanged(const QColor&)),
112  this, SLOT(configForegroundColorChanged(const QColor&)));
113  disconnect(config_, SIGNAL(numPlotsChanged(size_t, size_t)),
114  this, SLOT(configNumPlotsChanged(size_t, size_t)));
115  disconnect(config_, SIGNAL(linkScaleChanged(bool)),
116  this, SLOT(configLinkScaleChanged(bool)));
117  disconnect(config_, SIGNAL(linkCursorChanged(bool)),
118  this, SLOT(configLinkCursorChanged(bool)));
119  disconnect(config_, SIGNAL(trackPointsChanged(bool)),
120  this, SLOT(configTrackPointsChanged(bool)));
121  }
122 
123  config_ = config;
124 
125  if (config) {
126  connect(config, SIGNAL(backgroundColorChanged(const QColor&)),
127  this, SLOT(configBackgroundColorChanged(const QColor&)));
128  connect(config, SIGNAL(foregroundColorChanged(const QColor&)),
129  this, SLOT(configForegroundColorChanged(const QColor&)));
130  connect(config, SIGNAL(numPlotsChanged(size_t, size_t)),
131  this, SLOT(configNumPlotsChanged(size_t, size_t)));
132  connect(config, SIGNAL(linkScaleChanged(bool)),
133  this, SLOT(configLinkScaleChanged(bool)));
134  connect(config, SIGNAL(linkCursorChanged(bool)),
135  this, SLOT(configLinkCursorChanged(bool)));
136  connect(config, SIGNAL(trackPointsChanged(bool)),
137  this, SLOT(configTrackPointsChanged(bool)));
138 
141  configNumPlotsChanged(config->getNumRows(), config->getNumColumns());
145  }
146  }
147 }
148 
150  return config_;
151 }
152 
154  if (plotTable != plotTable_) {
155  if (plotTable_) {
156  disconnect(plotTable_, SIGNAL(plotPausedChanged()),
157  this, SLOT(plotTablePlotPausedChanged()));
158  disconnect(plotTable_, SIGNAL(jobStarted(const QString&)),
159  this, SLOT(plotTableJobStarted(const QString&)));
160  disconnect(plotTable_, SIGNAL(jobProgressChanged(double)),
161  this, SLOT(plotTableJobProgressChanged(double)));
162  disconnect(plotTable_, SIGNAL(jobFinished(const QString&)),
163  this, SLOT(plotTableJobFinished(const QString&)));
164  disconnect(plotTable_, SIGNAL(jobFailed(const QString&)),
165  this, SLOT(plotTableJobFailed(const QString&)));
166  }
167 
168  plotTable_ = plotTable;
169 
170  if (plotTable) {
171  connect(plotTable, SIGNAL(plotPausedChanged()),
172  this, SLOT(plotTablePlotPausedChanged()));
173  connect(plotTable, SIGNAL(jobStarted(const QString&)),
174  this, SLOT(plotTableJobStarted(const QString&)));
175  connect(plotTable, SIGNAL(jobProgressChanged(double)),
176  this, SLOT(plotTableJobProgressChanged(double)));
177  connect(plotTable, SIGNAL(jobFinished(const QString&)),
178  this, SLOT(plotTableJobFinished(const QString&)));
179  connect(plotTable, SIGNAL(jobFailed(const QString&)),
180  this, SLOT(plotTableJobFailed(const QString&)));
181 
183  }
184  }
185 }
186 
188  return plotTable_;
189 }
190 
192  if (plotTable_) {
193  plotTable_->runPlots();
194  }
195 }
196 
197 /*****************************************************************************/
198 /* Methods */
199 /*****************************************************************************/
200 
201 bool PlotTableConfigWidget::eventFilter(QObject* object, QEvent* event) {
202  if (config_) {
203  if (((object == ui_->labelBackgroundColor) ||
204  (object == ui_->labelForegroundColor)) &&
205  (event->type() == QEvent::MouseButtonPress)) {
206  QColorDialog dialog(this);
207 
208  dialog.setCurrentColor((object == ui_->labelBackgroundColor) ?
210 
211  if (dialog.exec() == QDialog::Accepted) {
212  if (object == ui_->labelBackgroundColor)
213  config_->setBackgroundColor(dialog.currentColor());
214  else
215  config_->setForegroundColor(dialog.currentColor());
216  }
217  }
218  }
219 
220  return false;
221 }
222 
223 /*****************************************************************************/
224 /* Slots */
225 /*****************************************************************************/
226 
228  color) {
229  QPalette palette = ui_->labelBackgroundColor->palette();
230  palette.setColor(QPalette::Window, color);
231 
232  ui_->labelBackgroundColor->setPalette(palette);
233 }
234 
236  color) {
237  QPalette palette = ui_->labelForegroundColor->palette();
238  palette.setColor(QPalette::Window, color);
239 
240  ui_->labelForegroundColor->setPalette(palette);
241 }
242 
244  numColumns) {
245  ui_->spinBoxRows->setValue(numRows);
246  ui_->spinBoxColumns->setValue(numColumns);
247 }
248 
250  ui_->checkBoxLinkScale->setCheckState(link ? Qt::Checked : Qt::Unchecked);
251 }
252 
254  ui_->checkBoxLinkCursor->setCheckState(link ? Qt::Checked : Qt::Unchecked);
255 }
256 
258  ui_->checkBoxTrackPoints->setCheckState(track ? Qt::Checked :
259  Qt::Unchecked);
260 }
261 
263  if (config_)
264  config_->setNumRows(value);
265 }
266 
268  if (config_)
269  config_->setNumColumns(value);
270 }
271 
273  if (config_)
274  config_->setLinkScale(state == Qt::Checked);
275 }
276 
278  if (config_)
279  config_->setLinkCursor(state == Qt::Checked);
280 }
281 
283  if (config_)
284  config_->setTrackPoints(state == Qt::Checked);
285 }
286 
288  if (plotTable_)
289  plotTable_->runPlots();
290 }
291 
293  if (plotTable_)
295 }
296 
298  if (plotTable_)
300 }
301 
303  menuImportExport_->popup(QCursor::pos());
304 }
305 
307  QFileDialog dialog(this, "Open Bag", QDir::homePath(),
308  "ROS Bag (*.bag)");
309 
310  dialog.setAcceptMode(QFileDialog::AcceptOpen);
311  dialog.setFileMode(QFileDialog::ExistingFile);
312 
313  if (dialog.exec() == QDialog::Accepted)
314  plotTable_->loadFromBagFile(dialog.selectedFiles().first());
315 }
316 
318  QFileDialog dialog(this, "Save Image File", QDir::homePath(),
319  "Portable Network Graphics (*.png)");
320 
321  dialog.setAcceptMode(QFileDialog::AcceptSave);
322  dialog.setFileMode(QFileDialog::AnyFile);
323  dialog.selectFile("rqt_multiplot.png");
324 
325  if (dialog.exec() == QDialog::Accepted)
326  plotTable_->saveToImageFile(dialog.selectedFiles().first());
327 }
328 
330  QFileDialog dialog(this, "Save Text File", QDir::homePath(),
331  "Text file (*.txt)");
332 
333  dialog.setAcceptMode(QFileDialog::AcceptSave);
334  dialog.setFileMode(QFileDialog::AnyFile);
335  dialog.selectFile("rqt_multiplot.txt");
336 
337  if (dialog.exec() == QDialog::Accepted)
338  plotTable_->saveToTextFile(dialog.selectedFiles().first());
339 }
340 
342  if (plotTable_) {
343  bool allPlotsPaused = true;
344  bool anyPlotPaused = false;
345 
346  for (size_t row = 0; row < plotTable_->getNumRows(); ++row) {
347  for (size_t column = 0; column < plotTable_->getNumColumns();
348  ++column) {
349  allPlotsPaused &= plotTable_->getPlotWidget(row, column)->isPaused();
350  anyPlotPaused |= plotTable_->getPlotWidget(row, column)->isPaused();
351  }
352  }
353 
354  ui_->pushButtonRun->setEnabled(anyPlotPaused);
355  ui_->pushButtonPause->setEnabled(!allPlotsPaused);
356  }
357 }
358 
359 void PlotTableConfigWidget::plotTableJobStarted(const QString& toolTip) {
360  ui_->widgetProgress->setEnabled(true);
361 
362  ui_->widgetProgress->start(toolTip);
363 }
364 
366  ui_->widgetProgress->setCurrentProgress(progress);
367 }
368 
369 void PlotTableConfigWidget::plotTableJobFinished(const QString& toolTip) {
370  ui_->widgetProgress->finish(toolTip);
371 }
372 
373 void PlotTableConfigWidget::plotTableJobFailed(const QString& toolTip) {
374  ui_->widgetProgress->fail(toolTip);
375 }
376 
377 }
void plotTableJobStarted(const QString &toolTip)
void plotTableJobFinished(const QString &toolTip)
void saveToTextFile(const QString &fileName)
const QColor & getForegroundColor() const
bool eventFilter(QObject *object, QEvent *event)
void setNumColumns(size_t numColumns)
void configForegroundColorChanged(const QColor &color)
const QColor & getBackgroundColor() const
void setForegroundColor(const QColor &color)
void loadFromBagFile(const QString &fileName)
void configNumPlotsChanged(size_t numRows, size_t numColumns)
PlotWidget * getPlotWidget(size_t row, size_t column) const
void setBackgroundColor(const QColor &color)
void setPlotTable(PlotTableWidget *plotTable)
ROSLIB_DECL std::string getPath(const std::string &package_name)
void saveToImageFile(const QString &fileName)
ROSCPP_DECL std::string append(const std::string &left, const std::string &right)
void configBackgroundColorChanged(const QColor &color)
void setConfig(PlotTableConfig *config)
PlotTableWidget * getPlotTableWidget() const
void plotTableJobFailed(const QString &toolTip)


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