PlotCurve.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 
25 
27 
28 namespace rqt_multiplot {
29 
30 /*****************************************************************************/
31 /* Constructors and Destructor */
32 /*****************************************************************************/
33 
34 PlotCurve::PlotCurve(QObject* parent) :
35  QObject(parent),
36  config_(0),
37  broker_(0),
38  data_(new CurveDataVector()),
39  dataSequencer_(new CurveDataSequencer(this)),
40  paused_(true) {
41  qRegisterMetaType<BoundingRectangle>("BoundingRectangle");
42 
43  connect(dataSequencer_, SIGNAL(pointReceived(const QPointF&)),
44  this, SLOT(dataSequencerPointReceived(const QPointF&)));
45 
46  setData(data_);
47 }
48 
50 }
51 
52 /*****************************************************************************/
53 /* Accessors */
54 /*****************************************************************************/
55 
57  if (config != config_) {
58  if (config_) {
59  disconnect(config_, SIGNAL(changed(const QString&)), this,
60  SLOT(configTitleChanged(const QString&)));
62  SIGNAL(changed()), this, SLOT(configAxisConfigChanged()));
64  SIGNAL(changed()), this, SLOT(configAxisConfigChanged()));
65  disconnect(config_->getColorConfig(), SIGNAL(currentColorChanged(
66  const QColor&)), this, SLOT(configColorConfigCurrentColorChanged(
67  const QColor&)));
68  disconnect(config_->getStyleConfig(), SIGNAL(changed()), this,
69  SLOT(configStyleConfigChanged()));
70  disconnect(config_->getDataConfig(), SIGNAL(changed()), this,
71  SLOT(configDataConfigChanged()));
72 
74  }
75 
76  config_ = config;
77 
78  if (config) {
79  connect(config, SIGNAL(titleChanged(const QString&)), this,
80  SLOT(configTitleChanged(const QString&)));
81  connect(config->getAxisConfig(CurveConfig::X),
82  SIGNAL(changed()), this, SLOT(configAxisConfigChanged()));
83  connect(config->getAxisConfig(CurveConfig::Y),
84  SIGNAL(changed()), this, SLOT(configAxisConfigChanged()));
85  connect(config->getColorConfig(), SIGNAL(currentColorChanged(
86  const QColor&)), this, SLOT(configColorConfigCurrentColorChanged(
87  const QColor&)));
88  connect(config->getStyleConfig(), SIGNAL(changed()), this,
89  SLOT(configStyleConfigChanged()));
90  connect(config->getDataConfig(), SIGNAL(changed()), this,
91  SLOT(configDataConfigChanged()));
92 
93  configTitleChanged(config->getTitle());
96  getCurrentColor());
99 
100  dataSequencer_->setConfig(config);
101  }
102  }
103 }
104 
106  return config_;
107 }
108 
110  if (broker != broker_) {
111  broker_ = broker;
112 
113  dataSequencer_->setBroker(broker);
114  }
115 }
116 
118  return broker_;
119 }
120 
122  return data_;
123 }
124 
126  return dataSequencer_;
127 }
128 
130  const {
131  QPair<double, double> axisBounds(0.0, -1.0);
132 
133  if (config_) {
134  CurveAxisScaleConfig* axisScaleConfig = config_->getAxisConfig(axis)->
135  getScaleConfig();
136 
137  if (axisScaleConfig->getType() == CurveAxisScaleConfig::Absolute) {
138  axisBounds.first = axisScaleConfig->getAbsoluteMinimum();
139  axisBounds.second = axisScaleConfig->getAbsoluteMaximum();
140  }
141  else if (axisScaleConfig->getType() == CurveAxisScaleConfig::Relative) {
142  if (!data_->isEmpty()) {
143  size_t index = data_->getNumPoints()-1;
144 
145  axisBounds.first = data_->getValue(index, axis)+axisScaleConfig->
146  getRelativeMinimum();
147  axisBounds.second = data_->getValue(index, axis)+axisScaleConfig->
148  getRelativeMaximum();
149  }
150  }
151  else
152  axisBounds = data_->getAxisBounds(axis);
153  }
154 
155  return axisBounds;
156 }
157 
159  QPair<double, double> xAxisBounds = getPreferredAxisScale(CurveConfig::X);
160  QPair<double, double> yAxisBounds = getPreferredAxisScale(CurveConfig::Y);
161 
162  return BoundingRectangle(QPointF(xAxisBounds.first, yAxisBounds.first),
163  QPointF(xAxisBounds.second, yAxisBounds.second));
164 }
165 
166 /*****************************************************************************/
167 /* Methods */
168 /*****************************************************************************/
169 
170 void PlotCurve::attach(QwtPlot* plot) {
171  QwtPlotCurve::attach(plot);
172 }
173 
175  QwtPlotCurve::detach();
176 }
177 
181 
182  if (paused_ &&
183  (!xAxisConfig->getField().isEmpty() ||
185  (!yAxisConfig->getField().isEmpty() ||
188 
189  paused_ = false;
190  }
191 }
192 
194  if (!paused_) {
196 
197  paused_ = true;
198  }
199 }
200 
202  data_->clearPoints();
203 
204  emit replotRequested();
205 }
206 
207 /*****************************************************************************/
208 /* Slots */
209 /*****************************************************************************/
210 
211 void PlotCurve::configTitleChanged(const QString& title) {
212  setTitle(title);
213 }
214 
217 }
218 
220  setPen(color);
221 
222  emit replotRequested();
223 }
224 
227 
228  if (styleConfig->getType() == rqt_multiplot::CurveStyleConfig::Sticks) {
229  setStyle(QwtPlotCurve::Sticks);
230 
231  setOrientation(styleConfig->getSticksOrientation());
232  setBaseline(styleConfig->getSticksBaseline());
233  }
234  else if (styleConfig->getType() == rqt_multiplot::CurveStyleConfig::
235  Steps) {
236  setStyle(QwtPlotCurve::Steps);
237 
238  setCurveAttribute(QwtPlotCurve::Inverted, styleConfig->
239  areStepsInverted());
240  }
241  else if (styleConfig->getType() == rqt_multiplot::CurveStyleConfig::
242  Points) {
243  setStyle(QwtPlotCurve::Dots);
244  }
245  else {
246  setStyle(QwtPlotCurve::Lines);
247 
248  setCurveAttribute(QwtPlotCurve::Fitted, styleConfig->
249  areLinesInterpolated());
250  }
251 
252  QPen pen = QwtPlotCurve::pen();
253 
254  pen.setWidth(styleConfig->getPenWidth());
255  pen.setStyle(styleConfig->getPenStyle());
256 
257  setPen(pen);
258 
259  setRenderHint(QwtPlotItem::RenderAntialiased, styleConfig->
260  isRenderAntialiased());
261 
262  emit replotRequested();
263 }
264 
267 
268  if (config->getType() == CurveDataConfig::List)
269  data_ = new CurveDataList();
270  if (config->getType() == CurveDataConfig::CircularBuffer)
272  if (config->getType() == CurveDataConfig::TimeFrame)
274  else
275  data_ = new CurveDataVector();
276 
277  setData(data_);
278 
279  emit replotRequested();
280 }
281 
282 void PlotCurve::dataSequencerPointReceived(const QPointF& point) {
283  if (!paused_) {
284  BoundingRectangle oldBounds = getPreferredScale();
285 
286  data_->appendPoint(point);
287 
289 
290  if (bounds != oldBounds)
291  emit preferredScaleChanged(bounds);
292 
293  emit replotRequested();
294  }
295 }
296 
297 }
size_t getCircularBufferCapacity() const
PlotCurve(QObject *parent=0)
Definition: PlotCurve.cpp:34
MessageBroker * broker_
Definition: PlotCurve.h:68
MessageBroker * getBroker() const
Definition: PlotCurve.cpp:117
virtual void clearPoints()=0
void configTitleChanged(const QString &title)
Definition: PlotCurve.cpp:211
CurveDataConfig * getDataConfig() const
Definition: CurveConfig.cpp:90
config
CurveAxisConfig * getAxisConfig(Axis axis) const
Definition: CurveConfig.cpp:73
CurveData * getData() const
Definition: PlotCurve.cpp:121
void attach(QwtPlot *plot)
Definition: PlotCurve.cpp:170
void setBroker(MessageBroker *broker)
Definition: PlotCurve.cpp:109
virtual void appendPoint(const QPointF &point)=0
CurveConfig * getConfig() const
Definition: PlotCurve.cpp:105
bool isEmpty() const
Definition: CurveData.cpp:75
CurveDataSequencer * dataSequencer_
Definition: PlotCurve.h:71
void setConfig(CurveConfig *config)
const QString & getField() const
void dataSequencerPointReceived(const QPointF &point)
Definition: PlotCurve.cpp:282
QPair< double, double > getAxisBounds(CurveConfig::Axis axis) const
Definition: CurveData.cpp:62
const QString & getTitle() const
Definition: CurveConfig.cpp:69
QPair< double, double > getPreferredAxisScale(CurveConfig::Axis axis) const
Definition: PlotCurve.cpp:129
virtual size_t getNumPoints() const =0
void preferredScaleChanged(const BoundingRectangle &bounds)
BoundingRectangle getPreferredScale() const
Definition: PlotCurve.cpp:158
Qt::Orientation getSticksOrientation() const
CurveStyleConfig * getStyleConfig() const
Definition: CurveConfig.cpp:86
void setBroker(MessageBroker *broker)
CurveConfig * config_
Definition: PlotCurve.h:66
void configColorConfigCurrentColorChanged(const QColor &color)
Definition: PlotCurve.cpp:219
CurveColorConfig * getColorConfig() const
Definition: CurveConfig.cpp:82
void setConfig(CurveConfig *config)
Definition: PlotCurve.cpp:56
double getValue(size_t index, CurveConfig::Axis axis) const
Definition: CurveData.cpp:37
CurveDataSequencer * getDataSequencer() const
Definition: PlotCurve.cpp:125


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