Changeset View
Changeset View
Standalone View
Standalone View
src/common/KReportSectionData.cpp
Show All 12 Lines | |||||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | 14 | * Lesser General Public License for more details. | ||
15 | * | 15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | 16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | 17 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "KReportSectionData.h" | 20 | #include "KReportSectionData.h" | ||
21 | #include "KReportDesigner.h" | ||||
21 | #include "KReportDocument.h" | 22 | #include "KReportDocument.h" | ||
23 | #include "KReportItemLine.h" | ||||
22 | #include "KReportPluginInterface.h" | 24 | #include "KReportPluginInterface.h" | ||
23 | #include "KReportPluginManager.h" | 25 | #include "KReportPluginManager.h" | ||
24 | #include "KReportItemLine.h" | 26 | #include "KReportUtils.h" | ||
25 | #include "KReportDesigner.h" | | |||
26 | #include "kreport_debug.h" | 27 | #include "kreport_debug.h" | ||
27 | 28 | | |||
28 | #include <KPropertySet> | 29 | #include <KPropertySet> | ||
29 | 30 | | |||
30 | #include <QDomElement> | 31 | #include <QDomElement> | ||
31 | 32 | | |||
32 | KReportSectionData::KReportSectionData(QObject* parent) | 33 | KReportSectionData::KReportSectionData(QObject *parent) : KReportSectionData(QDomElement(), parent) | ||
33 | : QObject(parent) | | |||
34 | { | 34 | { | ||
35 | createProperties(QDomElement()); | | |||
36 | } | 35 | } | ||
37 | 36 | | |||
38 | KReportSectionData::KReportSectionData(const QDomElement & elemSource, KReportDocument* report) | 37 | KReportSectionData::KReportSectionData(const QDomElement &elemSource, QObject *parent) | ||
39 | : QObject(report) | 38 | : QObject(parent) | ||
40 | { | 39 | { | ||
40 | if (elemSource.isNull()) { | ||||
41 | m_type = Type::None; | ||||
42 | } else { | ||||
41 | setObjectName(elemSource.tagName()); | 43 | setObjectName(elemSource.tagName()); | ||
42 | | ||||
43 | m_type = sectionTypeFromString(elemSource.attribute(QLatin1String("report:section-type"))); | 44 | m_type = sectionTypeFromString(elemSource.attribute(QLatin1String("report:section-type"))); | ||
45 | } | ||||
46 | | ||||
44 | createProperties(elemSource); | 47 | createProperties(elemSource); | ||
48 | | ||||
49 | if (elemSource.isNull()) { | ||||
50 | m_valid = true; | ||||
51 | } else { | ||||
52 | loadXml(elemSource); | ||||
53 | } | ||||
54 | m_set->clearModifiedFlags(); | ||||
55 | } | ||||
56 | | ||||
57 | void KReportSectionData::loadXml(const QDomElement &elemSource) | ||||
58 | { | ||||
45 | if (objectName() != QLatin1String("report:section") || m_type == KReportSectionData::Type::None) { | 59 | if (objectName() != QLatin1String("report:section") || m_type == KReportSectionData::Type::None) { | ||
46 | m_valid = false; | 60 | m_valid = false; | ||
47 | return; | 61 | return; | ||
48 | } | 62 | } | ||
49 | 63 | | |||
50 | m_backgroundColor->setValue(QColor(elemSource.attribute(QLatin1String("fo:background-color")))); | | |||
51 | | ||||
52 | KReportPluginManager* manager = KReportPluginManager::self(); | 64 | KReportPluginManager* manager = KReportPluginManager::self(); | ||
53 | 65 | | |||
54 | QDomNodeList section = elemSource.childNodes(); | 66 | QDomNodeList section = elemSource.childNodes(); | ||
55 | for (int nodeCounter = 0; nodeCounter < section.count(); nodeCounter++) { | 67 | for (int nodeCounter = 0; nodeCounter < section.count(); nodeCounter++) { | ||
56 | QDomElement elemThis = section.item(nodeCounter).toElement(); | 68 | QDomElement elemThis = section.item(nodeCounter).toElement(); | ||
57 | QString n = elemThis.tagName(); | 69 | QString n = elemThis.tagName(); | ||
58 | if (n.startsWith(QLatin1String("report:"))) { | 70 | if (n.startsWith(QLatin1String("report:"))) { | ||
71 | KReportItemBase *krobj = nullptr; | ||||
59 | QString reportItemName = n.mid(qstrlen("report:")); | 72 | QString reportItemName = n.mid(qstrlen("report:")); | ||
60 | if (reportItemName == QLatin1String("line")) { | 73 | if (reportItemName == QLatin1String("line")) { | ||
61 | KReportItemLine * line = new KReportItemLine(elemThis); | 74 | KReportItemLine * line = new KReportItemLine(elemThis); | ||
62 | m_objects.append(line); | 75 | krobj = line; | ||
63 | continue; | 76 | } else { | ||
64 | } | | |||
65 | KReportPluginInterface *plugin = manager->plugin(reportItemName); | 77 | KReportPluginInterface *plugin = manager->plugin(reportItemName); | ||
66 | if (plugin) { | 78 | if (plugin) { | ||
67 | QObject *obj = plugin->createRendererInstance(elemThis); | 79 | QObject *obj = plugin->createRendererInstance(elemThis); | ||
68 | if (obj) { | 80 | if (obj) { | ||
69 | KReportItemBase *krobj = dynamic_cast<KReportItemBase*>(obj); | 81 | krobj = dynamic_cast<KReportItemBase*>(obj); | ||
70 | if (krobj) { | 82 | } | ||
71 | m_objects.append(krobj); | | |||
72 | } | 83 | } | ||
73 | continue; | | |||
74 | } | 84 | } | ||
85 | if (krobj) { | ||||
86 | krobj->propertySet()->clearModifiedFlags(); | ||||
87 | m_objects.append(krobj); | ||||
75 | } | 88 | } | ||
76 | } | 89 | } | ||
77 | kreportWarning() << "While parsing section encountered an unknown element: " << n; | 90 | kreportWarning() << "While parsing section encountered an unknown element: " << n; | ||
78 | } | 91 | } | ||
79 | qSort(m_objects.begin(), m_objects.end(), zLessThan); | 92 | qSort(m_objects.begin(), m_objects.end(), zLessThan); | ||
80 | m_valid = true; | 93 | m_valid = true; | ||
81 | } | 94 | } | ||
82 | 95 | | |||
Show All 15 Lines | |||||
98 | 111 | | |||
99 | void KReportSectionData::createProperties(const QDomElement & elemSource) | 112 | void KReportSectionData::createProperties(const QDomElement & elemSource) | ||
100 | { | 113 | { | ||
101 | m_set = new KPropertySet(this); | 114 | m_set = new KPropertySet(this); | ||
102 | KReportDesigner::addMetaProperties(m_set, | 115 | KReportDesigner::addMetaProperties(m_set, | ||
103 | tr("Section", "Report section"), QLatin1String("kreport-section-element")); | 116 | tr("Section", "Report section"), QLatin1String("kreport-section-element")); | ||
104 | 117 | | |||
105 | m_height = new KProperty("height", KReportUnit(KReportUnit::Type::Centimeter).fromUserValue(2.0), tr("Height")); | 118 | m_height = new KProperty("height", KReportUnit(KReportUnit::Type::Centimeter).fromUserValue(2.0), tr("Height")); | ||
106 | m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color")); | 119 | m_backgroundColor = new KProperty( | ||
120 | "background-color", | ||||
121 | KReportUtils::attr(elemSource, "fo:background-color", QColor(Qt::white)), | ||||
122 | tr("Background Color")); | ||||
107 | m_height->setOption("unit", QLatin1String("cm")); | 123 | m_height->setOption("unit", QLatin1String("cm")); | ||
108 | if (!elemSource.isNull()) | 124 | if (!elemSource.isNull()) | ||
109 | m_height->setValue(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:height"), QLatin1String("2.0cm")))); | 125 | m_height->setValue(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:height"), QLatin1String("2.0cm")))); | ||
110 | 126 | | |||
111 | m_set->addProperty(m_height); | 127 | m_set->addProperty(m_height); | ||
112 | m_set->addProperty(m_backgroundColor); | 128 | m_set->addProperty(m_backgroundColor); | ||
129 | m_set->clearModifiedFlags(); | ||||
113 | } | 130 | } | ||
114 | 131 | | |||
115 | QString KReportSectionData::name() const | 132 | QString KReportSectionData::name() const | ||
116 | { | 133 | { | ||
117 | return (objectName() + QLatin1Char('-') + sectionTypeString(m_type)); | 134 | return (objectName() + QLatin1Char('-') + sectionTypeString(m_type)); | ||
118 | } | 135 | } | ||
119 | 136 | | |||
120 | QString KReportSectionData::sectionTypeString(KReportSectionData::Type type) | 137 | QString KReportSectionData::sectionTypeString(KReportSectionData::Type type) | ||
▲ Show 20 Lines • Show All 96 Lines • Show Last 20 Lines |