diff --git a/src/common/KReportSectionData.h b/src/common/KReportSectionData.h --- a/src/common/KReportSectionData.h +++ b/src/common/KReportSectionData.h @@ -65,8 +65,11 @@ }; explicit KReportSectionData(QObject* parent = nullptr); - KReportSectionData(const QDomElement &, KReportDocument* report); + + explicit KReportSectionData(const QDomElement &elemSource, QObject* parent = nullptr); + ~KReportSectionData() override; + KPropertySet* propertySet() const { return m_set; } @@ -102,6 +105,7 @@ private: void createProperties(const QDomElement & elemSource); + void loadXml(const QDomElement &elemSource); QList m_objects; diff --git a/src/common/KReportSectionData.cpp b/src/common/KReportSectionData.cpp --- a/src/common/KReportSectionData.cpp +++ b/src/common/KReportSectionData.cpp @@ -18,61 +18,74 @@ */ #include "KReportSectionData.h" +#include "KReportDesigner.h" #include "KReportDocument.h" +#include "KReportItemLine.h" #include "KReportPluginInterface.h" #include "KReportPluginManager.h" -#include "KReportItemLine.h" -#include "KReportDesigner.h" +#include "KReportUtils.h" #include "kreport_debug.h" #include #include -KReportSectionData::KReportSectionData(QObject* parent) - : QObject(parent) +KReportSectionData::KReportSectionData(QObject *parent) : KReportSectionData(QDomElement(), parent) { - createProperties(QDomElement()); } -KReportSectionData::KReportSectionData(const QDomElement & elemSource, KReportDocument* report) - : QObject(report) +KReportSectionData::KReportSectionData(const QDomElement &elemSource, QObject *parent) + : QObject(parent) { - setObjectName(elemSource.tagName()); + if (elemSource.isNull()) { + m_type = Type::None; + } else { + setObjectName(elemSource.tagName()); + m_type = sectionTypeFromString(elemSource.attribute(QLatin1String("report:section-type"))); + } - m_type = sectionTypeFromString(elemSource.attribute(QLatin1String("report:section-type"))); createProperties(elemSource); + + if (elemSource.isNull()) { + m_valid = true; + } else { + loadXml(elemSource); + } + m_set->clearModifiedFlags(); +} + +void KReportSectionData::loadXml(const QDomElement &elemSource) +{ if (objectName() != QLatin1String("report:section") || m_type == KReportSectionData::Type::None) { m_valid = false; return; } - m_backgroundColor->setValue(QColor(elemSource.attribute(QLatin1String("fo:background-color")))); - KReportPluginManager* manager = KReportPluginManager::self(); QDomNodeList section = elemSource.childNodes(); for (int nodeCounter = 0; nodeCounter < section.count(); nodeCounter++) { QDomElement elemThis = section.item(nodeCounter).toElement(); QString n = elemThis.tagName(); if (n.startsWith(QLatin1String("report:"))) { + KReportItemBase *krobj = nullptr; QString reportItemName = n.mid(qstrlen("report:")); if (reportItemName == QLatin1String("line")) { KReportItemLine * line = new KReportItemLine(elemThis); - m_objects.append(line); - continue; - } - KReportPluginInterface *plugin = manager->plugin(reportItemName); - if (plugin) { - QObject *obj = plugin->createRendererInstance(elemThis); - if (obj) { - KReportItemBase *krobj = dynamic_cast(obj); - if (krobj) { - m_objects.append(krobj); + krobj = line; + } else { + KReportPluginInterface *plugin = manager->plugin(reportItemName); + if (plugin) { + QObject *obj = plugin->createRendererInstance(elemThis); + if (obj) { + krobj = dynamic_cast(obj); } - continue; } } + if (krobj) { + krobj->propertySet()->clearModifiedFlags(); + m_objects.append(krobj); + } } kreportWarning() << "While parsing section encountered an unknown element: " << n; } @@ -103,13 +116,17 @@ tr("Section", "Report section"), QLatin1String("kreport-section-element")); m_height = new KProperty("height", KReportUnit(KReportUnit::Type::Centimeter).fromUserValue(2.0), tr("Height")); - m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color")); + m_backgroundColor = new KProperty( + "background-color", + KReportUtils::attr(elemSource, "fo:background-color", QColor(Qt::white)), + tr("Background Color")); m_height->setOption("unit", QLatin1String("cm")); if (!elemSource.isNull()) m_height->setValue(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:height"), QLatin1String("2.0cm")))); m_set->addProperty(m_height); m_set->addProperty(m_backgroundColor); + m_set->clearModifiedFlags(); } QString KReportSectionData::name() const diff --git a/src/wrtembed/KReportDesigner.h b/src/wrtembed/KReportDesigner.h --- a/src/wrtembed/KReportDesigner.h +++ b/src/wrtembed/KReportDesigner.h @@ -317,11 +317,6 @@ */ void setDetail(KReportDesignerSectionDetail *rsd); - /** - @brief Deletes the detail section - */ - void deleteDetail(); - void resizeEvent(QResizeEvent * event) override; //Properties diff --git a/src/wrtembed/KReportDesigner.cpp b/src/wrtembed/KReportDesigner.cpp --- a/src/wrtembed/KReportDesigner.cpp +++ b/src/wrtembed/KReportDesigner.cpp @@ -112,13 +112,21 @@ class Q_DECL_HIDDEN KReportDesigner::Private { public: - Private(){} + explicit Private(KReportDesigner *designer); ~Private() { delete dataSource; } + void init(const QDomElement *xml); + +#ifdef KREPORT_SCRIPTING + void updateScripts(); +#endif + + KReportDesigner * const q; + QGridLayout *grid; KReportRuler *hruler; KReportZoomHandler zoomHandler; @@ -188,68 +196,72 @@ #ifdef KREPORT_SCRIPTING KReportScriptSource *scriptSource = nullptr; #endif + +private: + void loadXml(const QDomElement &data); }; -KReportDesigner::KReportDesigner(QWidget * parent) - : QWidget(parent), d(new Private()) +KReportDesigner::Private::Private(KReportDesigner *designer) : q(designer) +{ +} + +// (must be init() instead of ctor because we are indirectly depending on initialized KReportDesigner::d here) +void KReportDesigner::Private::init(const QDomElement *xml) { KReportPluginManager::self(); // this loads icons early enough - createProperties(); - createActions(); + q->createProperties(); + q->createActions(); - d->grid = new QGridLayout(this); - d->grid->setSpacing(0); - d->grid->setMargin(0); - d->grid->setColumnStretch(1, 1); - d->grid->setRowStretch(1, 1); - d->grid->setSizeConstraint(QLayout::SetFixedSize); + grid = new QGridLayout(q); + grid->setSpacing(0); + grid->setMargin(0); + grid->setColumnStretch(1, 1); + grid->setRowStretch(1, 1); + grid->setSizeConstraint(QLayout::SetFixedSize); - d->vboxlayout = new QVBoxLayout(); - d->vboxlayout->setSpacing(0); - d->vboxlayout->setMargin(0); - d->vboxlayout->setSizeConstraint(QLayout::SetFixedSize); + vboxlayout = new QVBoxLayout(); + vboxlayout->setSpacing(0); + vboxlayout->setMargin(0); + vboxlayout->setSizeConstraint(QLayout::SetFixedSize); //Create nice rulers - d->hruler = new KReportRuler(this, Qt::Horizontal, d->zoomHandler); + hruler = new KReportRuler(nullptr, Qt::Horizontal, zoomHandler); - d->pageButton = new KReportPropertiesButton(this); + pageButton = new KReportPropertiesButton; - d->grid->addWidget(d->pageButton, 0, 0); - d->grid->addWidget(d->hruler, 0, 1); - d->grid->addLayout(d->vboxlayout, 1, 0, 1, 2); + grid->addWidget(pageButton, 0, 0); + grid->addWidget(hruler, 0, 1); + grid->addLayout(vboxlayout, 1, 0, 1, 2); - d->pageButton->setMaximumSize(QSize(19, 22)); - d->pageButton->setMinimumSize(QSize(19, 22)); + pageButton->setMaximumSize(QSize(19, 22)); + pageButton->setMinimumSize(QSize(19, 22)); - d->detail = new KReportDesignerSectionDetail(this); - d->vboxlayout->insertWidget(0, d->detail); - - setLayout(d->grid); - - connect(d->pageButton, SIGNAL(released()), this, SLOT(slotPageButton_Pressed())); - emit pagePropertyChanged(d->set); + if (!xml) { + detail = new KReportDesignerSectionDetail(q); + vboxlayout->insertWidget(0, detail); + } - connect(&d->set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), - this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); + connect(pageButton, &KReportPropertiesButton::released, + q, &KReportDesigner::slotPageButton_Pressed); + emit q->pagePropertyChanged(set); - changeSet(&d->set); -} + connect(&set, &KPropertySet::propertyChanged, q, &KReportDesigner::slotPropertyChanged); -KReportDesigner::~KReportDesigner() -{ - delete d; + if (xml) { + loadXml(*xml); + } + set.clearModifiedFlags(); + q->changeSet(&set); } -KReportDesigner::KReportDesigner(QWidget *parent, const QDomElement &data) - : KReportDesigner(parent) +void KReportDesigner::Private::loadXml(const QDomElement &data) { if (data.tagName() != QLatin1String("report:content")) { // arg we got an xml file but not one i know of kreportWarning() << "root element was not "; } //kreportDebug() << data.text(); - deleteDetail(); QDomNodeList nlist = data.childNodes(); QDomNode it; @@ -261,52 +273,52 @@ QString n = it.nodeName().toLower(); //kreportDebug() << n; if (n == QLatin1String("report:title")) { - setReportTitle(it.firstChild().nodeValue()); + q->setReportTitle(it.firstChild().nodeValue()); #ifdef KREPORT_SCRIPTING } else if (n == QLatin1String("report:script")) { - d->originalInterpreter = it.toElement().attribute(QLatin1String("report:script-interpreter"), QLatin1String("javascript")); - if (d->originalInterpreter.isEmpty()) { - d->originalInterpreter = QLatin1String("javascript"); + originalInterpreter = it.toElement().attribute(QLatin1String("report:script-interpreter"), QLatin1String("javascript")); + if (originalInterpreter.isEmpty()) { + originalInterpreter = QLatin1String("javascript"); } - d->originalScript = it.firstChild().nodeValue(); - d->script->setValue(d->originalScript); + originalScript = it.firstChild().nodeValue(); + script->setValue(originalScript); - if (d->originalInterpreter != QLatin1String("javascript") && d->originalInterpreter != QLatin1String("qtscript")) { + if (originalInterpreter != QLatin1String("javascript") && originalInterpreter != QLatin1String("qtscript")) { QString msg = tr("This report contains scripts of type \"%1\". " "Only scripts written in JavaScript language are " "supported. To prevent losing the scripts, their type " "and content will not be changed unless you change these scripts." - ).arg(d->originalInterpreter); - QMessageBox::warning(this, tr("Unsupported Script Type"), msg); + ).arg(originalInterpreter); + QMessageBox::warning(q, tr("Unsupported Script Type"), msg); } #endif } else if (n == QLatin1String("report:grid")) { - d->showGrid->setValue(it.toElement().attribute(QLatin1String("report:grid-visible"), QString::number(1)).toInt() != 0); - d->gridSnap->setValue(it.toElement().attribute(QLatin1String("report:grid-snap"), QString::number(1)).toInt() != 0); - d->gridDivisions->setValue(it.toElement().attribute(QLatin1String("report:grid-divisions"), QString::number(4)).toInt()); - d->unit->setValue(it.toElement().attribute(QLatin1String("report:page-unit"), QLatin1String("cm"))); + showGrid->setValue(it.toElement().attribute(QLatin1String("report:grid-visible"), QString::number(1)).toInt() != 0); + gridSnap->setValue(it.toElement().attribute(QLatin1String("report:grid-snap"), QString::number(1)).toInt() != 0); + gridDivisions->setValue(it.toElement().attribute(QLatin1String("report:grid-divisions"), QString::number(4)).toInt()); + unit->setValue(it.toElement().attribute(QLatin1String("report:page-unit"), QLatin1String("cm"))); } //! @todo Load page options else if (n == QLatin1String("report:page-style")) { QString pagetype = it.firstChild().nodeValue(); if (pagetype == QLatin1String("predefined")) { - d->pageSize->setValue(it.toElement().attribute(QLatin1String("report:page-size"), QLatin1String("A4"))); + pageSize->setValue(it.toElement().attribute(QLatin1String("report:page-size"), QLatin1String("A4"))); } else if (pagetype == QLatin1String("custom")) { - d->pageSize->setValue(QLatin1String("Custom")); - d->customPageSize->setValue(QSizeF(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-width"), QLatin1String(""))), + pageSize->setValue(QLatin1String("Custom")); + customPageSize->setValue(QSizeF(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-width"), QLatin1String(""))), KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-height"), QLatin1String(""))))); } else if (pagetype == QLatin1String("label")) { //! @todo } - d->rightMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-right"), QLatin1String("1.0cm")))); - d->leftMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-left"), QLatin1String("1.0cm")))); - d->topMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-top"), QLatin1String("1.0cm")))); - d->bottomMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-bottom"), QLatin1String("1.0cm")))); + rightMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-right"), QLatin1String("1.0cm")))); + leftMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-left"), QLatin1String("1.0cm")))); + topMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-top"), QLatin1String("1.0cm")))); + bottomMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-bottom"), QLatin1String("1.0cm")))); - d->orientation->setValue(it.toElement().attribute(QLatin1String("report:print-orientation"), QLatin1String("portrait"))); + orientation->setValue(it.toElement().attribute(QLatin1String("report:print-orientation"), QLatin1String("portrait"))); } else if (n == QLatin1String("report:body")) { QDomNodeList sectionlist = it.childNodes(); @@ -319,14 +331,14 @@ //kreportDebug() << sn; if (sn == QLatin1String("report:section")) { QString sectiontype = sec.toElement().attribute(QLatin1String("report:section-type")); - if (section(KReportSectionData::sectionTypeFromString(sectiontype)) == nullptr) { - insertSection(KReportSectionData::sectionTypeFromString(sectiontype)); - section(KReportSectionData::sectionTypeFromString(sectiontype))->initFromXML(sec); + if (q->section(KReportSectionData::sectionTypeFromString(sectiontype)) == nullptr) { + q->insertSection(KReportSectionData::sectionTypeFromString(sectiontype)); + q->section(KReportSectionData::sectionTypeFromString(sectiontype))->initFromXML(sec); } } else if (sn == QLatin1String("report:detail")) { - KReportDesignerSectionDetail * rsd = new KReportDesignerSectionDetail(this); + KReportDesignerSectionDetail * rsd = new KReportDesignerSectionDetail(q); rsd->initFromXML(&sec); - setDetail(rsd); + q->setDetail(rsd); } } else { kreportWarning() << "Encountered an unknown Element: " << n; @@ -337,10 +349,40 @@ kreportWarning() << "Encountered a child node of root that is not an Element"; } } - this->slotPageButton_Pressed(); - emit reportDataChanged(); - slotPropertyChanged(d->set, *d->unit); // set unit for all items - setModified(false); + updateScripts(); + emit q->reportDataChanged(); + q->slotPropertyChanged(set, *unit); // set unit for all items + q->setModified(false); +} + +#ifdef KREPORT_SCRIPTING +void KReportDesigner::Private::updateScripts() +{ + if (scriptSource) { + QStringList sl = scriptSource->scriptList(); + sl.prepend(QString()); // prepend "none" + script->setListData(sl, sl); + } +} +#endif + +// ---- + +KReportDesigner::KReportDesigner(QWidget * parent) + : QWidget(parent), d(new Private(this)) +{ + d->init(nullptr); +} + +KReportDesigner::KReportDesigner(QWidget *parent, const QDomElement &data) + : QWidget(parent), d(new Private(this)) +{ + d->init(&data); +} + +KReportDesigner::~KReportDesigner() +{ + delete d; } ///The saving code @@ -728,8 +770,8 @@ KPropertyListData *listData = new KPropertyListData(KReportPageSize::pageFormatKeys(), KReportPageSize::pageFormatNames()); QVariant defaultKey = KReportPageSize::pageSizeKey(KReportPageSize::defaultSize()); - d->pageSize = new KProperty("page-size", listData, defaultKey, tr("Page Size")); - + d->pageSize = new KProperty("page-size", listData, defaultKey, tr("Page Size")); + d->customPageSize = new KProperty("custom-page-size", QSizeF(KReportUnit(KReportUnit::Type::Centimeter).fromUserValue(10), KReportUnit(KReportUnit::Type::Centimeter).fromUserValue(10)), tr("Custom Page Size"), tr("Custom Page Size"), KProperty::SizeF); @@ -777,7 +819,6 @@ d->script = new KProperty("script", new KPropertyListData, QVariant(), tr("Object Script")); d->set.addProperty(d->script); #endif - } /** @@ -803,11 +844,7 @@ void KReportDesigner::slotPageButton_Pressed() { #ifdef KREPORT_SCRIPTING - if (d->scriptSource) { - QStringList sl = d->scriptSource->scriptList(); - sl.prepend(QString()); - d->script->setListData(sl, sl); - } + d->updateScripts(); changeSet(&d->set); #endif } @@ -857,23 +894,23 @@ { QSize pageSizePx; int pageWidth; - + if (d->set.property("page-size").value().toString() == QLatin1String("Custom")) { KReportUnit unit = pageUnit(); - + QSizeF customSize = d->set.property("custom-page-size").value().toSizeF(); QPageLayout layout(QPageSize(customSize, QPageSize::Point, QString(), QPageSize::ExactMatch), d->set.property("print-orientation").value().toString() == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape, QMarginsF(0,0,0,0)); - + pageSizePx = layout.fullRectPixels(KReportPrivate::dpiX()).size(); } else { QPageLayout layout = QPageLayout( QPageSize(KReportPageSize::pageSize(d->set.property("page-size").value().toString())), d->set.property("print-orientation").value().toString() == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape, QMarginsF(0,0,0,0)); pageSizePx = layout.fullRectPixels(KReportPrivate::dpiX()).size(); } - + pageWidth = pageSizePx.width(); pageWidth = pageWidth - POINT_TO_INCH(d->set.property("margin-left").value().toDouble()) * KReportPrivate::dpiX(); @@ -902,11 +939,6 @@ d->vboxlayout->insertWidget(idx, d->detail); } } -void KReportDesigner::deleteDetail() -{ - delete d->detail; - d->detail = nullptr; -} KReportUnit KReportDesigner::pageUnit() const { @@ -1021,6 +1053,7 @@ baseReportItem->setUnit(pageUnit()); KPropertySet *set = baseReportItem->propertySet(); KReportDesigner::addMetaProperties(set, classString, iconName); + set->clearModifiedFlags(); changeSet(set); if (v && v->designer()) { v->designer()->setModified(true); @@ -1178,6 +1211,7 @@ } else { new_obj->setPosition(KReportItemBase::positionFromScene(QPointF(0, 0))); } + new_obj->propertySet()->clearModifiedFlags(); changeSet(new_obj->propertySet()); } QGraphicsItem *pasted_ent = dynamic_cast(ent); diff --git a/src/wrtembed/KReportDesignerSection.cpp b/src/wrtembed/KReportDesignerSection.cpp --- a/src/wrtembed/KReportDesignerSection.cpp +++ b/src/wrtembed/KReportDesignerSection.cpp @@ -177,13 +177,17 @@ if (h < 1) h = 1; h = d->scene->gridPoint(QPointF(0, h)).y(); - d->sectionData->m_height->setValue(INCH_TO_POINT(h/d->dpiY)); + d->sectionData->m_height->setValue(INCH_TO_POINT(h / d->dpiY), + delta == 0 ? KProperty::ValueOption::IgnoreOld + : KProperty::ValueOption::None); d->sectionRuler->setRulerLength(h); d->scene->setSceneRect(0, 0, d->scene->width(), h); d->sceneView->resizeContents(QSize(d->scene->width(), h)); - d->reportDesigner->setModified(true); + if (delta != 0) { + d->reportDesigner->setModified(true); + } } void KReportDesignerSection::buildXML(QDomDocument *doc, QDomElement *section) @@ -214,35 +218,40 @@ slotResizeBarDragged(0); d->sectionData->m_backgroundColor->setValue(QColor(section.toElement().attribute(QLatin1String("fo:background-color"), QLatin1String("#ffffff")))); + d->sectionData->propertySet()->clearModifiedFlags(); + KReportPluginManager* manager = KReportPluginManager::self(); for (int i = 0; i < nl.count(); ++i) { node = nl.item(i); n = node.nodeName(); if (n.startsWith(QLatin1String("report:"))) { //Load objects //report:line is a special case as it is not a plugin + QObject *obj = nullptr; + KReportPluginInterface *plugin = nullptr; QString reportItemName = n.mid(qstrlen("report:")); if (reportItemName == QLatin1String("line")) { - (new KReportDesignerItemLine(node, d->sceneView->designer(), d->scene))->setVisible(true); - continue; + obj = new KReportDesignerItemLine(node, d->sceneView->designer(), d->scene); + } else { + plugin = manager->plugin(reportItemName); + if (plugin) { + obj = plugin->createDesignerInstance(node, d->reportDesigner, d->scene); + } } - KReportPluginManager* manager = KReportPluginManager::self(); - KReportPluginInterface *plugin = manager->plugin(reportItemName); - if (plugin) { - QObject *obj = plugin->createDesignerInstance(node, d->reportDesigner, d->scene); - if (obj) { - KReportDesignerItemRectBase *entity = dynamic_cast(obj); - if (entity) { - entity->setVisible(true); - } - KReportItemBase *item = dynamic_cast(obj); - if (item) { - item->setUnit(d->reportDesigner->pageUnit()); + if (obj) { + KReportDesignerItemRectBase *entity = dynamic_cast(obj); + if (entity) { + entity->setVisible(true); + } + KReportItemBase *item = dynamic_cast(obj); + if (item) { + item->setUnit(d->reportDesigner->pageUnit()); + if (plugin) { KReportDesigner::addMetaProperties(item->propertySet(), plugin->metaData()->name(), plugin->metaData()->iconName()); } - continue; + item->propertySet()->clearModifiedFlags(); } } }