/[qspeakers]/branches/qtcharts/speaker.cpp
ViewVC logotype

Contents of /branches/qtcharts/speaker.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 299 - (show annotations)
Wed Nov 25 20:05:12 2020 UTC (6 months, 2 weeks ago) by ben
File size: 7169 byte(s)
Display SPL value
1 #include "speaker.h"
2 #include <QDebug>
3
4 Speaker::Speaker() :
5 fs(0.0),
6 vas(0.0),
7 re(0.0),
8 qts(0.0),
9 sd(0.0),
10 xmax(0.0),
11 z(0.0),
12 le(0.0),
13 qms(0.0),
14 qes(0.0),
15 spl(0.0),
16 pe(0.0),
17 bl(0.0),
18 dia(0.0),
19 vc(1)
20 {
21 }
22
23 Speaker::Speaker(const Speaker &copy)
24 {
25 this->fs = copy.getFs();
26 this->vas = copy.getVas();
27 this->re = copy.getRe();
28 this->qts = copy.getQts();
29 this->sd = copy.getSd();
30 this->xmax = copy.getXmax();
31 this->z = copy.getZ();
32 this->dia = copy.getDia();
33 this->bl = copy.getBL();
34 this->le = copy.getLe();
35 this->pe = copy.getPe();
36 this->qes = copy.getQes();
37 this->qms = copy.getQms();
38 this->spl = copy.getSpl();
39 this->vc = copy.getVc();
40
41 this->vendor = copy.getVendor();
42 this->model = copy.getModel();
43 }
44
45 Speaker::~Speaker()
46 {
47 /* nothing to do, just for QMetatype */
48 }
49
50 Speaker &Speaker::operator=(const Speaker &copy)
51 {
52 this->fs = copy.getFs();
53 this->vas = copy.getVas();
54 this->re = copy.getRe();
55 this->qts = copy.getQts();
56 this->sd = copy.getSd();
57 this->xmax = copy.getXmax();
58 this->z = copy.getZ();
59 this->dia = copy.getDia();
60 this->bl = copy.getBL();
61 this->le = copy.getLe();
62 this->pe = copy.getPe();
63 this->qes = copy.getQes();
64 this->qms = copy.getQms();
65 this->spl = copy.getSpl();
66 this->vc = copy.getVc();
67
68 this->vendor = copy.getVendor();
69 this->model = copy.getModel();
70
71 return *this;
72 }
73
74 bool Speaker::operator!=(const Speaker& r) const
75 {
76 return this->fs != r.getFs() ||
77 this->vas != r.getVas() ||
78 this->re != r.getRe() ||
79 this->qts != r.getQts() ||
80 this->sd != r.getSd() ||
81 this->xmax != r.getXmax() ||
82 this->z != r.getZ() ||
83 this->dia != r.getDia() ||
84 this->le != r.getLe() ||
85 this->qms != r.getQms() ||
86 this->qes != r.getQes() ||
87 this->pe != r.getPe() ||
88 this->bl != r.getBL() ||
89 this->spl != r.getSpl() ||
90 this->vc != r.getVc();
91 }
92
93 bool Speaker::operator==(const Speaker& r) const
94 {
95 return !(*this != r);
96 }
97
98 bool Speaker::isValid() const
99 {
100 return !vendor.isNull() && !model.isNull();
101 }
102
103 void Speaker::setVendor(const QString &vnd)
104 {
105 vendor = vnd;
106 }
107
108 void Speaker::setModel(const QString &mdl)
109 {
110 model = mdl;
111 }
112
113 void Speaker::setFs(double val)
114 {
115 fs = val;
116 }
117
118 void Speaker::setVas(double val)
119 {
120 vas = val;
121 }
122
123 void Speaker::setRe(double val)
124 {
125 re = val;
126 }
127
128 void Speaker::setQts(double val)
129 {
130 qts = val;
131 }
132
133 void Speaker::setSd(double val)
134 {
135 sd = val;
136 }
137
138 void Speaker::setXmax(double val)
139 {
140 xmax = val;
141 }
142
143 void Speaker::setZ(double val)
144 {
145 z = val;
146 }
147
148 void Speaker::setLe(double val)
149 {
150 le = val;
151 }
152
153 void Speaker::setQms(double val)
154 {
155 qms = val;
156 }
157
158 void Speaker::setQes(double val)
159 {
160 qes = val;
161 }
162
163 void Speaker::setSpl(double val)
164 {
165 spl = val;
166 }
167
168 void Speaker::setPe(double val)
169 {
170 pe = val;
171 }
172
173 void Speaker::setBL(double val)
174 {
175 bl = val;
176 }
177
178 void Speaker::setDia(double val)
179 {
180 dia = val;
181 }
182
183 void Speaker::setVc(int val)
184 {
185 vc = val;
186 }
187
188 QString Speaker::getVendor() const
189 {
190 return vendor;
191 }
192
193 QString Speaker::getModel() const
194 {
195 return model;
196 }
197
198 double Speaker::getFs() const
199 {
200 return fs;
201 }
202
203 double Speaker::getVas() const
204 {
205 return vas;
206 }
207
208 double Speaker::getRe() const
209 {
210 return re;
211 }
212
213 double Speaker::getQts() const
214 {
215 return qts;
216 }
217
218 double Speaker::getSd() const
219 {
220 return sd;
221 }
222
223 double Speaker::getXmax() const
224 {
225 return xmax;
226 }
227
228 double Speaker::getZ() const
229 {
230 return z;
231 }
232
233 double Speaker::getLe() const
234 {
235 return le;
236 }
237
238 double Speaker::getQms() const
239 {
240 return qms;
241 }
242
243 double Speaker::getQes() const
244 {
245 return qes;
246 }
247
248 double Speaker::getSpl() const
249 {
250 return spl;
251 }
252
253 double Speaker::getPe() const
254 {
255 return pe;
256 }
257
258 double Speaker::getBL() const
259 {
260 return bl;
261 }
262
263 double Speaker::getDia() const
264 {
265 return dia;
266 }
267
268 int Speaker::getVc() const
269 {
270 return vc;
271 }
272
273 QDomElement Speaker::toDomElement(QDomDocument &doc) const
274 {
275 QDomElement e = doc.createElement("speaker");
276
277 e.setAttribute("vendor", vendor);
278 e.setAttribute("model", model);
279
280 QLocale c(QLocale::C);
281 e.setAttribute("fs", c.toString(fs));
282 e.setAttribute("vas", c.toString(vas));
283 e.setAttribute("re", c.toString(re));
284 e.setAttribute("qts", c.toString(qts));
285 e.setAttribute("sd", c.toString(sd));
286 e.setAttribute("xmax", c.toString(xmax));
287 e.setAttribute("z", c.toString(z));
288 e.setAttribute("le", c.toString(le));
289 e.setAttribute("qms", c.toString(qms));
290 e.setAttribute("qes", c.toString(qes));
291 e.setAttribute("spl", c.toString(spl));
292 e.setAttribute("pe", c.toString(pe));
293 e.setAttribute("bl", c.toString(bl));
294 e.setAttribute("dia", c.toString(dia));
295 e.setAttribute("vc", c.toString(vc));
296
297 return e;
298 }
299
300 void Speaker::fromDomElement(const QDomElement &el)
301 {
302 vendor = el.attribute("vendor");
303 model = el.attribute("model");
304
305 QLocale c(QLocale::C);
306 fs = c.toDouble(el.attribute("fs"));
307 vas = c.toDouble(el.attribute("vas"));
308 re = c.toDouble(el.attribute("re"));
309 qts = c.toDouble(el.attribute("qts"));
310 sd = c.toDouble(el.attribute("sd"));
311 xmax = c.toDouble(el.attribute("xmax"));
312 z = c.toDouble(el.attribute("z"));
313 le = c.toDouble(el.attribute("le"));
314 qms = c.toDouble(el.attribute("qms"));
315 qes = c.toDouble(el.attribute("qes"));
316 spl = c.toDouble(el.attribute("spl"));
317 pe = c.toDouble(el.attribute("pe"));
318 bl = c.toDouble(el.attribute("bl"));
319 dia = c.toDouble(el.attribute("dia"));
320 vc = c.toInt(el.attribute("vc"));
321
322 /* for older db compatibility */
323 vc = vc ? vc : 1;
324 }
325
326 void Speaker::render(QPainter *painter, const QRectF &area)
327 {
328 if (!painter)
329 return;
330
331 painter->drawRoundedRect(area.toRect(), 5, 5);
332
333 #define PARAMLEN 10
334
335 QString params[PARAMLEN];
336
337 params[0] = QString::fromUtf8("Spl: %1 dB").arg(getSpl());
338 params[1] = QString::fromUtf8("Fs: %1 Hz").arg(getFs());
339 params[2] = QString::fromUtf8("Qts: %1").arg(getQts());
340 params[3] = QString::fromUtf8("Vas: %1 L").arg(getVas());
341 params[4] = QString::fromUtf8("Dia: %1 m").arg(getDia());
342 params[5] = QString::fromUtf8("Sd: %1 m²").arg(getSd());
343 params[6] = QString::fromUtf8("Xmax: %1 mm").arg(getXmax());
344 params[7] = QString::fromUtf8("Z: %1 Ohm").arg(getZ());
345 params[8] = QString::fromUtf8("Re: %1 Ohm").arg(getRe());
346 params[9] = QString::fromUtf8("Vc: %1").arg(getVc());
347
348 qreal tab = area.left();
349
350 QString text = getVendor() + " " + getModel();
351 QRectF where(area.left(), area.top(), area.width(), area.height() / 2);
352 QTextOption option(Qt::AlignCenter);
353 painter->drawText(where, text, option);
354
355 for (int i = 0; i < PARAMLEN; i++) {
356 where.setRect(tab, area.top() + area.height() / 2, area.width() / PARAMLEN, area.height() / 2);
357 text = params[i];
358 option.setAlignment(Qt::AlignVCenter|Qt::AlignLeft);
359 painter->drawText(where, text, option);
360 tab += area.width() / PARAMLEN;
361 }
362 }

  ViewVC Help
Powered by ViewVC 1.1.26