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