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

Contents of /branches/qtcharts/sealedbox.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 267 - (show annotations)
Thu Oct 22 00:53:56 2020 UTC (7 months, 3 weeks ago) by ben
File size: 1213 byte(s)
Avoid deprecated drawing methods, update translation
1 #include <QLocale>
2 #include <QDebug>
3
4 #include "sealedbox.h"
5
6 SealedBox::SealedBox(double vol)
7 {
8 setVolume(vol);
9 }
10
11 void SealedBox::setVolume(double vol)
12 {
13 volume = double ((int)(vol * 100) / 100.0);
14 }
15
16 double SealedBox::getVolume() const
17 {
18 return volume;
19 }
20
21 QDomElement SealedBox::toDomElement(QDomDocument& doc) const
22 {
23 QDomElement e = Box::toDomElement(doc);
24 e.setAttribute("type", "sealed");
25
26 QLocale c(QLocale::C);
27 e.setAttribute("volume", c.toString(volume));
28
29 return e;
30 }
31
32 void SealedBox::fromDomElement(const QDomElement &e)
33 {
34 Box::fromDomElement(e);
35 if (e.attribute("type") != "sealed") {
36 qWarning() << __func__ << "wrong box type! (not sealed, giving up)";
37 return;
38 }
39
40 QLocale c(QLocale::C);
41 volume = c.toDouble(e.attribute("volume"));
42 }
43
44 void SealedBox::render(QPainter *painter, const QRectF &area) const
45 {
46 if (!painter)
47 return;
48
49 painter->drawRoundedRect(area.toRect(), 5, 5);
50
51 QString text = QObject::tr("Vol. %1 L").arg(getVolume());
52 QRectF where(area.left(), area.top(), area.width(), area.height());
53 QTextOption option(Qt::AlignVCenter|Qt::AlignLeft);
54 painter->drawText(where, text, option);
55 }

  ViewVC Help
Powered by ViewVC 1.1.26