Changeset View
Changeset View
Standalone View
Standalone View
src/common/KReportItemLine.cpp
Show All 11 Lines | |||||
12 | * Lesser General Public License for more details. | 12 | * Lesser General Public License for more details. | ||
13 | * | 13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public | 14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | 15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | 16 | */ | ||
17 | 17 | | |||
18 | #include "KReportItemLine.h" | 18 | #include "KReportItemLine.h" | ||
19 | #include "KReportRenderObjects.h" | 19 | #include "KReportRenderObjects.h" | ||
20 | #include "KReportUtils.h" | ||||
21 | #include "KReportUtils_p.h" | ||||
20 | #include "kreport_debug.h" | 22 | #include "kreport_debug.h" | ||
21 | 23 | | |||
22 | #include <KPropertySet> | 24 | #include <KPropertySet> | ||
23 | 25 | | |||
24 | #include <QCoreApplication> | 26 | #include <QCoreApplication> | ||
25 | #include <QDomNode> | 27 | #include <QDomNode> | ||
26 | 28 | | |||
27 | KReportItemLine::KReportItemLine() | 29 | KReportItemLine::KReportItemLine() | ||
28 | { | 30 | { | ||
29 | createProperties(); | 31 | createProperties(); | ||
30 | } | 32 | } | ||
31 | 33 | | |||
32 | KReportItemLine::KReportItemLine(const QDomNode & element) | 34 | KReportItemLine::KReportItemLine(const QDomNode & element) | ||
33 | : KReportItemLine() | 35 | : KReportItemLine() | ||
34 | { | 36 | { | ||
37 | nameProperty()->setValue(KReportUtils::readNameAttribute(element.toElement())); | ||||
38 | setZ(KReportUtils::readZAttribute(element.toElement())); | ||||
39 | | ||||
40 | const QPointF s(KReportUnit::parseValue(element.toElement().attribute( | ||||
41 | QLatin1String("svg:x1"), DEFAULT_ELEMENT_POS_STRING)), | ||||
42 | KReportUnit::parseValue(element.toElement().attribute( | ||||
43 | QLatin1String("svg:y1"), DEFAULT_ELEMENT_POS_STRING))); | ||||
44 | const QPointF e(KReportUnit::parseValue(element.toElement().attribute( | ||||
45 | QLatin1String("svg:x2"), DEFAULT_ELEMENT_POS_STRING)), | ||||
46 | KReportUnit::parseValue(element.toElement().attribute( | ||||
47 | QLatin1String("svg:y2"), | ||||
48 | QString::number(POINT_TO_CM(DEFAULT_ELEMENT_POS_PT.y() | ||||
49 | + DEFAULT_ELEMENT_SIZE_PT.height())) | ||||
50 | + QLatin1String("cm")))); | ||||
51 | setStartPosition(s); | ||||
52 | setEndPosition(e); | ||||
53 | | ||||
35 | QDomNodeList nl = element.childNodes(); | 54 | QDomNodeList nl = element.childNodes(); | ||
36 | QString n; | 55 | QString n; | ||
37 | QDomNode node; | 56 | QDomNode node; | ||
38 | QPointF _s, _e; | | |||
39 | | ||||
40 | nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); | | |||
41 | setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); | | |||
42 | | ||||
43 | _s.setX(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:x1"), QLatin1String("1cm")))); | | |||
44 | _s.setY(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:y1"), QLatin1String("1cm")))); | | |||
45 | _e.setX(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:x2"), QLatin1String("1cm")))); | | |||
46 | _e.setY(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:y2"), QLatin1String("2cm")))); | | |||
47 | m_start->setValue(_s); | | |||
48 | m_end->setValue(_e); | | |||
49 | | ||||
50 | for (int i = 0; i < nl.count(); i++) { | 57 | for (int i = 0; i < nl.count(); i++) { | ||
51 | node = nl.item(i); | 58 | node = nl.item(i); | ||
52 | n = node.nodeName(); | 59 | n = node.nodeName(); | ||
53 | 60 | | |||
54 | if (n == QLatin1String("report:line-style")) { | 61 | if (n == QLatin1String("report:line-style")) { | ||
55 | KReportLineStyle ls; | 62 | KReportLineStyle ls; | ||
56 | if (parseReportLineStyleData(node.toElement(), &ls)) { | 63 | if (parseReportLineStyleData(node.toElement(), &ls)) { | ||
57 | m_lineWeight->setValue(ls.weight()); | 64 | m_lineWeight->setValue(ls.weight()); | ||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | |||||
116 | 123 | | |||
117 | int KReportItemLine::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, | 124 | int KReportItemLine::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, | ||
118 | const QVariant &data, KReportScriptHandler *script) | 125 | const QVariant &data, KReportScriptHandler *script) | ||
119 | { | 126 | { | ||
120 | Q_UNUSED(script) | 127 | Q_UNUSED(script) | ||
121 | Q_UNUSED(data) | 128 | Q_UNUSED(data) | ||
122 | 129 | | |||
123 | OROLine * ln = new OROLine(); | 130 | OROLine * ln = new OROLine(); | ||
124 | QPointF s = scenePosition(m_start->value().toPointF()); | 131 | QPointF s = scenePosition(startPosition()); | ||
125 | QPointF e = scenePosition(m_end->value().toPointF()); | 132 | QPointF e = scenePosition(endPosition()); | ||
126 | 133 | | |||
127 | s += offset; | 134 | s += offset; | ||
128 | e += offset; | 135 | e += offset; | ||
129 | 136 | | |||
130 | ln->setStartPoint(s); | 137 | ln->setStartPoint(s); | ||
131 | ln->setEndPoint(e); | 138 | ln->setEndPoint(e); | ||
132 | ln->setLineStyle(lineStyle()); | 139 | ln->setLineStyle(lineStyle()); | ||
133 | if (page) page->insertPrimitive(ln); | 140 | if (page) page->insertPrimitive(ln); | ||
134 | 141 | | |||
135 | OROLine *l2 = dynamic_cast<OROLine*>(ln->clone()); | 142 | OROLine *l2 = dynamic_cast<OROLine*>(ln->clone()); | ||
136 | if (l2) { | 143 | if (l2) { | ||
137 | l2->setStartPoint(m_start->value().toPointF()); | 144 | l2->setStartPoint(startPosition()); | ||
138 | l2->setEndPoint(m_end->value().toPointF()); | 145 | l2->setEndPoint(endPosition()); | ||
139 | 146 | | |||
140 | if (section) section->addPrimitive(l2); | 147 | if (section) section->addPrimitive(l2); | ||
141 | } | 148 | } | ||
142 | return 0; | 149 | return 0; | ||
143 | } | 150 | } | ||
144 | 151 | | |||
145 | void KReportItemLine::setUnit(const KReportUnit &u) | 152 | void KReportItemLine::setUnit(const KReportUnit &u) | ||
146 | { | 153 | { | ||
147 | m_start->setOption("unit", u.symbol()); | 154 | if (unit() == u) { | ||
148 | m_end->setOption("unit", u.symbol()); | 155 | return; | ||
156 | } | ||||
157 | KReportUnit oldunit = unit(); | ||||
158 | KReportItemBase::setUnit(u); | ||||
159 | | ||||
160 | // convert values | ||||
161 | m_start->setValue(KReportUnit::convertFromUnitToUnit(m_start->value().toPointF(), oldunit, u), | ||||
162 | KProperty::ValueOption::IgnoreOld); | ||||
163 | m_end->setValue(KReportUnit::convertFromUnitToUnit(m_end->value().toPointF(), oldunit, u), | ||||
164 | KProperty::ValueOption::IgnoreOld); | ||||
165 | | ||||
166 | m_start->setOption("suffix", u.symbol()); | ||||
167 | m_end->setOption("suffix", u.symbol()); | ||||
149 | } | 168 | } | ||
150 | 169 | | |||
151 | QPointF KReportItemLine::startPosition() const | 170 | QPointF KReportItemLine::startPosition() const | ||
152 | { | 171 | { | ||
153 | return m_start->value().toPointF(); | 172 | return unit().convertToPoint(m_start->value().toPointF()); | ||
173 | } | ||||
174 | | ||||
175 | void KReportItemLine::setStartPosition(const QPointF &ptPos) | ||||
176 | { | ||||
177 | m_start->setValue(unit().convertFromPoint(ptPos)); | ||||
154 | } | 178 | } | ||
155 | 179 | | |||
156 | QPointF KReportItemLine::endPosition() const | 180 | QPointF KReportItemLine::endPosition() const | ||
157 | { | 181 | { | ||
158 | return m_end->value().toPointF(); | 182 | return unit().convertToPoint(m_end->value().toPointF()); | ||
159 | } | 183 | } | ||
160 | 184 | | |||
185 | void KReportItemLine::setEndPosition(const QPointF &ptPos) | ||||
186 | { | ||||
187 | m_end->setValue(unit().convertFromPoint(ptPos)); | ||||
188 | } |