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