PlotTableConfig.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 
20 
21 namespace rqt_multiplot {
22 
23 /*****************************************************************************/
24 /* Constructors and Destructor */
25 /*****************************************************************************/
26 
27 PlotTableConfig::PlotTableConfig(QObject* parent, const QColor&
28  backgroundColor, const QColor& foregroundColor, size_t numRows,
29  size_t numColumns, bool linkScale, bool linkCursor, bool trackPoints) :
30  Config(parent),
31  backgroundColor_(backgroundColor),
32  foregroundColor_(foregroundColor),
33  linkScale_(linkScale),
34  linkCursor_(linkCursor),
35  trackPoints_(trackPoints) {
36  if (numRows && numColumns) {
37  plotConfig_.resize(numRows);
38 
39  for (size_t row = 0; row < numRows; ++row) {
40  plotConfig_[row].resize(numColumns);
41 
42  for (size_t column = 0; column < numColumns; ++column) {
43  plotConfig_[row][column] = new PlotConfig(this);
44 
45  connect(plotConfig_[row][column], SIGNAL(changed()), this,
46  SLOT(plotConfigChanged()));
47  }
48  }
49  }
50 }
51 
53 }
54 
55 /*****************************************************************************/
56 /* Accessors */
57 /*****************************************************************************/
58 
59 void PlotTableConfig::setBackgroundColor(const QColor& color) {
60  if (color != backgroundColor_) {
61  backgroundColor_ = color;
62 
63  emit backgroundColorChanged(color);
64  emit changed();
65  }
66 }
67 
68 const QColor& PlotTableConfig::getBackgroundColor() const {
69  return backgroundColor_;
70 }
71 
72 void PlotTableConfig::setForegroundColor(const QColor& color) {
73  if (color != foregroundColor_) {
74  foregroundColor_ = color;
75 
76  emit foregroundColorChanged(color);
77  emit changed();
78  }
79 }
80 
81 const QColor& PlotTableConfig::getForegroundColor() const {
82  return foregroundColor_;
83 }
84 
85 void PlotTableConfig::setNumPlots(size_t numRows, size_t numColumns) {
86  if ((numRows != getNumRows()) || (numColumns != getNumColumns())) {
87  size_t oldNumRows = getNumRows();
88  size_t oldNumColumns = getNumColumns();
89 
90  if (!numRows || !numColumns) {
91  numRows = 0;
92  numColumns = 0;
93  }
94 
95  QVector<QVector<PlotConfig*> > plotConfig(numRows);
96 
97  for (size_t row = 0; row < numRows; ++row) {
98  plotConfig[row].resize(numColumns);
99 
100  for (size_t column = 0; column < numColumns; ++column) {
101  if ((row < oldNumRows) && (column < oldNumColumns))
102  plotConfig[row][column] = plotConfig_[row][column];
103  else {
104  plotConfig[row][column] = new PlotConfig(this);
105 
106  connect(plotConfig[row][column], SIGNAL(changed()), this,
107  SLOT(plotConfigChanged()));
108  }
109  }
110  }
111 
112  for (size_t row = 0; row < oldNumRows; ++row)
113  for (size_t column = 0; column < oldNumColumns; ++column)
114  if ((row >= numRows) || (column >= numColumns))
115  delete plotConfig_[row][column];
116 
117  plotConfig_ = plotConfig;
118 
119  emit numPlotsChanged(numRows, numColumns);
120  emit changed();
121  }
122 }
123 
124 void PlotTableConfig::setNumRows(size_t numRows) {
125  setNumPlots(numRows, getNumColumns());
126 }
127 
129  return plotConfig_.count();
130 }
131 
132 void PlotTableConfig::setNumColumns(size_t numColumns) {
133  setNumPlots(getNumRows(), numColumns);
134 }
135 
137  if (!plotConfig_.isEmpty())
138  return plotConfig_[0].count();
139  else
140  return 0;
141 }
142 
143 PlotConfig* PlotTableConfig::getPlotConfig(size_t row, size_t column) const {
144  if ((row < getNumRows()) && (column < getNumColumns()))
145  return plotConfig_[row][column];
146  else
147  return 0;
148 }
149 
151  if (link != linkScale_) {
152  linkScale_ = link;
153 
154  emit linkScaleChanged(link);
155  emit changed();
156  }
157 }
158 
160  return linkScale_;
161 }
162 
164  if (link != linkCursor_) {
165  linkCursor_ = link;
166 
167  emit linkCursorChanged(link);
168  emit changed();
169  }
170 }
171 
173  return linkCursor_;
174 }
175 
177  if (track != trackPoints_) {
178  trackPoints_ = track;
179 
180  emit trackPointsChanged(track);
181  emit changed();
182  }
183 }
184 
186  return trackPoints_;
187 }
188 
189 /*****************************************************************************/
190 /* Methods */
191 /*****************************************************************************/
192 
193 void PlotTableConfig::save(QSettings& settings) const {
194  settings.setValue("background_color", QVariant::fromValue<QColor>(
196  settings.setValue("foreground_color", QVariant::fromValue<QColor>(
198 
199  settings.beginGroup("plots");
200 
201  for (size_t row = 0; row < plotConfig_.count(); ++row) {
202  settings.beginGroup("row_"+QString::number(row));
203 
204  for (size_t column = 0; column < plotConfig_[row].count(); ++column) {
205  settings.beginGroup("column_"+QString::number(column));
206  plotConfig_[row][column]->save(settings);
207  settings.endGroup();
208  }
209 
210  settings.endGroup();
211  }
212 
213  settings.endGroup();
214 
215  settings.setValue("link_scale", linkScale_);
216  settings.setValue("link_cursor", linkCursor_);
217  settings.setValue("track_points", trackPoints_);
218 }
219 
220 void PlotTableConfig::load(QSettings& settings) {
221  setBackgroundColor(settings.value("background_color", (QColor)Qt::white).
222  value<QColor>());
223  setForegroundColor(settings.value("foreground_color", (QColor)Qt::black).
224  value<QColor>());
225 
226  settings.beginGroup("plots");
227 
228  QStringList rowGroups = settings.childGroups();
229  size_t row = 0;
230  size_t numColumns = 0;
231 
232  for (QStringList::iterator it = rowGroups.begin();
233  it != rowGroups.end(); ++it) {
234  if (row >= plotConfig_.count())
235  setNumRows(row+1);
236 
237  settings.beginGroup(*it);
238 
239  QStringList columnGroups = settings.childGroups();
240  size_t column = 0;
241 
242  for (QStringList::iterator jt = columnGroups.begin();
243  jt != columnGroups.end(); ++jt) {
244  if (column >= plotConfig_[row].count())
245  setNumColumns(column+1);
246 
247  settings.beginGroup(*jt);
248  plotConfig_[row][column]->load(settings);
249  settings.endGroup();
250 
251  ++column;
252  }
253 
254  settings.endGroup();
255 
256  numColumns = std::max(numColumns, column);
257  ++row;
258  }
259 
260  settings.endGroup();
261 
262  setNumPlots(row, numColumns);
263 
264  setLinkScale(settings.value("link_scale", false).toBool());
265  setLinkCursor(settings.value("link_cursor", false).toBool());
266  setTrackPoints(settings.value("track_points", false).toBool());
267 }
268 
270  setBackgroundColor(Qt::white);
271  setForegroundColor(Qt::black);
272 
273  setNumPlots(1, 1);
274  plotConfig_[0][0]->reset();
275 
276  setLinkScale(false);
277  setLinkCursor(false);
278  setTrackPoints(false);
279 }
280 
281 void PlotTableConfig::write(QDataStream& stream) const {
282  stream << backgroundColor_;
283  stream << foregroundColor_;
284 
285  stream << (quint64)getNumRows() << (quint64)getNumColumns();
286 
287  for (size_t row = 0; row < plotConfig_.count(); ++row)
288  for (size_t column = 0; column < plotConfig_[row].count(); ++column)
289  plotConfig_[row][column]->write(stream);
290 
291  stream << linkScale_;
292  stream << linkCursor_;
293  stream << trackPoints_;
294 }
295 
296 void PlotTableConfig::read(QDataStream& stream) {
297  QColor backgroundColor, foregroundColor;
298  bool linkScale, linkCursor, trackPoints;
299  quint64 numRows, numColumns;
300 
301  stream >> backgroundColor;
302  setBackgroundColor(backgroundColor);
303  stream >> foregroundColor;
304  setForegroundColor(foregroundColor);
305 
306  stream >> numRows >> numColumns;
307  setNumPlots(numRows, numColumns);
308  for (size_t row = 0; row < plotConfig_.count(); ++row)
309  for (size_t column = 0; column < plotConfig_[row].count(); ++column)
310  plotConfig_[row][column]->read(stream);
311 
312  stream >> linkScale;
313  setLinkScale(linkScale);
314  stream >> linkCursor;
315  setLinkCursor(linkCursor);
316  stream >> trackPoints;
317  setTrackPoints(trackPoints);
318 }
319 
320 /*****************************************************************************/
321 /* Operators */
322 /*****************************************************************************/
323 
327 
328  setNumPlots(src.getNumRows(), src.getNumColumns());
329 
330  for (size_t row = 0; row < getNumRows(); ++row)
331  for (size_t column = 0; column < getNumColumns(); ++column)
332  *plotConfig_[row][column] = *src.plotConfig_[row][column];
333 
337 
338  return *this;
339 }
340 
341 /*****************************************************************************/
342 /* Slots */
343 /*****************************************************************************/
344 
346  emit changed();
347 }
348 
349 }
QVector< QVector< PlotConfig * > > plotConfig_
void linkScaleChanged(bool link)
void load(QSettings &settings)
const QColor & getForegroundColor() const
void backgroundColorChanged(const QColor &color)
void setNumColumns(size_t numColumns)
void foregroundColorChanged(const QColor &color)
PlotConfig * getPlotConfig(size_t row, size_t column) const
const QColor & getBackgroundColor() const
void setForegroundColor(const QColor &color)
void linkCursorChanged(bool link)
void save(QSettings &settings) const
void write(QDataStream &stream) const
PlotTableConfig & operator=(const PlotTableConfig &src)
void setBackgroundColor(const QColor &color)
PlotTableConfig(QObject *parent, const QColor &backgroundColor=Qt::white, const QColor &foregroundColor=Qt::black, size_t numRows=1, size_t numColumns=1, bool linkScale=false, bool linkCursor=false, bool trackPoints=false)
void trackPointsChanged(bool track)
void numPlotsChanged(size_t numRows, size_t numColumns)
void setNumPlots(size_t numRows, size_t numColumns)
void read(QDataStream &stream)


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