Changeset View
Changeset View
Standalone View
Standalone View
src/common/KReportItemLine.cpp
Show All 15 Lines | |||||
16 | */ | 16 | */ | ||
17 | 17 | | |||
18 | #include "KReportItemLine.h" | 18 | #include "KReportItemLine.h" | ||
19 | #include "KReportRenderObjects.h" | 19 | #include "KReportRenderObjects.h" | ||
20 | #include "kreport_debug.h" | 20 | #include "kreport_debug.h" | ||
21 | 21 | | |||
22 | #include <KPropertySet> | 22 | #include <KPropertySet> | ||
23 | 23 | | |||
24 | #include <QCoreApplication> | ||||
24 | #include <QDomNode> | 25 | #include <QDomNode> | ||
25 | 26 | | |||
26 | KReportItemLine::KReportItemLine() | 27 | KReportItemLine::KReportItemLine() | ||
27 | { | 28 | { | ||
28 | createProperties(); | 29 | createProperties(); | ||
29 | } | 30 | } | ||
30 | 31 | | |||
31 | KReportItemLine::KReportItemLine(const QDomNode & element) | 32 | KReportItemLine::KReportItemLine(const QDomNode & element) | ||
32 | { | 33 | { | ||
33 | createProperties(); | 34 | createProperties(); | ||
34 | QDomNodeList nl = element.childNodes(); | 35 | QDomNodeList nl = element.childNodes(); | ||
35 | QString n; | 36 | QString n; | ||
36 | QDomNode node; | 37 | QDomNode node; | ||
37 | QPointF _s, _e; | 38 | QPointF _s, _e; | ||
38 | 39 | | |||
39 | nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); | 40 | nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); | ||
40 | setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); | 41 | setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); | ||
41 | 42 | | |||
42 | _s.setX(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:x1"), QLatin1String("1cm")))); | 43 | _s.setX(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:x1"), QLatin1String("1cm")))); | ||
43 | _s.setY(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:y1"), QLatin1String("1cm")))); | 44 | _s.setY(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:y1"), QLatin1String("1cm")))); | ||
44 | _e.setX(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:x2"), QLatin1String("1cm")))); | 45 | _e.setX(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:x2"), QLatin1String("1cm")))); | ||
45 | _e.setY(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:y2"), QLatin1String("2cm")))); | 46 | _e.setY(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:y2"), QLatin1String("2cm")))); | ||
46 | m_start.setPointPos(_s); | 47 | m_start->setValue(_s); | ||
47 | m_end.setPointPos(_e); | 48 | m_end->setValue(_e); | ||
48 | 49 | | |||
49 | for (int i = 0; i < nl.count(); i++) { | 50 | for (int i = 0; i < nl.count(); i++) { | ||
50 | node = nl.item(i); | 51 | node = nl.item(i); | ||
51 | n = node.nodeName(); | 52 | n = node.nodeName(); | ||
52 | 53 | | |||
53 | if (n == QLatin1String("report:line-style")) { | 54 | if (n == QLatin1String("report:line-style")) { | ||
54 | KReportLineStyle ls; | 55 | KReportLineStyle ls; | ||
55 | if (parseReportLineStyleData(node.toElement(), &ls)) { | 56 | if (parseReportLineStyleData(node.toElement(), &ls)) { | ||
56 | m_lineWeight->setValue(ls.width()); | 57 | m_lineWeight->setValue(ls.width()); | ||
57 | m_lineColor->setValue(ls.color()); | 58 | m_lineColor->setValue(ls.color()); | ||
58 | m_lineStyle->setValue(int(ls.penStyle())); | 59 | m_lineStyle->setValue(int(ls.penStyle())); | ||
59 | } | 60 | } | ||
60 | } else { | 61 | } else { | ||
61 | kreportWarning() << "while parsing line element encountered unknow element: " << n; | 62 | kreportWarning() << "while parsing line element encountered unknow element: " << n; | ||
62 | } | 63 | } | ||
63 | } | 64 | } | ||
64 | } | 65 | } | ||
65 | 66 | | |||
66 | KReportItemLine::~KReportItemLine() | 67 | KReportItemLine::~KReportItemLine() | ||
67 | { | 68 | { | ||
68 | } | 69 | } | ||
69 | 70 | | |||
70 | void KReportItemLine::createProperties() | 71 | void KReportItemLine::createProperties() | ||
71 | { | 72 | { | ||
73 | m_start = new KProperty("startposition", QPointF(), QCoreApplication::translate("StartPosition", "Start Position")); | ||||
74 | m_end = new KProperty("endposition", QPointF(), QCoreApplication::translate("EndPosition", "End Position")); | ||||
75 | | ||||
72 | m_lineWeight = new KProperty("line-weight", 1, tr("Line Weight")); | 76 | m_lineWeight = new KProperty("line-weight", 1, tr("Line Weight")); | ||
73 | m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); | 77 | m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); | ||
74 | m_lineStyle = new KProperty("line-style", (int)Qt::SolidLine, tr("Line Style"), tr("Line Style"), KProperty::LineStyle); | 78 | m_lineStyle = new KProperty("line-style", (int)Qt::SolidLine, tr("Line Style"), tr("Line Style"), KProperty::LineStyle); | ||
75 | m_start.setName(QLatin1String("Start")); | | |||
76 | m_end.setName(QLatin1String("End")); | | |||
77 | 79 | | |||
78 | propertySet()->addProperty(m_start.property()); | 80 | propertySet()->addProperty(m_start); | ||
79 | propertySet()->addProperty(m_end.property()); | 81 | propertySet()->addProperty(m_end); | ||
80 | propertySet()->addProperty(m_lineWeight); | 82 | propertySet()->addProperty(m_lineWeight); | ||
81 | propertySet()->addProperty(m_lineColor); | 83 | propertySet()->addProperty(m_lineColor); | ||
82 | propertySet()->addProperty(m_lineStyle); | 84 | propertySet()->addProperty(m_lineStyle); | ||
83 | } | 85 | } | ||
84 | 86 | | |||
85 | KReportLineStyle KReportItemLine::lineStyle() const | 87 | KReportLineStyle KReportItemLine::lineStyle() const | ||
86 | { | 88 | { | ||
87 | KReportLineStyle ls; | 89 | KReportLineStyle ls; | ||
Show All 20 Lines | |||||
108 | 110 | | |||
109 | int KReportItemLine::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, | 111 | int KReportItemLine::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, | ||
110 | const QVariant &data, KReportScriptHandler *script) | 112 | const QVariant &data, KReportScriptHandler *script) | ||
111 | { | 113 | { | ||
112 | Q_UNUSED(script) | 114 | Q_UNUSED(script) | ||
113 | Q_UNUSED(data) | 115 | Q_UNUSED(data) | ||
114 | 116 | | |||
115 | OROLine * ln = new OROLine(); | 117 | OROLine * ln = new OROLine(); | ||
116 | QPointF s = m_start.toScene(); | 118 | QPointF s = scenePosition(m_start->value().toPointF()); | ||
117 | QPointF e = m_end.toScene(); | 119 | QPointF e = scenePosition(m_end->value().toPointF()); | ||
118 | 120 | | |||
119 | s += offset; | 121 | s += offset; | ||
120 | e += offset; | 122 | e += offset; | ||
121 | 123 | | |||
122 | ln->setStartPoint(s); | 124 | ln->setStartPoint(s); | ||
123 | ln->setEndPoint(e); | 125 | ln->setEndPoint(e); | ||
124 | ln->setLineStyle(lineStyle()); | 126 | ln->setLineStyle(lineStyle()); | ||
125 | if (page) page->insertPrimitive(ln); | 127 | if (page) page->insertPrimitive(ln); | ||
126 | 128 | | |||
127 | OROLine *l2 = dynamic_cast<OROLine*>(ln->clone()); | 129 | OROLine *l2 = dynamic_cast<OROLine*>(ln->clone()); | ||
128 | l2->setStartPoint(m_start.toPoint()); | 130 | l2->setStartPoint(m_start->value().toPointF()); | ||
129 | l2->setEndPoint(m_end.toPoint()); | 131 | l2->setEndPoint(m_end->value().toPointF()); | ||
130 | if (section) section->addPrimitive(l2); | 132 | if (section) section->addPrimitive(l2); | ||
131 | 133 | | |||
132 | return 0; | 134 | return 0; | ||
133 | } | 135 | } | ||
134 | 136 | | |||
135 | void KReportItemLine::setUnit(const KReportUnit &u) | 137 | void KReportItemLine::setUnit(const KReportUnit &u) | ||
136 | { | 138 | { | ||
137 | m_start.setUnit(u); | 139 | m_start->setOption("unit", u.symbol()); | ||
138 | m_end.setUnit(u); | 140 | m_end->setOption("unit", u.symbol()); | ||
139 | } | 141 | } | ||
140 | 142 | | |||
141 | KReportPosition KReportItemLine::startPosition() const | 143 | QPointF KReportItemLine::startPosition() const | ||
142 | { | 144 | { | ||
143 | return m_start; | 145 | return m_start->value().toPointF(); | ||
144 | } | 146 | } | ||
145 | 147 | | |||
146 | KReportPosition KReportItemLine::endPosition() const | 148 | QPointF KReportItemLine::endPosition() const | ||
147 | { | 149 | { | ||
148 | return m_end; | 150 | return m_end->value().toPointF(); | ||
149 | } | 151 | } | ||
150 | 152 | |