Changeset View
Changeset View
Standalone View
Standalone View
src/common/KReportItemBase.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 "KReportItemBase.h" | 18 | #include "KReportItemBase.h" | ||
19 | 19 | | |||
20 | #include "KReportPosition.h" | | |||
21 | #include "KReportSize.h" | | |||
22 | #include "KReportUtils.h" | 20 | #include "KReportUtils.h" | ||
23 | #include <KPropertySet> | 21 | #include <KPropertySet> | ||
22 | #include <QApplication> | ||||
23 | #include <QDomElement> | ||||
24 | 24 | | |||
25 | KReportItemBase::KReportItemBase() | 25 | class Q_DECL_HIDDEN KReportItemBase::Private | ||
26 | { | 26 | { | ||
27 | Z = 0; | 27 | public: | ||
28 | m_name = new KProperty("name", QString(), tr("Name"), tr("Object Name")); | 28 | Private(); | ||
29 | m_name->setAutoSync(0); | 29 | ~Private(); | ||
30 | | ||||
31 | KPropertySet *set; | ||||
32 | KProperty *nameProperty; | ||||
33 | KProperty *sizeProperty; | ||||
34 | KProperty *positionProperty; | ||||
35 | QString oldName; | ||||
36 | qreal z; | ||||
37 | }; | ||||
38 | | ||||
39 | KReportItemBase::Private::Private() | ||||
40 | { | ||||
41 | set = new KPropertySet(); | ||||
42 | nameProperty = new KProperty("name", QString(), tr("Name"), tr("Object Name")); | ||||
43 | nameProperty->setAutoSync(0); | ||||
44 | | ||||
45 | positionProperty = new KProperty("position", QPointF(), QCoreApplication::translate("ItemPosition", "Position")); | ||||
46 | sizeProperty = new KProperty("size", QSizeF(), QCoreApplication::translate("ItemSize", "Size")); | ||||
47 | | ||||
48 | set->addProperty(nameProperty); | ||||
49 | set->addProperty(positionProperty); | ||||
50 | set->addProperty(sizeProperty); | ||||
51 | } | ||||
52 | | ||||
53 | KReportItemBase::Private::~Private() | ||||
54 | { | ||||
55 | delete set; | ||||
30 | } | 56 | } | ||
31 | 57 | | |||
32 | KReportItemBase::~KReportItemBase() { } | | |||
33 | 58 | | |||
34 | void KReportItemBase::addDefaultProperties() | 59 | KReportItemBase::KReportItemBase() : d(new Private()) | ||
35 | { | 60 | { | ||
36 | m_set->addProperty(m_name); | 61 | d->z = 0; | ||
37 | m_set->addProperty(m_pos.property()); | 62 | | ||
38 | m_set->addProperty(m_size.property()); | 63 | connect(propertySet(), &KPropertySet::propertyChanged, | ||
64 | this, &KReportItemBase::propertyChanged); | ||||
65 | } | ||||
66 | | ||||
67 | KReportItemBase::~KReportItemBase() | ||||
68 | { | ||||
69 | delete d; | ||||
39 | } | 70 | } | ||
40 | 71 | | |||
41 | bool KReportItemBase::parseReportTextStyleData(const QDomElement & elemSource, KRTextStyleData *ts) | 72 | bool KReportItemBase::parseReportTextStyleData(const QDomElement & elemSource, KRTextStyleData *ts) | ||
42 | { | 73 | { | ||
43 | return KReportUtils::parseReportTextStyleData(elemSource, ts); | 74 | return KReportUtils::parseReportTextStyleData(elemSource, ts); | ||
44 | } | 75 | } | ||
45 | 76 | | |||
46 | bool KReportItemBase::parseReportLineStyleData(const QDomElement & elemSource, KReportLineStyle *ls) | 77 | bool KReportItemBase::parseReportLineStyleData(const QDomElement & elemSource, KReportLineStyle *ls) | ||
47 | { | 78 | { | ||
48 | return KReportUtils::parseReportLineStyleData(elemSource, ls); | 79 | return KReportUtils::parseReportLineStyleData(elemSource, ls); | ||
49 | } | 80 | } | ||
50 | 81 | | |||
51 | 82 | | |||
52 | bool KReportItemBase::parseReportRect(const QDomElement & elemSource, KReportPosition *pos, KReportSize *size) | 83 | bool KReportItemBase::parseReportRect(const QDomElement & elemSource) | ||
53 | { | 84 | { | ||
54 | return KReportUtils::parseReportRect(elemSource, pos, size); | 85 | QPointF pos; | ||
86 | QSizeF size; | ||||
87 | | ||||
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; | ||||
97 | | ||||
staniek: do we need underlines here? | |||||
Probably not, it's just me ensuring there are no clashes with function names etc. Will change. piggz: Probably not, it's just me ensuring there are no clashes with function names etc. Will change. | |||||
55 | } | 98 | } | ||
56 | 99 | | |||
57 | void KReportItemBase::setUnit(const KReportUnit& u) | 100 | void KReportItemBase::setUnit(const KReportUnit& u) | ||
58 | { | 101 | { | ||
59 | m_pos.setUnit(u); | 102 | qDebug() << "Setting page unit to: " << u.symbol(); | ||
60 | m_size.setUnit(u); | 103 | d->positionProperty->setOption("unit", u.symbol()); | ||
104 | d->sizeProperty->setOption("unit", u.symbol()); | ||||
61 | } | 105 | } | ||
62 | 106 | | |||
63 | int KReportItemBase::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, | 107 | int KReportItemBase::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, | ||
64 | const QVariant &data, KReportScriptHandler* script) | 108 | const QVariant &data, KReportScriptHandler* script) | ||
65 | { | 109 | { | ||
66 | Q_UNUSED(page) | 110 | Q_UNUSED(page) | ||
67 | Q_UNUSED(section) | 111 | Q_UNUSED(section) | ||
68 | Q_UNUSED(offset) | 112 | Q_UNUSED(offset) | ||
Show All 13 Lines | 120 | { | |||
82 | return 0; | 126 | return 0; | ||
83 | } | 127 | } | ||
84 | 128 | | |||
85 | QString KReportItemBase::itemDataSource() const | 129 | QString KReportItemBase::itemDataSource() const | ||
86 | { | 130 | { | ||
87 | return QString(); | 131 | return QString(); | ||
88 | } | 132 | } | ||
89 | 133 | | |||
90 | KPropertySet* KReportItemBase::propertySet() const | 134 | KPropertySet* KReportItemBase::propertySet() | ||
91 | { | 135 | { | ||
92 | return m_set; | 136 | return d->set; | ||
93 | } | 137 | } | ||
94 | 138 | | |||
95 | bool KReportItemBase::supportsSubQuery() const | 139 | bool KReportItemBase::supportsSubQuery() const | ||
96 | { | 140 | { | ||
97 | return false; | 141 | return false; | ||
98 | } | 142 | } | ||
99 | 143 | | |||
100 | QString KReportItemBase::entityName() const | 144 | QString KReportItemBase::entityName() const | ||
101 | { | 145 | { | ||
102 | return m_name->value().toString(); | 146 | return d->nameProperty->value().toString(); | ||
103 | } | 147 | } | ||
104 | 148 | | |||
105 | void KReportItemBase::setEntityName(const QString& n) | 149 | void KReportItemBase::setEntityName(const QString& n) | ||
106 | { | 150 | { | ||
107 | m_name->setValue(n); | 151 | d->nameProperty->setValue(n); | ||
152 | } | ||||
153 | | ||||
154 | KProperty* KReportItemBase::nameProperty() | ||||
155 | { | ||||
156 | return d->nameProperty; | ||||
157 | } | ||||
158 | | ||||
159 | QString KReportItemBase::oldName() const | ||||
160 | { | ||||
161 | return d->oldName; | ||||
108 | } | 162 | } | ||
109 | 163 | | |||
110 | KReportPosition KReportItemBase::position() const | 164 | void KReportItemBase::setOldName(const QString& old) | ||
111 | { | 165 | { | ||
112 | return m_pos; | 166 | d->oldName = old; | ||
113 | } | 167 | } | ||
114 | 168 | | |||
115 | KReportSize KReportItemBase::size() const | 169 | QPointF KReportItemBase::position() const | ||
116 | { | 170 | { | ||
117 | return m_size; | 171 | return d->positionProperty->value().toPointF(); | ||
118 | } | 172 | } | ||
119 | 173 | | |||
174 | QSizeF KReportItemBase::size() const | ||||
175 | { | ||||
176 | return d->sizeProperty->value().toSizeF(); | ||||
177 | } | ||||
178 | | ||||
179 | const KPropertySet * KReportItemBase::propertySet() const | ||||
180 | { | ||||
181 | return propertySet(); | ||||
182 | } | ||||
183 | | ||||
184 | QPointF KReportItemBase::scenePosition(const QPointF &pos) | ||||
185 | { | ||||
186 | const qreal x = POINT_TO_INCH(pos.x()) * KReportDpi::dpiX(); | ||||
187 | const qreal y = POINT_TO_INCH(pos.y()) * KReportDpi::dpiY(); | ||||
188 | return QPointF(x, y); | ||||
189 | } | ||||
190 | | ||||
191 | QSizeF KReportItemBase::sceneSize(const QSizeF &size) | ||||
192 | { | ||||
193 | const qreal w = POINT_TO_INCH(size.width()) * KReportDpi::dpiX(); | ||||
194 | const qreal h = POINT_TO_INCH(size.height()) * KReportDpi::dpiY(); | ||||
195 | return QSizeF(w, h); | ||||
196 | } | ||||
197 | | ||||
198 | qreal KReportItemBase::z() const | ||||
199 | { | ||||
200 | return d->z; | ||||
staniek: When we're at this, how about changing d->zIndex to d->z for consistency? | |||||
201 | } | ||||
202 | | ||||
203 | void KReportItemBase::setZ(qreal z) | ||||
204 | { | ||||
205 | d->z = z; | ||||
206 | } | ||||
207 | | ||||
208 | void KReportItemBase::setPosition(const QPointF& pos) | ||||
209 | { | ||||
210 | d->positionProperty->setValue(pos); | ||||
211 | } | ||||
212 | | ||||
213 | void KReportItemBase::setSize(const QSizeF& size) | ||||
staniek: size | |||||
214 | { | ||||
215 | d->sizeProperty->setValue(size); | ||||
216 | } | ||||
217 | | ||||
218 | QPointF KReportItemBase::positionFromScene(const QPointF& pos) | ||||
219 | { | ||||
220 | const qreal x = INCH_TO_POINT(pos.x() / KReportDpi::dpiX()); | ||||
221 | const qreal y = INCH_TO_POINT(pos.y() / KReportDpi::dpiY()); | ||||
222 | return QPointF(x, y); | ||||
223 | } | ||||
224 | | ||||
225 | QSizeF KReportItemBase::sizeFromScene(const QSizeF& size) | ||||
226 | { | ||||
227 | qreal w = INCH_TO_POINT(size.width() / KReportDpi::dpiX()); | ||||
228 | qreal h = INCH_TO_POINT(size.height() / KReportDpi::dpiY()); | ||||
229 | return QSizeF(w, h); | ||||
230 | } | ||||
231 | | ||||
232 | void KReportItemBase::propertyChanged(KPropertySet& s, KProperty& p) | ||||
233 | { | ||||
staniek: missing Q_UNUSED | |||||
I know about these , my plan was a separate review concentrating on build warnings. Ok? piggz: I know about these , my plan was a separate review concentrating on build warnings. Ok? | |||||
staniek: OK! | |||||
234 | } | ||||
235 | | ||||
236 | | ||||
237 | |
do we need underlines here?