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 | m_start->setValue(unit().convertFromPoint(s)); | ||||
52 | m_end->setValue(unit().convertFromPoint(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 80 Lines • ▼ Show 20 Line(s) | 142 | if (l2) { | |||
138 | 145 | | |||
139 | if (section) section->addPrimitive(l2); | 146 | if (section) section->addPrimitive(l2); | ||
140 | } | 147 | } | ||
141 | return 0; | 148 | return 0; | ||
142 | } | 149 | } | ||
143 | 150 | | |||
144 | void KReportItemLine::setUnit(const KReportUnit &u) | 151 | void KReportItemLine::setUnit(const KReportUnit &u) | ||
145 | { | 152 | { | ||
146 | m_start->setOption("unit", u.symbol()); | 153 | if (unit() == u) { | ||
147 | m_end->setOption("unit", u.symbol()); | 154 | return; | ||
155 | } | ||||
156 | // convert values | ||||
157 | m_start->setValue( | ||||
158 | KReportUnit::convertFromUnitToUnit(m_start->value().toPointF(), unit(), u), | ||||
159 | KProperty::DefaultValueOptions | ||||
160 | & ~KProperty::ValueOptions(KProperty::ValueOption::RememberOld)); | ||||
161 | m_end->setValue( | ||||
162 | KReportUnit::convertFromUnitToUnit(m_end->value().toPointF(), unit(), u), | ||||
163 | KProperty::DefaultValueOptions | ||||
164 | & ~KProperty::ValueOptions(KProperty::ValueOption::RememberOld)); | ||||
165 | | ||||
166 | KReportItemBase::setUnit(u); | ||||
167 | m_start->setOption("suffix", u.symbol()); | ||||
168 | m_end->setOption("suffix", u.symbol()); | ||||
148 | } | 169 | } | ||
149 | 170 | | |||
150 | QPointF KReportItemLine::startPosition() const | 171 | QPointF KReportItemLine::startPosition() const | ||
151 | { | 172 | { | ||
152 | return m_start->value().toPointF(); | 173 | return m_start->value().toPointF(); | ||
153 | } | 174 | } | ||
154 | 175 | | |||
176 | void KReportItemLine::setStartPosition(const QPointF &ptPos) | ||||
177 | { | ||||
178 | m_start->setValue(unit().convertFromPoint(ptPos)); | ||||
179 | } | ||||
180 | | ||||
155 | QPointF KReportItemLine::endPosition() const | 181 | QPointF KReportItemLine::endPosition() const | ||
156 | { | 182 | { | ||
157 | return m_end->value().toPointF(); | 183 | return m_end->value().toPointF(); | ||
158 | } | 184 | } | ||
159 | 185 | | |||
186 | void KReportItemLine::setEndPosition(const QPointF &ptPos) | ||||
187 | { | ||||
188 | m_end->setValue(unit().convertFromPoint(ptPos)); | ||||
189 | } |