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 "KReportDocument.h" | 21 | #include "KReportDocument.h" | ||
22 | #include "KReportPluginInterface.h" | 22 | #include "KReportPluginInterface.h" | ||
23 | #include "KReportPluginManager.h" | 23 | #include "KReportPluginManager.h" | ||
24 | #include "KReportItemLine.h" | 24 | #include "KReportItemLine.h" | ||
25 | #include "KReportDesigner.h" | 25 | #include "KReportDesigner.h" | ||
26 | #include "KReportUtils.h" | ||||
27 | #include "KReportUtils_p.h" | ||||
26 | #include "kreport_debug.h" | 28 | #include "kreport_debug.h" | ||
27 | 29 | | |||
28 | #include <KPropertySet> | 30 | #include <KPropertySet> | ||
29 | 31 | | |||
30 | #include <QDomElement> | 32 | #include <QDomElement> | ||
31 | 33 | | |||
32 | KReportSectionData::KReportSectionData(QObject* parent) | 34 | KReportSectionData::KReportSectionData(QObject* parent) | ||
33 | : QObject(parent) | 35 | : QObject(parent) | ||
36 | , m_unit(DEFAULT_UNIT_TYPE) | ||||
34 | { | 37 | { | ||
35 | createProperties(QDomElement()); | 38 | createProperties(QDomElement()); | ||
36 | } | 39 | } | ||
37 | 40 | | |||
38 | KReportSectionData::KReportSectionData(const QDomElement & elemSource, KReportDocument* report) | 41 | KReportSectionData::KReportSectionData(const QDomElement & elemSource, KReportDocument* report) | ||
39 | : QObject(report) | 42 | : QObject(report) | ||
43 | , m_unit(DEFAULT_UNIT_TYPE) | ||||
40 | { | 44 | { | ||
41 | setObjectName(elemSource.tagName()); | 45 | setObjectName(elemSource.tagName()); | ||
42 | 46 | | |||
43 | m_type = sectionTypeFromString(elemSource.attribute(QLatin1String("report:section-type"))); | 47 | m_type = sectionTypeFromString(KReportUtils::readSectionTypeNameAttribute(elemSource)); | ||
44 | createProperties(elemSource); | 48 | createProperties(elemSource); | ||
45 | if (objectName() != QLatin1String("report:section") || m_type == KReportSectionData::Type::None) { | 49 | if (objectName() != QLatin1String("report:section") || m_type == KReportSectionData::Type::None) { | ||
46 | m_valid = false; | 50 | m_valid = false; | ||
47 | return; | 51 | return; | ||
48 | } | 52 | } | ||
49 | 53 | | |||
50 | m_backgroundColor->setValue(QColor(elemSource.attribute(QLatin1String("fo:background-color")))); | 54 | m_backgroundColor->setValue(QColor(elemSource.attribute(QLatin1String("fo:background-color")))); | ||
51 | 55 | | |||
Show All 29 Lines | |||||
81 | } | 85 | } | ||
82 | 86 | | |||
83 | KReportSectionData::~KReportSectionData() | 87 | KReportSectionData::~KReportSectionData() | ||
84 | { | 88 | { | ||
85 | delete m_set; | 89 | delete m_set; | ||
86 | qDeleteAll(m_objects); | 90 | qDeleteAll(m_objects); | ||
87 | } | 91 | } | ||
88 | 92 | | |||
93 | KReportUnit KReportSectionData::unit() const | ||||
94 | { | ||||
95 | return m_unit; | ||||
96 | } | ||||
97 | | ||||
98 | void KReportSectionData::setUnit(const KReportUnit &u) | ||||
99 | { | ||||
100 | if (m_unit == u) { | ||||
101 | return; | ||||
102 | } | ||||
103 | // convert values | ||||
104 | KReportUnit oldunit = m_unit; | ||||
105 | m_unit = u; | ||||
106 | | ||||
107 | m_height->setValue( | ||||
108 | KReportUnit::convertFromUnitToUnit(m_height->value().toReal(), oldunit, u), | ||||
109 | KProperty::DefaultValueOptions | ||||
110 | & ~KProperty::ValueOptions(KProperty::ValueOption::RememberOld)); | ||||
111 | m_height->setOption("suffix", u.symbol()); | ||||
112 | } | ||||
113 | | ||||
89 | bool KReportSectionData::zLessThan(KReportItemBase* s1, KReportItemBase* s2) | 114 | bool KReportSectionData::zLessThan(KReportItemBase* s1, KReportItemBase* s2) | ||
90 | { | 115 | { | ||
91 | return s1->z() < s2->z(); | 116 | return s1->z() < s2->z(); | ||
92 | } | 117 | } | ||
93 | 118 | | |||
94 | bool KReportSectionData::xLessThan(KReportItemBase* s1, KReportItemBase* s2) | 119 | bool KReportSectionData::xLessThan(KReportItemBase* s1, KReportItemBase* s2) | ||
95 | { | 120 | { | ||
96 | return s1->position().toPoint().x() < s2->position().toPoint().x(); | 121 | return s1->position().toPoint().x() < s2->position().toPoint().x(); | ||
97 | } | 122 | } | ||
98 | 123 | | |||
99 | void KReportSectionData::createProperties(const QDomElement & elemSource) | 124 | void KReportSectionData::createProperties(const QDomElement & elemSource) | ||
100 | { | 125 | { | ||
101 | m_set = new KPropertySet(this); | 126 | m_set = new KPropertySet(this); | ||
102 | KReportDesigner::addMetaProperties(m_set, | 127 | KReportDesigner::addMetaProperties(m_set, | ||
103 | tr("Section", "Report section"), QLatin1String("kreport-section-element")); | 128 | tr("Section", "Report section"), QLatin1String("kreport-section-element")); | ||
104 | 129 | | |||
105 | m_height = new KProperty("height", KReportUnit(KReportUnit::Type::Centimeter).fromUserValue(2.0), tr("Height")); | 130 | m_height = new KProperty("height", 0.0, tr("Height")); | ||
106 | m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color")); | 131 | m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color")); | ||
107 | m_height->setOption("unit", QLatin1String("cm")); | 132 | | ||
108 | if (!elemSource.isNull()) | 133 | m_height->setOption("suffix", QLatin1String("cm")); | ||
109 | m_height->setValue(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:height"), QLatin1String("2.0cm")))); | 134 | if (!elemSource.isNull()) { | ||
135 | m_height->setValue(m_unit.convertFromPoint( | ||||
136 | KReportUtils::readSizeAttributes( | ||||
137 | elemSource, QSizeF(DEFAULT_SECTION_SIZE_PT, DEFAULT_SECTION_SIZE_PT)) | ||||
138 | .height())); | ||||
139 | } | ||||
110 | 140 | | |||
111 | m_set->addProperty(m_height); | 141 | m_set->addProperty(m_height); | ||
112 | m_set->addProperty(m_backgroundColor); | 142 | m_set->addProperty(m_backgroundColor); | ||
113 | } | 143 | } | ||
114 | 144 | | |||
115 | QString KReportSectionData::name() const | 145 | QString KReportSectionData::name() const | ||
116 | { | 146 | { | ||
117 | return (objectName() + QLatin1Char('-') + sectionTypeString(m_type)); | 147 | return (objectName() + QLatin1Char('-') + sectionTypeString(m_type)); | ||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | 238 | else if (s == QLatin1String("group-footer")) | |||
209 | type = KReportSectionData::Type::GroupFooter; | 239 | type = KReportSectionData::Type::GroupFooter; | ||
210 | else if (s == QLatin1String("detail")) | 240 | else if (s == QLatin1String("detail")) | ||
211 | type = KReportSectionData::Type::Detail; | 241 | type = KReportSectionData::Type::Detail; | ||
212 | else | 242 | else | ||
213 | type = KReportSectionData::Type::None; | 243 | type = KReportSectionData::Type::None; | ||
214 | 244 | | |||
215 | return type; | 245 | return type; | ||
216 | } | 246 | } | ||
247 | | ||||
248 | qreal KReportSectionData::height() const | ||||
249 | { | ||||
250 | return m_unit.convertToPoint(m_height->value().toReal()); | ||||
251 | } | ||||
252 | | ||||
253 | void KReportSectionData::setHeight(qreal ptHeight) | ||||
254 | { | ||||
255 | m_height->setValue(m_unit.convertFromPoint(ptHeight)); | ||||
256 | } |