Changeset View
Changeset View
Standalone View
Standalone View
src/common/KReportItemBase.cpp
Show All 24 Lines | |||||
25 | #include <QDomElement> | 25 | #include <QDomElement> | ||
26 | 26 | | |||
27 | class Q_DECL_HIDDEN KReportItemBase::Private | 27 | class Q_DECL_HIDDEN KReportItemBase::Private | ||
28 | { | 28 | { | ||
29 | public: | 29 | public: | ||
30 | Private(); | 30 | Private(); | ||
31 | ~Private(); | 31 | ~Private(); | ||
32 | 32 | | |||
33 | void setUnit(const KReportUnit& u, bool force) | ||||
34 | { | ||||
35 | if (!force && unit == u) { | ||||
36 | return; | ||||
37 | } | ||||
38 | const QSignalBlocker blocker(set); | ||||
39 | KReportUnit oldunit = unit; | ||||
40 | unit = u; | ||||
41 | // convert values | ||||
42 | | ||||
43 | if (positionProperty) { | ||||
44 | positionProperty->setValue(KReportUnit::convertFromUnitToUnit( | ||||
45 | positionProperty->value().toPointF(), oldunit, u), | ||||
46 | KProperty::ValueOption::IgnoreOld); | ||||
47 | | ||||
48 | positionProperty->setOption("suffix", u.symbol()); | ||||
49 | | ||||
50 | } | ||||
51 | if (sizeProperty) { | ||||
52 | sizeProperty->setValue( | ||||
53 | KReportUnit::convertFromUnitToUnit(sizeProperty->value().toSizeF(), oldunit, u), | ||||
54 | KProperty::ValueOption::IgnoreOld); | ||||
55 | | ||||
56 | sizeProperty->setOption("suffix", u.symbol()); | ||||
57 | } | ||||
58 | | ||||
59 | } | ||||
60 | | ||||
33 | KPropertySet *set; | 61 | KPropertySet *set; | ||
34 | KProperty *nameProperty; | 62 | KProperty *nameProperty; | ||
35 | KProperty *sizeProperty; | 63 | KProperty *sizeProperty; | ||
36 | KProperty *positionProperty; | 64 | KProperty *positionProperty; | ||
37 | QString oldName; | 65 | QString oldName; | ||
38 | qreal z = 0; | 66 | qreal z = 0; | ||
67 | KReportUnit unit; | ||||
39 | }; | 68 | }; | ||
40 | 69 | | |||
41 | KReportItemBase::Private::Private() | 70 | KReportItemBase::Private::Private() | ||
42 | { | 71 | { | ||
43 | set = new KPropertySet(); | 72 | set = new KPropertySet(); | ||
44 | nameProperty = new KProperty("name", QString(), tr("Name"), tr("Object Name")); | 73 | nameProperty = new KProperty("name", QString(), tr("Name"), tr("Object Name")); | ||
45 | nameProperty->setValueSyncPolicy(KProperty::ValueSyncPolicy::FocusOut); | 74 | nameProperty->setValueSyncPolicy(KProperty::ValueSyncPolicy::FocusOut); | ||
46 | 75 | | |||
47 | positionProperty = new KProperty("position", QPointF(), QCoreApplication::translate("ItemPosition", "Position")); | 76 | positionProperty = new KProperty("position", QPointF(), QCoreApplication::translate("ItemPosition", "Position")); | ||
48 | sizeProperty = new KProperty("size", QSizeF(), QCoreApplication::translate("ItemSize", "Size")); | 77 | sizeProperty = new KProperty("size", QSizeF(), QCoreApplication::translate("ItemSize", "Size")); | ||
78 | setUnit(DEFAULT_UNIT, true); | ||||
49 | 79 | | |||
50 | set->addProperty(nameProperty); | 80 | set->addProperty(nameProperty); | ||
51 | set->addProperty(positionProperty); | 81 | set->addProperty(positionProperty); | ||
52 | set->addProperty(sizeProperty); | 82 | set->addProperty(sizeProperty); | ||
53 | } | 83 | } | ||
54 | 84 | | |||
55 | KReportItemBase::Private::~Private() | 85 | KReportItemBase::Private::~Private() | ||
56 | { | 86 | { | ||
57 | delete set; | 87 | delete set; | ||
58 | } | 88 | } | ||
59 | 89 | | |||
60 | 90 | | |||
61 | KReportItemBase::KReportItemBase() : d(new Private()) | 91 | KReportItemBase::KReportItemBase() : d(new Private()) | ||
62 | { | 92 | { | ||
63 | connect(propertySet(), &KPropertySet::propertyChanged, | 93 | connect(propertySet(), &KPropertySet::propertyChanged, | ||
64 | this, &KReportItemBase::propertyChanged); | 94 | this, &KReportItemBase::propertyChanged); | ||
95 | | ||||
96 | connect(propertySet(), &KPropertySet::aboutToDeleteProperty, this, &KReportItemBase::aboutToDeleteProperty); | ||||
65 | } | 97 | } | ||
66 | 98 | | |||
67 | KReportItemBase::~KReportItemBase() | 99 | KReportItemBase::~KReportItemBase() | ||
68 | { | 100 | { | ||
69 | delete d; | 101 | delete d; | ||
70 | } | 102 | } | ||
71 | 103 | | |||
72 | bool KReportItemBase::parseReportTextStyleData(const QDomElement & elemSource, KReportTextStyleData *ts) | 104 | bool KReportItemBase::parseReportTextStyleData(const QDomElement & elemSource, KReportTextStyleData *ts) | ||
73 | { | 105 | { | ||
74 | return KReportUtils::parseReportTextStyleData(elemSource, ts); | 106 | return KReportUtils::parseReportTextStyleData(elemSource, ts); | ||
75 | } | 107 | } | ||
76 | 108 | | |||
77 | bool KReportItemBase::parseReportLineStyleData(const QDomElement & elemSource, KReportLineStyle *ls) | 109 | bool KReportItemBase::parseReportLineStyleData(const QDomElement & elemSource, KReportLineStyle *ls) | ||
78 | { | 110 | { | ||
79 | return KReportUtils::parseReportLineStyleData(elemSource, ls); | 111 | return KReportUtils::parseReportLineStyleData(elemSource, ls); | ||
80 | } | 112 | } | ||
81 | 113 | | |||
82 | 114 | | |||
83 | bool KReportItemBase::parseReportRect(const QDomElement & elemSource) | 115 | bool KReportItemBase::parseReportRect(const QDomElement & elemSource) | ||
84 | { | 116 | { | ||
85 | QPointF pos; | 117 | const QRectF r(KReportUtils::readRectAttributes(elemSource, DEFAULT_ELEMENT_RECT_PT)); | ||
86 | QSizeF size; | 118 | setPosition(r.topLeft()); | ||
87 | 119 | setSize(r.size()); | |||
88 | pos.setX(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:x"), QLatin1String("1cm")))); | | |||
89 | pos.setY(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:y"), QLatin1String("1cm")))); | | |||
90 | size.setWidth(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:width"), QLatin1String("1cm")))); | | |||
91 | size.setHeight(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:height"), QLatin1String("1cm")))); | | |||
92 | | ||||
93 | setPosition(pos); | | |||
94 | setSize(size); | | |||
95 | | ||||
96 | return true; | 120 | return true; | ||
121 | } | ||||
97 | 122 | | |||
123 | KReportUnit KReportItemBase::unit() const | ||||
124 | { | ||||
125 | return d->unit; | ||||
98 | } | 126 | } | ||
99 | 127 | | |||
100 | void KReportItemBase::setUnit(const KReportUnit& u) | 128 | void KReportItemBase::setUnit(const KReportUnit& u) | ||
101 | { | 129 | { | ||
102 | qDebug() << "Setting page unit to: " << u.symbol(); | 130 | d->setUnit(u, false); | ||
103 | d->positionProperty->setOption("unit", u.symbol()); | | |||
104 | d->sizeProperty->setOption("unit", u.symbol()); | | |||
105 | } | 131 | } | ||
106 | 132 | | |||
107 | int KReportItemBase::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, | 133 | int KReportItemBase::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, | ||
108 | const QVariant &data, KReportScriptHandler* script) | 134 | const QVariant &data, KReportScriptHandler* script) | ||
109 | { | 135 | { | ||
110 | Q_UNUSED(page) | 136 | Q_UNUSED(page) | ||
111 | Q_UNUSED(section) | 137 | Q_UNUSED(section) | ||
112 | Q_UNUSED(offset) | 138 | Q_UNUSED(offset) | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | |||||
163 | 189 | | |||
164 | void KReportItemBase::setOldName(const QString& old) | 190 | void KReportItemBase::setOldName(const QString& old) | ||
165 | { | 191 | { | ||
166 | d->oldName = old; | 192 | d->oldName = old; | ||
167 | } | 193 | } | ||
168 | 194 | | |||
169 | QPointF KReportItemBase::position() const | 195 | QPointF KReportItemBase::position() const | ||
170 | { | 196 | { | ||
171 | return d->positionProperty->value().toPointF(); | 197 | return d->unit.convertToPoint(d->positionProperty->value().toPointF()); | ||
172 | } | 198 | } | ||
173 | 199 | | |||
174 | QSizeF KReportItemBase::size() const | 200 | QSizeF KReportItemBase::size() const | ||
175 | { | 201 | { | ||
176 | return d->sizeProperty->value().toSizeF(); | 202 | return d->unit.convertToPoint(d->sizeProperty->value().toSizeF()); | ||
177 | } | 203 | } | ||
178 | 204 | | |||
179 | const KPropertySet * KReportItemBase::propertySet() const | 205 | const KPropertySet * KReportItemBase::propertySet() const | ||
180 | { | 206 | { | ||
181 | return d->set; | 207 | return d->set; | ||
182 | } | 208 | } | ||
183 | 209 | | |||
184 | QPointF KReportItemBase::scenePosition(const QPointF &pos) | 210 | QPointF KReportItemBase::scenePosition(const QPointF &ptPos) | ||
185 | { | 211 | { | ||
186 | const qreal x = POINT_TO_INCH(pos.x()) * KReportPrivate::dpiX(); | 212 | const qreal x = POINT_TO_INCH(ptPos.x()) * KReportPrivate::dpiX(); | ||
187 | const qreal y = POINT_TO_INCH(pos.y()) * KReportPrivate::dpiY(); | 213 | const qreal y = POINT_TO_INCH(ptPos.y()) * KReportPrivate::dpiY(); | ||
188 | return QPointF(x, y); | 214 | return QPointF(x, y); | ||
189 | } | 215 | } | ||
190 | 216 | | |||
191 | QSizeF KReportItemBase::sceneSize(const QSizeF &size) | 217 | QSizeF KReportItemBase::sceneSize(const QSizeF &ptSize) | ||
192 | { | 218 | { | ||
193 | const qreal w = POINT_TO_INCH(size.width()) * KReportPrivate::dpiX(); | 219 | const qreal w = POINT_TO_INCH(ptSize.width()) * KReportPrivate::dpiX(); | ||
194 | const qreal h = POINT_TO_INCH(size.height()) * KReportPrivate::dpiY(); | 220 | const qreal h = POINT_TO_INCH(ptSize.height()) * KReportPrivate::dpiY(); | ||
195 | return QSizeF(w, h); | 221 | return QSizeF(w, h); | ||
196 | } | 222 | } | ||
197 | 223 | | |||
198 | qreal KReportItemBase::z() const | 224 | qreal KReportItemBase::z() const | ||
199 | { | 225 | { | ||
200 | return d->z; | 226 | return d->z; | ||
201 | } | 227 | } | ||
202 | 228 | | |||
203 | void KReportItemBase::setZ(qreal z) | 229 | void KReportItemBase::setZ(qreal z) | ||
204 | { | 230 | { | ||
205 | d->z = z; | 231 | d->z = z; | ||
206 | } | 232 | } | ||
207 | 233 | | |||
208 | void KReportItemBase::setPosition(const QPointF& pos) | 234 | void KReportItemBase::setPosition(const QPointF& ptPos) | ||
209 | { | 235 | { | ||
210 | d->positionProperty->setValue(pos); | 236 | d->positionProperty->setValue(d->unit.convertFromPoint(ptPos)); | ||
211 | } | 237 | } | ||
212 | 238 | | |||
213 | void KReportItemBase::setSize(const QSizeF& size) | 239 | void KReportItemBase::setSize(const QSizeF &ptSize) | ||
214 | { | 240 | { | ||
215 | d->sizeProperty->setValue(size); | 241 | d->sizeProperty->setValue(d->unit.convertFromPoint(ptSize)); | ||
216 | } | 242 | } | ||
217 | 243 | | |||
218 | QPointF KReportItemBase::positionFromScene(const QPointF& pos) | 244 | QPointF KReportItemBase::positionFromScene(const QPointF& pos) | ||
219 | { | 245 | { | ||
220 | const qreal x = INCH_TO_POINT(pos.x() / KReportPrivate::dpiX()); | 246 | const qreal x = INCH_TO_POINT(pos.x() / KReportPrivate::dpiX()); | ||
221 | const qreal y = INCH_TO_POINT(pos.y() / KReportPrivate::dpiY()); | 247 | const qreal y = INCH_TO_POINT(pos.y() / KReportPrivate::dpiY()); | ||
222 | return QPointF(x, y); | 248 | return QPointF(x, y); | ||
223 | } | 249 | } | ||
224 | 250 | | |||
225 | QSizeF KReportItemBase::sizeFromScene(const QSizeF& size) | 251 | QSizeF KReportItemBase::sizeFromScene(const QSizeF& size) | ||
226 | { | 252 | { | ||
227 | qreal w = INCH_TO_POINT(size.width() / KReportPrivate::dpiX()); | 253 | qreal w = INCH_TO_POINT(size.width() / KReportPrivate::dpiX()); | ||
228 | qreal h = INCH_TO_POINT(size.height() / KReportPrivate::dpiY()); | 254 | qreal h = INCH_TO_POINT(size.height() / KReportPrivate::dpiY()); | ||
229 | return QSizeF(w, h); | 255 | return QSizeF(w, h); | ||
230 | } | 256 | } | ||
231 | 257 | | |||
232 | void KReportItemBase::propertyChanged(KPropertySet& s, KProperty& p) | 258 | void KReportItemBase::propertyChanged(KPropertySet& s, KProperty& p) | ||
233 | { | 259 | { | ||
234 | Q_UNUSED(s) | 260 | Q_UNUSED(s) | ||
235 | Q_UNUSED(p) | 261 | Q_UNUSED(p) | ||
236 | } | 262 | } | ||
263 | | ||||
264 | void KReportItemBase::aboutToDeleteProperty(KPropertySet& set, KProperty& property) | ||||
265 | { | ||||
266 | Q_UNUSED(set) | ||||
267 | if (property.name() == "size") { | ||||
268 | d->sizeProperty = nullptr; | ||||
269 | } | ||||
270 | else if (property.name() == "position") { | ||||
271 | d->positionProperty = nullptr; | ||||
272 | } | ||||
273 | } | ||||
staniek: Minor
Move { to new line |
Minor
Move { to new line