Changeset View
Changeset View
Standalone View
Standalone View
src/common/KReportSectionData.cpp
Show All 17 Lines | |||||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "KReportSectionData.h" | 20 | #include "KReportSectionData.h" | ||
21 | #include "KReportDesigner.h" | 21 | #include "KReportDesigner.h" | ||
22 | #include "KReportDocument.h" | 22 | #include "KReportDocument.h" | ||
23 | #include "KReportItemLine.h" | 23 | #include "KReportItemLine.h" | ||
24 | #include "KReportPluginInterface.h" | 24 | #include "KReportPluginInterface.h" | ||
25 | #include "KReportPluginManager.h" | 25 | #include "KReportPluginManager.h" | ||
26 | #include "KReportItemLine.h" | ||||
27 | #include "KReportDesigner.h" | ||||
26 | #include "KReportUtils.h" | 28 | #include "KReportUtils.h" | ||
29 | #include "KReportUtils_p.h" | ||||
27 | #include "kreport_debug.h" | 30 | #include "kreport_debug.h" | ||
28 | 31 | | |||
29 | #include <KPropertySet> | 32 | #include <KPropertySet> | ||
30 | 33 | | |||
31 | #include <QDomElement> | 34 | #include <QDomElement> | ||
32 | 35 | | |||
33 | KReportSectionData::KReportSectionData(QObject *parent) : KReportSectionData(QDomElement(), parent) | 36 | KReportSectionData::KReportSectionData(QObject *parent) : KReportSectionData(QDomElement(), parent) | ||
34 | { | 37 | { | ||
35 | } | 38 | } | ||
36 | 39 | | |||
37 | KReportSectionData::KReportSectionData(const QDomElement &elemSource, QObject *parent) | 40 | KReportSectionData::KReportSectionData(const QDomElement & elemSource, QObject *parent) | ||
38 | : QObject(parent) | 41 | : QObject(parent) | ||
42 | , m_unit(DEFAULT_UNIT_TYPE) | ||||
39 | { | 43 | { | ||
40 | if (elemSource.isNull()) { | 44 | if (elemSource.isNull()) { | ||
41 | m_type = Type::None; | 45 | m_type = Type::None; | ||
42 | } else { | 46 | } else { | ||
43 | setObjectName(elemSource.tagName()); | 47 | setObjectName(elemSource.tagName()); | ||
44 | m_type = sectionTypeFromString(elemSource.attribute(QLatin1String("report:section-type"))); | 48 | m_type = sectionTypeFromString(KReportUtils::readSectionTypeNameAttribute(elemSource)); | ||
45 | } | 49 | } | ||
46 | 50 | | |||
47 | createProperties(elemSource); | 51 | createProperties(elemSource); | ||
48 | 52 | | |||
49 | if (elemSource.isNull()) { | 53 | if (elemSource.isNull()) { | ||
50 | m_valid = true; | 54 | m_valid = true; | ||
51 | } else { | 55 | } else { | ||
52 | loadXml(elemSource); | 56 | loadXml(elemSource); | ||
Show All 27 Lines | 82 | if (plugin) { | |||
80 | if (obj) { | 84 | if (obj) { | ||
81 | krobj = dynamic_cast<KReportItemBase*>(obj); | 85 | krobj = dynamic_cast<KReportItemBase*>(obj); | ||
82 | } | 86 | } | ||
83 | } | 87 | } | ||
84 | } | 88 | } | ||
85 | if (krobj) { | 89 | if (krobj) { | ||
86 | krobj->propertySet()->clearModifiedFlags(); | 90 | krobj->propertySet()->clearModifiedFlags(); | ||
87 | m_objects.append(krobj); | 91 | m_objects.append(krobj); | ||
92 | } else { | ||||
93 | kreportWarning() << "Could not create element of type" << reportItemName; | ||||
88 | } | 94 | } | ||
89 | } | 95 | } else { | ||
90 | kreportWarning() << "While parsing section encountered an unknown element: " << n; | 96 | kreportWarning() << "While parsing section encountered an unknown element:" << n; | ||
91 | } | 97 | } | ||
98 | } | ||||
92 | qSort(m_objects.begin(), m_objects.end(), zLessThan); | 99 | qSort(m_objects.begin(), m_objects.end(), zLessThan); | ||
93 | m_valid = true; | 100 | m_valid = true; | ||
94 | } | 101 | } | ||
95 | 102 | | |||
96 | KReportSectionData::~KReportSectionData() | 103 | KReportSectionData::~KReportSectionData() | ||
97 | { | 104 | { | ||
98 | delete m_set; | 105 | delete m_set; | ||
99 | qDeleteAll(m_objects); | 106 | qDeleteAll(m_objects); | ||
100 | } | 107 | } | ||
101 | 108 | | |||
109 | KReportUnit KReportSectionData::unit() const | ||||
110 | { | ||||
111 | return m_unit; | ||||
112 | } | ||||
113 | | ||||
114 | void KReportSectionData::setUnit(const KReportUnit &u) | ||||
115 | { | ||||
116 | if (m_unit == u) { | ||||
117 | return; | ||||
118 | } | ||||
119 | // convert values | ||||
120 | KReportUnit oldunit = m_unit; | ||||
121 | m_unit = u; | ||||
122 | | ||||
123 | m_height->setValue(KReportUnit::convertFromUnitToUnit(m_height->value().toReal(), oldunit, u), | ||||
124 | KProperty::ValueOption::IgnoreOld); | ||||
125 | m_height->setOption("suffix", u.symbol()); | ||||
126 | } | ||||
127 | | ||||
102 | bool KReportSectionData::zLessThan(KReportItemBase* s1, KReportItemBase* s2) | 128 | bool KReportSectionData::zLessThan(KReportItemBase* s1, KReportItemBase* s2) | ||
103 | { | 129 | { | ||
104 | return s1->z() < s2->z(); | 130 | return s1->z() < s2->z(); | ||
105 | } | 131 | } | ||
106 | 132 | | |||
107 | bool KReportSectionData::xLessThan(KReportItemBase* s1, KReportItemBase* s2) | 133 | bool KReportSectionData::xLessThan(KReportItemBase* s1, KReportItemBase* s2) | ||
108 | { | 134 | { | ||
109 | return s1->position().toPoint().x() < s2->position().toPoint().x(); | 135 | return s1->position().toPoint().x() < s2->position().toPoint().x(); | ||
110 | } | 136 | } | ||
111 | 137 | | |||
112 | void KReportSectionData::createProperties(const QDomElement & elemSource) | 138 | void KReportSectionData::createProperties(const QDomElement & elemSource) | ||
113 | { | 139 | { | ||
114 | m_set = new KPropertySet(this); | 140 | m_set = new KPropertySet(this); | ||
115 | KReportDesigner::addMetaProperties(m_set, | 141 | KReportDesigner::addMetaProperties(m_set, | ||
116 | tr("Section", "Report section"), QLatin1String("kreport-section-element")); | 142 | tr("Section", "Report section"), QLatin1String("kreport-section-element")); | ||
117 | 143 | | |||
118 | m_height = new KProperty("height", KReportUnit(KReportUnit::Type::Centimeter).fromUserValue(2.0), tr("Height")); | 144 | m_height = new KProperty("height", 0.0, tr("Height")); | ||
119 | m_backgroundColor = new KProperty( | 145 | m_backgroundColor = new KProperty( | ||
120 | "background-color", | 146 | "background-color", | ||
121 | KReportUtils::attr(elemSource, "fo:background-color", QColor(Qt::white)), | 147 | KReportUtils::attr(elemSource, QLatin1String("fo:background-color"), QColor(Qt::white)), | ||
122 | tr("Background Color")); | 148 | tr("Background Color")); | ||
123 | m_height->setOption("unit", QLatin1String("cm")); | 149 | m_height->setOption("unit", QLatin1String("cm")); | ||
124 | if (!elemSource.isNull()) | 150 | if (!elemSource.isNull()) { | ||
125 | m_height->setValue(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:height"), QLatin1String("2.0cm")))); | 151 | m_height->setValue(m_unit.convertFromPoint( | ||
152 | KReportUtils::readSizeAttributes( | ||||
153 | elemSource, QSizeF(DEFAULT_SECTION_SIZE_PT, DEFAULT_SECTION_SIZE_PT)) | ||||
154 | .height())); | ||||
155 | } | ||||
126 | 156 | | |||
127 | m_set->addProperty(m_height); | 157 | m_set->addProperty(m_height); | ||
128 | m_set->addProperty(m_backgroundColor); | 158 | m_set->addProperty(m_backgroundColor); | ||
129 | m_set->clearModifiedFlags(); | 159 | m_set->clearModifiedFlags(); | ||
130 | } | 160 | } | ||
131 | 161 | | |||
132 | QString KReportSectionData::name() const | 162 | QString KReportSectionData::name() const | ||
133 | { | 163 | { | ||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Line(s) | 255 | else if (s == QLatin1String("group-footer")) | |||
226 | type = KReportSectionData::Type::GroupFooter; | 256 | type = KReportSectionData::Type::GroupFooter; | ||
227 | else if (s == QLatin1String("detail")) | 257 | else if (s == QLatin1String("detail")) | ||
228 | type = KReportSectionData::Type::Detail; | 258 | type = KReportSectionData::Type::Detail; | ||
229 | else | 259 | else | ||
230 | type = KReportSectionData::Type::None; | 260 | type = KReportSectionData::Type::None; | ||
231 | 261 | | |||
232 | return type; | 262 | return type; | ||
233 | } | 263 | } | ||
264 | | ||||
265 | qreal KReportSectionData::height() const | ||||
266 | { | ||||
267 | return m_unit.convertToPoint(m_height->value().toReal()); | ||||
268 | } | ||||
269 | | ||||
270 | void KReportSectionData::setHeight(qreal ptHeight, KProperty::ValueOptions options) | ||||
271 | { | ||||
272 | m_height->setValue(m_unit.convertFromPoint(ptHeight), options); | ||||
273 | } | ||||
274 | | ||||
275 | void KReportSectionData::setHeight(qreal ptHeight) | ||||
276 | { | ||||
277 | setHeight(ptHeight, KProperty::ValueOptions()); | ||||
278 | } |