PlotConfigWidget.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 <QApplication>
20 #include <QClipboard>
21 #include <QKeyEvent>
22 #include <QLayout>
23 #include <QMimeData>
24 
25 #include <ros/package.h>
26 
30 
31 #include <ui_PlotConfigWidget.h>
32 
34 
35 namespace rqt_multiplot {
36 
37 /*****************************************************************************/
38 /* Constructors and Destructor */
39 /*****************************************************************************/
40 
42  QWidget(parent),
43  ui_(new Ui::PlotConfigWidget()),
44  config_(new PlotConfig(this)) {
45  ui_->setupUi(this);
46 
47  ui_->pushButtonAddCurve->setIcon(
48  QIcon(QString::fromStdString(ros::package::getPath("rqt_multiplot").
49  append("/resource/16x16/add.png"))));
50  ui_->pushButtonEditCurve->setIcon(
51  QIcon(QString::fromStdString(ros::package::getPath("rqt_multiplot").
52  append("/resource/16x16/edit.png"))));
53  ui_->pushButtonRemoveCurves->setIcon(
54  QIcon(QString::fromStdString(ros::package::getPath("rqt_multiplot").
55  append("/resource/16x16/remove.png"))));
56 
57  ui_->pushButtonEditCurve->setEnabled(false);
58  ui_->pushButtonRemoveCurves->setEnabled(false);
59 
60  ui_->pushButtonCopyCurves->setIcon(
61  QIcon(QString::fromStdString(ros::package::getPath("rqt_multiplot").
62  append("/resource/16x16/copy.png"))));
63  ui_->pushButtonPasteCurves->setIcon(
64  QIcon(QString::fromStdString(ros::package::getPath("rqt_multiplot").
65  append("/resource/16x16/paste.png"))));
66 
67  ui_->pushButtonCopyCurves->setEnabled(false);
68  ui_->pushButtonPasteCurves->setEnabled(false);
69 
70  ui_->curveListWidget->installEventFilter(this);
71 
72  ui_->axesConfigWidget->setConfig(config_->getAxesConfig());
73  ui_->legendConfigWidget->setConfig(config_->getLegendConfig());
74 
75  connect(config_, SIGNAL(titleChanged(const QString&)),
76  this, SLOT(configTitleChanged(const QString&)));
77  connect(config_, SIGNAL(plotRateChanged(double)),
78  this, SLOT(configPlotRateChanged(double)));
79 
80  connect(ui_->lineEditTitle, SIGNAL(editingFinished()), this,
82 
83  connect(ui_->pushButtonAddCurve, SIGNAL(clicked()), this,
85  connect(ui_->pushButtonEditCurve, SIGNAL(clicked()), this,
87  connect(ui_->pushButtonRemoveCurves, SIGNAL(clicked()), this,
89 
90  connect(ui_->pushButtonCopyCurves, SIGNAL(clicked()), this,
92  connect(ui_->pushButtonPasteCurves, SIGNAL(clicked()), this,
94 
95  connect(ui_->curveListWidget, SIGNAL(itemSelectionChanged()),
97  connect(ui_->curveListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
98  this, SLOT(curveListWidgetItemDoubleClicked(QListWidgetItem*)));
99 
100  connect(ui_->doubleSpinBoxPlotRate, SIGNAL(valueChanged(double)),
101  this, SLOT(doubleSpinBoxPlotRateValueChanged(double)));
102 
103  connect(QApplication::clipboard(), SIGNAL(dataChanged()),
104  this, SLOT(clipboardDataChanged()));
105 
108 
110 }
111 
113  delete ui_;
114 }
115 
116 /*****************************************************************************/
117 /* Accessors */
118 /*****************************************************************************/
119 
121  ui_->curveListWidget->clear();
122 
123  *config_ = config;
124 
125  for (size_t index = 0; index < config_->getNumCurves(); ++index)
126  ui_->curveListWidget->addCurve(config_->getCurveConfig(index));
127 }
128 
130  return *config_;
131 }
132 
133 /*****************************************************************************/
134 /* Methods */
135 /*****************************************************************************/
136 
138  QList<QListWidgetItem*> items = ui_->curveListWidget->selectedItems();
139 
140  if (!items.isEmpty()) {
141  QByteArray data;
142  QDataStream stream(&data, QIODevice::WriteOnly);
143 
144  stream << (quint64)items.count();
145 
146  for (QList<QListWidgetItem*>::const_iterator it = items.begin();
147  it != items.end(); ++it) {
148  CurveItemWidget* itemWidget = static_cast<CurveItemWidget*>(
149  ui_->curveListWidget->itemWidget(*it));
150 
151  stream << *itemWidget->getConfig();
152  }
153 
154  QMimeData* mimeData = new QMimeData();
155  mimeData->setData(CurveConfig::MimeType+"-list", data);
156 
157  QApplication::clipboard()->setMimeData(mimeData);
158  }
159 }
160 
162  const QMimeData* mimeData = QApplication::clipboard()->mimeData();
163 
164  if (mimeData && mimeData->hasFormat(CurveConfig::MimeType+"-list")) {
165  QByteArray data = mimeData->data(CurveConfig::MimeType+"-list");
166  QDataStream stream(&data, QIODevice::ReadOnly);
167 
168  quint64 numCurves;
169  stream >> numCurves;
170 
171  for (size_t index = 0; index < numCurves; ++index) {
172  CurveConfig* curveConfig = config_->addCurve();
173  stream >> *curveConfig;
174 
175  while (config_->findCurves(curveConfig->getTitle()).count() > 1)
176  curveConfig->setTitle("Copy of "+curveConfig->getTitle());
177 
178  ui_->curveListWidget->addCurve(curveConfig);
179  }
180  }
181 }
182 
183 bool PlotConfigWidget::eventFilter(QObject* object, QEvent* event) {
184  if (object == ui_->curveListWidget) {
185  if (event->type() == QEvent::KeyPress) {
186  QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
187 
188  if (keyEvent->modifiers() == Qt::ControlModifier) {
189  if (keyEvent->key() == Qt::Key_C)
191  else if (keyEvent->key() == Qt::Key_V)
192  pasteCurves();
193  }
194  }
195  }
196 
197  return false;
198 }
199 
200 /*****************************************************************************/
201 /* Slots */
202 /*****************************************************************************/
203 
204 void PlotConfigWidget::configTitleChanged(const QString& title) {
205  ui_->lineEditTitle->setText(title);
206 }
207 
209  ui_->doubleSpinBoxPlotRate->setValue(rate);
210 }
211 
213  config_->setTitle(ui_->lineEditTitle->text());
214 }
215 
217  CurveConfigDialog dialog(this);
218 
219  dialog.setWindowTitle(config_->getTitle().isEmpty() ?
220  "Add Curve to Plot" :
221  "Add Curve to \""+config_->getTitle()+"\"");
223  config_->getNumCurves());
224 
225  if (dialog.exec() == QDialog::Accepted) {
226  CurveConfig* curveConfig = config_->addCurve();
227  *curveConfig = dialog.getWidget()->getConfig();
228 
229  ui_->curveListWidget->addCurve(curveConfig);
230  }
231 }
232 
234  QListWidgetItem* item = ui_->curveListWidget->currentItem();
235 
236  if (item) {
237  CurveItemWidget* widget = static_cast<CurveItemWidget*>(
238  ui_->curveListWidget->itemWidget(item));
239  CurveConfig* curveConfig = widget->getConfig();
240 
241  CurveConfigDialog dialog(this);
242 
243  dialog.setWindowTitle(curveConfig->getTitle().isEmpty() ?
244  "Edit Curve" :
245  "Edit \""+curveConfig->getTitle()+"\"");
246  dialog.getWidget()->setConfig(*curveConfig);
247 
248  if (dialog.exec() == QDialog::Accepted)
249  *curveConfig = dialog.getWidget()->getConfig();
250  }
251 }
252 
254  QList<QListWidgetItem*> items = ui_->curveListWidget->selectedItems();
255 
256  for (QList<QListWidgetItem*>::iterator it = items.begin();
257  it != items.end(); ++it) {
258  CurveItemWidget* widget = static_cast<CurveItemWidget*>(
259  ui_->curveListWidget->itemWidget(*it));
260  CurveConfig* curveConfig = widget->getConfig();
261 
262  delete *it;
263 
264  config_->removeCurve(curveConfig);
265  }
266 }
267 
270 }
271 
273  pasteCurves();
274 }
275 
277  QList<QListWidgetItem*> items = ui_->curveListWidget->selectedItems();
278 
279  ui_->pushButtonEditCurve->setEnabled(items.count() == 1);
280  ui_->pushButtonRemoveCurves->setEnabled(!items.isEmpty());
281 
282  ui_->pushButtonCopyCurves->setEnabled(!items.isEmpty());
283 }
284 
286  item) {
288 }
289 
291  config_->setPlotRate(value);
292 }
293 
295  const QMimeData* mimeData = QApplication::clipboard()->mimeData();
296 
297  ui_->pushButtonPasteCurves->setEnabled(mimeData && mimeData->hasFormat(
298  CurveConfig::MimeType+"-list"));
299 }
300 
301 }
const PlotConfig & getConfig() const
static const QString MimeType
Definition: CurveConfig.h:41
PlotAxesConfig * getAxesConfig() const
Definition: PlotConfig.cpp:79
void setConfig(const CurveConfig &config)
QVector< CurveConfig * > findCurves(const QString &title) const
Definition: PlotConfig.cpp:145
bool eventFilter(QObject *object, QEvent *event)
void setConfig(const PlotConfig &config)
void curveListWidgetItemDoubleClicked(QListWidgetItem *item)
CurveConfig * addCurve()
Definition: PlotConfig.cpp:104
PlotLegendConfig * getLegendConfig() const
Definition: PlotConfig.cpp:83
void setAutoColorIndex(unsigned char index)
Ui::PlotConfigWidget * ui_
const QString & getTitle() const
Definition: PlotConfig.cpp:56
double getPlotRate() const
Definition: PlotConfig.cpp:96
void setPlotRate(double rate)
Definition: PlotConfig.cpp:87
void doubleSpinBoxPlotRateValueChanged(double value)
ROSLIB_DECL std::string getPath(const std::string &package_name)
CurveConfig * getCurveConfig(size_t index) const
Definition: PlotConfig.cpp:72
CurveConfigWidget * getWidget() const
size_t getNumCurves() const
Definition: PlotConfig.cpp:68
const QString & getTitle() const
Definition: CurveConfig.cpp:69
void setTitle(const QString &title)
Definition: PlotConfig.cpp:47
void removeCurve(CurveConfig *curveConfig)
Definition: PlotConfig.cpp:121
void configTitleChanged(const QString &title)
ROSCPP_DECL std::string append(const std::string &left, const std::string &right)
void setTitle(const QString &title)
Definition: CurveConfig.cpp:60
CurveConfig * getConfig() const
CurveColorConfig * getColorConfig() const
Definition: CurveConfig.cpp:82


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