CurveConfig.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 /* Static initializations */
25 /*****************************************************************************/
26 
27 const QString CurveConfig::MimeType = "application/rqt-multiplot-curve-config";
28 
29 /*****************************************************************************/
30 /* Constructors and Destructor */
31 /*****************************************************************************/
32 
33 CurveConfig::CurveConfig(QObject* parent, const QString& title, size_t
34  subscriberQueueSize) :
35  Config(parent),
36  title_(title),
37  colorConfig_(new CurveColorConfig(this)),
38  styleConfig_(new CurveStyleConfig(this)),
39  dataConfig_(new CurveDataConfig(this)),
40  subscriberQueueSize_(subscriberQueueSize) {
41  axisConfig_[X] = new CurveAxisConfig(this);
42  axisConfig_[Y] = new CurveAxisConfig(this);
43 
44  connect(axisConfig_[X], SIGNAL(changed()), this, SLOT(axisConfigChanged()));
45  connect(axisConfig_[Y], SIGNAL(changed()), this, SLOT(axisConfigChanged()));
46 
47  connect(colorConfig_, SIGNAL(changed()), this, SLOT(colorConfigChanged()));
48  connect(styleConfig_, SIGNAL(changed()), this, SLOT(styleConfigChanged()));
49 
50  connect(dataConfig_, SIGNAL(changed()), this, SLOT(dataConfigChanged()));
51 }
52 
54 }
55 
56 /*****************************************************************************/
57 /* Accessors */
58 /*****************************************************************************/
59 
60 void CurveConfig::setTitle(const QString& title) {
61  if (title != title_) {
62  title_ = title;
63 
64  emit titleChanged(title);
65  emit changed();
66  }
67 }
68 
69 const QString& CurveConfig::getTitle() const {
70  return title_;
71 }
72 
74  QMap<Axis, CurveAxisConfig*>::const_iterator it = axisConfig_.find(axis);
75 
76  if (it != axisConfig_.end())
77  return it.value();
78  else
79  return 0;
80 }
81 
83  return colorConfig_;
84 }
85 
87  return styleConfig_;
88 }
89 
91  return dataConfig_;
92 }
93 
94 void CurveConfig::setSubscriberQueueSize(size_t queueSize) {
95  if (queueSize != subscriberQueueSize_) {
96  subscriberQueueSize_ = queueSize;
97 
98  emit subscriberQueueSizeChanged(queueSize);
99  emit changed();
100  }
101 }
102 
104  return subscriberQueueSize_;
105 }
106 
107 /*****************************************************************************/
108 /* Methods */
109 /*****************************************************************************/
110 
111 void CurveConfig::save(QSettings& settings) const {
112  settings.setValue("title", title_);
113 
114  settings.beginGroup("axes");
115  settings.beginGroup("x_axis");
116  axisConfig_[X]->save(settings);
117  settings.endGroup();
118  settings.beginGroup("y_axis");
119  axisConfig_[Y]->save(settings);
120  settings.endGroup();
121  settings.endGroup();
122 
123  settings.beginGroup("color");
124  colorConfig_->save(settings);
125  settings.endGroup();
126 
127  settings.beginGroup("style");
128  styleConfig_->save(settings);
129  settings.endGroup();
130 
131  settings.beginGroup("data");
132  dataConfig_->save(settings);
133  settings.endGroup();
134 
135  settings.setValue("subscriber_queue_size", QVariant::
136  fromValue<qulonglong>(subscriberQueueSize_));
137 }
138 
139 void CurveConfig::load(QSettings& settings) {
140  setTitle(settings.value("title", "Untitled Curve").toString());
141 
142  settings.beginGroup("axes");
143  settings.beginGroup("x_axis");
144  axisConfig_[X]->load(settings);
145  settings.endGroup();
146  settings.beginGroup("y_axis");
147  axisConfig_[Y]->load(settings);
148  settings.endGroup();
149  settings.endGroup();
150 
151  settings.beginGroup("color");
152  colorConfig_->load(settings);
153  settings.endGroup();
154 
155  settings.beginGroup("style");
156  styleConfig_->load(settings);
157  settings.endGroup();
158 
159  settings.beginGroup("data");
160  dataConfig_->load(settings);
161  settings.endGroup();
162 
163  setSubscriberQueueSize(settings.value("subscriber_queue_size", 100).
164  toULongLong());
165 }
166 
168  setTitle("Untitled Curve");
169 
170  axisConfig_[X]->reset();
171  axisConfig_[Y]->reset();
172 
173  colorConfig_->reset();
174  styleConfig_->reset();
175 
176  dataConfig_->reset();
177 
179 }
180 
181 void CurveConfig::write(QDataStream& stream) const {
182  stream << title_;
183 
184  axisConfig_[X]->write(stream);
185  axisConfig_[Y]->write(stream);
186 
187  colorConfig_->write(stream);
188  styleConfig_->write(stream);
189 
190  dataConfig_->write(stream);
191 
192  stream << (quint64)subscriberQueueSize_;
193 }
194 
195 void CurveConfig::read(QDataStream& stream) {
196  QString title;
197  quint64 subscriberQueueSize;
198 
199  stream >> title;
200  setTitle(title);
201 
202  axisConfig_[X]->read(stream);
203  axisConfig_[Y]->read(stream);
204 
205  colorConfig_->read(stream);
206  styleConfig_->read(stream);
207 
208  dataConfig_->read(stream);
209 
210  stream >> subscriberQueueSize;
211  setSubscriberQueueSize(subscriberQueueSize);
212 }
213 
214 /*****************************************************************************/
215 /* Operators */
216 /*****************************************************************************/
217 
219  setTitle(src.title_);
220 
221  *axisConfig_[X] = *src.axisConfig_[X];
222  *axisConfig_[Y] = *src.axisConfig_[Y];
223 
224  *colorConfig_ = *src.colorConfig_;
225  *styleConfig_ = *src.styleConfig_;
226 
227  *dataConfig_ = *src.dataConfig_;
228 
230 
231  return *this;
232 }
233 
234 /*****************************************************************************/
235 /* Slots */
236 /*****************************************************************************/
237 
239  emit changed();
240 }
241 
243  emit changed();
244 }
245 
247  emit changed();
248 }
249 
251  emit changed();
252 }
253 
254 }
void save(QSettings &settings) const
static const QString MimeType
Definition: CurveConfig.h:41
void subscriberQueueSizeChanged(size_t queueSize)
CurveColorConfig * colorConfig_
Definition: CurveConfig.h:72
CurveDataConfig * getDataConfig() const
Definition: CurveConfig.cpp:90
void load(QSettings &settings)
void save(QSettings &settings) const
size_t getSubscriberQueueSize() const
CurveAxisConfig * getAxisConfig(Axis axis) const
Definition: CurveConfig.cpp:73
void save(QSettings &settings) const
void save(QSettings &settings) const
void read(QDataStream &stream)
void read(QDataStream &stream)
void load(QSettings &settings)
CurveStyleConfig * styleConfig_
Definition: CurveConfig.h:73
void write(QDataStream &stream) const
void write(QDataStream &stream) const
QMap< Axis, CurveAxisConfig * > axisConfig_
Definition: CurveConfig.h:71
void titleChanged(const QString &title)
CurveDataConfig * dataConfig_
Definition: CurveConfig.h:74
void write(QDataStream &stream) const
void read(QDataStream &stream)
void write(QDataStream &stream) const
void setSubscriberQueueSize(size_t queueSize)
Definition: CurveConfig.cpp:94
const QString & getTitle() const
Definition: CurveConfig.cpp:69
CurveConfig(QObject *parent=0, const QString &title="Untitled Curve", size_t subscriberQueueSize=100)
Definition: CurveConfig.cpp:33
void setTitle(const QString &title)
Definition: CurveConfig.cpp:60
void load(QSettings &settings)
CurveStyleConfig * getStyleConfig() const
Definition: CurveConfig.cpp:86
CurveConfig & operator=(const CurveConfig &src)
void load(QSettings &settings)
CurveColorConfig * getColorConfig() const
Definition: CurveConfig.cpp:82
void read(QDataStream &stream)


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