diff --git a/autotests/ElementsTest.cpp b/autotests/ElementsTest.cpp index 95918777..27bda4f8 100644 --- a/autotests/ElementsTest.cpp +++ b/autotests/ElementsTest.cpp @@ -1,231 +1,231 @@ /* This file is part of the KDE project * Copyright (C) 2015 Jarosław Staniek * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "ElementsTest.h" #include "KReportTestUtils.h" #include #include #include #include #include QTEST_MAIN(ElementsTest) Q_DECLARE_METATYPE(KReportElement) Q_DECLARE_METATYPE(KReportLabelElement) Q_DECLARE_METATYPE(KReportSection) void ElementsTest::testElements() { KReportElement e; QCOMPARE(e, e); QCOMPARE(e.name(), ""); QCOMPARE(e.rect(), QRectF()); QCOMPARE(e.z(), 0.0); QCOMPARE(e.backgroundColor(), QColor()); QCOMPARE(e.foregroundColor(), QColor()); QCOMPARE(e.backgroundOpacity(), 0.0); e.setZ(10.3); QCOMPARE(e.z(), 10.3); e.setName("element1"); QCOMPARE(e.name(), "element1"); e.setRect(QRect(1, 2, 3, 4)); QCOMPARE(e.rect(), QRectF(1, 2, 3, 4)); e.setBackgroundColor(Qt::red); QCOMPARE(e.backgroundColor(), QColor(Qt::red)); e.setForegroundColor(Qt::white); QCOMPARE(e.foregroundColor(), QColor(Qt::white)); QCOMPARE(e, e); KReportElement e2 = e; e.setName(""); QCOMPARE(e, e2); QCOMPARE(e.name(), e2.name()); QCOMPARE(e.rect(), e2.rect()); e2.setName("element2"); KReportLabelElement lbl1(e2); QCOMPARE(e2.name(), lbl1.name()); e2.setName(""); QCOMPARE(lbl1.name(), "element2"); lbl1.setText("label1"); QCOMPARE(lbl1.text(), "label1"); e = lbl1; KReportLabelElement lbl2(e); // e points to lbl1 so shares lbl1 in fact QCOMPARE(lbl1, lbl2); QCOMPARE(KReportLabelElement(e), lbl2); lbl2 = e; QCOMPARE(KReportLabelElement(e), lbl2); lbl1 = KReportLabelElement(); QCOMPARE(lbl1.alignment(), Qt::AlignLeft | Qt::AlignVCenter); // defaults lbl1.setAlignment(Qt::AlignHCenter|Qt::AlignBottom); QCOMPARE(lbl1.alignment(), Qt::AlignHCenter|Qt::AlignBottom); lbl1.setBackgroundOpacity(20.0); QCOMPARE(lbl1.backgroundOpacity(), 1.0); // 1.0 is max lbl1.setBackgroundOpacity(-100.10); QCOMPARE(lbl1.backgroundOpacity(), 0.0); // 0.0 is min lbl1.setFont(QApplication::font()); QFont f = lbl1.font(); QCOMPARE(f, QApplication::font()); QCOMPARE(lbl1.borderStyle().weight(), 0.0); // default QCOMPARE(lbl1.borderStyle().penStyle(), Qt::NoPen); // default QCOMPARE(lbl1.borderStyle().color(), QColor()); // default KReportLineStyle lineStyle; lineStyle.setWeight(2.0); lineStyle.setPenStyle(Qt::DashLine); lineStyle.setColor(QColor("brown")); lbl1.setBorderStyle(lineStyle); QCOMPARE(lbl1.borderStyle(), lineStyle); lineStyle.setColor(Qt::yellow); QCOMPARE(lbl1.borderStyle().color(), QColor(Qt::yellow)); // shared } void ElementsTest::testElementCloning() { KReportLabelElement lbl1("text1"), lbl2; lbl1.setName("label1"); lbl2 = lbl1.clone(); QVERIFY(lbl1 != lbl2); // a deep copy, not equal lbl1.setText(""); QCOMPARE(lbl1.name(), lbl2.name()); QCOMPARE(lbl1.text(), ""); QCOMPARE(lbl2.text(), "text1"); // this is another copy, not affected by lbl1.setText("") lbl1.setName("label1"); lbl1.setText("text1"); KReportElement e1 = lbl1; KReportElement e2 = e1.clone(); QVERIFY2(e1 != e2, "Cloned element not equal to the original"); QCOMPARE(e1.name(), "label1"); QCOMPARE(e2.name(), "label1"); QVERIFY2(KReportLabelElement(e2) != lbl1, "Reference to original not equal to a clone"); QVERIFY2(KReportLabelElement(e2) != KReportLabelElement(e1), "Reference to original not equal to reference to a clone"); lbl1.setName(""); lbl1.setText(""); QCOMPARE(e1.name(), ""); // shared with lbl1 QCOMPARE(e2.name(), "label1"); // shared with lbl1's clone QCOMPARE(KReportLabelElement(e1).text(), ""); QCOMPARE(KReportLabelElement(e2).text(), "text1"); KReportLabelElement lbl3 = e2; // e2 points to a lbl1's clone with name=label1, text=text1, so: KReportLabelElement(e2).setText("text2"); // This affect e2 and lbl2 because // KReportLabelElement(e2) upcasts it to the KReportLabelElement type QCOMPARE(KReportLabelElement(e2).text(), "text2"); QCOMPARE(lbl3.text(), "text2"); QCOMPARE(lbl1.text(), ""); // lbl1 unaffected } void ElementsTest::testSections() { // types KReportSection sec1; - QCOMPARE(sec1.type(), KReportSection::InvalidType); - QCOMPARE(KReportSection(sec1).type(), KReportSection::InvalidType); - sec1.setType(KReportSection::PageFooterFirst); + QCOMPARE(sec1.type(), KReportSection::Type::Invalid); + QCOMPARE(KReportSection(sec1).type(), KReportSection::Type::Invalid); + sec1.setType(KReportSection::Type::PageFooterFirst); KReportSection sec2(sec1); QCOMPARE(sec1.type(), sec2.type()); QCOMPARE(sec1, sec2); - sec1.setType(KReportSection::PageFooterEven); + sec1.setType(KReportSection::Type::PageFooterEven); QCOMPARE(sec1.type(), sec2.type()); // shared QCOMPARE(sec1, sec2); // shared // height KReportSection::setDefaultHeight(-1); // sanity: reset QCOMPARE(sec1.height(), KReportSection::defaultHeight()); // initially: default height KReportSection::setDefaultHeight(CM_TO_POINT(10.0)); // sanity: reset QCOMPARE(KReportSection::defaultHeight(), CM_TO_POINT(10.0)); QCOMPARE(sec1.height(), KReportSection::defaultHeight()); // still default height KReportSection::setDefaultHeight(-1); // reset QCOMPARE(sec1.height(), KReportSection::defaultHeight()); // still default height sec1.setHeight(CM_TO_POINT(7.0)); QCOMPARE(sec1.height(), CM_TO_POINT(7.0)); // custom height // background color KReportSection::setDefaultBackgroundColor(QColor()); // sanity: reset QCOMPARE(sec1.backgroundColor(), KReportSection::defaultBackgroundColor()); // initially: default color KReportSection::setDefaultBackgroundColor(Qt::yellow); // sanity: reset QCOMPARE(KReportSection::defaultBackgroundColor(), QColor(Qt::yellow)); QCOMPARE(sec1.backgroundColor(), KReportSection::defaultBackgroundColor()); // still default color KReportSection::setDefaultBackgroundColor(QColor()); // reset QCOMPARE(sec1.backgroundColor(), KReportSection::defaultBackgroundColor()); // still default color sec1.setBackgroundColor(Qt::lightGray); QCOMPARE(sec1.backgroundColor(), QColor(Qt::lightGray)); // custom color // elements QVERIFY2(sec1.elements().isEmpty(), "Initially section has no elements inside"); QVERIFY2(sec2.elements().isEmpty(), "Initially section has no elements inside"); KReportLabelElement lbl1("text1"); QVERIFY(sec1.addElement(lbl1)); QCOMPARE(sec1.elements().count(), 1); QCOMPARE(sec2.elements().count(), 1); QCOMPARE(sec1.elements().first(), sec1.elements().last()); QCOMPARE(KReportLabelElement(sec1.elements().first()), lbl1); QCOMPARE(KReportLabelElement(sec1.elements().at(0)), lbl1); QVERIFY2(!sec1.addElement(lbl1), "Adding the same element twice isn't possible"); QCOMPARE(sec1.elements().count(), 1); KReportLabelElement lbl2("text2"); QVERIFY2(!sec1.removeElement(lbl2), "Removing not added element isn't possible"); QCOMPARE(sec1.elements().count(), 1); QVERIFY(sec1.removeElement(lbl1)); QCOMPARE(sec1.elements().count(), 0); QCOMPARE(sec2.elements().count(), 0); lbl2 = lbl1.clone(); QVERIFY(sec1.addElement(lbl1)); QVERIFY(sec1.addElement(lbl2)); QCOMPARE(sec1.elements().count(), 2); QCOMPARE(sec2.elements().count(), 2); // insert sec1 = KReportSection(); QVERIFY(sec1.insertElement(0, lbl1)); QVERIFY2(!sec1.insertElement(0, lbl1), "Cannot insert the same element twice"); QVERIFY2(!sec1.insertElement(2, lbl2), "Cannot insert element at position 2"); QVERIFY2(!sec1.insertElement(-1, lbl2), "Cannot insert element at position -1"); QVERIFY(sec1.insertElement(0, lbl2)); // indexOf QCOMPARE(sec1.elements().indexOf(lbl1), 1); QCOMPARE(sec1.elements().indexOf(lbl2), 0); QCOMPARE(KReportLabelElement(sec1.elements().last()), lbl1); // removeAt QVERIFY2(!sec1.removeElementAt(2), "Cannot remove element at position 2"); QVERIFY2(!sec1.removeElementAt(-1), "Cannot remove element at position -1"); QVERIFY(sec1.removeElementAt(1)); QVERIFY(sec1.removeElementAt(0)); // cloning sections sec1 = KReportSection(); QVERIFY(sec1.addElement(lbl1)); QVERIFY(sec1.addElement(lbl2)); sec2 = sec1.clone(); QCOMPARE(sec1.elements().count(), sec2.elements().count()); QVERIFY2(sec1.elements() != sec2.elements(), "Cloned sections have different sets of elements"); QVERIFY2(sec1 != sec2, "Cloned section not equal to the original"); QVERIFY2(sec1.elements().first() != sec2.elements().first(), "Elements of cloned sections have different sets of elements"); } diff --git a/autotests/format/FormatTest.cpp b/autotests/format/FormatTest.cpp index 805b84f0..a407b0e0 100644 --- a/autotests/format/FormatTest.cpp +++ b/autotests/format/FormatTest.cpp @@ -1,218 +1,218 @@ /* This file is part of the KDE project * Copyright (C) 2012 Dag Andersen * Copyright (C) 2015 Jarosław Staniek * * QFUZZYCOMPARE() from marble/tests/TestUtils.h: * Copyright (C) 2013 Dennis Nienhüser * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "FormatTest.h" #include "KReportTestUtils.h" #include "KReportPreRenderer.h" #include "KReportDesigner.h" #include "KReportLabelElement.h" #include "KReportDocument.h" #include "KReportDesignerSectionDetail.h" #include "KReportSection.h" #include "KReportDesignerItemLine.h" #include "KReportItemLine.h" #include "KReportDesignerItemRectBase.h" #include "KReportUnit.h" #include #include #include #include #include #include #include #include QTEST_MAIN(FormatTest) static bool openDesignFile(KReportDesign *design, QString *errorMessage) { const QString dir(QFile::decodeName(FILES_DATA_DIR)); const QString fname(QLatin1String(QTest::currentTestFunction()) + QLatin1String(".kreport")); QFile file(dir + QDir::separator() + fname); bool ok = file.open(QFile::ReadOnly | QFile::Text); if (!ok) { *errorMessage = QString::fromLatin1("Could not open file %1: ").arg(file.fileName()) + file.errorString(); return false; } QString content = file.readAll(); if (file.error() != QFileDevice::NoError) { *errorMessage = QString::fromLatin1("Error reading file %1: ").arg(file.fileName()) + file.errorString(); return false; } KReportDesignReadingStatus status; if (!design->setContent(content, &status)) { QString message; QDebug(&message) << status; *errorMessage = QLatin1String("Failed to load content. ") + message; return false; } errorMessage->clear(); return true; } void FormatTest::testPageLayout() { KReportDesign design; QString errorMessage; if (!openDesignFile(&design, &errorMessage)) { QFAIL(qPrintable(errorMessage)); } const QPageLayout pageLayout = design.pageLayout(); QVERIFY(pageLayout.isValid()); QCOMPARE(pageLayout.pageSize().id(), QPageSize::A5); QCOMPARE(pageLayout.pageSize().sizePoints(), QPageSize(QPageSize::A5).sizePoints()); QCOMPARE(pageLayout.orientation(), QPageLayout::Portrait); QCOMPARE(pageLayout.margins(QPageLayout::Millimeter), QMarginsF(30.0, 20.0, 40.0, 15.0)); //! @todo move this renderer test to a separate place #if 0 KReportDesigner designer; QCOMPARE(designer.propertySet()->property("page-size").value().toString(), QLatin1String("A5")); QCOMPARE(designer.propertySet()->property("margin-bottom").value().toDouble(), KReportUnit::parseValue("1.5cm")); QCOMPARE(designer.propertySet()->property("margin-top").value().toDouble(), KReportUnit::parseValue("2.0cm")); QCOMPARE(designer.propertySet()->property("margin-left").value().toDouble(), KReportUnit::parseValue("3.0cm")); QCOMPARE(designer.propertySet()->property("margin-right").value().toDouble(), KReportUnit::parseValue("4.0cm")); KReportPreRenderer renderer( designer.document() ); renderer.generate(); ReportPageOptions opt = renderer.reportData()->pageOptions(); QCOMPARE(opt.getPageSize(), QString("A5")); QScreen *srn = QApplication::screens().at(0); const qreal dpiY = srn->logicalDotsPerInchY(); qDebug() << opt.getMarginBottom() << INCH_TO_POINT(opt.getMarginBottom()) << KReportPrivate::dpiY() << dpiY << KReportUnit::parseValue("1.5cm"); QFUZZYCOMPARE(INCH_TO_POINT(opt.getMarginBottom()) / KReportPrivate::dpiY(), KReportUnit::parseValue("1.5cm"), 0.2); QFUZZYCOMPARE(INCH_TO_POINT(opt.getMarginTop()) / KReportPrivate::dpiY(), KReportUnit::parseValue("2.0cm"), 0.2); QFUZZYCOMPARE(INCH_TO_POINT(opt.getMarginLeft()) / KReportPrivate::dpiX(), KReportUnit::parseValue("3.0cm"), 0.2); QFUZZYCOMPARE(INCH_TO_POINT(opt.getMarginRight()) / KReportPrivate::dpiX(), KReportUnit::parseValue("4.0cm"), 0.3); #endif } void FormatTest::testLineElement() { #if 0 // todo KReportDesign design; QString errorMessage; if (!openDesignFile(&design, &errorMessage)) { QFAIL(qPrintable(errorMessage)); } #endif //! @todo move this renderer test to a separate place #if 0 KReportDesigner designer; ReportSectionDetail *ds = designer.detailSection(); ReportSection *sec = ds->detailSection(); KReportItemLine *l = dynamic_cast(sec->items().first()); QVERIFY(l != 0); QCOMPARE(l->Z, 1.5); KReportPosition start = l->startPosition(); KReportPosition end = l->endPosition(); QCOMPARE(start.toPoint(), QPointF(KReportUnit::parseValue("1.5cm"), KReportUnit::parseValue("0.5cm"))); QCOMPARE(end.toPoint(), QPointF(KReportUnit::parseValue("4.5cm"), KReportUnit::parseValue("2.5cm"))); KReportPreRenderer renderer( designer.document() ); renderer.generate(); l = dynamic_cast(renderer.reportData()->object("line1")); QVERIFY(l != 0); QCOMPARE(l->Z, 1.5); start = l->startPosition(); end = l->endPosition(); QCOMPARE(start.toPoint(), QPointF(KReportUnit::parseValue("1.5cm"), KReportUnit::parseValue("0.5cm"))); QCOMPARE(end.toPoint(), QPointF(KReportUnit::parseValue("4.5cm"), KReportUnit::parseValue("2.5cm"))); #endif } void FormatTest::testLabelElement() { KReportDesign design; QString errorMessage; if (!openDesignFile(&design, &errorMessage)) { QFAIL(qPrintable(errorMessage)); } QCOMPARE(design.title(), QLatin1String("Label Element Test Report")); - QVERIFY(design.hasSection(KReportSection::Detail)); - KReportSection detailSection = design.section(KReportSection::Detail); - QCOMPARE(detailSection.type(), KReportSection::Detail); + QVERIFY(design.hasSection(KReportSection::Type::Detail)); + KReportSection detailSection = design.section(KReportSection::Type::Detail); + QCOMPARE(detailSection.type(), KReportSection::Type::Detail); QCOMPARE(detailSection.height(), CM_TO_POINT(5.0)); QCOMPARE(detailSection.backgroundColor(), QColor("#eeeeee")); QList elements = detailSection.elements(); QCOMPARE(elements.count(), 1); KReportElement element = elements.first(); QCOMPARE(element.name(), QLatin1String("label1")); KReportLabelElement label1(elements.first()); QCOMPARE(label1.text(), "Label"); QCOMPARE(label1.z(), 2.5); const QRectF rect(CM_TO_POINT(1.5), CM_TO_POINT(0.5), CM_TO_POINT(4.5), CM_TO_POINT(0.75)); QCOMPARE(label1.rect(), rect); QCOMPARE(label1.backgroundColor(), QColor("#dddddd")); QCOMPARE(label1.foregroundColor(), QColor("#101010")); QCOMPARE(label1.backgroundOpacity(), 0.9); QCOMPARE(label1.alignment(), Qt::AlignRight | Qt::AlignBottom); QCOMPARE(label1.font().capitalization(), QFont::AllLowercase); QCOMPARE(label1.font().bold(), true); QCOMPARE(label1.font().weight(), 99); QCOMPARE(label1.font().italic(), true); QCOMPARE(label1.font().fixedPitch(), true); QCOMPARE(label1.font().family(), "Ubuntu"); QCOMPARE(label1.font().kerning(), true); QCOMPARE(label1.font().underline(), true); QCOMPARE(label1.font().strikeOut(), true); QCOMPARE(label1.font().pointSizeF(), 9.0); QCOMPARE(label1.font().letterSpacing(), 110.0); QCOMPARE(label1.font().letterSpacingType(), QFont::PercentageSpacing); QCOMPARE(label1.borderStyle().weight(), 1.0); QCOMPARE(label1.borderStyle().color(), QColor("#400000")); QCOMPARE(label1.borderStyle().penStyle(), Qt::DashLine); //! @todo move this renderer test to a separate place #if 0 KReportDesigner designer;//, doc.documentElement()); ReportSectionDetail *ds = designer.detailSection(); ReportSection *sec = ds->detailSection(); QVERIFY(sec->items().count() == 1); KReportDesignerItemRectBase *rect = dynamic_cast(sec->items().first()); QVERIFY(rect != 0); QRectF expected( QPointF(KReportUnit::parseValue("1.5cm"), KReportUnit::parseValue("0.5cm")), QSizeF(KReportUnit::parseValue("4.5cm"), KReportUnit::parseValue("0.75cm"))); QCOMPARE(rect->pointRect(), expected); KReportPreRenderer renderer( designer.document() ); renderer.generate(); KReportItemBase *item = dynamic_cast(renderer.reportData()->object("label1")); QVERIFY(item != 0); KReportPosition pos = item->position(); KReportSize size = item->size(); QCOMPARE(pos.toPoint().x(), KReportUnit::parseValue("1.5cm")); QCOMPARE(pos.toPoint().y(), KReportUnit::parseValue("0.5cm")); QCOMPARE(size.toPoint(), QSizeF(KReportUnit::parseValue("4.5cm"), KReportUnit::parseValue("0.75cm"))); QCOMPARE(size.toPoint(), QSizeF(KReportUnit::parseValue("4.5cm"), KReportUnit::parseValue("0.75cm"))); #endif } diff --git a/src/common/KReportDesign.cpp b/src/common/KReportDesign.cpp index 26378d3a..841fb500 100644 --- a/src/common/KReportDesign.cpp +++ b/src/common/KReportDesign.cpp @@ -1,267 +1,267 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC * Copyright (C) 2007-2010 by Adam Pigg * Copyright (C) 2011-2015 Jarosław Staniek * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportDesign.h" #include "KReportDesign_p.h" #include "KReportElement.h" #include "KReportUnit.h" #include "KReportUtils.h" #include "KReportPluginManager.h" #include "KReportPluginInterface.h" #include #include #include #include class Q_DECL_HIDDEN KReportDesignReadingStatus::Private { public: QString errorMessage; QString errorDetails; int errorLineNumber = -1; int errorColumnNumber = -1; }; KReportDesignReadingStatus::KReportDesignReadingStatus() : d(new Private) { } KReportDesignReadingStatus::~KReportDesignReadingStatus() { delete d; } KReportDesignReadingStatus::KReportDesignReadingStatus(const KReportDesignReadingStatus& other) : d(new Private) { *this = other; } KReportDesignReadingStatus& KReportDesignReadingStatus::operator=(const KReportDesignReadingStatus &other) { if (this != &other) { setErrorMessage(other.errorMessage()); setErrorDetails(other.errorDetails()); setErrorLineNumber(other.errorLineNumber()); setErrorColumnNumber(other.errorColumnNumber()); } return *this; } bool KReportDesignReadingStatus::isError() const { return d->errorLineNumber >= 0 && d->errorColumnNumber >= 0; } int KReportDesignReadingStatus::errorColumnNumber() const { return d->errorColumnNumber; } QString KReportDesignReadingStatus::errorDetails() const { return d->errorDetails; } QString KReportDesignReadingStatus::errorMessage() const { return d->errorMessage; } int KReportDesignReadingStatus::errorLineNumber() const { return d->errorLineNumber; } void KReportDesignReadingStatus::setErrorColumnNumber(int column) { d->errorColumnNumber = column; } void KReportDesignReadingStatus::setErrorDetails(const QString& details) { d->errorDetails = details; } void KReportDesignReadingStatus::setErrorLineNumber(int line) { d->errorLineNumber = line; } void KReportDesignReadingStatus::setErrorMessage(const QString& msg) { d->errorMessage = msg; } QDebug operator<<(QDebug dbg, const KReportDesignReadingStatus& status) { if (status.isError()) { dbg.nospace() << qPrintable( QString::fromLatin1("KReportDesignReadingStatus: errorMessage=\"%1\" " "errorDetails=\"%2\" line=%3 column=%4") .arg(status.errorMessage()).arg(status.errorDetails()) .arg(status.errorLineNumber()).arg(status.errorColumnNumber())); } else { dbg.nospace() << "KReportDesignReadingStatus: OK"; } return dbg.space(); } //----------------------------------- KReportDesign::KReportDesign() : d(new Private(this)) { } KReportDesign::~KReportDesign() { delete d; } bool KReportDesign::setContent(const QString &text, KReportDesignReadingStatus *status) { QDomDocument doc; QString errorDetails; int errorLine; int errorColumn; if (!doc.setContent(text, &errorDetails, &errorLine, &errorColumn)) { if (status) { status->setErrorMessage(tr("Could not parse XML document.")); status->setErrorDetails(errorDetails); status->setErrorLineNumber(errorLine); status->setErrorColumnNumber(errorColumn); } return false; } bool ret = d->processDocument(doc, status); if (!ret && status) { status->setErrorMessage(tr("Error in XML document.")); } return ret; } QString KReportDesign::toString(int indent) const { Q_UNUSED(indent); //! @todo return QString(); } QPageLayout KReportDesign::pageLayout() const { return d->pageLayout; } QString KReportDesign::title() const { return d->title; } void KReportDesign::setTitle(const QString &title) { d->title = title; } void KReportDesign::setPageLayout(const QPageLayout &pageLayout) { d->pageLayout = pageLayout; d->pageLayout.setUnits(QPageLayout::Point); } KReportElement KReportDesign::createElement(const QString &typeName, QString *errorMessage) { QDomElement el; KReportDesignReadingStatus status; KReportPluginInterface* plugin = d->findPlugin(typeName, el, &status); if (!plugin) { if (errorMessage) { *errorMessage = status.errorMessage(); } return KReportElement(); } return plugin->createElement(); } bool KReportDesign::hasSection(KReportSection::Type type) const { - const int index = type - 1; + const int index = static_cast(type) - 1; if (0 <= index && index < d->sections.length()) { return d->sections[index]; } return false; } KReportSection KReportDesign::section(KReportSection::Type type) const { - const int index = type - 1; + const int index = static_cast(type) - 1; if (0 <= index && index < d->sections.length()) { KReportSection *section = d->sections[index]; if (section) { return *section; } } return KReportSection(); } void KReportDesign::addSection(const KReportSection §ion) { - const int index = section.type() - 1; + const int index = static_cast(section.type()) - 1; if (0 <= index && index < d->sections.length()) { if (d->sections[index]) { *d->sections[index] = section; } else { d->sections[index] = new KReportSection(section); } } } // static QPageLayout KReportDesign::defaultPageLayout() { QPageLayout layout = KReportDesignGlobal::self()->defaultPageLayout; if (!layout.pageSize().isValid()) { if (!QPrinterInfo::defaultPrinter().isNull()) { layout.setPageSize(QPrinterInfo::defaultPrinter().defaultPageSize()); } else { layout.setPageSize(QPageSize(DEFAULT_PAGE_SIZE)); } } return layout; } // static void KReportDesign::setDefaultPageLayout(const QPageLayout &pageLayout) { KReportDesignGlobal::self()->defaultPageLayout = pageLayout; KReportDesignGlobal::self()->defaultPageLayout.setUnits(QPageLayout::Point); } #ifdef KREPORT_SCRIPTING QString KReportDesign::script() const { return d->script; } #endif diff --git a/src/common/KReportDesign_p.cpp b/src/common/KReportDesign_p.cpp index f3b497fd..29bd02f0 100644 --- a/src/common/KReportDesign_p.cpp +++ b/src/common/KReportDesign_p.cpp @@ -1,458 +1,463 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC * Copyright (C) 2007-2010 by Adam Pigg * Copyright (C) 2011-2015 Jarosław Staniek * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportDesign_p.h" #include "KReportElement.h" #include "KReportUtils.h" #include "KReportPluginManager.h" #include "KReportPluginInterface.h" #include #include #include #include KReportDesign::Private::Private(KReportDesign *design) : q(design) , showGrid(DEFAULT_SHOW_GRID) , snapToGrid(DEFAULT_SNAP_TO_GRID) , gridDivisions(DEFAULT_GRID_DIVISIONS) , pageUnit(DEFAULT_UNIT) - , sections(KReportSection::Detail) + , sections(static_cast(KReportSection::Type::Detail)) { memset(static_cast(sections.data()), 0, sizeof(void*) * sections.length()); pageLayout.setUnits(QPageLayout::Point); // initializate because of https://bugreports.qt.io/browse/QTBUG-47551 } KReportDesign::Private::~Private() { qDeleteAll(sections); } KReportDesignGlobal::KReportDesignGlobal() : defaultSectionHeight(CM_TO_POINT(2.0)) , defaultSectionBackgroundColor(Qt::white) { defaultPageLayout.setUnits(QPageLayout::Point); defaultPageLayout.setMargins(QMarginsF(DEFAULT_PAGE_MARGIN, DEFAULT_PAGE_MARGIN, DEFAULT_PAGE_MARGIN, DEFAULT_PAGE_MARGIN)); defaultPageLayout.setMode(QPageLayout::StandardMode); defaultPageLayout.setOrientation(DEFAULT_PAGE_ORIENTATION); } KReportSection::Type KReportDesignGlobal::sectionType(const QString& typeName) { initSectionTypes(); - return sectionTypesForName.value(typeName); // returns InvalidType for invalid name + return sectionTypesForName.value(typeName); // returns Invalid typefor invalid name +} + +inline uint qHash(KReportSection::Type sectionType, uint seed = 0) +{ + return qHash(static_cast(sectionType), seed); } QString KReportDesignGlobal::sectionTypeName(KReportSection::Type sectionType) { initSectionTypes(); return sectionTypeNames.value(sectionType); } void KReportDesignGlobal::initSectionTypes() { if (!sectionTypesForName.isEmpty()) { return; } for (const SectionTypeInfo *info = sectionTypes; info->name; ++info) { sectionTypesForName.insert(QString::fromLatin1(info->name), info->type); sectionTypeNames.insert(info->type, QString::fromLatin1(info->name)); } } const KReportDesignGlobal::SectionTypeInfo KReportDesignGlobal::sectionTypes[] = { - { KReportSection::InvalidType, "" }, - { KReportSection::PageHeaderAny, "header-page-any" }, - { KReportSection::PageHeaderEven, "header-page-even" }, - { KReportSection::PageHeaderOdd, "header-page-odd" }, - { KReportSection::PageHeaderFirst, "header-page-first" }, - { KReportSection::PageHeaderLast, "header-page-last" }, - { KReportSection::PageFooterAny, "footer-page-any" }, - { KReportSection::PageFooterEven, "footer-page-even" }, - { KReportSection::PageFooterOdd, "footer-page-odd" }, - { KReportSection::PageFooterFirst, "footer-page-first" }, - { KReportSection::PageFooterLast, "footer-page-last" }, - { KReportSection::ReportHeader, "header-report" }, - { KReportSection::ReportFooter, "footer-report" }, - { KReportSection::GroupHeader, "group-header" }, - { KReportSection::GroupFooter, "group-footer" }, - { KReportSection::Detail, "detail" }, - { KReportSection::InvalidType, nullptr } + { KReportSection::Type::Invalid, "" }, + { KReportSection::Type::PageHeaderAny, "header-page-any" }, + { KReportSection::Type::PageHeaderEven, "header-page-even" }, + { KReportSection::Type::PageHeaderOdd, "header-page-odd" }, + { KReportSection::Type::PageHeaderFirst, "header-page-first" }, + { KReportSection::Type::PageHeaderLast, "header-page-last" }, + { KReportSection::Type::PageFooterAny, "footer-page-any" }, + { KReportSection::Type::PageFooterEven, "footer-page-even" }, + { KReportSection::Type::PageFooterOdd, "footer-page-odd" }, + { KReportSection::Type::PageFooterFirst, "footer-page-first" }, + { KReportSection::Type::PageFooterLast, "footer-page-last" }, + { KReportSection::Type::ReportHeader, "header-report" }, + { KReportSection::Type::ReportFooter, "footer-report" }, + { KReportSection::Type::GroupHeader, "group-header" }, + { KReportSection::Type::GroupFooter, "group-footer" }, + { KReportSection::Type::Detail, "detail" }, + { KReportSection::Type::Invalid, nullptr } }; Q_GLOBAL_STATIC(KReportDesignGlobal, s_global) //static KReportDesignGlobal* KReportDesignGlobal::self() { return s_global; } static void setStatus(KReportDesignReadingStatus *status, const QString& details, const QDomNode &node) { if (status) { status->setErrorDetails(details); status->setErrorLineNumber(node.lineNumber() == -1 ? 0 /* mark error */ : node.lineNumber()); status->setErrorColumnNumber(node.columnNumber() == -1 ? 0 /* mark error */ : node.columnNumber()); } } static bool checkElement(const QDomNode &node, KReportDesignReadingStatus *status) { if (node.isElement()) { return true; } setStatus(status, QString::fromLatin1("Element expected inside of <%1>") .arg(node.parentNode().toElement().tagName()), node); return false; } static void setNoAttributeStatus(const QDomElement &el, const char *attrName, KReportDesignReadingStatus *status) { setStatus(status, QString::fromLatin1("Attribute \"%1\" expected inside of <%1>") .arg(QLatin1String(attrName)).arg(el.tagName()), el); } #if 0 // TODO unused for now static bool checkAttribute(const QDomElement &el, const char *attrName, KReportDesignReadingStatus *status) { if (el.hasAttribute(QLatin1String(attrName))) { return true; } setNoAttributeStatus(el, attrName, status); return false; } #endif KReportSection KReportDesign::Private::processSectionElement(const QDomElement &el, KReportDesignReadingStatus *status) { const QString sectionTypeName = KReportUtils::attr(el, "report:section-type", QString()); KReportSection::Type sectionType = s_global->sectionType(sectionTypeName); - if (sectionType == KReportSection::InvalidType) { + if (sectionType == KReportSection::Type::Invalid) { setStatus(status, QString::fromLatin1("Invalid value of report:section-type=\"%1\" in element <%2>") .arg(sectionTypeName).arg(el.tagName()), el); return KReportSection(); } KReportSection section; section.setType(sectionType); qreal height = KReportUtils::attr(el, "svg:height", -1.0); if (height >= 0.0) { section.setHeight(height); } section.setBackgroundColor(QColor(KReportUtils::attr(el, "fo:background-color", QString()))); for (QDomNode node = el.firstChild(); !node.isNull(); node = node.nextSibling()) { if (!checkElement(node, status)) { return KReportSection(); } KReportElement element = processSectionElementChild(node.toElement(), status); if (!element.rect().isValid() || (status && status->isError())) { return KReportSection(); } (void)section.addElement(element); } return section; } KReportPluginInterface* KReportDesign::Private::findPlugin(const QString &typeName, const QDomElement &el, KReportDesignReadingStatus *status) { KReportPluginInterface* plugin = KReportPluginManager::self()->plugin(typeName); if (!plugin) { setStatus(status, QString::fromLatin1("No such plugin \"%1\"").arg(typeName), el); return nullptr; } return plugin; } KReportElement KReportDesign::Private::processSectionElementChild(const QDomElement &el, KReportDesignReadingStatus *status) { const QByteArray name = el.tagName().toLatin1(); const char* elNamespace = "report:"; if (!name.startsWith(elNamespace)) { unexpectedElement(el, status); return KReportElement(); } const QByteArray reportElementName = name.mid(qstrlen(elNamespace)); //qDebug() << "Found Report Element:" << reportElementName; KReportPluginInterface *plugin = findPlugin(QLatin1String(reportElementName), el, status); if (!plugin) { return KReportElement(); } KReportElement element = plugin->createElement(); if (!plugin->loadElement(&element, el, status)) { return KReportElement(); } element.setName(KReportUtils::attr(el, "report:name", QString())); if (element.name().isEmpty()) { setNoAttributeStatus(el, "report:name", status); return KReportElement(); } return element; } bool KReportDesign::Private::processGroupElement(const QDomElement &el, KReportDesignReadingStatus *status) { Q_UNUSED(el); Q_UNUSED(status); //! @todo return true; } //! The report:detail element contains a single report:section child of type 'detail' //! and 0 or more report:group children. bool KReportDesign::Private::processDetailElement(const QDomElement &el, KReportDesignReadingStatus *status) { QDomElement sectionEl; for (QDomNode node = el.firstChild(); !node.isNull(); node = node.nextSibling()) { if (!checkElement(node, status)) { return false; } QDomElement childEl = node.toElement(); const QByteArray name = childEl.tagName().toLatin1(); if (name == "report:section") { if (!sectionEl.isNull()) { return false; } KReportSection section = processSectionElement(childEl, status); if (status && status->isError()) { return false; } - if (section.type() != KReportSection::Detail) { + if (section.type() != KReportSection::Type::Detail) { setStatus(status, QString::fromLatin1("Only section of type \"detail\" allowed in "), el); return false; } q->addSection(section); } else if (name == "report:group") { if (!processGroupElement(childEl, status)) { return false; } } else { unexpectedElement(childEl, status); return false; } } // finally make sure we have one report:section (void)requiredChildElement(el, "report:section", status); if (status && status->isError()) { return false; } return true; } /*!
        
         *.. (up to 12 sections)
          
             // any number of groups
              *.. (group-header, group-footer)
            
          
        
     
 */
 bool KReportDesign::Private::processBodyElementChild(const QDomElement &el,
                                                      KReportDesignReadingStatus *status)
 {
     const QByteArray name = el.tagName().toLatin1();
     //kreportDebug() << name;
     if (name == "report:section") {
         KReportSection section = processSectionElement(el, status);
         if (status && status->isError()) {
             return false;
         }
         if (q->hasSection(section.type())) {
             setStatus(status, QString::fromLatin1("Could not add two sections of type \"%1\" "
                                                   "to the same report design")
                                 .arg(s_global->sectionTypeName(section.type())), el);
             return false;
         }
-        if (section.type() == KReportSection::Detail) {
+        if (section.type() == KReportSection::Type::Detail) {
             setStatus(status,
                 QString::fromLatin1("Section of type \"detail\" not allowed in "), el);
             return false;
         }
         q->addSection(section);
 #if 0 //TODO
         if (section(KReportSectionData::sectionTypeFromString(sectiontype)) == 0) {
             insertSection(KReportSectionData::sectionTypeFromString(sectiontype));
             section(KReportSectionData::sectionTypeFromString(sectiontype))->initFromXML(sec);
         }
 #endif
     } else if (name == "report:detail") {
         if (!processDetailElement(el, status)) {
             return false;
         }
 #if 0 //TODO
         ReportSectionDetail * rsd = new ReportSectionDetail(this);
         rsd->initFromXML(&sec);
         setDetail(rsd);
 #endif
     }
     return true;
 }
 
 /* NOTE: don't translate these extremely detailed messages. */
 //! @todo Load page options
 bool KReportDesign::Private::processContentElementChild(const QDomElement &el,
                                                         KReportDesignReadingStatus *status)
 {
     const QByteArray name = el.tagName().toLatin1();
     QPageLayout defaultPageLayout = KReportDesign::defaultPageLayout();
     //kreportDebug() << name;
     if (name == "report:title") {
         title = el.text();
 #ifdef KREPORT_SCRIPTING
     } else if (name == "report:script") {
         script = el.firstChildElement().text();
         originalInterpreter = KReportUtils::attr(el, "report:script-interpreter", QString());
 #endif
     } else if (name == "report:grid") {
         showGrid = KReportUtils::attr(el, "report:grid-visible", DEFAULT_SHOW_GRID);
         snapToGrid = KReportUtils::attr(el, "report:grid-snap", DEFAULT_SNAP_TO_GRID);
         gridDivisions = KReportUtils::attr(el, "report:grid-divisions", DEFAULT_GRID_DIVISIONS);
         const QString pageUnitString = KReportUtils::attr(el, "report:page-unit", QString());
         bool found;
         pageUnit = KReportUnit::fromSymbol(pageUnitString, &found);
         if (!found) {
             pageUnit = DEFAULT_UNIT;
             if (!pageUnitString.isEmpty()) {
                 qWarning() << "Invalid page unit" << pageUnitString << "specified in" << name
                            << "element, defaulting to" << pageUnit.symbol();
             }
         }
     }
     else if (name == "report:page-style") { // see https://git.reviewboard.kde.org/r/115314
         const QByteArray pagetype = el.text().toLatin1();
         if (pagetype == "predefined") {
             pageLayout.setPageSize(
                         KReportUtils::pageSize(KReportUtils::attr(el, "report:page-size",
                                                QPageSize(DEFAULT_PAGE_SIZE).key())));
         } else if (pagetype.isEmpty() || pagetype == "custom") {
             QSizeF size(KReportUtils::attr(el, "fo:page-width", -1.0),
                         KReportUtils::attr(el, "fo:page-height", -1.0));
             if (size.isValid()) {
                 pageLayout.setPageSize(QPageSize(size, QPageSize::Point));
             } else {
                 pageLayout.setPageSize(defaultPageLayout.pageSize());
             }
         } else if (pagetype == "label") {
             //! @todo?
             pageLayout.setPageSize(defaultPageLayout.pageSize());
         }
         QMarginsF margins(KReportUtils::attr(el, "fo:margin-left", defaultPageLayout.margins().left()),
                  KReportUtils::attr(el, "fo:margin-top", defaultPageLayout.margins().top()),
                  KReportUtils::attr(el, "fo:margin-right", defaultPageLayout.margins().right()),
                  KReportUtils::attr(el, "fo:margin-bottom", defaultPageLayout.margins().bottom()));
         bool b = pageLayout.setMargins(margins);
         if (!b) {
             qWarning() << "Failed to set page margins to" << margins;
         }
         const QString s = KReportUtils::attr(el, "report:print-orientation", QString());
         if (s == QLatin1String("portrait")) {
             pageLayout.setOrientation(QPageLayout::Portrait);
         } else if (s == QLatin1String("landscape")) {
             pageLayout.setOrientation(QPageLayout::Landscape);
         }
         else {
             pageLayout.setOrientation(defaultPageLayout.orientation());
         }
     } else if (name == "report:body") {
         for (QDomNode node = el.firstChild(); !node.isNull(); node = node.nextSibling()) {
             if (!checkElement(node, status)) {
                 return false;
             }
             if (!processBodyElementChild(node.toElement(), status)) {
                 return false;
             }
         }
     }
     return true;
 }
 
 void KReportDesign::Private::unexpectedElement(const QDomElement &element,
                                                KReportDesignReadingStatus *status) const
 {
     setStatus(status, QString::fromLatin1("Unexpected child element <%1> found in <%2>")
           .arg(element.tagName()).arg(element.parentNode().toElement().tagName()), element);
 }
 
 QDomElement KReportDesign::Private::requiredChildElement(const QDomElement &parent,
                                                          const char* childElementName,
                                                          KReportDesignReadingStatus *status) const
 {
     const QDomElement result = parent.firstChildElement(QLatin1String(childElementName));
     if (result.isNull()) {
         setStatus(status, QString::fromLatin1("Child element <%1> not found in <%2>")
               .arg(QLatin1String(childElementName)).arg(parent.tagName()), parent);
     }
     return result;
 }
 
 /* NOTE: don't translate these extremely detailed messages. */
 bool KReportDesign::Private::processDocument(const QDomDocument &doc,
                                              KReportDesignReadingStatus *status)
 {
     const QDomElement rootEl = doc.documentElement();
     const QLatin1String rootElName("kexireport"); // legacy name kept for compatibility
     if (doc.doctype().name() != rootElName) {
         setStatus(status, QString::fromLatin1("Document type should be \"%1\"").arg(rootElName), rootEl);
         return false;
     }
     if (rootEl.tagName() != rootElName) {
         setStatus(status, QString::fromLatin1("Root element should be <%1>").arg(rootElName), rootEl);
         return false;
     }
     const QDomElement contentEl = requiredChildElement(rootEl, "report:content", status);
     if (status && status->isError()) {
         return false;
     }
     //! @todo check namespaces as in:
     //! 
 
 //    deleteDetail();
 
     for (QDomNode node = contentEl.firstChild(); !node.isNull(); node = node.nextSibling()) {
         if (!checkElement(node, status)) {
             return false;
         }
         if (!processContentElementChild(node.toElement(), status)) {
             return false;
         }
     }
 
     if (status) {
         *status = KReportDesignReadingStatus();
     }
     return true;
 }
diff --git a/src/common/KReportDesign_p.h b/src/common/KReportDesign_p.h
index fa252787..34d9c580 100644
--- a/src/common/KReportDesign_p.h
+++ b/src/common/KReportDesign_p.h
@@ -1,130 +1,130 @@
 /* This file is part of the KDE project
  * Copyright (C) 2001-2007 by OpenMFG, LLC 
  * Copyright (C) 2007-2010 by Adam Pigg 
  * Copyright (C) 2011-2015 Jarosław Staniek 
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library.  If not, see .
  */
 
 #ifndef KREPORTDESIGN_P_H
 #define KREPORTDESIGN_P_H
 
 #include "KReportDesign.h"
 #include "KReportUnit.h"
 #include "KReportUtils_p.h"
 
 #include 
 #include 
 #include 
 
 class QDomDocument;
 class QDomElement;
 class KReportPluginInterface;
 
 static const bool DEFAULT_SHOW_GRID = true;
 static const bool DEFAULT_SNAP_TO_GRID = true;
 static const int DEFAULT_GRID_DIVISIONS = 4;
 static const KReportUnit DEFAULT_UNIT = KReportUnit(KReportUnit::Centimeter);
 static const int DEFAULT_PAGE_MARGIN = CM_TO_POINT(1.0);
 static const QPageSize::PageSizeId DEFAULT_PAGE_SIZE = QPageSize::A4;
 static const QPageLayout::Orientation DEFAULT_PAGE_ORIENTATION = QPageLayout::Landscape;
 
 class Q_DECL_HIDDEN KReportDesign::Private
 {
 public:
     explicit Private(KReportDesign *design);
 
     ~Private();
 
     QDomElement requiredChildElement(const QDomElement &parent,
                                      const char* childElementName,
                                      KReportDesignReadingStatus *status) const;
 
     void unexpectedElement(const QDomElement &element,
                            KReportDesignReadingStatus *status) const;
 
     //! Processes document @a doc and sets status @a status
     bool processDocument(const QDomDocument &doc, KReportDesignReadingStatus *status);
 
     //! Processes @a el, a child of /report:content element and sets status @a status
     bool processContentElementChild(const QDomElement &el, KReportDesignReadingStatus *status);
 
     //! Processes @a el, a child of /report:content/report:body element and sets status @a status
     bool processBodyElementChild(const QDomElement &el, KReportDesignReadingStatus *status);
 
     //! Processes @a el, a /report:content/report:body/report:section element and sets status @a status
     KReportSection processSectionElement(const QDomElement &el, KReportDesignReadingStatus *status);
 
     //! Processes @a el,
     //! a child of /report:content/report:body/report:section element
     //! or a child of /report:content/report:body/report:detail/report:section element
     //! and sets status @a status.
     //! It is probably the lowest level in hierarchy and @a el refers to a single report element.
     KReportElement processSectionElementChild(const QDomElement &el, KReportDesignReadingStatus *status);
 
     //! Processes @a el, a child of /report:content/report:body/report:detail element and sets status @a status
     bool processDetailElement(const QDomElement &el, KReportDesignReadingStatus *status);
 
     //! Processes @a el, a /report:content/report:body/report:detail/report:group element and sets status @a status
     bool processGroupElement(const QDomElement &el, KReportDesignReadingStatus *status);
 
     KReportPluginInterface* findPlugin(const QString &typeName, const QDomElement &el,
                                         KReportDesignReadingStatus *status);
 
     KReportDesign * const q;
 
     // Visual settings only
     bool showGrid;
     bool snapToGrid;
     int gridDivisions;
     KReportUnit pageUnit;
     // END OF: Visual settings only
     QString title;
     KReportPrivate::PageLayout pageLayout;
-    QVarLengthArray sections;
+    QVarLengthArray(KReportSection::Type::Detail)> sections;
 #ifdef KREPORT_SCRIPTING
     QString script;
     QString originalInterpreter; //!< used for backward-compatibility to save the original
 #endif
 };
 
 class KReportDesignGlobal
 {
 public:
     KReportDesignGlobal();
 
     static KReportDesignGlobal* self();
 
     struct SectionTypeInfo {
         KReportSection::Type type;
         const char *name;
     };
 
     KReportSection::Type sectionType(const QString& typeName);
 
     QString sectionTypeName(KReportSection::Type sectionType);
 
     KReportPrivate::PageLayout defaultPageLayout;
     qreal defaultSectionHeight;
     QColor defaultSectionBackgroundColor;
 
 private:
     void initSectionTypes();
 
     static const SectionTypeInfo sectionTypes[];
     QHash sectionTypesForName;
     QHash sectionTypeNames;
 };
 
 #endif
diff --git a/src/common/KReportDocument.cpp b/src/common/KReportDocument.cpp
index 8101c273..f196ad9d 100644
--- a/src/common/KReportDocument.cpp
+++ b/src/common/KReportDocument.cpp
@@ -1,384 +1,387 @@
 /* This file is part of the KDE project
  * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library.  If not, see .
  */
 
 #include "KReportDocument.h"
 #include "KReportUnit.h"
 #include "KReportDetailSectionData.h"
 #include "KReportItemBase.h"
 #include "KReportUtils_p.h"
 #include "KReportPageSize.h"
 
 #include 
 #include 
 #include "kreport_debug.h"
 
 class Q_DECL_HIDDEN KReportDocument::Private
 {
 public:
     bool valid;
     QString title;
     QString name;
     QString query;
 #ifdef KREPORT_SCRIPTING
     QString script;
     QString interpreter;
 #endif
     bool externalData;
     KReportPrivate::PageLayout pageLayout;
     QString pageSize;
     QString labelType;
 };
 
 void KReportDocument::init()
 {
     m_pageHeaderFirst = m_pageHeaderOdd = m_pageHeaderEven = m_pageHeaderLast = m_pageHeaderAny = nullptr;
     m_pageFooterFirst = m_pageFooterOdd = m_pageFooterEven = m_pageFooterLast = m_pageFooterAny = nullptr;
     m_reportHeader = m_reportFooter = nullptr;
 }
 
 KReportDocument::KReportDocument(QObject *parent)
         : QObject(parent),
         m_detailSection(nullptr),
         d(new Private())
 {
     init();
     d->valid = true;
 }
 
 KReportDocument::KReportDocument(const QDomElement & elemSource, QObject *parent)
         : QObject(parent),
         m_detailSection(nullptr),
         d(new Private())
 {
     d->valid = false;
     init();
     //kreportDebug();
     if (elemSource.tagName() != QLatin1String("report:content")) {
         kreportWarning() << "QDomElement is not  tag"
                    << elemSource.text();
         return;
     }
 
     QDomNodeList sections = elemSource.childNodes();
     for (int nodeCounter = 0; nodeCounter < sections.count(); nodeCounter++) {
         QDomElement elemThis = sections.item(nodeCounter).toElement();
         if (elemThis.tagName() == QLatin1String("report:title")) {
             d->title = elemThis.text();
 #ifdef KREPORT_SCRIPTING
         } else if (elemThis.tagName() == QLatin1String("report:script")) {
             d->script = elemThis.text();
             d->interpreter = elemThis.attribute(QLatin1String("report:script-interpreter"));
 #endif
         } else if (elemThis.tagName() == QLatin1String("report:page-style")) {            
             QString pagetype = elemThis.firstChild().nodeValue();
 
             //Full page mode is required to allow margins to be set to whatever the user has specified
             d->pageLayout.setMode(QPageLayout::FullPageMode);
             
             if (pagetype == QLatin1String("predefined")) {
                 setPageSize(elemThis.attribute(QLatin1String("report:page-size"), QLatin1String("A4")));
                 d->pageLayout.setPageSize(QPageSize(KReportPageSize::pageSize(pageSize())));
             } else if (pagetype == QLatin1String("custom")) {
                 QPageSize custom(QSize(elemThis.attribute(QLatin1String("report:custom-page-width"), QString()).toFloat() , elemThis.attribute(QLatin1String("report:custom-page-height"), QString()).toFloat()), QLatin1String("Custom"));
 
                 d->pageLayout.setPageSize(custom);
             } else if (pagetype == QLatin1String("label")) {
                 setLabelType(elemThis.firstChild().nodeValue());
             }
             //! @todo add config for default margins or add within templates support
             d->pageLayout.setUnits(QPageLayout::Point);
             d->pageLayout.setLeftMargin(KReportUnit::parseValue(elemThis.attribute(QLatin1String("fo:margin-left"), QLatin1String("1.0cm"))));
             d->pageLayout.setRightMargin(KReportUnit::parseValue(elemThis.attribute(QLatin1String("fo:margin-right"), QLatin1String("1.0cm"))));
             d->pageLayout.setTopMargin(KReportUnit::parseValue(elemThis.attribute(QLatin1String("fo:margin-top"), QLatin1String("1.0cm"))));
             d->pageLayout.setBottomMargin(KReportUnit::parseValue(elemThis.attribute(QLatin1String("fo:margin-bottom"), QLatin1String("1.0cm"))));
             d->pageLayout.setOrientation(elemThis.attribute(QLatin1String("report:print-orientation"), QLatin1String("portrait")) == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape);
         } else if (elemThis.tagName() == QLatin1String("report:body")) {
             QDomNodeList sectionlist = elemThis.childNodes();
             QDomNode sec;
 
             for (int s = 0; s < sectionlist.count(); ++s) {
                 sec = sectionlist.item(s);
                 if (sec.isElement()) {
                     QString sn = sec.nodeName().toLower();
                     //kreportDebug() << sn;
                     if (sn == QLatin1String("report:section")) {
                         KReportSectionData * sd = new KReportSectionData(sec.toElement(), this);
                         if (!sd->isValid()) {
                             kreportDebug() << "Invalid section";
                             delete sd;
                         } else {
                             //kreportDebug() << "Adding section of type " << sd->type();
                             switch (sd->type()) {
-                            case KReportSectionData::PageHeaderFirst:
+                            case KReportSectionData::Type::PageHeaderFirst:
                                 m_pageHeaderFirst = sd;
                                 break;
-                            case KReportSectionData::PageHeaderOdd:
+                            case KReportSectionData::Type::PageHeaderOdd:
                                 m_pageHeaderOdd = sd;
                                 break;
-                            case KReportSectionData::PageHeaderEven:
+                            case KReportSectionData::Type::PageHeaderEven:
                                 m_pageHeaderEven = sd;
                                 break;
-                            case KReportSectionData::PageHeaderLast:
+                            case KReportSectionData::Type::PageHeaderLast:
                                 m_pageHeaderLast = sd;
                                 break;
-                            case KReportSectionData::PageHeaderAny:
+                            case KReportSectionData::Type::PageHeaderAny:
                                 m_pageHeaderAny = sd;
                                 break;
-                            case KReportSectionData::ReportHeader:
+                            case KReportSectionData::Type::ReportHeader:
                                 m_reportHeader = sd;
                                 break;
-                            case KReportSectionData::ReportFooter:
+                            case KReportSectionData::Type::ReportFooter:
                                 m_reportFooter = sd;
                                 break;
-                            case KReportSectionData::PageFooterFirst:
+                            case KReportSectionData::Type::PageFooterFirst:
                                 m_pageFooterFirst = sd;
                                 break;
-                            case KReportSectionData::PageFooterOdd:
+                            case KReportSectionData::Type::PageFooterOdd:
                                 m_pageFooterOdd = sd;
                                 break;
-                            case KReportSectionData::PageFooterEven:
+                            case KReportSectionData::Type::PageFooterEven:
                                 m_pageFooterEven = sd;
                                 break;
-                            case KReportSectionData::PageFooterLast:
+                            case KReportSectionData::Type::PageFooterLast:
                                 m_pageFooterLast = sd;
                                 break;
-                            case KReportSectionData::PageFooterAny:
+                            case KReportSectionData::Type::PageFooterAny:
                                 m_pageFooterAny = sd;
                                 break;
                             default:
                                 ;
                             }
                         }
 
                     } else if (sn == QLatin1String("report:detail")) {
                         KReportDetailSectionData * dsd = new KReportDetailSectionData(sec.toElement(), this);
 
                         if (dsd->isValid()) {
                             m_detailSection = dsd;
                         } else {
                             kreportDebug() << "Invalid detail section";
                             delete dsd;
                         }
                     }
                 } else {
                     kreportWarning() << "Encountered an unknown Element: "  << elemThis.tagName();
                 }
             }
         }
 
         d->valid = true;
     }
 }
 
 KReportDocument::~KReportDocument()
 {
     delete d;
 }
 
 QList KReportDocument::objects() const
 {
     QList obs;
-    for (int i = 1; i <= KReportSectionData::PageFooterAny; i++) {
-        KReportSectionData *sec = section((KReportSectionData::Section)i);
+    for (int i = static_cast(KReportSectionData::Type::None) + 1;
+         i <= static_cast(KReportSectionData::Type::GroupFooter); i++)
+    {
+        KReportSectionData *sec = section(static_cast(i));
         if (sec) {
             obs << sec->objects();
         }
     }
 
     if (m_detailSection) {
         //kreportDebug() << "Number of groups: " << m_detailSection->m_groupList.count();
         foreach(KReportDetailGroupSectionData* g, m_detailSection->groupList) {
             if (g->groupHeader) {
                 obs << g->groupHeader->objects();
             }
             if (g->groupFooter) {
                 obs << g->groupFooter->objects();
             }
         }
         if (m_detailSection->detailSection)
             obs << m_detailSection->detailSection->objects();
     }
 
     /*kreportDebug() << "Object List:";
     foreach(KReportItemBase* o, obs) {
         kreportDebug() << o->entityName();
     }*/
     return obs;
 }
 
 KReportItemBase* KReportDocument::object(const QString& n) const
 {
     QList obs = objects();
 
     foreach(KReportItemBase* o, obs) {
         if (o->entityName() == n) {
             return o;
         }
     }
     return nullptr;
 }
 
 QList KReportDocument::sections() const
 {
     QList secs;
-    for (int i = 0; i < 12 ; ++i) {
-        KReportSectionData *sec = section((KReportSectionData::Section)(i + 1));
+    for (int i = static_cast(KReportSectionData::Type::None) + 1;
+         i <= static_cast(KReportSectionData::Type::GroupFooter); i++)
+    {
+        KReportSectionData *sec = section(static_cast(i));
         if (sec) {
             secs << sec;
         }
     }
 
     if (m_detailSection) {
         //kreportDebug() << "Number of groups: " << m_detailSection->m_groupList.count();
         foreach(KReportDetailGroupSectionData* g, m_detailSection->groupList) {
             if (g->groupHeader) {
                 secs << g->groupHeader;
             }
             if (g->groupFooter) {
                 secs << g->groupFooter;
             }
         }
         if (m_detailSection->detailSection)
             secs << m_detailSection->detailSection;
     }
 
     return secs;
 }
 
 KReportSectionData* KReportDocument::section(const QString& sn) const
 {
     QList secs = sections();
 
     foreach(KReportSectionData *sec, secs) {
         if (sec->name() == sn) {
             return sec;
         }
     }
     return nullptr;
 }
 
-KReportSectionData* KReportDocument::section(KReportSectionData::Section s) const
+KReportSectionData* KReportDocument::section(KReportSectionData::Type type) const
 {
     KReportSectionData *sec;
-    switch (s) {
-    case KReportSectionData::PageHeaderAny:
+    switch (type) {
+    case KReportSectionData::Type::PageHeaderAny:
         sec = m_pageHeaderAny;
         break;
-    case KReportSectionData::PageHeaderEven:
+    case KReportSectionData::Type::PageHeaderEven:
         sec = m_pageHeaderEven;
         break;
-    case KReportSectionData::PageHeaderOdd:
+    case KReportSectionData::Type::PageHeaderOdd:
         sec = m_pageHeaderOdd;
         break;
-    case KReportSectionData::PageHeaderFirst:
+    case KReportSectionData::Type::PageHeaderFirst:
         sec = m_pageHeaderFirst;
         break;
-    case KReportSectionData::PageHeaderLast:
+    case KReportSectionData::Type::PageHeaderLast:
         sec = m_pageHeaderLast;
         break;
-    case KReportSectionData::PageFooterAny:
+    case KReportSectionData::Type::PageFooterAny:
         sec = m_pageFooterAny;
         break;
-    case KReportSectionData::PageFooterEven:
+    case KReportSectionData::Type::PageFooterEven:
         sec = m_pageFooterEven;
         break;
-    case KReportSectionData::PageFooterOdd:
+    case KReportSectionData::Type::PageFooterOdd:
         sec = m_pageFooterOdd;
         break;
-    case KReportSectionData::PageFooterFirst:
+    case KReportSectionData::Type::PageFooterFirst:
         sec = m_pageFooterFirst;
         break;
-    case KReportSectionData::PageFooterLast:
+    case KReportSectionData::Type::PageFooterLast:
         sec = m_pageFooterLast;
         break;
-    case KReportSectionData::ReportHeader:
+    case KReportSectionData::Type::ReportHeader:
         sec = m_reportHeader;
         break;
-    case KReportSectionData::ReportFooter:
+    case KReportSectionData::Type::ReportFooter:
         sec = m_reportFooter;
         break;
     default:
         sec = nullptr;
     }
     return sec;
 }
 
 QPageLayout KReportDocument::pageLayout() const
 {
     return d->pageLayout;
 }
 
 bool KReportDocument::isValid() const
 {
     return d->valid;
 }
 
 QString KReportDocument::title() const
 {
     return d->title;
 }
 
 bool KReportDocument::externalData() const
 {
     return d->externalData;
 }
 
 QString KReportDocument::interpreter() const
 {
     return d->interpreter;
 }
 
 QString KReportDocument::name() const
 {
     return d->name;
 }
 
 void KReportDocument::setName(const QString& n)
 {
     d->name = n;
 }
 
 QString KReportDocument::query() const
 {
     return d->query;
 }
 
 QString KReportDocument::script() const
 {
     return d->script;
 }
 
 QString KReportDocument::pageSize()
 {
     return d->pageSize;
 }
 
 void KReportDocument::setPageSize(const QString& size)
 {
     d->pageSize = size;
 }
 
 QString KReportDocument::labelType() const
 {
     return d->labelType;
 }
 
 void KReportDocument::setLabelType(const QString& label)
 {
     d->labelType = label;
 }
-
diff --git a/src/common/KReportDocument.h b/src/common/KReportDocument.h
index f1f33931..a74cf727 100644
--- a/src/common/KReportDocument.h
+++ b/src/common/KReportDocument.h
@@ -1,136 +1,136 @@
 /* This file is part of the KDE project
  * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
  * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library.  If not, see .
  */
 
 #ifndef KREPORTDOCUMENT_H
 #define KREPORTDOCUMENT_H
 
 #include "config-kreport.h"
 #include "kreport_export.h"
 #include "KReportSectionData.h"
 
 #include 
 
 class KReportDetailSectionData;
 
 #ifdef KREPORT_SCRIPTING
 namespace Scripting
 {
 class Report;
 }
 #endif
 
 /**
 */
 class KREPORT_EXPORT KReportDocument : public QObject
 {
     Q_OBJECT
 
 public:
     explicit KReportDocument(const QDomElement &elemSource, QObject *parent = nullptr);
     explicit KReportDocument(QObject *parent = nullptr);
     ~KReportDocument() override;
 
     bool isValid() const;
 
     /**
     \return a list of all objects in the report
     */
     QList objects() const;
 
     /**
     \return a report object given its name
     */
     KReportItemBase* object(const QString&) const;
 
     /**
     \return all the sections, including groups and detail
     */
     QList sections() const;
 
     /**
-    \return a sectiondata given a section enum
+    \return a sectiondata given a section type
     */
-    KReportSectionData* section(KReportSectionData::Section) const;
+    KReportSectionData* section(KReportSectionData::Type type) const;
 
     /**
     \return a sectiondata given its name
     */
-    KReportSectionData* section(const QString&) const;
+    KReportSectionData* section(const QString &name) const;
 
     QString query() const;
 #ifdef KREPORT_SCRIPTING
     QString script() const;
 
     QString interpreter() const;
 #endif
 
     bool externalData() const;
 
     KReportDetailSectionData* detail() const {
         return m_detailSection;
     }
 
     void setName(const QString&n);
     QString name() const;
 
     QString title() const;
 
     QPageLayout pageLayout() const;
     
     QString pageSize();
     void setPageSize(const QString &size);
     
 protected:
 
 
     KReportSectionData * m_pageHeaderFirst;
     KReportSectionData * m_pageHeaderOdd;
     KReportSectionData * m_pageHeaderEven;
     KReportSectionData * m_pageHeaderLast;
     KReportSectionData * m_pageHeaderAny;
 
     KReportSectionData * m_reportHeader;
     KReportSectionData * m_reportFooter;
 
     KReportSectionData * m_pageFooterFirst;
     KReportSectionData * m_pageFooterOdd;
     KReportSectionData * m_pageFooterEven;
     KReportSectionData * m_pageFooterLast;
     KReportSectionData * m_pageFooterAny;
 
     KReportDetailSectionData* m_detailSection;
 
 private:
     void init();
     
     friend class KReportPreRendererPrivate;
     friend class KReportPreRenderer;
 #ifdef KREPORT_SCRIPTING
     friend class KReportScriptHandler;
     friend class Scripting::Report;
 #endif
     
     //! TODO add support for labels
     QString labelType() const;
     void setLabelType(const QString &label);
     
     class Private;
     Private * const d;
 };
 
 #endif
diff --git a/src/common/KReportRenderObjects.cpp b/src/common/KReportRenderObjects.cpp
index afb37655..24c6ceb2 100644
--- a/src/common/KReportRenderObjects.cpp
+++ b/src/common/KReportRenderObjects.cpp
@@ -1,968 +1,968 @@
 /* This file is part of the KDE project
  * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
  * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library.  If not, see .
  */
 #include "KReportRenderObjects.h"
 #include "KReportUtils_p.h"
 
 #include "kreport_debug.h"
 
 // Helper functions
 static bool xLessThan(OROPrimitive* s1, OROPrimitive* s2)
 {
     return s1->position().x() < s2->position().x();
 }
 
 //
 // ORODocument
 //
 
 class Q_DECL_HIDDEN ORODocument::Private
 {
 public:
     Private();
     ~Private();
     QString title;
     QList pages;
     QList sections;
     KReportPrivate::PageLayout pageLayout;
 };
 
 ORODocument::Private::Private()
 {
 
 }
 
 ORODocument::Private::~Private()
 {
     qDeleteAll(pages);
     qDeleteAll(sections);
 }
 
 
 ORODocument::ORODocument(const QString& title) : d(new Private())
 {
     d->title = title;
 }
 
 ORODocument::~ORODocument()
 {
     delete d;
 }
 
 void ORODocument::setTitle(const QString &title)
 {
     d->title = title;
 }
 
 OROPage* ORODocument::page(int index)
 {
     return d->pages.value(index);
 }
 
 const OROPage * ORODocument::page(int index) const
 {
     return d->pages.value(index);
 }
 
 void ORODocument::addPage(OROPage* p)
 {
     if (p == nullptr) {
         return;
     }
 
     if (p->document() != nullptr && p->document() != this) {
         return;
     }
 
     p->setDocument(this);
     d->pages.append(p);
 }
 
 OROSection* ORODocument::section(int pnum)
 {
     return d->sections.value(pnum);
 }
 
 const OROSection * ORODocument::section(int index) const
 {
     return d->sections.value(index);
 }
 
 
 void ORODocument::addSection(OROSection* s)
 {
     if (s == nullptr)
         return;
 
     if (s->document() != nullptr && s->document() != this) {
         return;
     }
     s->setDocument(this);
     d->sections.append(s);
 }
 
 void ORODocument::setPageLayout(const QPageLayout & options)
 {
     d->pageLayout = options;
 }
 
 void ORODocument::notifyChange(int pageNo)
 {
     emit(updated(pageNo));
 }
 
 QPageLayout ORODocument::pageLayout() const
 {
     return d->pageLayout;
 }
 
 int ORODocument::pageCount() const
 {
     return d->pages.count();
 }
 
 int ORODocument::sectionCount() const
 {
     return d->sections.count();
 }
 
 QString ORODocument::title() const
 {
     return d->title;
 }
 
 void ORODocument::removePage(OROPage* page)
 {
     d->pages.removeOne(page);
     delete page;
 }
 
 void ORODocument::takePage(OROPage* page)
 {
     d->pages.removeOne(page);
 }
 
 void ORODocument::removeSection(OROSection* section)
 {
     d->sections.removeOne(section);
     delete section;
 }
 
 void ORODocument::takeSection(OROSection* section)
 {
     d->sections.removeOne(section);
 }
 
 int ORODocument::pageIndex(const OROPage* page) const
 {
     return d->pages.indexOf(const_cast(page));
 }
 
 //
 // OROPage
 //
 class Q_DECL_HIDDEN OROPage::Private
 {
 public:
     Private();
     ~Private();
     ORODocument *document;
     QList primitives;
 };
 
 OROPage::Private::Private()
 {
 }
 
 OROPage::Private::~Private()
 {
     qDeleteAll(primitives);
 }
 
 OROPage::OROPage(ORODocument * pDocument)
         : d(new Private())
 {
     d->document = pDocument;
 }
 
 OROPage::~OROPage()
 {
     if (d->document) {
         d->document->takePage(this);
     }
     delete d;
 }
 
 int OROPage::pageNumber() const
 {
     if (d->document) {
         return d->document->pageIndex(this);
     }
     return -1;
 }
 
 OROPrimitive* OROPage::primitive(int index)
 {
     return d->primitives.value(index);
 }
 
 const OROPrimitive * OROPage::primitive(int index) const
 {
     return d->primitives.value(index);
 }
 
 
 void OROPage::insertPrimitive(OROPrimitive* p, int index)
 {
     //kreportDebug() << "Adding primitive" << p->type() << "to page" << page();
     if (p == nullptr)
         return;
 
     p->setPage(this);
     if (index == -1) {
         d->primitives.append(p);
     } else {
         d->primitives.insert(index, p);
     }
 
 #if 0
 //TODO
     if (notify) {
         if (d->document) {
             d->document->notifyChange(pageNumber());
         }
     }
 #endif
 }
 
 ORODocument * OROPage::document()
 {
     return d->document;
 }
 
 const ORODocument * OROPage::document() const
 {
     return d->document;
 }
 
 int OROPage::primitiveCount() const
 {
     return d->primitives.count();
 }
 
 void OROPage::setDocument(ORODocument* doc)
 {
     d->document = doc;
 }
 
 void OROPage::removePrimitive(OROPrimitive* primitive)
 {
     d->primitives.removeOne(primitive);
     delete primitive;
 }
 
 void OROPage::takePrimitive(OROPrimitive* primitive)
 {
     d->primitives.removeOne(primitive);
 }
 
 //
 // OROSection
 //
 
 class Q_DECL_HIDDEN OROSection::Private
 {
 public:
     Private();
     ~Private();
     ORODocument * document;
     QList primitives;
     qint64 row = 0;
     int height = 0;
-    KReportSectionData::Section type = KReportSectionData::None;
+    KReportSectionData::Type type = KReportSectionData::Type::None;
     QColor backgroundColor = Qt::white;
 };
 
 OROSection::Private::Private()
 {
 
 }
 
 OROSection::Private::~Private()
 {
     qDeleteAll(primitives);
     primitives.clear();
 }
 
 OROSection::OROSection(ORODocument* doc) : d(new Private())
 {
     d->document = doc;
 }
 
 OROSection::~OROSection()
 {
     if (d->document) {
         d->document->takeSection(this);
     }
 
     delete d;
 }
 
 OROPrimitive* OROSection::primitive(int index)
 {
     return d->primitives.value(index);
 }
 
 const OROPrimitive * OROSection::primitive(int index) const
 {
     return d->primitives.value(index);
 }
 
 void OROSection::addPrimitive(OROPrimitive* primitive)
 {
     if (primitive == nullptr)
         return;
 
     d->primitives.append(primitive);
 }
 
 void OROSection::setHeight(int h)
 {
     d->height = h;
 }
 
 int OROSection::height() const
 {
     return d->height;
 }
 
 void OROSection::setBackgroundColor(const QColor& color)
 {
     d->backgroundColor = color;
 }
 
 QColor OROSection::backgroundColor() const
 {
     return d->backgroundColor;
 }
 
 void OROSection::sortPrimitives(Qt::Orientation orientation)
 {
     if (orientation == Qt::Horizontal) {
         qSort(d->primitives.begin(), d->primitives.end(), xLessThan);
     }
 }
 
 ORODocument * OROSection::document()
 {
     return d->document;
 }
 
 const ORODocument * OROSection::document() const
 {
     return d->document;
 }
 
 
 int OROSection::primitiveCount() const
 {
     return d->primitives.count();
 }
 
-void OROSection::setType(KReportSectionData::Section t)
+void OROSection::setType(KReportSectionData::Type type)
 {
-    d->type = t;
+    d->type = type;
 }
 
-KReportSectionData::Section OROSection::type() const
+KReportSectionData::Type OROSection::type() const
 {
     return d->type;
 }
 
 void OROSection::setDocument(ORODocument* doc)
 {
     d->document = doc;
 }
 
 //
 // OROPrimitive
 //
 
 class Q_DECL_HIDDEN OROPrimitive::Private
 {
 public:
     OROPage * page = nullptr;
     QPointF position;
     QSizeF size;
 };
 
 OROPrimitive::OROPrimitive()
         : d(new Private())
 {
 }
 
 OROPrimitive::~OROPrimitive()
 {
    if (d->page) {
         d->page->takePrimitive(this);
     }
 
     delete d;
 }
 
 void OROPrimitive::setPosition(const QPointF& pos)
 {
     d->position = pos;
 }
 
 void OROPrimitive::setSize(const QSizeF & s)
 {
     d->size = s;
 }
 
 OROPage * OROPrimitive::page()
 {
     return d->page;
 }
 
 const OROPage * OROPrimitive::page() const
 {
     return d->page;
 }
 
 QPointF OROPrimitive::position() const
 {
     return d->position;
 }
 
 QSizeF OROPrimitive::size() const
 {
     return d->size;
 }
 
 void OROPrimitive::setPage(OROPage* page)
 {
     d->page = page;
 }
 
 //
 // OROTextBox
 //
 
 class Q_DECL_HIDDEN OROTextBox::Private
 {
 public:
     Private();
     ~Private();
     QString text;
     KReportTextStyleData textStyle;
     KReportLineStyle lineStyle;
     Qt::Alignment alignment;
     int flags; // Qt::AlignmentFlag and Qt::TextFlag OR'd
     bool wordWrap;
     bool canGrow;
     bool requiresPostProcessing;
 
 };
 
 OROTextBox::Private::Private()
 {
     flags = 0;
     wordWrap = false;
     canGrow = false;
     requiresPostProcessing = false;
 
     lineStyle.setColor(Qt::black);
     lineStyle.setWeight(0);
     lineStyle.setPenStyle(Qt::NoPen);
 }
 
 OROTextBox::Private::~Private()
 {
 }
 
 OROTextBox::OROTextBox() : d(new Private())
 {
 
 }
 
 OROTextBox::~OROTextBox()
 {
     delete d;
 }
 
 void OROTextBox::setText(const QString & s)
 {
     d->text = s;
 }
 
 void OROTextBox::setTextStyle(const KReportTextStyleData & ts)
 {
     d->textStyle = ts;
 }
 
 void OROTextBox::setLineStyle(const KReportLineStyle & ls)
 {
     d->lineStyle = ls;
 }
 
 void OROTextBox::setFont(const QFont & f)
 {
     d->textStyle.font = f;
 }
 
 void OROTextBox::setFlags(int f)
 {
     d->flags = f;
 }
 
 bool OROTextBox::canGrow() const
 {
     return d->canGrow;
 }
 
 int OROTextBox::flags() const
 {
     return d->flags;
 }
 
 KReportLineStyle OROTextBox::lineStyle() const
 {
     return d->lineStyle;
 }
 
 bool OROTextBox::requiresPostProcessing() const
 {
     return d->requiresPostProcessing;
 }
 
 void OROTextBox::setCanGrow(bool grow)
 {
     d->canGrow = grow;
 }
 
 void OROTextBox::setRequiresPostProcessing(bool pp)
 {
     d->requiresPostProcessing = pp;
 }
 
 void OROTextBox::setWordWrap(bool ww)
 {
     d->wordWrap = ww;
 }
 
 QString OROTextBox::text() const
 {
     return d->text;
 }
 
 KReportTextStyleData OROTextBox::textStyle() const
 {
     return d->textStyle;
 }
 
 bool OROTextBox::wordWrap() const
 {
     return d->wordWrap;
 }
 
 OROPrimitive* OROTextBox::clone() const
 {
     OROTextBox *theClone = new OROTextBox();
     theClone->setSize(size());
     theClone->setPosition(position());
     theClone->setText(text());
     theClone->setTextStyle(textStyle());
     theClone->setLineStyle(lineStyle());
     theClone->setFlags(flags());
     theClone->setCanGrow(canGrow());
     theClone->setWordWrap(wordWrap());
     theClone->setRequiresPostProcessing(requiresPostProcessing());
     return theClone;
 }
 
 
 //
 // OROLine
 //
 
 class Q_DECL_HIDDEN OROLine::Private
 {
 public:
     QPointF endPoint;
     KReportLineStyle lineStyle;
 };
 
 OROLine::OROLine() : d(new Private())
 {
 
 }
 
 OROLine::~OROLine()
 {
     delete d;
 }
 
 void OROLine::setStartPoint(const QPointF & p)
 {
     setPosition(p);
 }
 
 void OROLine::setEndPoint(const QPointF & p)
 {
     d->endPoint = p;
 }
 
 void OROLine::setLineStyle(const KReportLineStyle& style)
 {
     d->lineStyle = style;
 }
 
 QPointF OROLine::endPoint() const
 {
     return d->endPoint;
 }
 
 KReportLineStyle OROLine::lineStyle() const
 {
     return d->lineStyle;
 }
 
 OROPrimitive* OROLine::clone() const
 {
     OROLine *theClone = new OROLine();
     theClone->setStartPoint(position());
     theClone->setEndPoint(endPoint());
     theClone->setLineStyle(lineStyle());
     return theClone;
 }
 
 //
 // OROImage
 //
 
 class Q_DECL_HIDDEN OROImage::Private
 {
 public:
     QImage image;
     bool scaled;
     Qt::TransformationMode transformFlags;
     Qt::AspectRatioMode aspectFlags;
 };
 
 OROImage::OROImage() : d(new Private())
 {
     d->scaled = false;
     d->transformFlags = Qt::FastTransformation;
     d->aspectFlags = Qt::IgnoreAspectRatio;
 }
 
 OROImage::~OROImage()
 {
     delete d;
 }
 
 void OROImage::setImage(const QImage & img)
 {
     d->image = img;
 }
 
 void OROImage::setScaled(bool b)
 {
     d->scaled = b;
 }
 
 void OROImage::setTransformationMode(Qt::TransformationMode transformation)
 {
     d->transformFlags = transformation;
 }
 
 void OROImage::setAspectRatioMode(Qt::AspectRatioMode aspectRatioMode)
 {
     d->aspectFlags = aspectRatioMode;
 }
 
 Qt::AspectRatioMode OROImage::aspectRatioMode() const
 {
     return d->aspectFlags;
 }
 
 QImage OROImage::image() const
 {
     return d->image;
 }
 
 bool OROImage::isScaled() const
 {
     return d->scaled;
 }
 
 Qt::TransformationMode OROImage::transformationMode() const
 {
     return d->transformFlags;
 }
 
 OROPrimitive* OROImage::clone() const
 {
     OROImage *theClone = new OROImage();
     theClone->setSize(size());
     theClone->setPosition(position());
     theClone->setImage(image());
     theClone->setScaled(isScaled());
     theClone->setTransformationMode(transformationMode());
     theClone->setAspectRatioMode(aspectRatioMode());
     return theClone;
 }
 
 //
 // OROPicture
 //
 
 class Q_DECL_HIDDEN OROPicture::Private
 {
 public:
     QPicture picture;
 };
 
 OROPicture::OROPicture() : d(new Private())
 {
 
 }
 
 OROPicture::~OROPicture()
 {
     delete d;
 }
 
 OROPrimitive* OROPicture::clone() const
 {
     OROPicture *theClone = new OROPicture();
     theClone->setSize(size());
     theClone->setPosition(position());
 //     theClone->setPicture(*(picture()ddddddds));
     return theClone;
 }
 
 QPicture* OROPicture::picture()
 {
     return &d->picture;
 }
 
 void OROPicture::setPicture(const QPicture& p)
 {
     d->picture = p;
 }
 
 //
 // ORORect
 //
 
 class Q_DECL_HIDDEN ORORect::Private
 {
 public:
     QPen pen;
     QBrush brush;
 };
 
 ORORect::ORORect() : d(new Private())
 {
 }
 
 ORORect::~ORORect()
 {
     delete d;
 }
 
 void ORORect::setRect(const QRectF & r)
 {
     setPosition(r.topLeft());
     setSize(r.size());
 }
 
 void ORORect::setPen(const QPen & p)
 {
     d->pen = p;
 }
 
 void ORORect::setBrush(const QBrush & b)
 {
     d->brush = b;
 }
 
 QBrush ORORect::brush() const
 {
     return d->brush;
 }
 
 QPen ORORect::pen() const
 {
     return d->pen;
 }
 
 QRectF ORORect::rect() const
 {
     return QRectF(position(), size());
 }
 
 OROPrimitive* ORORect::clone() const
 {
     ORORect *theClone = new ORORect();
     theClone->setSize(size());
     theClone->setPosition(position());
     theClone->setPen(pen());
     theClone->setBrush(brush());
     return theClone;
 }
 //
 // OROEllipse
 //
 
 class Q_DECL_HIDDEN OROEllipse::Private
 {
 public:
     QPen pen;
     QBrush brush;
 };
 
 OROEllipse::OROEllipse() : d(new Private())
 {
 }
 
 OROEllipse::~OROEllipse()
 {
     delete d;
 }
 
 void OROEllipse::setRect(const QRectF & r)
 {
     setPosition(r.topLeft());
     setSize(r.size());
 }
 
 void OROEllipse::setPen(const QPen & p)
 {
     d->pen = p;
 }
 
 void OROEllipse::setBrush(const QBrush & b)
 {
     d->brush = b;
 }
 
 QBrush OROEllipse::brush() const
 {
     return d->brush;
 }
 
 QPen OROEllipse::pen() const
 {
     return d->pen;
 }
 
 QRectF OROEllipse::rect() const
 {
     return QRectF(position(), size());
 }
 
 OROPrimitive* OROEllipse::clone() const
 {
     OROEllipse *theClone = new OROEllipse();
     theClone->setSize(size());
     theClone->setPosition(position());
     theClone->setPen(pen());
     theClone->setBrush(brush());
     return theClone;
 }
 
 //
 // OROCheck
 //
 
 class Q_DECL_HIDDEN OROCheckBox::Private
 {
 public:
     OROCheckBox::Type checkType;
     bool value;
     KReportLineStyle lineStyle;
     QColor foregroundColor;
 };
 
 OROCheckBox::OROCheckBox() : d(new Private())
 {
     d->value = false;
 }
 
 OROCheckBox::~OROCheckBox()
 {
     delete d;
 }
 
 OROCheckBox::Type OROCheckBox::checkType() const
 {
     return d->checkType;
 }
 
 QColor OROCheckBox::foregroundColor() const
 {
     return d->foregroundColor;
 }
 
 KReportLineStyle OROCheckBox::lineStyle() const
 {
     return d->lineStyle;
 }
 
 void OROCheckBox::setForegroundColor(const QColor& fg)
 {
     d->foregroundColor = fg;
 }
 
 void OROCheckBox::setLineStyle(const KReportLineStyle& ls)
 {
     d->lineStyle = ls;
 }
 
 void OROCheckBox::setValue(bool v)
 {
     d->value = v;
 }
 
 bool OROCheckBox::value() const
 {
     return d->value;
 }
 
 void OROCheckBox::setCheckType(Type type)
 {
-    if (type == Cross || type == Tick || type == Dot) {
+    if (type == Type::Cross || type == Type::Tick || type == Type::Dot) {
         d->checkType = type;
     } else {
-        d->checkType = Cross;
+        d->checkType = Type::Cross;
     }
 }
 
 OROPrimitive* OROCheckBox::clone() const
 {
     OROCheckBox *theClone = new OROCheckBox();
     theClone->setSize(size());
     theClone->setPosition(position());
     theClone->setLineStyle(lineStyle());
     theClone->setForegroundColor(foregroundColor());
     theClone->setValue(value());
     theClone->setCheckType(checkType());
     return theClone;
 }
diff --git a/src/common/KReportRenderObjects.h b/src/common/KReportRenderObjects.h
index afb4de50..2ef50771 100644
--- a/src/common/KReportRenderObjects.h
+++ b/src/common/KReportRenderObjects.h
@@ -1,462 +1,462 @@
 /* This file is part of the KDE project
  * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
  * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library.  If not, see .
  */
 #ifndef KREPORTRENDEROBJECTS_H
 #define KREPORTRENDEROBJECTS_H
 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 
 #include "KReportDataSource.h"
 #include "KReportItemBase.h"
 #include "KReportSectionData.h"
 #include "KReportLineStyle.h"
 
 class ORODocument;
 class OROPage;
 class OROPrimitive;
 class OROTextBox;
 class OROLine;
 class OROImage;
 class OROSection;
 
 //
 // ORODocument
 // This object is a single document containing one or more OROPage elements
 //
 class KREPORT_EXPORT ORODocument : public QObject
 {
     Q_OBJECT
 
 public:
     explicit ORODocument(const QString &title = QString());
     ~ORODocument() override;
 
     QString title() const;
     void setTitle(const QString &title);
 
     
     /**
      * @brief Return the total number of pages in the document
      * 
      */
     int pageCount() const;
     
     /**
      * @brief Return a pointer to a given page
      * 
      * @param index page number to find
      * @return OROPage*
      */
     OROPage* page(int index);
     const OROPage* page(int index) const;
     
     /**
      * @brief Adds the supplied page to this document
      * 
      * Ownership of the page is tranferred the document
      * 
      * @param page an OROPage* to be added
      */
     void addPage(OROPage* page);
     
     /**
      * @brief Returns the index of the supplied page in the document
      * 
      * @param page OROPage* to find
      * @return int page index
      */
     int pageIndex(const OROPage* page) const;
     
     /**
      * @brief Removes the given page from the document
      * 
      * The page is also deleted
      * 
      * @param page OROPage* to delete
      */
     void removePage(OROPage* page);
 
     /**
      * @brief Takes the page from the document but does not delete it
      * 
      * @param page OROPage* to take from the document
      */
     void takePage(OROPage *page);
     
     /**
      * @brief Return the total number of sections in the document
      * 
      */
     int sectionCount() const;
     
     /**
      * @brief Return a pointer to a given section
      * 
      * @param index section number to find
      * @return OROSection*
      */
     OROSection* section(int index);
     const OROSection* section(int index) const;
     
     /**
      * @brief Adds the supplied sectin to the document
      * 
      * Ownership of the section is transferred to the document
      * 
      * @param section OROSection* to add to the document
      */
     void addSection(OROSection* section);
     
     /**
      * @brief Removes the supplied section from the document
      * 
      * The section will also be deleted
      * 
      * @param section OROSection* to remove and delete
      */
     void removeSection(OROSection *section);
     
     /**
      * @brief Takes the section from the document but does not delete it
      * 
      * @param page OROSection* to take from the document
      */
     void takeSection(OROSection *section);
     
     void setPageLayout(const QPageLayout &layout);
     QPageLayout pageLayout() const;
 
     void notifyChange(int pageNo);
     
 Q_SIGNALS:
     void updated(int pageNo);
     
 private:
     class Private;
     Private * const d;
 };
 
 //
 // OROPage
 // This object is a single page in a document and may contain zero or more
 // OROPrimitive objects all of which represent some form of mark to made on
 // a page.
 //
 class KREPORT_EXPORT OROPage
 {
 public:
     explicit OROPage(ORODocument * doc = nullptr);
     ~OROPage();
 
     ORODocument* document();
     const ORODocument* document() const;
     void setDocument(ORODocument *doc);
     
     int pageNumber() const; // returns this pages current page number
 
     int primitiveCount() const;
     
     OROPrimitive* primitive(int index);
     const OROPrimitive* primitive(int index) const;
     
     void insertPrimitive(OROPrimitive* primitive, int index = -1);
     void removePrimitive(OROPrimitive *primitive);
     void takePrimitive(OROPrimitive *primitive);
 
 private:
     class Private;
     Private * const d;
 };
 //
 // OROSection
 // This object is a single row in a document and may contain zero or more
 // OROPrimitives
 //
 class KREPORT_EXPORT OROSection
 {
 public:
     explicit OROSection(ORODocument* doc = nullptr);
     ~OROSection();
 
     void setHeight(int);
     int height() const;
 
     void setBackgroundColor(const QColor& color);
     QColor backgroundColor() const;
 
     ORODocument* document();
     const ORODocument* document() const;
     void setDocument(ORODocument *doc);
 
-    void setType(KReportSectionData::Section t);
-    KReportSectionData::Section type() const;
+    void setType(KReportSectionData::Type type);
+    KReportSectionData::Type type() const;
 
     int primitiveCount() const;
     OROPrimitive* primitive(int index);
     const OROPrimitive* primitive(int index) const;
     void addPrimitive(OROPrimitive* primitive);
     void sortPrimitives(Qt::Orientation orientation);
 
 private:
     class Private;
     Private * const d;
 };
 
 
 //
 // OROPrimitive
 // This object represents the basic primitive with a position and type.
 // Other primitives are subclasses with a defined type and any additional
 // information they require to define that primitive.
 //
 class KREPORT_EXPORT OROPrimitive
 {
 public:
     virtual ~OROPrimitive();
 
     OROPage* page();
     const OROPage* page() const;
     void setPage(OROPage *page);
 
     QPointF position() const;
     void setPosition(const QPointF &pos);
     
     QSizeF size() const;
     void setSize(const QSizeF &s);
 
     virtual OROPrimitive* clone() const = 0;
     
 protected:
     OROPrimitive();
     
 private:
     class Private;
     Private * const d;
 };
 
 //
 // OROTextBox
 // This is a text box primitive it defines a box region and text that will
 // be rendered inside that region. It also contains information for font
 // and positioning of the text.
 //
 class KREPORT_EXPORT OROTextBox : public OROPrimitive
 {
 public:
     OROTextBox();
     ~OROTextBox() override;
 
     QString text() const;
     void setText(const QString &text);
 
     KReportTextStyleData textStyle() const;
     void setTextStyle(const KReportTextStyleData&);
 
     KReportLineStyle lineStyle() const;
     void setLineStyle(const KReportLineStyle&);
 
     void setFont(const QFont &font);
 
     int flags() const;
     void setFlags(int flags);
 
     OROPrimitive* clone() const override;
 
     bool requiresPostProcessing() const;
     void setRequiresPostProcessing(bool pp);
 
     bool wordWrap() const;
     void setWordWrap(bool ww);
 
     bool canGrow() const;
     void setCanGrow(bool grow);
     
 private:
     class Private;
     Private * const d;
 };
 
 //
 // OROLine
 // This primitive defines a line with a width/weight.
 //
 class KREPORT_EXPORT OROLine : public OROPrimitive
 {
 public:
     OROLine();
     ~OROLine() override;
 
     QPointF startPoint() const {
         return position();
     };
     void setStartPoint(const QPointF &start);
 
     QPointF endPoint() const;
     void setEndPoint(const QPointF &end);
 
     KReportLineStyle lineStyle() const;
     void setLineStyle(const KReportLineStyle& style);
 
     OROPrimitive* clone() const override;
     
 private:
     class Private;
     Private * const d;
 };
 
 //
 // OROImage
 // This primitive defines an image
 //
 class KREPORT_EXPORT OROImage: public OROPrimitive
 {
 public:
     OROImage();
     ~OROImage() override;
 
     QImage image() const;
     void setImage(const QImage &img);
 
     bool isScaled() const;
     void setScaled(bool scaled);
 
     Qt::TransformationMode transformationMode() const;
     void setTransformationMode(Qt::TransformationMode transformation);
 
     Qt::AspectRatioMode aspectRatioMode() const;
     void setAspectRatioMode(Qt::AspectRatioMode aspect);
 
     OROPrimitive* clone() const override;
     
 private:
     class Private;
     Private * const d;
 };
 
 //
 // OROPicture
 // This primitive defines a picture
 //
 class KREPORT_EXPORT OROPicture: public OROPrimitive
 {
 public:
     OROPicture();
     ~OROPicture() override;
 
     void setPicture(const QPicture& pic);
     QPicture* picture();
 
     OROPrimitive* clone() const override;
     
 private:
     class Private;
     Private * const d;
 
 };
 //
 // ORORect
 // This primitive defines a drawn rectangle
 //
 class KREPORT_EXPORT ORORect: public OROPrimitive
 {
 public:
     ORORect();
     ~ORORect() override;
 
     QRectF rect() const;
     void setRect(const QRectF &rectangle);
 
     QPen pen() const;
     void setPen(const QPen &pen);
 
     QBrush brush() const;
     void setBrush(const QBrush &brush);
 
     OROPrimitive* clone() const override;
     
 private:
     class Private;
     Private * const d;
 };
 
 //
 // ORORect
 // This primitive defines a drawn rectangle
 //
 class KREPORT_EXPORT OROEllipse: public OROPrimitive
 {
 public:
     OROEllipse();
     ~OROEllipse() override;
 
     QRectF rect() const;
     void setRect(const QRectF &rectangle);
 
     QPen pen() const;
     void setPen(const QPen &pen);
 
     QBrush brush() const;
     void setBrush(const QBrush &brush);
 
     OROPrimitive* clone() const override;
     
 private:
     class Private;
     Private * const d;
 };
 
 class KREPORT_EXPORT OROCheckBox : public OROPrimitive
 {
 public:
-    enum Type {
-        Cross = 1,
+    enum class Type {
+        Cross,
         Tick,
         Dot
     };
     
     OROCheckBox();
     ~OROCheckBox() override;
     OROPrimitive* clone() const override;
 
     void setCheckType(Type type);
     Type checkType() const;
 
     void setValue(bool val);
     bool value() const;
 
     void setLineStyle(const KReportLineStyle& ls);
     KReportLineStyle lineStyle() const;
     
     void setForegroundColor(const QColor& fg);
     QColor foregroundColor() const;
 
 private:
     class Private;
     Private * const d;
 
 };
 
 #endif // __RENDEROBJECTS_H__
diff --git a/src/common/KReportSection.shared.h b/src/common/KReportSection.shared.h
index 0ebe256c..1ba2ac16 100644
--- a/src/common/KReportSection.shared.h
+++ b/src/common/KReportSection.shared.h
@@ -1,132 +1,132 @@
 /* This file is part of the KDE project
  * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
  * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
  * Copyright (C) 2010-2015 Jarosław Staniek 
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library.  If not, see .
  */
 
 #ifndef KREPORTSECTION_H
 #define KREPORTSECTION_H
 
 #include 
 #include 
 #include 
 
 //! @brief The KReportSection class represents a section of a report design
 /*! A section has optional report header, report footer, page header, page footer,
     group header, group footer and detail.
     In the case of page header and page footer it is possible to define (firstpage, odd, even or lastpage). */
 class KREPORT_EXPORT KReportSection //SDC: explicit operator== virtual_dtor custom_clone
 {
     Q_DECLARE_TR_FUNCTIONS(KReportSection)
 public:
-    enum Type {
-        InvalidType = 0,
-        PageHeaderFirst = 1,
+    enum class Type {
+        Invalid,
+        PageHeaderFirst,
         PageHeaderOdd,
         PageHeaderEven,
         PageHeaderLast,
         PageHeaderAny,
         ReportHeader,
         ReportFooter,
         PageFooterFirst,
         PageFooterOdd,
         PageFooterEven,
         PageFooterLast,
         PageFooterAny,
         GroupHeader,
         GroupFooter,
         Detail
     };
 
     /*!
     @getter
     @return section type
-    Default section type is InvalidType.
+    Default section type is Invalid.
     @setter
     Sets section type.
     */
-    KReportSection::Type type;  //SDC: default=KReportSection::InvalidType simple_type
+    KReportSection::Type type;  //SDC: default=KReportSection::Type::Invalid simple_type
 
     /*!
     @getter
     @return section height measured in points
     It is equal to KReportSection::defaultHeight() unless setHeight()
     is called with value > 0.
     @setter
     Sets section height measured in points.
     Set negative value to reset to the default height.
     */
     qreal height; //SDC: default=-1 custom_getter
 
     /*!
     @getter
     @return section background color
     It is equal to KReportSection::defaultBackgroundColor() unless setBackgroundColor()
     is called with a valid color.
     @setter
     Sets section background color.
     Set invalid color (QColor()) to reset to the default background color.
     */
     QColor backgroundColor;  //SDC: custom_getter
 
     /*!
     @getter
     @return all elements of this section
     */
     QList elements;  //SDC: custom_getter no_setter
 
     /*!
     @internal A set that helps to quickly check if element is part of the section.
     */
     QSet elementsSet; //SDC: internal
 
     //! Adds element @a element to this section.
     //! @return true on success.
     //! Adding fails if element is already added to this or other section.
     //! Use KReportElement::clone() to add a copy.
     bool addElement(const KReportElement &element);
 
     //! Adds element @a element to this section at index position @a i.
     //! @return true on success.
     //! Adding fails if element is already added to this or other section or if
     //! position @a i is out of bounds.
     //! Use KReportElement::clone() to add a copy.
     bool insertElement(int i, const KReportElement &element);
 
     //! Removes element @a element from this section.
     //! @return true on success.
     //! Removing fails if element @a element is not added in this section.
     bool removeElement(const KReportElement &element);
 
     //! Removes element from index position @a i from this section.
     //! @return true on success.
     //! Removing fails position @a i is out of bounds.
     bool removeElementAt(int i);
 
     //! @return default height for report sections. The standard is 2cm (converted to points).
     static qreal defaultHeight();
 
     //! Sets default height for report sections in points.
     static void setDefaultHeight(qreal height);
 
     //! @return default background color for report sections. The standard is white.
     static QColor defaultBackgroundColor();
 
     //! Sets default background color for report sections.
     static void setDefaultBackgroundColor(const QColor &color);
 };
 
 #endif // KREPORTSECTION_H
diff --git a/src/common/KReportSectionData.cpp b/src/common/KReportSectionData.cpp
index 67393878..c0500972 100644
--- a/src/common/KReportSectionData.cpp
+++ b/src/common/KReportSectionData.cpp
@@ -1,216 +1,216 @@
 /* This file is part of the KDE project
  * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
  * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
  * Copyright (C) 2010 Jarosław Staniek 
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library.  If not, see .
  */
 
 #include "KReportSectionData.h"
 #include "KReportDocument.h"
 #include "KReportPluginInterface.h"
 #include "KReportPluginManager.h"
 #include "KReportItemLine.h"
 #include "KReportDesigner.h"
 #include "kreport_debug.h"
 
 #include 
 
 #include 
 
 KReportSectionData::KReportSectionData(QObject* parent)
  : QObject(parent)
 {
     createProperties(QDomElement());
 }
 
 KReportSectionData::KReportSectionData(const QDomElement & elemSource, KReportDocument* report)
  : QObject(report)
 {
     setObjectName(elemSource.tagName());
 
     m_type = sectionTypeFromString(elemSource.attribute(QLatin1String("report:section-type")));
     createProperties(elemSource);
-    if (objectName() != QLatin1String("report:section") || m_type == KReportSectionData::None) {
+    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:"))) {
             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);
                     }
                     continue;
                 }
             }
         }
         kreportWarning() << "While parsing section encountered an unknown element: " << n;
     }
     qSort(m_objects.begin(), m_objects.end(), zLessThan);
     m_valid = true;
 }
 
 KReportSectionData::~KReportSectionData()
 {
     delete m_set;
     qDeleteAll(m_objects);
 }
 
 bool KReportSectionData::zLessThan(KReportItemBase* s1, KReportItemBase* s2)
 {
     return s1->z() < s2->z();
 }
 
 bool KReportSectionData::xLessThan(KReportItemBase* s1, KReportItemBase* s2)
 {
     return s1->position().toPoint().x() < s2->position().toPoint().x();
 }
 
 void KReportSectionData::createProperties(const QDomElement & elemSource)
 {
     m_set = new KPropertySet(this);
     KReportDesigner::addMetaProperties(m_set,
         tr("Section", "Report section"), QLatin1String("kreport-section-element"));
 
     m_height = new KProperty("height", KReportUnit(KReportUnit::Centimeter).fromUserValue(2.0), tr("Height"));
     m_backgroundColor = new KProperty("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);
 }
 
 QString KReportSectionData::name() const
 {
     return (objectName() + QLatin1Char('-') + sectionTypeString(m_type));
 }
 
-QString KReportSectionData::sectionTypeString(KReportSectionData::Section s)
+QString KReportSectionData::sectionTypeString(KReportSectionData::Type type)
 {
 //! @todo use QMap
     QString sectiontype;
-    switch (s) {
-    case KReportSectionData::PageHeaderAny:
+    switch (type) {
+    case KReportSectionData::Type::PageHeaderAny:
         sectiontype = QLatin1String("header-page-any");
         break;
-    case KReportSectionData::PageHeaderEven:
+    case KReportSectionData::Type::PageHeaderEven:
         sectiontype = QLatin1String("header-page-even");
         break;
-    case KReportSectionData::PageHeaderOdd:
+    case KReportSectionData::Type::PageHeaderOdd:
         sectiontype = QLatin1String("header-page-odd");
         break;
-    case KReportSectionData::PageHeaderFirst:
+    case KReportSectionData::Type::PageHeaderFirst:
         sectiontype = QLatin1String("header-page-first");
         break;
-    case KReportSectionData::PageHeaderLast:
+    case KReportSectionData::Type::PageHeaderLast:
         sectiontype = QLatin1String("header-page-last");
         break;
-    case KReportSectionData::PageFooterAny:
+    case KReportSectionData::Type::PageFooterAny:
         sectiontype = QLatin1String("footer-page-any");
         break;
-    case KReportSectionData::PageFooterEven:
+    case KReportSectionData::Type::PageFooterEven:
         sectiontype = QLatin1String("footer-page-even");
         break;
-    case KReportSectionData::PageFooterOdd:
+    case KReportSectionData::Type::PageFooterOdd:
         sectiontype = QLatin1String("footer-page-odd");
         break;
-    case KReportSectionData::PageFooterFirst:
+    case KReportSectionData::Type::PageFooterFirst:
         sectiontype = QLatin1String("footer-page-first");
         break;
-    case KReportSectionData::PageFooterLast:
+    case KReportSectionData::Type::PageFooterLast:
         sectiontype = QLatin1String("footer-page-last");
         break;
-    case KReportSectionData::ReportHeader:
+    case KReportSectionData::Type::ReportHeader:
         sectiontype = QLatin1String("header-report");
         break;
-    case KReportSectionData::ReportFooter:
+    case KReportSectionData::Type::ReportFooter:
         sectiontype = QLatin1String("footer-report");
         break;
-    case KReportSectionData::GroupHeader:
+    case KReportSectionData::Type::GroupHeader:
         sectiontype = QLatin1String("group-header");
         break;
-    case KReportSectionData::GroupFooter:
+    case KReportSectionData::Type::GroupFooter:
         sectiontype = QLatin1String("group-footer");
         break;
-    case KReportSectionData::Detail:
+    case KReportSectionData::Type::Detail:
         sectiontype = QLatin1String("detail");
         break;
     default:
-        ;
+        break;
     }
 
     return sectiontype;
 }
 
-KReportSectionData::Section KReportSectionData::sectionTypeFromString(const QString& s)
+KReportSectionData::Type KReportSectionData::sectionTypeFromString(const QString& s)
 {
 //! @todo use QMap
-    KReportSectionData::Section sec;
+    KReportSectionData::Type type;
     //kreportDebug() << "Determining section type for " << s;
     if (s == QLatin1String("header-page-any"))
-        sec = KReportSectionData::PageHeaderAny;
+        type = KReportSectionData::Type::PageHeaderAny;
     else if (s == QLatin1String("header-page-even"))
-        sec = KReportSectionData::PageHeaderEven;
+        type = KReportSectionData::Type::PageHeaderEven;
     else if (s == QLatin1String("header-page-odd"))
-        sec = KReportSectionData::PageHeaderOdd;
+        type = KReportSectionData::Type::PageHeaderOdd;
     else if (s == QLatin1String("header-page-first"))
-        sec = KReportSectionData::PageHeaderFirst;
+        type = KReportSectionData::Type::PageHeaderFirst;
     else if (s == QLatin1String("header-page-last"))
-        sec = KReportSectionData::PageHeaderLast;
+        type = KReportSectionData::Type::PageHeaderLast;
     else if (s == QLatin1String("header-report"))
-        sec = KReportSectionData::ReportHeader;
+        type = KReportSectionData::Type::ReportHeader;
     else if (s == QLatin1String("footer-page-any"))
-        sec = KReportSectionData::PageFooterAny;
+        type = KReportSectionData::Type::PageFooterAny;
     else if (s == QLatin1String("footer-page-even"))
-        sec = KReportSectionData::PageFooterEven;
+        type = KReportSectionData::Type::PageFooterEven;
     else if (s == QLatin1String("footer-page-odd"))
-        sec = KReportSectionData::PageFooterOdd;
+        type = KReportSectionData::Type::PageFooterOdd;
     else if (s == QLatin1String("footer-page-first"))
-        sec = KReportSectionData::PageFooterFirst;
+        type = KReportSectionData::Type::PageFooterFirst;
     else if (s == QLatin1String("footer-page-last"))
-        sec = KReportSectionData::PageFooterLast;
+        type = KReportSectionData::Type::PageFooterLast;
     else if (s == QLatin1String("footer-report"))
-        sec = KReportSectionData::ReportFooter;
+        type = KReportSectionData::Type::ReportFooter;
     else if (s == QLatin1String("group-header"))
-        sec = KReportSectionData::GroupHeader;
+        type = KReportSectionData::Type::GroupHeader;
     else if (s == QLatin1String("group-footer"))
-        sec = KReportSectionData::GroupFooter;
+        type = KReportSectionData::Type::GroupFooter;
     else if (s == QLatin1String("detail"))
-        sec = KReportSectionData::Detail;
+        type = KReportSectionData::Type::Detail;
     else
-        sec = KReportSectionData::None;
+        type = KReportSectionData::Type::None;
 
-    return sec;
+    return type;
 }
diff --git a/src/common/KReportSectionData.h b/src/common/KReportSectionData.h
index 84f7a278..fe3cc9a9 100644
--- a/src/common/KReportSectionData.h
+++ b/src/common/KReportSectionData.h
@@ -1,119 +1,119 @@
 /* This file is part of the KDE project
  * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
  * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
  * Copyright (C) 2010 Jarosław Staniek 
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library.  If not, see .
  */
 
 
 #ifndef KREPORTSECTIONDATA_H
 #define KREPORTSECTIONDATA_H
 
 #include 
 
 #include 
 
 class KReportItemBase;
 class KReportDocument;
 class QDomElement;
 
 namespace Scripting
 {
 class Section;
 }
 
 //
 // KReportSectionData is used to store the information about a specific
 // section.
 // A section has a name and optionally extra data. `name'
 // reportheader, reportfooter, pageheader, pagefooter, groupheader, groupfooter or detail.
 // In the case of pghead and pgfoot extra would contain the page
 // designation (firstpage, odd, even or lastpage).
 class KReportSectionData : public QObject
 {
     Q_OBJECT
 public:
-    enum Section {
-        None = 0,
-        PageHeaderFirst = 1,
+    enum class Type {
+        None,
+        PageHeaderFirst,
         PageHeaderOdd,
         PageHeaderEven,
         PageHeaderLast,
         PageHeaderAny,
         ReportHeader,
         ReportFooter,
         PageFooterFirst,
         PageFooterOdd,
         PageFooterEven,
         PageFooterLast,
         PageFooterAny,
         GroupHeader,
         GroupFooter,
         Detail
     };
 
     explicit KReportSectionData(QObject* parent = nullptr);
     KReportSectionData(const QDomElement &, KReportDocument* report);
     ~KReportSectionData() override;
     KPropertySet* propertySet() const {
         return m_set;
     }
 
     bool isValid() const {
         return m_valid;
     }
 
     qreal height() const {
         return m_height->value().toDouble();
     }
 
     QList objects() const {
         return m_objects;
     }
 
     QString name() const;
 
     QColor backgroundColor() const {
         return m_backgroundColor->value().value();
     }
 
-    Section type() const {
+    Type type() const {
         return m_type;
     }
 
-    static KReportSectionData::Section sectionTypeFromString(const QString& s);
-    static QString sectionTypeString(KReportSectionData::Section s);
+    static KReportSectionData::Type sectionTypeFromString(const QString& s);
+    static QString sectionTypeString(KReportSectionData::Type type);
 protected:
     KPropertySet *m_set;
     KProperty *m_height;
     KProperty *m_backgroundColor;
 
 private:
     void createProperties(const QDomElement & elemSource);
 
     QList m_objects;
 
-    Section m_type;
+    Type m_type;
 
     static bool zLessThan(KReportItemBase* s1, KReportItemBase* s2);
     static bool xLessThan(KReportItemBase* s1, KReportItemBase* s2);
 
     bool m_valid;
 
     friend class Scripting::Section;
     friend class KReportDesignerSection;
 };
 
 #endif
diff --git a/src/items/check/KReportItemCheck.cpp b/src/items/check/KReportItemCheck.cpp
index 62cc6b9e..feb53488 100644
--- a/src/items/check/KReportItemCheck.cpp
+++ b/src/items/check/KReportItemCheck.cpp
@@ -1,194 +1,194 @@
 /* This file is part of the KDE project
  * Copyright (C) 2009-2010 by Adam Pigg (adam@piggz.co.uk)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library.  If not, see .
  */
 
 #include "KReportItemCheck.h"
 #include "KReportRenderObjects.h"
 #include "kreportplugin_debug.h"
 #ifdef KREPORT_SCRIPTING
 #include "renderer/scripting/KReportScriptHandler.h"
 #endif
 
 #include 
 
 #include 
 #include 
 
 KReportItemCheckBox::KReportItemCheckBox()
 {
     createProperties();
 }
 
 KReportItemCheckBox::KReportItemCheckBox(const QDomNode &element)
     : KReportItemCheckBox()
 {
     nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name")));
     m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source")));
     setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble());
     m_foregroundColor->setValue(QColor(element.toElement().attribute(QLatin1String("fo:foreground-color"))));
     m_checkStyle->setValue(element.toElement().attribute(QLatin1String("report:check-style")));
     m_staticValue->setValue(QVariant(element.toElement().attribute(QLatin1String("report:value"))).toBool());
 
     parseReportRect(element.toElement());
 
     QDomNodeList nl = element.childNodes();
     QString n;
     QDomNode node;
     for (int i = 0; i < nl.count(); i++) {
         node = nl.item(i);
         n = node.nodeName();
 
         if (n == QLatin1String("report:line-style")) {
             KReportLineStyle ls;
             if (parseReportLineStyleData(node.toElement(), &ls)) {
                 m_lineWeight->setValue(ls.weight());
                 m_lineColor->setValue(ls.color());
                 m_lineStyle->setValue(static_cast(ls.penStyle()));
             }
         } else {
             kreportpluginWarning() << "while parsing check element encountered unknown element: " << n;
         }
     }
 
 }
 
 KReportItemCheckBox::~KReportItemCheckBox()
 {
 }
 
 void KReportItemCheckBox::createProperties()
 {
     QStringList keys, strings;
 
     keys << QLatin1String("Cross") << QLatin1String("Tick") << QLatin1String("Dot");
     strings << tr("Cross") << tr("Tick") << tr("Dot");
     m_checkStyle = new KProperty("check-style", keys, strings, QLatin1String("Cross"), tr("Style"));
 
     m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source"));
     m_controlSource->setOption("extraValueAllowed", QLatin1String("true"));
 
     m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color"));
 
     m_lineWeight = new KProperty("line-weight", 1.0, tr("Line Weight"));
     m_lineWeight->setOption("step", 1.0);
     m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color"));
     m_lineStyle = new KProperty("line-style", static_cast(Qt::SolidLine), tr("Line Style"), QString(), KProperty::LineStyle);
     m_staticValue = new KProperty("value", QVariant(false), tr("Value"), tr("Value used if not bound to a field"));
 
     propertySet()->addProperty(m_controlSource);
     propertySet()->addProperty(m_staticValue);
     propertySet()->addProperty(m_checkStyle);
     propertySet()->addProperty(m_foregroundColor);
     propertySet()->addProperty(m_lineWeight);
     propertySet()->addProperty(m_lineColor);
     propertySet()->addProperty(m_lineStyle);
 }
 
 KReportLineStyle KReportItemCheckBox::lineStyle()
 {
     KReportLineStyle ls;
     ls.setWeight(m_lineWeight->value().toReal());
     ls.setColor(m_lineColor->value().value());
     ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt());
     return ls;
 }
 
 QString KReportItemCheckBox::itemDataSource() const
 {
     return m_controlSource->value().toString();
 }
 
 // RTTI
 QString KReportItemCheckBox::typeName() const
 {
     return QLatin1String("check");
 }
 
 int KReportItemCheckBox::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset,
                                         const QVariant &data, KReportScriptHandler *script)
 {
     OROCheckBox *chk = new OROCheckBox();
 
     chk->setPosition(scenePosition(position()) + offset);
     chk->setSize(sceneSize(size()));
 
     chk->setLineStyle(lineStyle());
     chk->setForegroundColor(m_foregroundColor->value().value());
     if (m_checkStyle->value().toString() == QLatin1String("Cross")) {
-        chk->setCheckType(OROCheckBox::Cross);
+        chk->setCheckType(OROCheckBox::Type::Cross);
     } else if (m_checkStyle->value().toString() == QLatin1String("Dot")) {
-        chk->setCheckType(OROCheckBox::Dot);
+        chk->setCheckType(OROCheckBox::Type::Dot);
     } else {
-        chk->setCheckType(OROCheckBox::Tick);
+        chk->setCheckType(OROCheckBox::Type::Tick);
     }
 
     QString str;
     bool v = false;
     QString cs = itemDataSource();
 
     //kreportpluginDebug() << "ControlSource:" << cs;
     if (!cs.isEmpty()) {
 #ifdef KREPORT_SCRIPTING
         if (cs.left(1) == QLatin1String("=") && script) {
             str = script->evaluate(cs.mid(1)).toString();
         } else
 #else
         Q_UNUSED(script);
 #endif
         {
             str = data.toString();
         }
 
         str = str.toLower();
 
         //kreportpluginDebug() << "Check Value:" << str;
         if (str == QLatin1String("t") || str == QLatin1String("y") || str == QLatin1String("true") || str == QLatin1String("1"))
             v = true;
 
     } else {
         v = value();
     }
 
     chk->setValue(v);
 
     if (page) {
         page->insertPrimitive(chk);
     }
 
     if (section) {
         OROCheckBox *chk2 = dynamic_cast(chk->clone());
         if (chk2) {
             chk2->setPosition(scenePosition(position()));
             section->addPrimitive(chk2);
         }
     }
 
     if (!page) {
         delete chk;
     }
 
     return 0; //Item doesn't stretch the section height
 }
 
 bool KReportItemCheckBox::value() const
 {
     return m_staticValue->value().toBool();
 }
 
 void KReportItemCheckBox::setValue(bool v)
 {
     m_staticValue->setValue(v);
 }
diff --git a/src/renderer/KReportHTMLCSSRenderer_p.cpp b/src/renderer/KReportHTMLCSSRenderer_p.cpp
index 50ccdd5a..f3798740 100644
--- a/src/renderer/KReportHTMLCSSRenderer_p.cpp
+++ b/src/renderer/KReportHTMLCSSRenderer_p.cpp
@@ -1,215 +1,219 @@
 /* This file is part of the KDE project
  * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
  * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library.  If not, see .
  */
 
 #include "KReportHTMLCSSRenderer_p.h"
 #include "KReportRenderObjects.h"
 #include "kreport_debug.h"
 
 #include 
 #include 
 #include 
 #include 
 
 namespace KReportPrivate {
   
 HTMLCSSRenderer::HTMLCSSRenderer()
 {
 
 }
 
 HTMLCSSRenderer::~HTMLCSSRenderer()
 {
 
 }
 
 bool HTMLCSSRenderer::render(const KReportRendererContext& context, ORODocument *document, int page)
 {
     Q_UNUSED(page);
     QTemporaryFile tempHtmlFile; // auto removed by default on destruction
     if (!tempHtmlFile.open()) {
         kreportWarning() << "Couldn't create temporary file to write into";
         return false;
     }
 
     QTextStream out(&tempHtmlFile);
 
     QString dirSuffix = QLatin1String(".files");
     QDir tempDir;
     QFileInfo fi(tempHtmlFile);
 
     QString tempFileName = fi.absoluteFilePath();
     m_tempDirName = tempFileName + dirSuffix;
     m_actualDirName = context.url().fileName() + dirSuffix;
 
     if (!tempDir.mkpath(m_tempDirName))
         return false;
 
     out << renderCSS(document);
 
     out.flush();
     tempHtmlFile.close();
 
     bool status = true; //!< @todo KIO
 //    if (KIO::NetAccess::upload(tempFileName, context.destinationUrl, 0) && KIO::NetAccess::dircopy(QUrl(m_tempDirName),  QUrl(context.destinationUrl.url() + dirSuffix), 0)) {
 //        status = true;
 //    }
 
     // cleanup the temporary directory
     tempDir.setPath(m_tempDirName);
     QStringList fileList = tempDir.entryList();
     foreach(const QString& fileName, fileList) {
         tempDir.remove(fileName);
     }
     tempDir.rmdir(m_tempDirName);
 
     return status;
 }
 
 //! @todo use QTextStream for efficiency
 QString HTMLCSSRenderer::renderCSS(ORODocument *document)
 {
     QString html;
     QString body;
     QString style;
     QStringList styles;
     int styleindex;
     bool renderedPageHead = false;
     bool renderedPageFoot = false;
 
     QDir d(m_tempDirName);
     // Render Each Section
     for (int s = 0; s < document->sectionCount(); s++) {
         OROSection *section = document->section(s);
 
-        if (section->type() == KReportSectionData::GroupHeader ||
-                section->type() == KReportSectionData::GroupFooter ||
-                section->type() == KReportSectionData::Detail ||
-                section->type() == KReportSectionData::ReportHeader ||
-                section->type() == KReportSectionData::ReportFooter ||
-                (section->type() == KReportSectionData::PageHeaderAny && !renderedPageHead) ||
-                (section->type() == KReportSectionData::PageFooterAny && !renderedPageFoot && s > document->sectionCount() - 2)) { //render the page foot right at the end, it will either be the last or second last section if there is a report footer
-            if (section->type() == KReportSectionData::PageHeaderAny)
+        if (section->type() == KReportSectionData::Type::GroupHeader
+            || section->type() == KReportSectionData::Type::GroupFooter
+            || section->type() == KReportSectionData::Type::Detail
+            || section->type() == KReportSectionData::Type::ReportHeader
+            || section->type() == KReportSectionData::Type::ReportFooter
+            || (section->type() == KReportSectionData::Type::PageHeaderAny && !renderedPageHead)
+            || (section->type() == KReportSectionData::Type::PageFooterAny && !renderedPageFoot
+                && s > document->sectionCount() - 2))
+        { // render the page foot right at the end, it
+          // will either be the last or second last
+          // section if there is a report footer
+            if (section->type() == KReportSectionData::Type::PageHeaderAny)
                 renderedPageHead = true;
 
-            if (section->type() == KReportSectionData::PageFooterAny)
+            if (section->type() == KReportSectionData::Type::PageFooterAny)
                 renderedPageFoot = true;
 
             style = QLatin1String("position: relative; top: 0pt; left: 0pt; background-color: ") + section->backgroundColor().name() + QLatin1String("; height: ") + QString::number(section->height()) + QLatin1String("pt;");
 
             if (!styles.contains(style)) {
                 styles << style;
             }
             styleindex = styles.indexOf(style);
 
             body += QLatin1String("
\n"); //Render the objects in each section for (int i = 0; i < section->primitiveCount(); i++) { OROPrimitive * prim = section->primitive(i); //kreportDebug() << "Got object type" << prim->type(); if (OROTextBox *tb = dynamic_cast(prim)) { QColor bg = tb->textStyle().backgroundColor; style = QLatin1String("position: absolute; ") + QLatin1String("background-color: ") + QString::fromLatin1("rgba(%1,%2,%3,%4)") .arg(bg.red()) .arg(bg.green()) .arg(bg.blue()) .arg(0.01 * tb->textStyle().backgroundOpacity) +QLatin1String( "; ") + QLatin1String("top: ") + QString::number(tb->position().y()) + QLatin1String("pt; ") + QLatin1String("left: ") + QString::number(tb->position().x()) + QLatin1String("pt; ") + QLatin1String("font-size: ") + QString::number(tb->textStyle().font.pointSize()) + QLatin1String("pt; ") + QLatin1String("color: ") + tb->textStyle().foregroundColor.name() + QLatin1String("; ") + QLatin1String("width: ") + QString::number(tb->size().width()) + QLatin1String("px;") + QLatin1String("height: ") + QString::number(tb->size().height()) + QLatin1String("px;") ; //! @todo opaque text + translucent background //it looks a pain to implement //http://developer.mozilla.org/en/docs/Useful_CSS_tips:Color_and_Background //style += "filter:alpha(opacity=" + QString::number((tb->textStyle().bgOpacity / 255) * 100) + ");"; //ie opacity //style += "opacity: " + QString::number(tb->textStyle().bgOpacity / 255.0) + ";"; if (!styles.contains(style)) { styles << style; } styleindex = styles.indexOf(style); body += QLatin1String("
") + tb->text() + QLatin1String("
\n"); } else if (OROImage *im = dynamic_cast(prim)) { style = QLatin1String("position: absolute; ") + QLatin1String("top: ") + QString::number(im->position().y()) + QLatin1String("pt; ") + QLatin1String("left: ") + QString::number(im->position().x()) + QLatin1String("pt; "); if (!styles.contains(style)) { styles << style; } styleindex = styles.indexOf(style); body += QLatin1String("
") + QLatin1String("size().width()) + QLatin1String("px") + QLatin1String("\" height=\"") + QString::number(im->size().height()) + QLatin1String("px") + QLatin1String("\" src=\"./") + m_actualDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png\">") + QLatin1String("
\n"); im->image().save(m_tempDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png")); } else if (OROPicture *im = dynamic_cast(prim)) { style = QLatin1String("position: absolute; ") + QLatin1String("top: ") + QString::number(im->position().y()) + QLatin1String("pt; ") + QLatin1String("left: ") + QString::number(im->position().x()) + QLatin1String("pt; "); if (!styles.contains(style)) { styles << style; } styleindex = styles.indexOf(style); body += QLatin1String("
") + QLatin1String("size().width()) + QLatin1String("px") + QLatin1String("\" height=\"") + QString::number(im->size().height()) + QLatin1String("px") + QLatin1String("\" src=\"./") + m_actualDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png\">") + QLatin1String("
\n"); QImage image(im->size().toSize(), QImage::Format_RGB32); QPainter painter(&image); im->picture()->play(&painter); image.save(m_tempDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png")); } else { kreportWarning() << "unrecognized primitive type"; } } body += QLatin1String("
\n"); } } //! @todo add option for creating separate css file html = QLatin1String("\n" "\n" "\n" "\n") + QLatin1String("") + document->title() + QLatin1String("\n") + QLatin1String("\n") + QLatin1String("\n") + QLatin1String("\n") + QLatin1String("\n") + body + QLatin1String("\n\n") + QLatin1String("\n"); return html; } } diff --git a/src/renderer/KReportHTMLTableRenderer_p.cpp b/src/renderer/KReportHTMLTableRenderer_p.cpp index 8091a1ef..182fef7f 100644 --- a/src/renderer/KReportHTMLTableRenderer_p.cpp +++ b/src/renderer/KReportHTMLTableRenderer_p.cpp @@ -1,165 +1,169 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportHTMLTableRenderer_p.h" #include "KReportRenderObjects.h" #include #include "kreport_debug.h" #include #include #include namespace KReportPrivate { HTMLTableRenderer::HTMLTableRenderer() { } HTMLTableRenderer::~HTMLTableRenderer() { } bool HTMLTableRenderer::render(const KReportRendererContext& context, ORODocument *document, int page) { Q_UNUSED(page); QTemporaryFile tempHtmlFile; // auto removed by default on destruction if (!tempHtmlFile.open()) { kreportWarning() << "Couldn't create temporary file to write into"; return false; } QTextStream out(&tempHtmlFile); QString dirSuffix = QLatin1String(".files"); QDir tempDir; QFileInfo fi(tempHtmlFile); QString tempFileName = fi.absoluteFilePath(); m_tempDirName = tempFileName + dirSuffix; m_actualDirName = context.url().fileName() + dirSuffix; if (!tempDir.mkpath(m_tempDirName)) return false; out << renderTable(document); out.flush(); tempHtmlFile.close(); bool status = true; //! @todo port KIO; // if (KIO::NetAccess::upload(tempFileName, context.destinationUrl, 0) && KIO::NetAccess::dircopy(QUrl(m_tempDirName), QUrl(context.destinationUrl.url() + dirSuffix), 0)) { // status = true; // } // cleanup the temporary directory tempDir.setPath(m_tempDirName); QStringList fileList = tempDir.entryList(); foreach(const QString& fileName, fileList) { tempDir.remove(fileName); } tempDir.rmdir(m_tempDirName); return status; } QString HTMLTableRenderer::renderTable(ORODocument *document) { QString html; QString body; QString tr; bool renderedPageHeader = false; bool renderedPageFooter = false; QDir d(m_tempDirName); // Render Each Section body = QLatin1String("\n"); for (int s = 0; s < document->sectionCount(); s++) { OROSection *section = document->section(s); section->sortPrimitives(Qt::Horizontal); - if (section->type() == KReportSectionData::GroupHeader || - section->type() == KReportSectionData::GroupFooter || - section->type() == KReportSectionData::Detail || - section->type() == KReportSectionData::ReportHeader || - section->type() == KReportSectionData::ReportFooter || - (section->type() == KReportSectionData::PageHeaderAny && !renderedPageHeader) || - (section->type() == KReportSectionData::PageFooterAny && !renderedPageFooter && s > document->sectionCount() - 2)) { //render the page foot right at the end, it will either be the last or second last section if there is a report footer - if (section->type() == KReportSectionData::PageHeaderAny) + if (section->type() == KReportSectionData::Type::GroupHeader + || section->type() == KReportSectionData::Type::GroupFooter + || section->type() == KReportSectionData::Type::Detail + || section->type() == KReportSectionData::Type::ReportHeader + || section->type() == KReportSectionData::Type::ReportFooter + || (section->type() == KReportSectionData::Type::PageHeaderAny && !renderedPageHeader) + || (section->type() == KReportSectionData::Type::PageFooterAny && !renderedPageFooter + && s > document->sectionCount() - 2)) + { // render the page foot right at the end, it + // will either be the last or second last + // section if there is a report footer + if (section->type() == KReportSectionData::Type::PageHeaderAny) renderedPageHeader = true; - if (section->type() == KReportSectionData::PageFooterAny) + if (section->type() == KReportSectionData::Type::PageFooterAny) renderedPageFooter = true; tr = QLatin1String("backgroundColor().name() + QLatin1String("\">\n"); //Render the objects in each section for (int i = 0; i < section->primitiveCount(); i++) { OROPrimitive * prim = section->primitive(i); if (OROTextBox *tb = dynamic_cast(prim)) { tr += QLatin1String("\n"); } else if (OROImage *im = dynamic_cast(prim)) { tr += QLatin1String("\n"); im->image().save(m_tempDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png")); } else if (OROPicture *im = dynamic_cast(prim)) { tr += QLatin1String("\n"); QImage image(im->size().toSize(), QImage::Format_RGB32); QPainter painter(&image); im->picture()->play(&painter); image.save(m_tempDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png")); } else { kreportWarning() << "unhandled primitive type"; } } tr += QLatin1String("\n"); if (tr.contains(QLatin1String("
") + tb->text() + QLatin1String("" "" "" "" "
"))) { body += tr; } } } body += QLatin1String("
\n"); html = QLatin1String("\n" "\n" "\n" "") + document->title() + QLatin1String("\n" "\n" "\n" "\n" "\n") + body + QLatin1String("\n\n" "\n"); return html; } } diff --git a/src/renderer/KReportPrintRenderer_p.cpp b/src/renderer/KReportPrintRenderer_p.cpp index 0250d8bb..f2821c84 100644 --- a/src/renderer/KReportPrintRenderer_p.cpp +++ b/src/renderer/KReportPrintRenderer_p.cpp @@ -1,247 +1,247 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportPrintRenderer_p.h" #include "kreport_debug.h" #include "KReportRenderObjects.h" #include "KReportPageSize.h" #include "KReportUtils_p.h" #include #include #include namespace KReportPrivate { PrintRenderer::PrintRenderer() { } PrintRenderer::~PrintRenderer() { } bool PrintRenderer::setupPrinter( ORODocument * document, QPrinter * pPrinter) { if (document == nullptr || pPrinter == nullptr) return false; pPrinter->setCreator(QLatin1String("KReport Print Renderer")); pPrinter->setDocName(document->title()); pPrinter->setFullPage(true); pPrinter->setOrientation((document->pageLayout().orientation() == QPageLayout::Portrait ? QPrinter::Portrait : QPrinter::Landscape)); pPrinter->setPageOrder(QPrinter::FirstPageFirst); if (!document->pageLayout().pageSize().isValid()) { pPrinter->setPageSize(QPrinter::Custom); } else { pPrinter->setPageSize(QPageSize(document->pageLayout().pageSize())); } return true; } bool PrintRenderer::render(const KReportRendererContext &context, ORODocument *document, int page) { Q_UNUSED(page); if (document == nullptr || context.printer() == nullptr || context.painter() == nullptr) return false; setupPrinter(document, context.printer()); bool endWhenComplete = false; if (!context.painter()->isActive()) { endWhenComplete = true; if (!context.painter()->begin(context.printer())) return false; } int fromPage = context.printer()->fromPage(); if (fromPage > 0) fromPage -= 1; int toPage = context.printer()->toPage(); if (toPage == 0 || toPage > document->pageCount()) toPage = document->pageCount(); qreal scaleX = context.printer()->resolution() / qreal(KReportPrivate::dpiX()); qreal scaleY = context.printer()->resolution() / qreal(KReportPrivate::dpiY()); for (int copy = 0; copy < context.printer()->numCopies(); copy++) { for (int page = fromPage; page < toPage; page++) { if (page > fromPage) context.printer()->newPage(); OROPage * p = document->page(page); if (context.printer()->pageOrder() == QPrinter::LastPageFirst) p = document->page(toPage - 1 - page); // Render Page Objects for (int i = 0; i < p->primitiveCount(); i++) { OROPrimitive * prim = p->primitive(i); prim->setPosition(QPointF(prim->position().x() * scaleX, prim->position().y() * scaleY)); prim->setSize(QSizeF(prim->size().width() * scaleX, prim->size().height() * scaleY)); //kreportDebug() << "Rendering object" << i << "type" << prim->type(); if (OROTextBox *tb = dynamic_cast(prim)) { QPointF ps = tb->position(); QSizeF sz = tb->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); context.painter()->save(); //Background QColor bg = tb->textStyle().backgroundColor; bg.setAlphaF(0.01 * tb->textStyle().backgroundOpacity); //_painter()->setBackgroundMode(Qt::OpaqueMode); context.painter()->fillRect(rc, bg); //Text context.painter()->setBackgroundMode(Qt::TransparentMode); context.painter()->setFont(tb->textStyle().font); context.painter()->setPen(tb->textStyle().foregroundColor); context.painter()->drawText(rc, tb->flags(), tb->text()); //outer line context.painter()->setPen(QPen(tb->lineStyle().color(), tb->lineStyle().weight() * scaleX, tb->lineStyle().penStyle())); context.painter()->drawRect(rc); //Reset back to defaults for next element context.painter()->restore(); } else if (OROLine *ln = dynamic_cast(prim)) { QPointF s = ln->startPoint(); QPointF e(ln->endPoint().x() * scaleX, ln->endPoint().y() * scaleY); //QPen pen ( _painter()->pen() ); QPen pen(ln->lineStyle().color(), ln->lineStyle().weight() * scaleX, ln->lineStyle().penStyle()); context.painter()->save(); context.painter()->setRenderHint(QPainter::Antialiasing, true); context.painter()->setPen(pen); context.painter()->drawLine(QLineF(s.x(), s.y(), e.x(), e.y())); context.painter()->setRenderHint(QPainter::Antialiasing, false); context.painter()->restore(); } else if (OROImage *im = dynamic_cast(prim)) { QPointF ps = im->position(); QSizeF sz = im->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); QImage img = im->image(); if (im->isScaled()) img = img.scaled(rc.size().toSize(), (Qt::AspectRatioMode) im->aspectRatioMode(), (Qt::TransformationMode) im->transformationMode()); QRectF sr = QRectF(QPointF(0.0, 0.0), rc.size().boundedTo(img.size())); context.painter()->drawImage(rc.topLeft(), img, sr); } else if (ORORect *re = dynamic_cast(prim)) { QPointF ps = re->position(); QSizeF sz = re->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); context.painter()->save(); context.painter()->setPen(re->pen()); context.painter()->setBrush(re->brush()); context.painter()->drawRect(rc); context.painter()->restore(); } else if (OROEllipse *re = dynamic_cast(prim)) { QPointF ps = re->position(); QSizeF sz = re->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); context.painter()->save(); context.painter()->setPen(re->pen()); context.painter()->setBrush(re->brush()); context.painter()->drawEllipse(rc); context.painter()->restore(); } else if (OROPicture *im = dynamic_cast(prim)) { QPointF ps = im->position(); QSizeF sz = im->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); context.painter()->drawPicture(rc.topLeft(), *(im->picture())); } else if (OROCheckBox *chk = dynamic_cast(prim)) { QPointF ps = chk->position(); QSizeF sz = chk->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); context.painter()->save(); context.painter()->setBackgroundMode(Qt::OpaqueMode); context.painter()->setRenderHint(QPainter::Antialiasing); context.painter()->setPen(chk->foregroundColor()); if (chk->lineStyle().penStyle() == Qt::NoPen || chk->lineStyle().weight() <= 0) { context.painter()->setPen(QPen(Qt::lightGray)); } else { context.painter()->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().weight() * scaleX, chk->lineStyle().penStyle())); } qreal ox = sz.width() / 5; qreal oy = sz.height() / 5; //Checkbox Style - if (chk->checkType() == OROCheckBox::Cross) { + if (chk->checkType() == OROCheckBox::Type::Cross) { context.painter()->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); if (chk->value()) { QPen lp; lp.setColor(chk->foregroundColor()); lp.setWidth(ox > oy ? oy : ox); context.painter()->setPen(lp); context.painter()->drawLine(QPointF(ox, oy) + ps, QPointF(sz.width() - ox, sz.height() - oy) + ps); context.painter()->drawLine(QPointF(ox, sz.height() - oy) + ps, QPoint(sz.width() - ox, oy) + ps); } - } else if (chk->checkType() == OROCheckBox::Dot) { + } else if (chk->checkType() == OROCheckBox::Type::Dot) { //Radio Style context.painter()->drawEllipse(rc); if (chk->value()) { QBrush lb(chk->foregroundColor()); context.painter()->setBrush(lb); context.painter()->setPen(Qt::NoPen); context.painter()->drawEllipse(rc.center(), sz.width() / 2 - ox, sz.height() / 2 - oy); } } else { //Tickbox Style context.painter()->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); if (chk->value()) { QPen lp; lp.setColor(chk->foregroundColor()); lp.setWidth(ox > oy ? oy : ox); context.painter()->setPen(lp); context.painter()->drawLine(QPointF(ox, sz.height() / 2) + ps, QPointF(sz.width() / 2, sz.height() - oy) + ps); context.painter()->drawLine(QPointF(sz.width() / 2, sz.height() - oy) + ps, QPointF(sz.width() - ox, oy) + ps); } } context.painter()->restore(); } } } } if (endWhenComplete) context.painter()->end(); return true; } } diff --git a/src/renderer/KReportScreenRenderer_p.cpp b/src/renderer/KReportScreenRenderer_p.cpp index 51c82bc6..0fe8b6db 100644 --- a/src/renderer/KReportScreenRenderer_p.cpp +++ b/src/renderer/KReportScreenRenderer_p.cpp @@ -1,209 +1,209 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportScreenRenderer_p.h" #include "KReportRenderObjects.h" #include "KReportUnit.h" #include "kreport_debug.h" namespace KReportPrivate { ScreenRenderer::ScreenRenderer() { } ScreenRenderer::~ScreenRenderer() { } bool ScreenRenderer::render(const KReportRendererContext& context, ORODocument *document, int page) { if (!document) return false; if (!context.painter()) return false; OROPage *p = document->page(page); if (!p) { return false; } // Render Page Objects for (int i = 0; i < p->primitiveCount(); i++) { OROPrimitive *prim = p->primitive(i); if (OROTextBox *tb = dynamic_cast(prim)) { QPointF ps = tb->position(); QSizeF sz = tb->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); context.painter()->save(); //Background context.painter()->setBackgroundMode(Qt::TransparentMode); QColor bg = tb->textStyle().backgroundColor; bg.setAlphaF(0.01 * tb->textStyle().backgroundOpacity); context.painter()->fillRect(rc, bg); //Text context.painter()->setFont(tb->textStyle().font); context.painter()->setPen(tb->textStyle().foregroundColor); context.painter()->drawText(rc.adjusted(2, 2, 0, 0), tb->flags(), tb->text()); //outer line context.painter()->setPen(QPen(tb->lineStyle().color(), tb->lineStyle().weight(), tb->lineStyle().penStyle())); context.painter()->drawRect(rc); //Reset back to defaults for next element context.painter()->restore(); } else if (OROLine *ln = dynamic_cast(prim)) { QPointF s = ln->startPoint(); QPointF e = ln->endPoint(); //QPen pen ( _painter->pen() ); QPen pen(ln->lineStyle().color(), ln->lineStyle().weight(), ln->lineStyle().penStyle()); context.painter()->save(); context.painter()->setRenderHint(QPainter::Antialiasing, true); context.painter()->setPen(pen); context.painter()->drawLine(QLineF(s.x(), s.y(), e.x(), e.y())); context.painter()->setRenderHint(QPainter::Antialiasing, false); context.painter()->restore(); } else if (ORORect *re = dynamic_cast(prim)) { QPointF ps = re->position(); QSizeF sz = re->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); context.painter()->save(); context.painter()->setPen(re->pen()); context.painter()->setBrush(re->brush()); context.painter()->drawRect(rc); context.painter()->restore(); } else if (OROEllipse *re = dynamic_cast(prim)) { QPointF ps = re->position(); QSizeF sz = re->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); context.painter()->save(); context.painter()->setPen(re->pen()); context.painter()->setBrush(re->brush()); context.painter()->drawEllipse(rc); context.painter()->restore(); } else if ( OROImage *im = dynamic_cast(prim)) { QPointF ps = im->position(); QSizeF sz = im->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); QImage img = im->image(); if (im->isScaled()) img = img.scaled(rc.size().toSize(), (Qt::AspectRatioMode) im->aspectRatioMode(), (Qt::TransformationMode) im->transformationMode()); QRectF sr = QRectF(QPointF(0.0, 0.0), rc.size().boundedTo(img.size())); context.painter()->drawImage(rc.topLeft(), img, sr); } else if (OROPicture *im = dynamic_cast(prim)) { QPointF ps = im->position(); QSizeF sz = im->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); context.painter()->save(); context.painter()->drawPicture(rc.topLeft(), *(im->picture())); context.painter()->restore(); } else if (OROCheckBox *chk = dynamic_cast(prim)) { QPointF ps = chk->position(); QSizeF sz = chk->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); context.painter()->save(); context.painter()->setBackgroundMode(Qt::OpaqueMode); context.painter()->setRenderHint(QPainter::Antialiasing); context.painter()->setPen(chk->foregroundColor()); if (chk->lineStyle().penStyle() == Qt::NoPen || chk->lineStyle().weight() <= 0) { context.painter()->setPen(QPen(Qt::lightGray)); } else { context.painter()->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().weight(), chk->lineStyle().penStyle())); } qreal ox = sz.width() / 5; qreal oy = sz.height() / 5; //Checkbox Style - if (chk->checkType() == OROCheckBox::Cross) { + if (chk->checkType() == OROCheckBox::Type::Cross) { context.painter()->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); if (chk->value()) { QPen lp; lp.setColor(chk->foregroundColor()); lp.setWidth(ox > oy ? oy : ox); context.painter()->setPen(lp); context.painter()->drawLine(QPointF(ox, oy) + ps, QPointF(sz.width() - ox, sz.height() - oy) + ps); context.painter()->drawLine(QPointF(ox, sz.height() - oy) + ps, QPoint(sz.width() - ox, oy) + ps); } } - else if (chk->checkType() == OROCheckBox::Dot) { + else if (chk->checkType() == OROCheckBox::Type::Dot) { //Radio Style context.painter()->drawEllipse(rc); if (chk->value()) { QBrush lb(chk->foregroundColor()); context.painter()->setBrush(lb); context.painter()->setPen(Qt::NoPen); context.painter()->drawEllipse(rc.center(), sz.width() / 2 - ox, sz.height() / 2 - oy); } } else { //Tickbox Style context.painter()->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); if (chk->value()) { QPen lp; lp.setColor(chk->foregroundColor()); lp.setWidth(ox > oy ? oy : ox); context.painter()->setPen(lp); context.painter()->drawLine( QPointF(ox, sz.height() / 2) + ps, QPointF(sz.width() / 2, sz.height() - oy) + ps); context.painter()->drawLine( QPointF(sz.width() / 2, sz.height() - oy) + ps, QPointF(sz.width() - ox, oy) + ps); } } context.painter()->restore(); } else { kreportWarning() << "unrecognized primitive type"; } } return true; } } diff --git a/src/renderer/scripting/KReportScriptConstants.h b/src/renderer/scripting/KReportScriptConstants.h index 3303393c..034a53ca 100644 --- a/src/renderer/scripting/KReportScriptConstants.h +++ b/src/renderer/scripting/KReportScriptConstants.h @@ -1,71 +1,71 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef KRSCRIPTCONSTANTS_H #define KRSCRIPTCONSTANTS_H #include /** @brief Helper giving access to various scripting constants Contains methods for retreiving the current page number, page total and access to the PenStyle enums from user scripts */ class KReportScriptConstants : public QObject { Q_OBJECT public: explicit KReportScriptConstants(QObject *parent = nullptr); ~KReportScriptConstants() override; Q_ENUMS(PenStyle) //!Enum values for pen styles that can be accessed from user scripts using //! \code //! constants.QtSolidLine //! \endcode //! for example - enum PenStyle {QtNoPen = 0, QtSolidLine, QtDashLine, QtDotLine, QtDashDotLine, QtDashDotDotLine}; + enum PenStyle {QtNoPen, QtSolidLine, QtDashLine, QtDotLine, QtDashDotLine, QtDashDotDotLine}; void setPageNumber(int p) { m_currentPage = p; } void setPageTotal(int t) { m_totalPages = t; }; public Q_SLOTS: //! @return the current page number int PageNumber() { return m_currentPage; }; //! @return the total number of pages int PageTotal() { return m_totalPages; }; private: int m_currentPage; int m_totalPages; }; #endif diff --git a/src/wrtembed/KReportDesigner.cpp b/src/wrtembed/KReportDesigner.cpp index 16de7785..fcc37ab2 100644 --- a/src/wrtembed/KReportDesigner.cpp +++ b/src/wrtembed/KReportDesigner.cpp @@ -1,1542 +1,1552 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC * Copyright (C) 2007-2010 by Adam Pigg * Copyright (C) 2011-2017 Jarosław Staniek * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportDesigner.h" #include "KReportDesignerSection.h" #include "KReportDesignerSectionScene.h" #include "KReportDesignerSectionView.h" #include "KReportDesignerSectionDetailGroup.h" #include "KReportPropertiesButton.h" #include "KReportSectionEditor.h" #include "KReportDesignerSectionDetail.h" #include "KReportDesignerItemLine.h" #include "KReportRuler_p.h" #include "KReportZoomHandler_p.h" #include "KReportPageSize.h" #include "KReportUtils_p.h" #include "KReportUtils.h" #include "KReportPluginInterface.h" #include "KReportPluginManager.h" #include "KReportSection.h" #include "KReportPluginMetaData.h" #include "kreport_debug.h" #ifdef KREPORT_SCRIPTING #include "KReportScriptSource.h" #endif #include #include #include #include #include #include #include #include #include #include #include #include #include //! Also add public method for runtime? const char ns[] = "http://kexi-project.org/report/2.0"; static QDomElement propertyToElement(QDomDocument* d, KProperty* p) { QDomElement e = d->createElement(QLatin1String("report:" + p->name().toLower())); e.appendChild(d->createTextNode(p->value().toString())); return e; } // // define and implement the ReportWriterSectionData class // a simple class to hold/hide data in the ReportHandler class // class ReportWriterSectionData { public: ReportWriterSectionData() { selected_x_offset = 0; selected_y_offset = 0; - mouseAction = ReportWriterSectionData::MA_None; + mouseAction = MouseAction::None; } virtual ~ReportWriterSectionData() { } - enum MouseAction { - MA_None = 0, - MA_Insert = 1, - MA_Grab = 2, - MA_MoveStartPoint, - MA_MoveEndPoint, - MA_ResizeNW = 8, - MA_ResizeN, - MA_ResizeNE, - MA_ResizeE, - MA_ResizeSE, - MA_ResizeS, - MA_ResizeSW, - MA_ResizeW + enum class MouseAction { + None = 0, + Insert = 1, + Grab = 2, + MoveStartPoint, + MoveEndPoint, + ResizeNW = 8, + ResizeN, + ResizeNE, + ResizeE, + ResizeSE, + ResizeS, + ResizeSW, + ResizeW }; int selected_x_offset; int selected_y_offset; MouseAction mouseAction; QString itemToInsert; QList copy_list; QList cut_list; }; //! @internal class Q_DECL_HIDDEN KReportDesigner::Private { public: Private(){} ~Private() { delete dataSource; } QGridLayout *grid; KReportRuler *hruler; KReportZoomHandler zoomHandler; QVBoxLayout *vboxlayout; KReportPropertiesButton *pageButton; QGraphicsScene *activeScene = nullptr; ReportWriterSectionData sectionData; KReportDesignerSection *reportHeader = nullptr; KReportDesignerSection *pageHeaderFirst = nullptr; KReportDesignerSection *pageHeaderOdd = nullptr; KReportDesignerSection *pageHeaderEven = nullptr; KReportDesignerSection *pageHeaderLast = nullptr; KReportDesignerSection *pageHeaderAny = nullptr; KReportDesignerSection *pageFooterFirst = nullptr; KReportDesignerSection *pageFooterOdd = nullptr; KReportDesignerSection *pageFooterEven = nullptr; KReportDesignerSection *pageFooterLast = nullptr; KReportDesignerSection *pageFooterAny = nullptr; KReportDesignerSection *reportFooter = nullptr; KReportDesignerSectionDetail *detail = nullptr; //Properties KPropertySet set; KPropertySet *itemSet; KProperty *title; KProperty *pageSize; KProperty *orientation; KProperty *unit; KProperty *customHeight; KProperty *customWidth; KProperty *leftMargin; KProperty *rightMargin; KProperty *topMargin; KProperty *bottomMargin; KProperty *showGrid; KProperty *gridDivisions; KProperty *gridSnap; KProperty *labelType; #ifdef KREPORT_SCRIPTING KProperty *script; #endif //Actions QAction *editCutAction; QAction *editCopyAction; QAction *editPasteAction; QAction *editDeleteAction; QAction *sectionEdit; QAction *parameterEdit; QAction *itemRaiseAction; QAction *itemLowerAction; qreal pressX = -1; qreal pressY = -1; qreal releaseX = -1; qreal releaseY = -1; bool modified = false; // true if this document has been modified, false otherwise QString originalInterpreter; //Value of the script interpreter at load time QString originalScript; //Value of the script at load time KReportDataSource *dataSource = nullptr; #ifdef KREPORT_SCRIPTING KReportScriptSource *scriptSource = nullptr; #endif }; KReportDesigner::KReportDesigner(QWidget * parent) : QWidget(parent), d(new Private()) { KReportPluginManager::self(); // this loads icons early enough createProperties(); 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); d->vboxlayout = new QVBoxLayout(); d->vboxlayout->setSpacing(0); d->vboxlayout->setMargin(0); d->vboxlayout->setSizeConstraint(QLayout::SetFixedSize); //Create nice rulers d->hruler = new KReportRuler(this, Qt::Horizontal, d->zoomHandler); d->pageButton = new KReportPropertiesButton(this); d->hruler->setUnit(KReportUnit(KReportUnit::Centimeter)); d->grid->addWidget(d->pageButton, 0, 0); d->grid->addWidget(d->hruler, 0, 1); d->grid->addLayout(d->vboxlayout, 1, 0, 1, 2); d->pageButton->setMaximumSize(QSize(19, 22)); d->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); connect(&d->set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); changeSet(&d->set); } KReportDesigner::~KReportDesigner() { delete d; } KReportDesigner::KReportDesigner(QWidget *parent, const QDomElement &data) : KReportDesigner(parent) { 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; for (int i = 0; i < nlist.count(); ++i) { it = nlist.item(i); // at this level all the children we get should be Elements if (it.isElement()) { QString n = it.nodeName().toLower(); //kreportDebug() << n; if (n == QLatin1String("report:title")) { 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"); } d->originalScript = it.firstChild().nodeValue(); d->script->setValue(d->originalScript); if (d->originalInterpreter != QLatin1String("javascript") && d->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); } #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"))); } //! @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"))); } else if (pagetype == QLatin1String("custom")) { d->pageSize->setValue(QLatin1String("custom")); d->customHeight->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-height"), QLatin1String("")))); d->customWidth->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-widtht"), 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")))); d->orientation->setValue(it.toElement().attribute(QLatin1String("report:print-orientation"), QLatin1String("portrait"))); } else if (n == QLatin1String("report:body")) { QDomNodeList sectionlist = it.childNodes(); QDomNode sec; for (int s = 0; s < sectionlist.count(); ++s) { sec = sectionlist.item(s); if (sec.isElement()) { QString sn = sec.nodeName().toLower(); //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); } } else if (sn == QLatin1String("report:detail")) { KReportDesignerSectionDetail * rsd = new KReportDesignerSectionDetail(this); rsd->initFromXML(&sec); setDetail(rsd); } } else { kreportWarning() << "Encountered an unknown Element: " << n; } } } } else { 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); } ///The saving code QDomElement KReportDesigner::document() const { QDomDocument doc; QString saveInterpreter; QDomElement content = doc.createElement(QLatin1String("report:content")); content.setAttribute(QLatin1String("xmlns:report"), QLatin1String(ns)); content.setAttribute(QLatin1String("xmlns:fo"), QLatin1String("urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0")); content.setAttribute(QLatin1String("xmlns:svg"), QLatin1String("urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0")); doc.appendChild(content); //title content.appendChild(propertyToElement(&doc, d->title)); #ifdef KREPORT_SCRIPTING if (d->originalInterpreter.isEmpty()) { d->originalInterpreter = QLatin1String("javascript"); } saveInterpreter = d->originalInterpreter; if (!d->script->value().toString().isEmpty()) { if (d->script->value().toString() != d->originalScript || d->originalInterpreter == QLatin1String("qtscript") || d->originalInterpreter.isEmpty() ) { //The script has changed so force interpreter to 'javascript'. Also set if was using qtscript saveInterpreter = QLatin1String("javascript"); } } QDomElement scr = propertyToElement(&doc, d->script); scr.setAttribute(QLatin1String("report:script-interpreter"), saveInterpreter); content.appendChild(scr); #endif QDomElement grd = doc.createElement(QLatin1String("report:grid")); KReportUtils::addPropertyAsAttribute(&grd, d->showGrid); KReportUtils::addPropertyAsAttribute(&grd, d->gridDivisions); KReportUtils::addPropertyAsAttribute(&grd, d->gridSnap); KReportUtils::addPropertyAsAttribute(&grd, d->unit); content.appendChild(grd); // pageOptions // -- size QDomElement pagestyle = doc.createElement(QLatin1String("report:page-style")); if (d->pageSize->value().toString() == QLatin1String("Custom")) { pagestyle.appendChild(doc.createTextNode(QLatin1String("custom"))); KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-width"), d->customWidth->value().toDouble()); KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-height"), d->customHeight->value().toDouble()); } else if (d->pageSize->value().toString() == QLatin1String("Label")) { pagestyle.appendChild(doc.createTextNode(QLatin1String("label"))); pagestyle.setAttribute(QLatin1String("report:page-label-type"), d->labelType->value().toString()); } else { pagestyle.appendChild(doc.createTextNode(QLatin1String("predefined"))); KReportUtils::addPropertyAsAttribute(&pagestyle, d->pageSize); //pagestyle.setAttribute("report:page-size", d->pageSize->value().toString()); } // -- orientation KReportUtils::addPropertyAsAttribute(&pagestyle, d->orientation); // -- margins: save as points, and not localized KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-top"), d->topMargin->value().toDouble()); KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-bottom"), d->bottomMargin->value().toDouble()); KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-right"), d->rightMargin->value().toDouble()); KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-left"), d->leftMargin->value().toDouble()); content.appendChild(pagestyle); QDomElement body = doc.createElement(QLatin1String("report:body")); QDomElement domsection; - for (int i = KReportSectionData::PageHeaderFirst; i <= KReportSectionData::PageFooterAny; ++i) { - KReportDesignerSection *sec = section((KReportSectionData::Section)i); + for (int i = static_cast(KReportSectionData::Type::PageHeaderFirst); + i <= static_cast(KReportSectionData::Type::PageFooterAny); ++i) + { + KReportDesignerSection *sec = section(static_cast(i)); if (sec) { domsection = doc.createElement(QLatin1String("report:section")); - domsection.setAttribute(QLatin1String("report:section-type"), KReportSectionData::sectionTypeString(KReportSectionData::Section(i))); + domsection.setAttribute( + QLatin1String("report:section-type"), + KReportSectionData::sectionTypeString(static_cast(i))); sec->buildXML(&doc, &domsection); body.appendChild(domsection); } } QDomElement detail = doc.createElement(QLatin1String("report:detail")); d->detail->buildXML(&doc, &detail); body.appendChild(detail); content.appendChild(body); return content; } void KReportDesigner::slotSectionEditor() { KReportSectionEditor se(this); (void)se.exec(); } void KReportDesigner::setDataSource(KReportDataSource* source) { if (d->dataSource == source) { return; } delete d->dataSource; d->dataSource = source; slotPageButton_Pressed(); setModified(true); emit reportDataChanged(); } #ifdef KREPORT_SCRIPTING void KReportDesigner::setScriptSource(KReportScriptSource* source) { d->scriptSource = source; } #endif -KReportDesignerSection * KReportDesigner::section(KReportSectionData::Section s) const +KReportDesignerSection * KReportDesigner::section(KReportSectionData::Type type) const { KReportDesignerSection *sec; - switch (s) { - case KReportSectionData::PageHeaderAny: + switch (type) { + case KReportSectionData::Type::PageHeaderAny: sec = d->pageHeaderAny; break; - case KReportSectionData::PageHeaderEven: + case KReportSectionData::Type::PageHeaderEven: sec = d->pageHeaderEven; break; - case KReportSectionData::PageHeaderOdd: + case KReportSectionData::Type::PageHeaderOdd: sec = d->pageHeaderOdd; break; - case KReportSectionData::PageHeaderFirst: + case KReportSectionData::Type::PageHeaderFirst: sec = d->pageHeaderFirst; break; - case KReportSectionData::PageHeaderLast: + case KReportSectionData::Type::PageHeaderLast: sec = d->pageHeaderLast; break; - case KReportSectionData::PageFooterAny: + case KReportSectionData::Type::PageFooterAny: sec = d->pageFooterAny; break; - case KReportSectionData::PageFooterEven: + case KReportSectionData::Type::PageFooterEven: sec = d->pageFooterEven; break; - case KReportSectionData::PageFooterOdd: + case KReportSectionData::Type::PageFooterOdd: sec = d->pageFooterOdd; break; - case KReportSectionData::PageFooterFirst: + case KReportSectionData::Type::PageFooterFirst: sec = d->pageFooterFirst; break; - case KReportSectionData::PageFooterLast: + case KReportSectionData::Type::PageFooterLast: sec = d->pageFooterLast; break; - case KReportSectionData::ReportHeader: + case KReportSectionData::Type::ReportHeader: sec = d->reportHeader; break; - case KReportSectionData::ReportFooter: + case KReportSectionData::Type::ReportFooter: sec = d->reportFooter; break; default: sec = nullptr; } return sec; } KReportDesignerSection* KReportDesigner::createSection() { return new KReportDesignerSection(this, d->zoomHandler); } -void KReportDesigner::removeSection(KReportSectionData::Section s) +void KReportDesigner::removeSection(KReportSectionData::Type type) { - KReportDesignerSection* sec = section(s); + KReportDesignerSection* sec = section(type); if (sec) { delete sec; - switch (s) { - case KReportSectionData::PageHeaderAny: + switch (type) { + case KReportSectionData::Type::PageHeaderAny: d->pageHeaderAny = nullptr; break; - case KReportSectionData::PageHeaderEven: + case KReportSectionData::Type::PageHeaderEven: sec = d->pageHeaderEven = nullptr; break; - case KReportSectionData::PageHeaderOdd: + case KReportSectionData::Type::PageHeaderOdd: d->pageHeaderOdd = nullptr; break; - case KReportSectionData::PageHeaderFirst: + case KReportSectionData::Type::PageHeaderFirst: d->pageHeaderFirst = nullptr; break; - case KReportSectionData::PageHeaderLast: + case KReportSectionData::Type::PageHeaderLast: d->pageHeaderLast = nullptr; break; - case KReportSectionData::PageFooterAny: + case KReportSectionData::Type::PageFooterAny: d->pageFooterAny = nullptr; break; - case KReportSectionData::PageFooterEven: + case KReportSectionData::Type::PageFooterEven: d->pageFooterEven = nullptr; break; - case KReportSectionData::PageFooterOdd: + case KReportSectionData::Type::PageFooterOdd: d->pageFooterOdd = nullptr; break; - case KReportSectionData::PageFooterFirst: + case KReportSectionData::Type::PageFooterFirst: d->pageFooterFirst = nullptr; break; - case KReportSectionData::PageFooterLast: + case KReportSectionData::Type::PageFooterLast: d->pageFooterLast = nullptr; break; - case KReportSectionData::ReportHeader: + case KReportSectionData::Type::ReportHeader: d->reportHeader = nullptr; break; - case KReportSectionData::ReportFooter: + case KReportSectionData::Type::ReportFooter: d->reportFooter = nullptr; break; default: sec = nullptr; } setModified(true); adjustSize(); } } -void KReportDesigner::insertSection(KReportSectionData::Section s) +void KReportDesigner::insertSection(KReportSectionData::Type type) { - KReportDesignerSection* sec = section(s); + KReportDesignerSection* sec = section(type); if (!sec) { int idx = 0; - for (int i = 1; i <= s; ++i) { - if (section((KReportSectionData::Section)i)) + for (int i = static_cast(KReportSectionData::Type::None) + 1; + i <= static_cast(type); ++i) + { + if (section(static_cast(i))) idx++; } - if (s > KReportSectionData::ReportHeader) + if (type > KReportSectionData::Type::ReportHeader) idx++; //kreportDebug() << idx; KReportDesignerSection *rs = createSection(); d->vboxlayout->insertWidget(idx, rs); - switch (s) { - case KReportSectionData::PageHeaderAny: + switch (type) { + case KReportSectionData::Type::PageHeaderAny: rs->setTitle(tr("Page Header (Any)")); d->pageHeaderAny = rs; break; - case KReportSectionData::PageHeaderEven: + case KReportSectionData::Type::PageHeaderEven: rs->setTitle(tr("Page Header (Even)")); d->pageHeaderEven = rs; break; - case KReportSectionData::PageHeaderOdd: + case KReportSectionData::Type::PageHeaderOdd: rs->setTitle(tr("Page Header (Odd)")); d->pageHeaderOdd = rs; break; - case KReportSectionData::PageHeaderFirst: + case KReportSectionData::Type::PageHeaderFirst: rs->setTitle(tr("Page Header (First)")); d->pageHeaderFirst = rs; break; - case KReportSectionData::PageHeaderLast: + case KReportSectionData::Type::PageHeaderLast: rs->setTitle(tr("Page Header (Last)")); d->pageHeaderLast = rs; break; - case KReportSectionData::PageFooterAny: + case KReportSectionData::Type::PageFooterAny: rs->setTitle(tr("Page Footer (Any)")); d->pageFooterAny = rs; break; - case KReportSectionData::PageFooterEven: + case KReportSectionData::Type::PageFooterEven: rs->setTitle(tr("Page Footer (Even)")); d->pageFooterEven = rs; break; - case KReportSectionData::PageFooterOdd: + case KReportSectionData::Type::PageFooterOdd: rs->setTitle(tr("Page Footer (Odd)")); d->pageFooterOdd = rs; break; - case KReportSectionData::PageFooterFirst: + case KReportSectionData::Type::PageFooterFirst: rs->setTitle(tr("Page Footer (First)")); d->pageFooterFirst = rs; break; - case KReportSectionData::PageFooterLast: + case KReportSectionData::Type::PageFooterLast: rs->setTitle(tr("Page Footer (Last)")); d->pageFooterLast = rs; break; - case KReportSectionData::ReportHeader: + case KReportSectionData::Type::ReportHeader: rs->setTitle(tr("Report Header")); d->reportHeader = rs; break; - case KReportSectionData::ReportFooter: + case KReportSectionData::Type::ReportFooter: rs->setTitle(tr("Report Footer")); d->reportFooter = rs; break; //These sections cannot be inserted this way - case KReportSectionData::None: - case KReportSectionData::GroupHeader: - case KReportSectionData::GroupFooter: - case KReportSectionData::Detail: + case KReportSectionData::Type::None: + case KReportSectionData::Type::GroupHeader: + case KReportSectionData::Type::GroupFooter: + case KReportSectionData::Type::Detail: break; } rs->show(); setModified(true); adjustSize(); emit pagePropertyChanged(d->set); } } void KReportDesigner::setReportTitle(const QString & str) { if (reportTitle() != str) { d->title->setValue(str); setModified(true); } } KPropertySet* KReportDesigner::propertySet() const { return &d->set; } KPropertySet* KReportDesigner::selectedItemPropertySet() const { return d->itemSet; } KReportDataSource *KReportDesigner::reportDataSource() const { return d->dataSource; } KReportDesignerSectionDetail * KReportDesigner::detailSection() const { return d->detail; } QString KReportDesigner::reportTitle() const { return d->title->value().toString(); } bool KReportDesigner::isModified() const { return d->modified; } void KReportDesigner::setModified(bool modified) { d->modified = modified; if (d->modified) { emit dirty(); } } QStringList KReportDesigner::fieldNames() const { QStringList qs; qs << QString(); if (d->dataSource) qs << d->dataSource->fieldNames(); return qs; } QStringList KReportDesigner::fieldKeys() const { QStringList qs; qs << QString(); if (d->dataSource) qs << d->dataSource->fieldKeys(); return qs; } void KReportDesigner::createProperties() { QStringList keys, strings; KReportDesigner::addMetaProperties(&d->set, tr("Report", "Main report element"), QLatin1String("kreport-report-element")); connect(&d->set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); d->title = new KProperty("title", QLatin1String("Report"), tr("Title"), tr("Report Title")); keys.clear(); keys = KReportPageSize::pageFormatKeys(); strings = KReportPageSize::pageFormatNames(); QString defaultKey = KReportPageSize::pageSizeKey(KReportPageSize::defaultSize()); d->pageSize = new KProperty("page-size", keys, strings, defaultKey, tr("Page Size")); keys.clear(); strings.clear(); keys << QLatin1String("portrait") << QLatin1String("landscape"); strings << tr("Portrait") << tr("Landscape"); d->orientation = new KProperty("print-orientation", keys, strings, QLatin1String("portrait"), tr("Page Orientation")); keys.clear(); strings.clear(); strings = KReportUnit::listOfUnitNameForUi(KReportUnit::HidePixel); QString unit; foreach(const QString &un, strings) { unit = un.mid(un.indexOf(QLatin1String("(")) + 1, 2); keys << unit; } d->unit = new KProperty("page-unit", keys, strings, QLatin1String("cm"), tr("Page Unit")); d->showGrid = new KProperty("grid-visible", true, tr("Show Grid")); d->gridSnap = new KProperty("grid-snap", true, tr("Snap to Grid")); d->gridDivisions = new KProperty("grid-divisions", 4, tr("Grid Divisions")); d->leftMargin = new KProperty("margin-left", KReportUnit(KReportUnit::Centimeter).fromUserValue(1.0), tr("Left Margin"), tr("Left Margin"), KProperty::Double); d->rightMargin = new KProperty("margin-right", KReportUnit(KReportUnit::Centimeter).fromUserValue(1.0), tr("Right Margin"), tr("Right Margin"), KProperty::Double); d->topMargin = new KProperty("margin-top", KReportUnit(KReportUnit::Centimeter).fromUserValue(1.0), tr("Top Margin"), tr("Top Margin"), KProperty::Double); d->bottomMargin = new KProperty("margin-bottom", KReportUnit(KReportUnit::Centimeter).fromUserValue(1.0), tr("Bottom Margin"), tr("Bottom Margin"), KProperty::Double); d->leftMargin->setOption("unit", QLatin1String("cm")); d->rightMargin->setOption("unit", QLatin1String("cm")); d->topMargin->setOption("unit", QLatin1String("cm")); d->bottomMargin->setOption("unit", QLatin1String("cm")); d->set.addProperty(d->title); d->set.addProperty(d->pageSize); d->set.addProperty(d->orientation); d->set.addProperty(d->unit); d->set.addProperty(d->gridSnap); d->set.addProperty(d->showGrid); d->set.addProperty(d->gridDivisions); d->set.addProperty(d->leftMargin); d->set.addProperty(d->rightMargin); d->set.addProperty(d->topMargin); d->set.addProperty(d->bottomMargin); #ifdef KREPORT_SCRIPTING d->script = new KProperty("script", QStringList(), QStringList(), QString(), tr("Object Script")); d->set.addProperty(d->script); #endif // KProperty* _customHeight; // KProperty* _customWidth; } /** @brief Handle property changes */ void KReportDesigner::slotPropertyChanged(KPropertySet &s, KProperty &p) { setModified(true); emit pagePropertyChanged(s); if (p.name() == "page-unit") { d->hruler->setUnit(pageUnit()); QString newstr = d->set.property("page-unit").value().toString(); d->set.property("margin-left").setOption("unit", newstr); d->set.property("margin-right").setOption("unit", newstr); d->set.property("margin-top").setOption("unit", newstr); d->set.property("margin-bottom").setOption("unit", newstr); } } void KReportDesigner::slotPageButton_Pressed() { #ifdef KREPORT_SCRIPTING if (d->scriptSource) { QStringList sl = d->scriptSource->scriptList(); sl.prepend(QString()); d->script->setListData(sl, sl); } changeSet(&d->set); #endif } QSize KReportDesigner::sizeHint() const { int w = 0; int h = 0; if (d->pageFooterAny) h += d->pageFooterAny->sizeHint().height(); if (d->pageFooterEven) h += d->pageFooterEven->sizeHint().height(); if (d->pageFooterFirst) h += d->pageFooterFirst->sizeHint().height(); if (d->pageFooterLast) h += d->pageFooterLast->sizeHint().height(); if (d->pageFooterOdd) h += d->pageFooterOdd->sizeHint().height(); if (d->pageHeaderAny) h += d->pageHeaderAny->sizeHint().height(); if (d->pageHeaderEven) h += d->pageHeaderEven->sizeHint().height(); if (d->pageHeaderFirst) h += d->pageHeaderFirst->sizeHint().height(); if (d->pageHeaderLast) h += d->pageHeaderLast->sizeHint().height(); if (d->pageHeaderOdd) h += d->pageHeaderOdd->sizeHint().height(); if (d->reportHeader) h += d->reportHeader->sizeHint().height(); if (d->reportFooter) { h += d->reportFooter->sizeHint().height(); } if (d->detail) { h += d->detail->sizeHint().height(); w += d->detail->sizeHint().width(); } h += d->hruler->height(); return QSize(w, h); } int KReportDesigner::pageWidthPx() const { 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)); QSize pageSizePx = layout.fullRectPixels(KReportPrivate::dpiX()).size(); int width = pageSizePx.width(); width = width - POINT_TO_INCH(d->set.property("margin-left").value().toDouble()) * KReportPrivate::dpiX(); width = width - POINT_TO_INCH(d->set.property("margin-right").value().toDouble()) * KReportPrivate::dpiX(); return width; } void KReportDesigner::resizeEvent(QResizeEvent * event) { Q_UNUSED(event); d->hruler->setRulerLength(pageWidthPx()); } void KReportDesigner::setDetail(KReportDesignerSectionDetail *rsd) { if (!d->detail) { int idx = 0; if (d->pageHeaderFirst) idx++; if (d->pageHeaderOdd) idx++; if (d->pageHeaderEven) idx++; if (d->pageHeaderLast) idx++; if (d->pageHeaderAny) idx++; if (d->reportHeader) idx++; d->detail = rsd; d->vboxlayout->insertWidget(idx, d->detail); } } void KReportDesigner::deleteDetail() { delete d->detail; d->detail = nullptr; } KReportUnit KReportDesigner::pageUnit() const { QString u; bool found; u = d->unit->value().toString(); KReportUnit unit = KReportUnit::fromSymbol(u, &found); if (!found) { unit = KReportUnit(KReportUnit::Centimeter); } return unit; } void KReportDesigner::setGridOptions(bool vis, int div) { d->showGrid->setValue(QVariant(vis)); d->gridDivisions->setValue(div); } // // methods for the sectionMouse*Event() // void KReportDesigner::sectionContextMenuEvent(KReportDesignerSectionScene * s, QGraphicsSceneContextMenuEvent * e) { Q_UNUSED(s); QMenu pop; bool itemsSelected = selectionCount() > 0; if (itemsSelected) { //! @todo KF5 use KStandardAction QAction *a = new QAction(QIcon::fromTheme(QLatin1String("edit-cut")), tr("Cut"), this); connect(a, SIGNAL(triggered()), this, SLOT(slotEditCut())); pop.addAction(a); //! @todo KF5 use KStandardAction a = new QAction(QIcon::fromTheme(QLatin1String("edit-copy")), tr("Copy"), this); connect(a, SIGNAL(triggered()), this, SLOT(slotEditCopy())); pop.addAction(a); } if (!d->sectionData.copy_list.isEmpty()) { QAction *a = new QAction(QIcon::fromTheme(QLatin1String("edit-paste")), tr("Paste"), this); connect(a, SIGNAL(triggered()), this, SLOT(slotEditPaste())); pop.addAction(a); } if (itemsSelected) { pop.addSeparator(); //! @todo KF5 use KStandard* //const KGuiItem del = KStandardGuiItem::del(); //a->setToolTip(del.toolTip()); //a->setShortcut(QKeySequence(QKeySequence::Delete)); QAction *a = new QAction(QIcon::fromTheme(QLatin1String("edit-delete")), tr("Delete"), this); connect(a, SIGNAL(triggered()), SLOT(slotEditDelete())); pop.addAction(a); } if (!pop.actions().isEmpty()) { pop.exec(e->screenPos()); } } void KReportDesigner::sectionMousePressEvent(KReportDesignerSectionView * v, QMouseEvent * e) { Q_UNUSED(v); d->pressX = e->pos().x(); d->pressY = e->pos().y(); } void KReportDesigner::sectionMouseReleaseEvent(KReportDesignerSectionView * v, QMouseEvent * e) { e->accept(); d->releaseX = e->pos().x(); d->releaseY = e->pos().y(); if (e->button() == Qt::LeftButton) { QPointF pos(d->pressX, d->pressY); QPointF end(d->releaseX, d->releaseY); if (d->releaseY >= v->scene()->height()) { d->releaseY = v->scene()->height(); end.setY(v->scene()->height()); } if (d->releaseX >= v->scene()->width()) { d->releaseX = v->scene()->width(); end.setX(v->scene()->width()); } - if (d->sectionData.mouseAction == ReportWriterSectionData::MA_Insert) { + if (d->sectionData.mouseAction == ReportWriterSectionData::MouseAction::Insert) { QGraphicsItem * item = nullptr; QString classString; QString iconName; if (d->sectionData.itemToInsert == QLatin1String("org.kde.kreport.line")) { item = new KReportDesignerItemLine(v->designer(), v->scene(), pos, end); classString = tr("Line", "Report line element"); iconName = QLatin1String("kreport-line-element"); } else { KReportPluginManager* pluginManager = KReportPluginManager::self(); KReportPluginInterface *plug = pluginManager->plugin(d->sectionData.itemToInsert); if (plug) { QObject *obj = plug->createDesignerInstance(v->designer(), v->scene(), pos); if (obj) { item = dynamic_cast(obj); classString = plug->metaData()->name(); iconName = plug->metaData()->iconName(); } } else { kreportWarning() << "attempted to insert an unknown item"; } } if (item) { item->setVisible(true); item->setSelected(true); KReportItemBase* baseReportItem = dynamic_cast(item); if (baseReportItem) { baseReportItem->setUnit(pageUnit()); KPropertySet *set = baseReportItem->propertySet(); KReportDesigner::addMetaProperties(set, classString, iconName); changeSet(set); if (v && v->designer()) { v->designer()->setModified(true); } emit itemInserted(d->sectionData.itemToInsert); } } - d->sectionData.mouseAction = ReportWriterSectionData::MA_None; + d->sectionData.mouseAction = ReportWriterSectionData::MouseAction::None; d->sectionData.itemToInsert.clear(); unsetSectionCursor(); } } } unsigned int KReportDesigner::selectionCount() const { if (activeScene()) return activeScene()->selectedItems().count(); else return 0; } void KReportDesigner::changeSet(KPropertySet *s) { //Set the checked state of the report properties button if (s == &d->set) d->pageButton->setCheckState(Qt::Checked); else d->pageButton->setCheckState(Qt::Unchecked); d->itemSet = s; emit propertySetChanged(); } // // Actions // void KReportDesigner::slotItem(const QString &entity) { //kreportDebug() << entity; - d->sectionData.mouseAction = ReportWriterSectionData::MA_Insert; + d->sectionData.mouseAction = ReportWriterSectionData::MouseAction::Insert; d->sectionData.itemToInsert = entity; setSectionCursor(QCursor(Qt::CrossCursor)); } void KReportDesigner::slotEditDelete() { QGraphicsItem * item = nullptr; bool modified = false; while (selectionCount() > 0) { item = activeScene()->selectedItems().value(0); if (item) { QGraphicsScene * scene = item->scene(); delete item; scene->update(); - d->sectionData.mouseAction = ReportWriterSectionData::MA_None; + d->sectionData.mouseAction = ReportWriterSectionData::MouseAction::None; modified = true; } } activeScene()->selectedItems().clear(); /*! @todo temporary: clears cut and copy lists to make sure we do not crash if weve deleted something in the list should really check if an item is in the list first and remove it. */ d->sectionData.cut_list.clear(); d->sectionData.copy_list.clear(); if (modified) { setModified(true); } } void KReportDesigner::slotEditCut() { if (selectionCount() > 0) { //First delete any items that are curerntly in the list //so as not to leak memory qDeleteAll(d->sectionData.cut_list); d->sectionData.cut_list.clear(); QGraphicsItem * item = activeScene()->selectedItems().first(); bool modified = false; if (item) { d->sectionData.copy_list.clear(); foreach(QGraphicsItem *item, activeScene()->selectedItems()) { d->sectionData.cut_list.append(dynamic_cast(item)); d->sectionData.copy_list.append(dynamic_cast(item)); } foreach(QGraphicsItem *item, activeScene()->selectedItems()) { activeScene()->removeItem(item); activeScene()->update(); modified = true; } d->sectionData.selected_x_offset = 10; d->sectionData.selected_y_offset = 10; } if (modified) { setModified(true); } } } void KReportDesigner::slotEditCopy() { if (selectionCount() < 1) return; QGraphicsItem * item = activeScene()->selectedItems().first(); if (item) { d->sectionData.copy_list.clear(); foreach(QGraphicsItem *item, activeScene()->selectedItems()) { d->sectionData.copy_list.append(dynamic_cast(item)); } d->sectionData.selected_x_offset = 10; d->sectionData.selected_y_offset = 10; } } void KReportDesigner::slotEditPaste() { // call the editPaste function passing it a reportsection slotEditPaste(activeScene()); } void KReportDesigner::slotEditPaste(QGraphicsScene * canvas) { // paste a new item of the copy we have in the specified location if (!d->sectionData.copy_list.isEmpty()) { QList activeItems = canvas->selectedItems(); QGraphicsItem *activeItem = nullptr; if (activeItems.count() == 1) { activeItem = activeItems.first(); } canvas->clearSelection(); - d->sectionData.mouseAction = ReportWriterSectionData::MA_None; + d->sectionData.mouseAction = ReportWriterSectionData::MouseAction::None; //! @todo this code sucks :) //! The setPos calls only work AFTER the name has been set ?!?!? foreach(KReportDesignerItemBase *item, d->sectionData.copy_list) { KReportItemBase *obj = dynamic_cast(item); const QString type = obj ? obj->typeName() : QLatin1String("object"); //kreportDebug() << type; KReportDesignerItemBase *ent = item->clone(); KReportItemBase *new_obj = dynamic_cast(ent); if (new_obj) { new_obj->setEntityName(suggestEntityName(type)); if (activeItem) { new_obj->setPosition(KReportItemBase::positionFromScene(QPointF(activeItem->x() + 10, activeItem->y() + 10))); } else { new_obj->setPosition(KReportItemBase::positionFromScene(QPointF(0, 0))); } changeSet(new_obj->propertySet()); } QGraphicsItem *pasted_ent = dynamic_cast(ent); if (pasted_ent) { pasted_ent->setSelected(true); canvas->addItem(pasted_ent); pasted_ent->show(); - d->sectionData.mouseAction = ReportWriterSectionData::MA_Grab; + d->sectionData.mouseAction = ReportWriterSectionData::MouseAction::Grab; setModified(true); } } } } void KReportDesigner::slotRaiseSelected() { dynamic_cast(activeScene())->raiseSelected(); } void KReportDesigner::slotLowerSelected() { dynamic_cast(activeScene())->lowerSelected(); } QGraphicsScene* KReportDesigner::activeScene() const { return d->activeScene; } void KReportDesigner::setActiveScene(QGraphicsScene* a) { if (d->activeScene && d->activeScene != a) d->activeScene->clearSelection(); d->activeScene = a; //Trigger an update so that the last scene redraws its title; update(); } QString KReportDesigner::suggestEntityName(const QString &name) const { KReportDesignerSection *sec; int itemCount = 0; - //Count items in the main sections - for (int i = 1; i <= KReportSectionData::PageFooterAny; i++) { - sec = section((KReportSectionData::Section) i); + // Count items in the main sections + for (int i = static_cast(KReportSectionData::Type::None) + 1; + i <= static_cast(KReportSectionData::Type::GroupFooter); i++) + { + sec = section(static_cast(i)); if (sec) { const QGraphicsItemList l = sec->items(); itemCount += l.count(); } } if (d->detail) { //Count items in the group headers/footers for (int i = 0; i < d->detail->groupSectionCount(); i++) { sec = d->detail->groupSection(i)->groupHeader(); if (sec) { const QGraphicsItemList l = sec->items(); itemCount += l.count(); } sec = d->detail->groupSection(i)->groupFooter(); if (sec) { const QGraphicsItemList l = sec->items(); itemCount += l.count(); } } sec = d->detail->detailSection(); if (sec) { const QGraphicsItemList l = sec->items(); itemCount += l.count(); } } while (!isEntityNameUnique(name + QString::number(itemCount))) { itemCount++; } return name + QString::number(itemCount); } bool KReportDesigner::isEntityNameUnique(const QString &name, KReportItemBase* ignore) const { KReportDesignerSection *sec; bool unique = true; - //Check items in the main sections - for (int i = 1; i <= KReportSectionData::PageFooterAny; i++) { - sec = section((KReportSectionData::Section)i); + // Check items in the main sections + for (int i = static_cast(KReportSectionData::Type::None); + i <= static_cast(KReportSectionData::Type::GroupFooter); i++) + { + sec = section(static_cast(i)); if (sec) { const QGraphicsItemList l = sec->items(); for (QGraphicsItemList::const_iterator it = l.constBegin(); it != l.constEnd(); ++it) { KReportItemBase* itm = dynamic_cast(*it); if (itm && itm->entityName() == name && itm != ignore) { unique = false; break; } } if (!unique) break; } } //Count items in the group headers/footers if (unique && d->detail) { for (int i = 0; i < d->detail->groupSectionCount(); ++i) { sec = d->detail->groupSection(i)->groupHeader(); if (sec) { const QGraphicsItemList l = sec->items(); for (QGraphicsItemList::const_iterator it = l.constBegin(); it != l.constEnd(); ++it) { KReportItemBase* itm = dynamic_cast(*it); if (itm && itm->entityName() == name && itm != ignore) { unique = false; break; } } } sec = d->detail->groupSection(i)->groupFooter(); if (unique && sec) { const QGraphicsItemList l = sec->items(); for (QGraphicsItemList::const_iterator it = l.constBegin(); it != l.constEnd(); ++it) { KReportItemBase* itm = dynamic_cast(*it); if (itm && itm->entityName() == name && itm != ignore) { unique = false; break; } } } } } if (unique && d->detail) { sec = d->detail->detailSection(); if (sec) { const QGraphicsItemList l = sec->items(); for (QGraphicsItemList::const_iterator it = l.constBegin(); it != l.constEnd(); ++it) { KReportItemBase* itm = dynamic_cast(*it); if (itm && itm->entityName() == name && itm != ignore) { unique = false; break; } } } } return unique; } static bool actionPriortyLessThan(QAction* act1, QAction* act2) { if (act1->data().toInt() > 0 && act2->data().toInt() > 0) { return act1->data().toInt() < act2->data().toInt(); } return false; } QList KReportDesigner::itemActions(QActionGroup* group) { KReportPluginManager* manager = KReportPluginManager::self(); QList actList = manager->createActions(group); //! @todo make line a real plugin so this isn't needed: QAction *act = new QAction(QIcon::fromTheme(QLatin1String("kreport-line-element")), tr("Line"), group); act->setObjectName(QLatin1String("org.kde.kreport.line")); act->setData(9); act->setCheckable(true); actList << act; qSort(actList.begin(), actList.end(), actionPriortyLessThan); int i = 0; /*! @todo maybe this is a bit hackish It finds the first plugin based on the priority in userdata The lowest oriority a plugin can have is 10 And inserts a separator before it. */ bool sepInserted = false; foreach(QAction *a, actList) { ++i; if (!sepInserted && a->data().toInt() >= 10) { QAction *sep = new QAction(QLatin1String("separator"), group); sep->setSeparator(true); actList.insert(i-1, sep); sepInserted = true; } if (group) { group->addAction(a); } } return actList; } QList< QAction* > KReportDesigner::designerActions() { QList al; QAction *sep = new QAction(QString(), this); sep->setSeparator(true); al << d->editCutAction << d->editCopyAction << d->editPasteAction << d->editDeleteAction << sep << d->sectionEdit << sep << d->itemLowerAction << d->itemRaiseAction; return al; } void KReportDesigner::createActions() { d->editCutAction = new QAction(QIcon::fromTheme(QLatin1String("edit-cut")), tr("Cu&t"), this); d->editCutAction->setObjectName(QLatin1String("edit_cut")); d->editCutAction->setToolTip(tr("Cut selection to clipboard")); d->editCutAction->setShortcuts(KStandardShortcut::cut()); d->editCutAction->setProperty("iconOnly", true); d->editCopyAction = new QAction(QIcon::fromTheme(QLatin1String("edit-copy")), tr("&Copy"), this); d->editCopyAction->setObjectName(QLatin1String("edit_copy")); d->editCopyAction->setToolTip(tr("Copy selection to clipboard")); d->editCopyAction->setShortcuts(KStandardShortcut::copy()); d->editCopyAction->setProperty("iconOnly", true); d->editPasteAction = new QAction(QIcon::fromTheme(QLatin1String("edit-paste")), tr("&Paste"), this); d->editPasteAction->setObjectName(QLatin1String("edit_paste")); d->editPasteAction->setToolTip(tr("Paste clipboard content")); d->editPasteAction->setShortcuts(KStandardShortcut::paste()); d->editPasteAction->setProperty("iconOnly", true); const KGuiItem del = KStandardGuiItem::del(); d->editDeleteAction = new QAction(del.icon(), del.text(), this); d->editDeleteAction->setObjectName(QLatin1String("edit_delete")); d->editDeleteAction->setToolTip(del.toolTip()); d->editDeleteAction->setWhatsThis(del.whatsThis()); d->editDeleteAction->setProperty("iconOnly", true); d->sectionEdit = new QAction(tr("Edit Sections"), this); d->sectionEdit->setObjectName(QLatin1String("section_edit")); d->itemRaiseAction = new QAction(QIcon::fromTheme(QLatin1String("arrow-up")), tr("Raise"), this); d->itemRaiseAction->setObjectName(QLatin1String("item_raise")); d->itemLowerAction = new QAction(QIcon::fromTheme(QLatin1String("arrow-down")), tr("Lower"), this); d->itemLowerAction->setObjectName(QLatin1String("item_lower")); //Edit Actions connect(d->editCutAction, SIGNAL(triggered(bool)), this, SLOT(slotEditCut())); connect(d->editCopyAction, SIGNAL(triggered(bool)), this, SLOT(slotEditCopy())); connect(d->editPasteAction, SIGNAL(triggered(bool)), this, SLOT(slotEditPaste())); connect(d->editDeleteAction, SIGNAL(triggered(bool)), this, SLOT(slotEditDelete())); connect(d->sectionEdit, SIGNAL(triggered(bool)), this, SLOT(slotSectionEditor())); //Raise/Lower connect(d->itemRaiseAction, SIGNAL(triggered(bool)), this, SLOT(slotRaiseSelected())); connect(d->itemLowerAction, SIGNAL(triggered(bool)), this, SLOT(slotLowerSelected())); } void KReportDesigner::setSectionCursor(const QCursor& c) { if (d->pageFooterAny) d->pageFooterAny->setSectionCursor(c); if (d->pageFooterEven) d->pageFooterEven->setSectionCursor(c); if (d->pageFooterFirst) d->pageFooterFirst->setSectionCursor(c); if (d->pageFooterLast) d->pageFooterLast->setSectionCursor(c); if (d->pageFooterOdd) d->pageFooterOdd->setSectionCursor(c); if (d->pageHeaderAny) d->pageHeaderAny->setSectionCursor(c); if (d->pageHeaderEven) d->pageHeaderEven->setSectionCursor(c); if (d->pageHeaderFirst) d->pageHeaderFirst->setSectionCursor(c); if (d->pageHeaderLast) d->pageHeaderLast->setSectionCursor(c); if (d->pageHeaderOdd) d->pageHeaderOdd->setSectionCursor(c); if (d->detail) d->detail->setSectionCursor(c); } void KReportDesigner::unsetSectionCursor() { if (d->pageFooterAny) d->pageFooterAny->unsetSectionCursor(); if (d->pageFooterEven) d->pageFooterEven->unsetSectionCursor(); if (d->pageFooterFirst) d->pageFooterFirst->unsetSectionCursor(); if (d->pageFooterLast) d->pageFooterLast->unsetSectionCursor(); if (d->pageFooterOdd) d->pageFooterOdd->unsetSectionCursor(); if (d->pageHeaderAny) d->pageHeaderAny->unsetSectionCursor(); if (d->pageHeaderEven) d->pageHeaderEven->unsetSectionCursor(); if (d->pageHeaderFirst) d->pageHeaderFirst->unsetSectionCursor(); if (d->pageHeaderLast) d->pageHeaderLast->unsetSectionCursor(); if (d->pageHeaderOdd) d->pageHeaderOdd->unsetSectionCursor(); if (d->detail) d->detail->unsetSectionCursor(); } qreal KReportDesigner::countSelectionHeight() const { if (d->releaseY == -1 || d->pressY == -1) { return -1; } return qAbs(d->releaseY - d->pressY); } qreal KReportDesigner::countSelectionWidth() const { if (d->releaseX == -1 || d->pressX == -1) { return -1; } return qAbs(d->releaseX - d->pressX); } qreal KReportDesigner::getSelectionPressX() const { return d->pressX; } qreal KReportDesigner::getSelectionPressY() const { return d->pressY; } QPointF KReportDesigner::getPressPoint() const { return QPointF(d->pressX, d->pressY); } QPointF KReportDesigner::getReleasePoint() const { return QPointF(d->releaseX, d->releaseY); } void KReportDesigner::plugItemActions(const QList &actList) { foreach(QAction *a, actList) { connect(a, SIGNAL(triggered(bool)), this, SLOT(slotItemTriggered(bool))); } } void KReportDesigner::slotItemTriggered(bool checked) { if (!checked) { return; } QObject *theSender = sender(); if (!theSender) { return; } slotItem(theSender->objectName()); } void KReportDesigner::addMetaProperties(KPropertySet* set, const QString &classString, const QString &iconName) { Q_ASSERT(set); KProperty *prop; set->addProperty(prop = new KProperty("this:classString", classString)); prop->setVisible(false); set->addProperty(prop = new KProperty("this:iconName", iconName)); prop->setVisible(false); } diff --git a/src/wrtembed/KReportDesigner.h b/src/wrtembed/KReportDesigner.h index fee140bf..97b91f91 100644 --- a/src/wrtembed/KReportDesigner.h +++ b/src/wrtembed/KReportDesigner.h @@ -1,360 +1,360 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC * Copyright (C) 2007-2008 by Adam Pigg * Copyright (C) 2011-2017 Jarosław Staniek * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef KREPORTDESIGNER_H #define KREPORTDESIGNER_H #include #include "KReportDocument.h" #include "KReportDataSource.h" class KProperty; class KPropertySet; class KReportItemBase; class QGraphicsScene; class QActionGroup; class QGraphicsSceneContextMenuEvent; class QString; class KReportDesignerSectionDetail; class KReportDesignerSection; class KReportUnit; class KReportDesignerSectionScene; class KReportDesignerSectionView; class QAction; #ifdef KREPORT_SCRIPTING class KReportScriptSource; #endif // // Class ReportDesigner // The ReportDesigner is the main widget for designing a report // class KREPORT_EXPORT KReportDesigner : public QWidget { Q_OBJECT public: /** @brief Constructor that create a blank designer @param widget QWidget parent */ explicit KReportDesigner(QWidget *parent = nullptr); /** @brief Constructor that create a designer, and loads the report described in the QDomElement @param widget QWidget parent @param element Report structure XML element */ KReportDesigner(QWidget *parent, const QDomElement &data); /** @brief Desctructor */ ~KReportDesigner() override; /** @brief Sets the report data The report data interface contains functions to retrieve data and information about the fields. @param source Pointer to KReportDataSource instance, ownership is transferred */ void setDataSource(KReportDataSource* source); #ifdef KREPORT_SCRIPTING /** @brief Sets the script source for the designer The script source contains function to return scripts supplied by the parent application @param source Pointer to KReportScriptSource instance, ownership is NOT transferred as it may be an application window */ void setScriptSource(KReportScriptSource *source); #endif /** @brief Return a pointer to the reports data @return Pointer to report data */ KReportDataSource *reportDataSource() const; /** @brief Return a pointer to the section specified @param section KReportSectionData::Section enum value of the section to return @return Pointer to report section object, or 0 if no section exists */ - KReportDesignerSection* section(KReportSectionData::Section) const; + KReportDesignerSection* section(KReportSectionData::Type type) const; /** @brief Creates new section @return Pointer to a new report section section object, ownership is transferred to the caller */ KReportDesignerSection* createSection() Q_REQUIRED_RESULT; /** @brief Deletes the section specified @param section KReportSectionData::Section enum value of the section to return */ - void removeSection(KReportSectionData::Section); + void removeSection(KReportSectionData::Type type); /** @brief Create a new section and insert it into the report @param section KReportSectionData::Section enum value of the section to return */ - void insertSection(KReportSectionData::Section); + void insertSection(KReportSectionData::Type type); /** @brief Return a pointer to the detail section. The detail section contains the actual detail section and related group sections @return Pointer to detail section */ KReportDesignerSectionDetail* detailSection() const; /** @brief Sets the title of the reportData @param title Report Title */ void setReportTitle(const QString &); /** @brief Sets the parameters for the display of the background gridpoints @param visible Grid visibility @param divisions Number of minor divisions between major points */ void setGridOptions(bool visible, int divisions); /** @brief Return the title of the report */ QString reportTitle() const; /** @brief Return an XML description of the report @return QDomElement describing the report definition */ QDomElement document() const; /** @brief Return true if the design has been modified @return modified status */ bool isModified() const; /** @return a list of field names in the selected KReportData */ QStringList fieldNames() const; /** @return a list of field keys in the selected KReportData The keys can be used to reference the names */ QStringList fieldKeys() const; /** @brief Calculate the width of the page in pixels given the paper size, orientation, dpi and margin @return integer value of width in pixels */ int pageWidthPx() const; /** @return the scene (section) that is currently active */ QGraphicsScene* activeScene() const; /** @brief Sets the active Scene @param scene The scene to make active */ void setActiveScene(QGraphicsScene* scene); /** @return the property set for the general report properties */ KPropertySet* propertySet() const; /** @brief Give a hint on the size of the widget */ QSize sizeHint() const override; /** @brief Return the current unit assigned to the report */ KReportUnit pageUnit() const; /** @brief Handle the context menu event for a report section @param scene The associated scene (section) */ void sectionContextMenuEvent(KReportDesignerSectionScene *s, QGraphicsSceneContextMenuEvent * e); /** @brief Handle the mouse release event for a report section */ void sectionMouseReleaseEvent(KReportDesignerSectionView *v, QMouseEvent * e); void sectionMousePressEvent(KReportDesignerSectionView *v, QMouseEvent * e); /** @brief Sets the property set for the currently selected item @param set Property set of item */ void changeSet(KPropertySet *); /** @brief Return the property set for the curently selected item */ KPropertySet* selectedItemPropertySet() const; /** @brief Sets the modified status, defaulting to true for modified @param modified Modified status */ void setModified(bool modified); /** @brief Return a unique name that can be used by the entity @param entity Name of entity */ QString suggestEntityName(const QString &name) const; /** @brief Checks if the supplied name is unique among all entities */ bool isEntityNameUnique(const QString &name, KReportItemBase *ignore = nullptr) const; /** @brief Returns a list of actions that represent the entities that can be inserted into the report. Actions are created as children of @a group and belong to the group. @return list of actions */ static QList itemActions(QActionGroup* group = nullptr); /** @brief Populates the toolbar with actions that can be applied to the report Actions are created as children of @a group and belong to the group. @return list of actions */ QList designerActions(); /** @return X position of mouse when mouse press occurs */ qreal getSelectionPressX() const; /** @return Y position of mouse when mouse press occurs */ qreal getSelectionPressY() const; /** @return difference between X position of mouse release and press */ qreal countSelectionWidth() const; /** @return difference between Y position of mouse release and press */ qreal countSelectionHeight() const; /** @return point that contains X,Y coordinates of mouse press */ QPointF getPressPoint() const; /** @return point that contains X,Y coordinates of mouse press */ QPointF getReleasePoint() const; void plugItemActions(const QList &actList); /** * @brief Adds meta-properties to the property set @a set for consumption by property editor * - "this:classString" - user-visible translated name of element type, e.g. tr("Label") * - "this:iconName" - name of user-visible icon, e.g. "kreport-label-element" * * All the properties are set to invisible. * @see propertySet() */ static void addMetaProperties(KPropertySet* set, const QString &classString, const QString &iconName); public Q_SLOTS: void slotEditDelete(); void slotEditCut(); void slotEditCopy(); void slotEditPaste(); void slotEditPaste(QGraphicsScene *); void slotItem(const QString&); void slotSectionEditor(); void slotRaiseSelected(); void slotLowerSelected(); private: /** @brief Sets the detail section to the given section */ void setDetail(KReportDesignerSectionDetail *rsd); /** @brief Deletes the detail section */ void deleteDetail(); void resizeEvent(QResizeEvent * event) override; //Properties void createProperties(); unsigned int selectionCount() const; void setSectionCursor(const QCursor&); void unsetSectionCursor(); void createActions(); private Q_SLOTS: void slotPropertyChanged(KPropertySet &s, KProperty &p); /** @brief When the 'page' button in the top left is pressed, change the property set to the reports properties. */ void slotPageButton_Pressed(); void slotItemTriggered(bool checked); Q_SIGNALS: void pagePropertyChanged(KPropertySet &s); void propertySetChanged(); void dirty(); void reportDataChanged(); void itemInserted(const QString& entity); private: Q_DISABLE_COPY(KReportDesigner) class Private; Private * const d; }; #endif diff --git a/src/wrtembed/KReportDesignerItemRectBase.cpp b/src/wrtembed/KReportDesignerItemRectBase.cpp index b3ea31a2..060ceb7f 100644 --- a/src/wrtembed/KReportDesignerItemRectBase.cpp +++ b/src/wrtembed/KReportDesignerItemRectBase.cpp @@ -1,396 +1,398 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportDesignerItemRectBase.h" #include "KReportDesignerSectionView.h" #include "KReportDesigner.h" #include "KReportDesignerSectionScene.h" #include "KReportUtils_p.h" #include #include #include class Q_DECL_HIDDEN KReportDesignerItemRectBase::Private { public: Private(); ~Private(); int grabAction = 0; }; KReportDesignerItemRectBase::Private::Private() { } KReportDesignerItemRectBase::Private::~Private() { } KReportDesignerItemRectBase::KReportDesignerItemRectBase(KReportDesigner *r, KReportItemBase *b) : QGraphicsRectItem(), KReportDesignerItemBase(r, b), d(new KReportDesignerItemRectBase::Private) { m_dpiX = KReportPrivate::dpiX(); m_dpiY = KReportPrivate::dpiY(); d->grabAction = 0; setAcceptHoverEvents(true); setFlags(ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges); } KReportDesignerItemRectBase::~KReportDesignerItemRectBase() { delete d; } QRectF KReportDesignerItemRectBase::sceneRect() { return QRectF(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size())); } QRectF KReportDesignerItemRectBase::pointRect() const { return QRectF(item()->position(), item()->size()); } -void KReportDesignerItemRectBase::setSceneRect(const QPointF& topLeft, const QSizeF& size, UpdatePropertyFlag update) +void KReportDesignerItemRectBase::setSceneRect(const QPointF& topLeft, const QSizeF& size, SceneRectFlag update) { setSceneRect(QRectF(topLeft, size), update); } -void KReportDesignerItemRectBase::setSceneRect(const QRectF& rect, UpdatePropertyFlag update) +void KReportDesignerItemRectBase::setSceneRect(const QRectF& rect, SceneRectFlag update) { QGraphicsRectItem::setPos(rect.x(), rect.y()); setRect(0, 0, rect.width(), rect.height()); - if (update == UpdateProperty) { + if (update == SceneRectFlag::UpdateProperty) { item()->setPosition(KReportItemBase::positionFromScene(QPointF(rect.x(), rect.y()))); item()->setSize(KReportItemBase::sizeFromScene(QSizeF(rect.width(), rect.height()))); } this->update(); } void KReportDesignerItemRectBase::mousePressEvent(QGraphicsSceneMouseEvent * event) { //Update and show properties item()->setPosition(KReportItemBase::positionFromScene(QPointF(sceneRect().x(), sceneRect().y()))); designer()->changeSet(item()->propertySet()); setSelected(true); scene()->update(); QGraphicsItem::mousePressEvent(event); } void KReportDesignerItemRectBase::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) { //Keep the size and position in sync item()->setPosition(KReportItemBase::positionFromScene(pos())); item()->setSize(KReportItemBase::sizeFromScene(QSizeF(rect().width(), rect().height()))); QGraphicsItem::mouseReleaseEvent(event); } void KReportDesignerItemRectBase::mouseMoveEvent(QGraphicsSceneMouseEvent * event) { //kreportDebug() << m_grabAction; qreal w, h; KReportDesignerSectionScene *section = qobject_cast(scene()); if (!section) { return; } QPointF p = section->gridPoint(event->scenePos()); w = p.x() - scenePos().x(); h = p.y() - scenePos().y(); //! @todo use an enum for the directions switch (d->grabAction) { case 1: if (sceneRect().y() - p.y() + rect().height() > 0 && sceneRect().x() - p.x() + rect().width() >= 0) setSceneRect(QPointF(p.x(), p.y()), QSizeF(sceneRect().x() - p.x() + rect().width(), sceneRect().y() - p.y() + rect().height())); break; case 2: if (sceneRect().y() - p.y() + rect().height() >= 0) setSceneRect(QPointF(sceneRect().x(), p.y()), QSizeF(rect().width(), sceneRect().y() - p.y() + rect().height())); break; case 3: if (sceneRect().y() - p.y() + rect().height() >= 0 && w >= 0) setSceneRect(QPointF(sceneRect().x(), p.y()), QSizeF(w, sceneRect().y() - p.y() + rect().height())); break; case 4: if (w >= 0) setSceneRect(QPointF(sceneRect().x(), sceneRect().y()), QSizeF(w, (rect().height()))); break; case 5: if (h >= 0 && w >= 0) setSceneRect(QPointF(sceneRect().x(), sceneRect().y()), QSizeF(w, h)); break; case 6: if (h >= 0) setSceneRect(QPointF(sceneRect().x(), sceneRect().y()), QSizeF((rect().width()), h)); break; case 7: if (sceneRect().x() - p.x() + rect().width() >= 0 && h >= 0) setSceneRect(QPointF(p.x(), sceneRect().y()), QSizeF(sceneRect().x() - p.x() + rect().width(), h)); break; case 8: if (sceneRect().x() - p.x() + rect().width() >= 0) setSceneRect(QPointF(p.x(), sceneRect().y()), QSizeF(sceneRect().x() - p.x() + rect().width(), rect().height())); break; default: QGraphicsItem::mouseMoveEvent(event); } } void KReportDesignerItemRectBase::hoverMoveEvent(QGraphicsSceneHoverEvent * event) { //m_grabAction = 0; if (isSelected()) { d->grabAction = grabHandle(event->pos()); switch (d->grabAction) { case 1: setCursor(Qt::SizeFDiagCursor); break; case 2: setCursor(Qt::SizeVerCursor); break; case 3: setCursor(Qt::SizeBDiagCursor); break; case 4: setCursor(Qt::SizeHorCursor); break; case 5: setCursor(Qt::SizeFDiagCursor); break; case 6: setCursor(Qt::SizeVerCursor); break; case 7: setCursor(Qt::SizeBDiagCursor); break; case 8: setCursor(Qt::SizeHorCursor); break; default: unsetCursor(); } } //kreportDebug() << m_grabAction; } void KReportDesignerItemRectBase::drawHandles(QPainter *painter) { if (isSelected()) { // draw a selected border for visual purposes painter->setPen(QPen(QColor(128, 128, 255), 0, Qt::DotLine)); painter->drawRect(rect()); const QRectF r = rect(); double halfW = (r.width() / 2); double halfH = (r.height() / 2); QPointF center = r.center(); center += QPointF(0.75,0.75); painter->fillRect(center.x() - halfW, center.y() - halfH , 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() - 2, center.y() - halfH , 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() + halfW - 4, center.y() - halfH, 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() + (halfW - 4), center.y() - 2, 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() + halfW - 4 , center.y() + halfH - 4 , 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() - 2, center.y() + halfH - 4, 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() - halfW, center.y() + halfH - 4 , 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() - halfW, center.y() - 2, 5, 5, QColor(128, 128, 255)); } } /** @return 1 2 3 8 0 4 7 6 5 */ int KReportDesignerItemRectBase::grabHandle(const QPointF &pos) { QRectF r = boundingRect(); int halfW = (int)(r.width() / 2); int halfH = (int)(r.height() / 2); QPointF center = r.center(); if (QRectF(center.x() - (halfW), center.y() - (halfH), 5, 5).contains(pos)) { // we are over the top-left handle return 1; } else if (QRectF(center.x() - 2, center.y() - (halfH), 5, 5).contains(pos)) { // top-middle handle return 2; } else if (QRectF(center.x() + (halfW - 4), center.y() - (halfH), 5, 5).contains(pos)) { // top-right return 3; } else if (QRectF(center.x() + (halfW - 4), center.y() - 2, 5, 5).contains(pos)) { // middle-right return 4; } else if (QRectF(center.x() + (halfW - 4), center.y() + (halfH - 4), 5, 5).contains(pos)) { // bottom-left return 5; } else if (QRectF(center.x() - 2, center.y() + (halfH - 4), 5, 5).contains(pos)) { // bottom-middle return 6; } else if (QRectF(center.x() - (halfW), center.y() + (halfH - 4), 5, 5).contains(pos)) { // bottom-right return 7; } else if (QRectF(center.x() - (halfW), center.y() - 2, 5, 5).contains(pos)) { // middle-right return 8; } return 0; } QVariant KReportDesignerItemRectBase::itemChange(GraphicsItemChange change, const QVariant &value) { KReportDesignerSectionScene *section = qobject_cast(scene()); if (section) { if (change == ItemPositionChange) { QPointF newPos = value.toPointF(); newPos = section->gridPoint(newPos); if (newPos.x() < 0) newPos.setX(0); else if (newPos.x() > (scene()->width() - rect().width())) newPos.setX(scene()->width() - rect().width()); if (newPos.y() < 0) newPos.setY(0); else if (newPos.y() > (scene()->height() - rect().height())) newPos.setY(scene()->height() - rect().height()); return newPos; } else if (change == ItemPositionHasChanged) { item()->setPosition(KReportItemBase::positionFromScene(value.toPointF())); //TODO dont update property //m_ppos->setScenePos(value.toPointF(), KReportPosition::DontUpdateProperty); } else if (change == ItemSceneHasChanged && item()) { QPointF newPos = pos(); newPos = section->gridPoint(newPos); if (newPos.x() < 0) newPos.setX(0); else if (newPos.x() > (scene()->width() - rect().width())) newPos.setX(scene()->width() - rect().width()); if (newPos.y() < 0) newPos.setY(0); else if (newPos.y() > (scene()->height() - rect().height())) newPos.setY(scene()->height() - rect().height()); - setSceneRect(newPos, KReportItemBase::sceneSize(item()->size()), KReportDesignerItemRectBase::DontUpdateProperty); + setSceneRect(newPos, KReportItemBase::sceneSize(item()->size()), + KReportDesignerItemRectBase::SceneRectFlag::DontUpdateProperty); } } return QGraphicsItem::itemChange(change, value); } void KReportDesignerItemRectBase::propertyChanged(const KPropertySet &s, const KProperty &p) { Q_UNUSED(s) Q_UNUSED(p) #if 0 if (p.name() == "position") { item()->setPosition(item()->unit().convertToPoint(p.value().toPointF())); //TODO dont update property } else if (p.name() == "size") { item()->setSize(item()->unit().convertToPoint(p.value().toSizeF())); //TODO dont update property } #endif - setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size()), DontUpdateProperty); + setSceneRect(KReportItemBase::scenePosition(item()->position()), + KReportItemBase::sceneSize(item()->size()), SceneRectFlag::DontUpdateProperty); } void KReportDesignerItemRectBase::move(const QPointF& /*m*/) { //! @todo } QPointF KReportDesignerItemRectBase::properPressPoint(const KReportDesigner &d) const { const QPointF pressPoint = d.getPressPoint(); const QPointF releasePoint = d.getReleasePoint(); if (releasePoint.x() < pressPoint.x() && releasePoint.y() < pressPoint.y()) { return releasePoint; } if (releasePoint.x() < pressPoint.x() && releasePoint.y() > pressPoint.y()) { return QPointF(releasePoint.x(), pressPoint.y()); } if (releasePoint.x() > pressPoint.x() && releasePoint.y() < pressPoint.y()) { return QPointF(pressPoint.x(), releasePoint.y()); } return QPointF(pressPoint); } QRectF KReportDesignerItemRectBase::properRect(const KReportDesigner &d, qreal minWidth, qreal minHeight) const { QPointF tempPressPoint = properPressPoint(d); qreal currentPressX = tempPressPoint.x(); qreal currentPressY = tempPressPoint.y(); const qreal width = qMax(d.countSelectionWidth(), minWidth); const qreal height = qMax(d.countSelectionHeight(), minHeight); qreal tempReleasePointX = tempPressPoint.x() + width; qreal tempReleasePointY = tempPressPoint.y() + height; if (tempReleasePointX > scene()->width()) { int offsetWidth = tempReleasePointX - scene()->width(); currentPressX = tempPressPoint.x() - offsetWidth; } if (tempReleasePointY > scene()->height()) { int offsetHeight = tempReleasePointY - scene()->height(); currentPressY = tempPressPoint.y() - offsetHeight; } return (QRectF(QPointF(currentPressX, currentPressY), QSizeF(width, height))); } void KReportDesignerItemRectBase::enterInlineEditingMode() { } void KReportDesignerItemRectBase::exitInlineEditingMode() { } void KReportDesignerItemBase::updateRenderText(const QString &itemDataSource, const QString &itemStaticValue, const QString &itemType) { if (itemDataSource.isEmpty()) { if (itemType.isEmpty()) { setRenderText(itemStaticValue); } else { setRenderText(dataSourceAndObjectTypeName(itemStaticValue, itemType)); } } else { if (itemType.isEmpty()) { setRenderText(itemDataSource); } else { setRenderText(dataSourceAndObjectTypeName(itemDataSource, itemType)); } } } diff --git a/src/wrtembed/KReportDesignerItemRectBase.h b/src/wrtembed/KReportDesignerItemRectBase.h index 4d0575a9..de1605ce 100644 --- a/src/wrtembed/KReportDesignerItemRectBase.h +++ b/src/wrtembed/KReportDesignerItemRectBase.h @@ -1,81 +1,83 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef KREPORTDESIGNERITEMRECTBASE_H #define KREPORTDESIGNERITEMRECTBASE_H #include #include "KReportDesignerItemBase.h" #include "kreport_export.h" class KReportDesigner; class KPropertySet; const int KREPORT_ITEM_RECT_DEFAULT_WIDTH = 100; const int KREPORT_ITEM_RECT_DEFAULT_HEIGHT = 100; /** */ class KREPORT_EXPORT KReportDesignerItemRectBase : public QGraphicsRectItem, public KReportDesignerItemBase { public: explicit KReportDesignerItemRectBase(KReportDesigner *r, KReportItemBase *b); ~KReportDesignerItemRectBase() override; QRectF pointRect() const; virtual void enterInlineEditingMode(); virtual void exitInlineEditingMode(); protected: int m_dpiX; int m_dpiY; - enum UpdatePropertyFlag { + enum class SceneRectFlag { UpdateProperty, DontUpdateProperty }; - void setSceneRect(const QPointF& topLeft, const QSizeF& size, UpdatePropertyFlag update = UpdateProperty); - void setSceneRect(const QRectF& rect, UpdatePropertyFlag update = UpdateProperty); + void setSceneRect(const QPointF &topLeft, const QSizeF &size, + SceneRectFlag update = SceneRectFlag::UpdateProperty); + void setSceneRect(const QRectF &rect, + SceneRectFlag update = SceneRectFlag::UpdateProperty); void drawHandles(QPainter*); QRectF sceneRect(); void mousePressEvent(QGraphicsSceneMouseEvent * event) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent * event) override; void mouseMoveEvent(QGraphicsSceneMouseEvent * event) override; void hoverMoveEvent(QGraphicsSceneHoverEvent * event) override; QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; void propertyChanged(const KPropertySet &s, const KProperty &p); void move(const QPointF&) override; QRectF properRect(const KReportDesigner &d, qreal minWidth, qreal minHeight) const; private: int grabHandle(const QPointF &pos); QPointF properPressPoint(const KReportDesigner &d) const; class Private; Private * const d; }; #endif diff --git a/src/wrtembed/KReportRuler_p.cpp b/src/wrtembed/KReportRuler_p.cpp index 60cc9ea2..4c3c5d6b 100644 --- a/src/wrtembed/KReportRuler_p.cpp +++ b/src/wrtembed/KReportRuler_p.cpp @@ -1,1518 +1,1528 @@ /* This file is part of the KDE project Copyright (C) 1998, 1999 Reginald Stadlbauer Copyright (C) 2006 Peter Simonsson Copyright (C) 2007 C. Boemann Copyright (C) 2007-2008 Jan Hambrecht Copyright (C) 2007 Thomas Zander This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "KReportRuler_p.h" #include "KReportZoomHandler_p.h" #include #include #include #include // the distance in pixels of a mouse position considered outside the rule static const int OutsideRulerThreshold = 20; // static const int fullStepMarkerLength = 6; static const int halfStepMarkerLength = 6; static const int quarterStepMarkerLength = 3; static const int measurementTextAboveBelowMargin = 1; class RulerTabChooser : public QWidget { public: RulerTabChooser(QWidget *parent) : QWidget(parent), m_type(QTextOption::LeftTab), m_showTabs(false) {} ~RulerTabChooser() override {} inline QTextOption::TabType type() {return m_type;} void setShowTabs(bool showTabs) { if (m_showTabs == showTabs) return; m_showTabs = showTabs; update(); } void mousePressEvent(QMouseEvent *) override; void paintEvent(QPaintEvent *) override; private: QTextOption::TabType m_type; bool m_showTabs :1; }; // ---- class PaintingStrategy { public: /// constructor PaintingStrategy() {} /// destructor virtual ~PaintingStrategy() {} /** * Draw the background of the ruler. * @param ruler the ruler to draw on. * @param painter the painter we can paint with. */ virtual QRectF drawBackground(const KReportRuler::Private *ruler, QPainter *painter) = 0; /** * Draw the indicators for text-tabs. * @param ruler the ruler to draw on. * @param painter the painter we can paint with. */ virtual void drawTabs(const KReportRuler::Private *ruler, QPainter *painter) = 0; /** * Draw the indicators for the measurements which typically are drawn every [unit]. * @param ruler the ruler to draw on. * @param painter the painter we can paint with. * @param rectangle */ virtual void drawMeasurements(const KReportRuler::Private *ruler, QPainter *painter, const QRectF &rectangle) = 0; /** * Draw the indicators for the indents of a text paragraph * @param ruler the ruler to draw on. * @param painter the painter we can paint with. */ virtual void drawIndents(const KReportRuler::Private *ruler, QPainter *painter) = 0; /** *returns the size suggestion for a ruler with this strategy. */ virtual QSize sizeHint() = 0; }; // ---- class HorizontalPaintingStrategy : public PaintingStrategy { public: HorizontalPaintingStrategy() : lengthInPixel(1) {} QRectF drawBackground(const KReportRuler::Private *ruler, QPainter *painter) override; void drawTabs(const KReportRuler::Private *ruler, QPainter *painter) override; void drawMeasurements(const KReportRuler::Private *ruler, QPainter *painter, const QRectF &rectangle) override; void drawIndents(const KReportRuler::Private *ruler, QPainter *painter) override; QSize sizeHint() override; private: qreal lengthInPixel; }; // ---- class VerticalPaintingStrategy : public PaintingStrategy { public: VerticalPaintingStrategy() : lengthInPixel(1) {} QRectF drawBackground(const KReportRuler::Private *ruler, QPainter *painter) override; void drawTabs(const KReportRuler::Private *, QPainter *) override {} void drawMeasurements(const KReportRuler::Private *ruler, QPainter *painter, const QRectF &rectangle) override; void drawIndents(const KReportRuler::Private *, QPainter *) override {} QSize sizeHint() override; private: qreal lengthInPixel; }; class HorizontalDistancesPaintingStrategy : public HorizontalPaintingStrategy { public: HorizontalDistancesPaintingStrategy() {} void drawMeasurements(const KReportRuler::Private *ruler, QPainter *painter, const QRectF &rectangle) override; private: void drawDistanceLine(const KReportRuler::Private *d, QPainter *painter, qreal start, qreal end); }; // ---- class KReportRuler::Private { public: Private(KReportRuler *parent, const KReportZoomHandler &zoomHandler, Qt::Orientation orientation); ~Private(); void emitTabChanged(); KReportUnit unit; const Qt::Orientation orientation; const KReportZoomHandler * const viewConverter; int offset; qreal rulerLength; qreal activeRangeStart; qreal activeRangeEnd; qreal activeOverrideRangeStart; qreal activeOverrideRangeEnd; int mouseCoordinate; int showMousePosition; bool showSelectionBorders; qreal firstSelectionBorder; qreal secondSelectionBorder; bool showIndents; qreal firstLineIndent; qreal paragraphIndent; qreal endIndent; bool showTabs; bool relativeTabs; bool tabMoved; // set to true on first move of a selected tab QList tabs; int originalIndex; //index of selected tab before we started dragging it. int currentIndex; //index of selected tab or selected HotSpot - only valid when selected indicates tab or hotspot KReportRuler::Tab deletedTab; qreal tabDistance; struct HotSpotData { qreal position; int id; }; QList hotspots; bool rightToLeft; - enum Selection { + enum class Selection { None, Tab, FirstLineIndent, ParagraphIndent, EndIndent, HotSpot }; Selection selected; int selectOffset; QList popupActions; RulerTabChooser *tabChooser; // Cached painting strategies PaintingStrategy * normalPaintingStrategy; PaintingStrategy * distancesPaintingStrategy; // Current painting strategy PaintingStrategy * paintingStrategy; KReportRuler *ruler; qreal numberStepForUnit() const; /// @return The rounding of value to the nearest multiple of stepValue qreal doSnapping(qreal value) const; Selection selectionAtPosition(const QPoint &pos, int *selectOffset = nullptr); int hotSpotIndex(const QPoint &pos); qreal effectiveActiveRangeStart() const; qreal effectiveActiveRangeEnd() const; friend class VerticalPaintingStrategy; friend class HorizontalPaintingStrategy; }; // ---- void RulerTabChooser::mousePressEvent(QMouseEvent *) { if (! m_showTabs) { return; } switch(m_type) { case QTextOption::LeftTab: m_type = QTextOption::RightTab; break; case QTextOption::RightTab: m_type = QTextOption::CenterTab; break; case QTextOption::CenterTab: m_type = QTextOption::DelimiterTab; break; case QTextOption::DelimiterTab: m_type = QTextOption::LeftTab; break; } update(); } void RulerTabChooser::paintEvent(QPaintEvent *) { if (! m_showTabs) { return; } QPainter painter(this); QPolygonF polygon; painter.setPen(palette().color(QPalette::Text)); painter.setBrush(palette().color(QPalette::Text)); painter.setRenderHint( QPainter::Antialiasing ); qreal x = qreal(width())/2.0; painter.translate(0,-height()/2+5); switch (m_type) { case QTextOption::LeftTab: polygon << QPointF(x+0.5, height() - 8.5) << QPointF(x+6.5, height() - 2.5) << QPointF(x+0.5, height() - 2.5); painter.drawPolygon(polygon); break; case QTextOption::RightTab: polygon << QPointF(x+0.5, height() - 8.5) << QPointF(x-5.5, height() - 2.5) << QPointF(x+0.5, height() - 2.5); painter.drawPolygon(polygon); break; case QTextOption::CenterTab: polygon << QPointF(x+0.5, height() - 8.5) << QPointF(x-5.5, height() - 2.5) << QPointF(x+6.5, height() - 2.5); painter.drawPolygon(polygon); break; case QTextOption::DelimiterTab: polygon << QPointF(x-5.5, height() - 2.5) << QPointF(x+6.5, height() - 2.5); painter.drawPolyline(polygon); polygon << QPointF(x+0.5, height() - 2.5) << QPointF(x+0.5, height() - 8.5); painter.drawPolyline(polygon); break; default: break; } } static int compareTabs(const KReportRuler::Tab &tab1, const KReportRuler::Tab &tab2) { return tab1.position < tab2.position; } QRectF HorizontalPaintingStrategy::drawBackground(const KReportRuler::Private *d, QPainter *painter) { lengthInPixel = d->viewConverter->documentToViewX(d->rulerLength); QRectF rectangle; rectangle.setX(qMax(0, d->offset)); rectangle.setY(0); rectangle.setWidth(qMin(qreal(d->ruler->width() - 1.0 - rectangle.x()), (d->offset >= 0) ? lengthInPixel : lengthInPixel + d->offset)); rectangle.setHeight(d->ruler->height() - 1); QRectF activeRangeRectangle; activeRangeRectangle.setX(qMax(rectangle.x() + 1, d->viewConverter->documentToViewX(d->effectiveActiveRangeStart()) + d->offset)); activeRangeRectangle.setY(rectangle.y() + 1); activeRangeRectangle.setRight(qMin(rectangle.right() - 1, d->viewConverter->documentToViewX(d->effectiveActiveRangeEnd()) + d->offset)); activeRangeRectangle.setHeight(rectangle.height() - 2); painter->setPen(d->ruler->palette().color(QPalette::Mid)); painter->drawRect(rectangle); if(d->effectiveActiveRangeStart() != d->effectiveActiveRangeEnd()) painter->fillRect(activeRangeRectangle, d->ruler->palette().brush(QPalette::Base)); if(d->showSelectionBorders) { // Draw first selection border if(d->firstSelectionBorder > 0) { qreal border = d->viewConverter->documentToViewX(d->firstSelectionBorder) + d->offset; painter->drawLine(QPointF(border, rectangle.y() + 1), QPointF(border, rectangle.bottom() - 1)); } // Draw second selection border if(d->secondSelectionBorder > 0) { qreal border = d->viewConverter->documentToViewX(d->secondSelectionBorder) + d->offset; painter->drawLine(QPointF(border, rectangle.y() + 1), QPointF(border, rectangle.bottom() - 1)); } } return rectangle; } void HorizontalPaintingStrategy::drawTabs(const KReportRuler::Private *d, QPainter *painter) { if (! d->showTabs) return; QPolygonF polygon; const QColor tabColor = d->ruler->palette().color(QPalette::Text); painter->setPen(tabColor); painter->setBrush(tabColor); painter->setRenderHint( QPainter::Antialiasing ); qreal position = -10000; foreach (const KReportRuler::Tab & t, d->tabs) { qreal x; if (d->rightToLeft) { x = d->viewConverter->documentToViewX(d->effectiveActiveRangeEnd() - (d->relativeTabs ? d->paragraphIndent : 0) - t.position) + d->offset; } else { x = d->viewConverter->documentToViewX(d->effectiveActiveRangeStart() + (d->relativeTabs ? d->paragraphIndent : 0) + t.position) + d->offset; } position = qMax(position, t.position); polygon.clear(); switch (t.type) { case QTextOption::LeftTab: polygon << QPointF(x+0.5, d->ruler->height() - 6.5) << QPointF(x+6.5, d->ruler->height() - 0.5) << QPointF(x+0.5, d->ruler->height() - 0.5); painter->drawPolygon(polygon); break; case QTextOption::RightTab: polygon << QPointF(x+0.5, d->ruler->height() - 6.5) << QPointF(x-5.5, d->ruler->height() - 0.5) << QPointF(x+0.5, d->ruler->height() - 0.5); painter->drawPolygon(polygon); break; case QTextOption::CenterTab: polygon << QPointF(x+0.5, d->ruler->height() - 6.5) << QPointF(x-5.5, d->ruler->height() - 0.5) << QPointF(x+6.5, d->ruler->height() - 0.5); painter->drawPolygon(polygon); break; case QTextOption::DelimiterTab: polygon << QPointF(x-5.5, d->ruler->height() - 0.5) << QPointF(x+6.5, d->ruler->height() - 0.5); painter->drawPolyline(polygon); polygon << QPointF(x+0.5, d->ruler->height() - 0.5) << QPointF(x+0.5, d->ruler->height() - 6.5); painter->drawPolyline(polygon); break; default: break; } } // and also draw the regular interval tab that are non editable if (d->tabDistance > 0.0) { // first possible position position = qMax(position, d->relativeTabs ? 0 : d->paragraphIndent); if (position < 0) { position = int(position / d->tabDistance) * d->tabDistance; } else { position = (int(position / d->tabDistance) + 1) * d->tabDistance; } while (position < d->effectiveActiveRangeEnd() - d->effectiveActiveRangeStart() - d->endIndent) { qreal x; if (d->rightToLeft) { x = d->viewConverter->documentToViewX(d->effectiveActiveRangeEnd() - (d->relativeTabs ? d->paragraphIndent : 0) - position) + d->offset; } else { x = d->viewConverter->documentToViewX(d->effectiveActiveRangeStart() + (d->relativeTabs ? d->paragraphIndent : 0) + position) + d->offset; } polygon.clear(); polygon << QPointF(x+0.5, d->ruler->height() - 3.5) << QPointF(x+4.5, d->ruler->height() - 0.5) << QPointF(x+0.5, d->ruler->height() - 0.5); painter->drawPolygon(polygon); position += d->tabDistance; } } } void HorizontalPaintingStrategy::drawMeasurements(const KReportRuler::Private *d, QPainter *painter, const QRectF &rectangle) { qreal numberStep = d->numberStepForUnit(); // number step in unit // QRectF activeRangeRectangle; int numberStepPixel = qRound(d->viewConverter->documentToViewX(d->unit.fromUserValue(numberStep))); // const bool adjustMillimeters = (d->unit.type() == KReportUnit::Millimeter); const QFont font = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont); const QFontMetrics fontMetrics(font); painter->setFont(font); if (numberStepPixel == 0 || numberStep == 0) return; // Calc the longest text length int textLength = 0; for(int i = 0; i < lengthInPixel; i += numberStepPixel) { int number = qRound((i / numberStepPixel) * numberStep); textLength = qMax(textLength, fontMetrics.width(QString::number(number))); } textLength += 4; // Add some padding // Change number step so all digits fits while(textLength > numberStepPixel) { numberStepPixel += numberStepPixel; numberStep += numberStep; } int start=0; // Calc the first number step if(d->offset < 0) start = qAbs(d->offset); // make a little hack so rulers shows correctly inversed number aligned const qreal lengthInUnit = d->unit.toUserValue(d->rulerLength); const qreal hackyLength = lengthInUnit - fmod(lengthInUnit, numberStep); if(d->rightToLeft) { start -= int(d->viewConverter->documentToViewX(fmod(d->rulerLength, d->unit.fromUserValue(numberStep)))); } int stepCount = (start / numberStepPixel) + 1; int halfStepCount = (start / qRound(numberStepPixel * 0.5)) + 1; int quarterStepCount = (start / qRound(numberStepPixel * 0.25)) + 1; int pos = 0; const QPen numberPen(d->ruler->palette().color(QPalette::Text)); const QPen markerPen(d->ruler->palette().color(QPalette::Inactive, QPalette::Text)); painter->setPen(markerPen); if(d->offset > 0) painter->translate(d->offset, 0); const int len = qRound(rectangle.width()) + start; int nextStep = qRound(d->viewConverter->documentToViewX( d->unit.fromUserValue(numberStep * stepCount))); int nextHalfStep = qRound(d->viewConverter->documentToViewX(d->unit.fromUserValue( numberStep * 0.5 * halfStepCount))); int nextQuarterStep = qRound(d->viewConverter->documentToViewX(d->unit.fromUserValue( numberStep * 0.25 * quarterStepCount))); for(int i = start; i < len; ++i) { pos = i - start; if(i == nextStep) { if(pos != 0) painter->drawLine(QPointF(pos, rectangle.bottom()-1), QPointF(pos, rectangle.bottom() - fullStepMarkerLength)); int number = qRound(stepCount * numberStep); QString numberText = QString::number(number); int x = pos; if (d->rightToLeft) { // this is done in a hacky way with the fine tuning done above numberText = QString::number(hackyLength - stepCount * numberStep); } painter->setPen(numberPen); painter->drawText(QPointF(x-fontMetrics.width(numberText)/2.0, rectangle.bottom() -fullStepMarkerLength -measurementTextAboveBelowMargin), numberText); painter->setPen(markerPen); ++stepCount; nextStep = qRound(d->viewConverter->documentToViewX( d->unit.fromUserValue(numberStep * stepCount))); ++halfStepCount; nextHalfStep = qRound(d->viewConverter->documentToViewX(d->unit.fromUserValue( numberStep * 0.5 * halfStepCount))); ++quarterStepCount; nextQuarterStep = qRound(d->viewConverter->documentToViewX(d->unit.fromUserValue( numberStep * 0.25 * quarterStepCount))); } else if(i == nextHalfStep) { if(pos != 0) painter->drawLine(QPointF(pos, rectangle.bottom()-1), QPointF(pos, rectangle.bottom() - halfStepMarkerLength)); ++halfStepCount; nextHalfStep = qRound(d->viewConverter->documentToViewX(d->unit.fromUserValue( numberStep * 0.5 * halfStepCount))); ++quarterStepCount; nextQuarterStep = qRound(d->viewConverter->documentToViewX(d->unit.fromUserValue( numberStep * 0.25 * quarterStepCount))); } else if(i == nextQuarterStep) { if(pos != 0) painter->drawLine(QPointF(pos, rectangle.bottom()-1), QPointF(pos, rectangle.bottom() - quarterStepMarkerLength)); ++quarterStepCount; nextQuarterStep = qRound(d->viewConverter->documentToViewX(d->unit.fromUserValue( numberStep * 0.25 * quarterStepCount))); } } // Draw the mouse indicator const int mouseCoord = d->mouseCoordinate - start; - if (d->selected == KReportRuler::Private::None || d->selected == KReportRuler::Private::HotSpot) { + if (d->selected == KReportRuler::Private::Selection::None + || d->selected == KReportRuler::Private::Selection::HotSpot) + { const qreal top = rectangle.y() + 1; const qreal bottom = rectangle.bottom() -1; - if (d->selected == KReportRuler::Private::None && d->showMousePosition && mouseCoord > 0 && mouseCoord < rectangle.width() ) + if (d->selected == KReportRuler::Private::Selection::None && d->showMousePosition + && mouseCoord > 0 && mouseCoord < rectangle.width()) + { painter->drawLine(QPointF(mouseCoord, top), QPointF(mouseCoord, bottom)); + } foreach (const KReportRuler::Private::HotSpotData & hp, d->hotspots) { const qreal x = d->viewConverter->documentToViewX(hp.position) + d->offset; painter->drawLine(QPointF(x, top), QPointF(x, bottom)); } } } void HorizontalPaintingStrategy::drawIndents(const KReportRuler::Private *d, QPainter *painter) { QPolygonF polygon; painter->setBrush(d->ruler->palette().brush(QPalette::Base)); painter->setRenderHint( QPainter::Antialiasing ); qreal x; // Draw first line start indent if (d->rightToLeft) x = d->effectiveActiveRangeEnd() - d->firstLineIndent - d->paragraphIndent; else x = d->effectiveActiveRangeStart() + d->firstLineIndent + d->paragraphIndent; // convert and use the +0.5 to go to nearest integer so that the 0.5 added below ensures sharp lines x = int(d->viewConverter->documentToViewX(x) + d->offset + 0.5); polygon << QPointF(x+6.5, 0.5) << QPointF(x+0.5, 8.5) << QPointF(x-5.5, 0.5) << QPointF(x+5.5, 0.5); painter->drawPolygon(polygon); // draw the hanging indent. if (d->rightToLeft) x = d->effectiveActiveRangeStart() + d->endIndent; else x = d->effectiveActiveRangeStart() + d->paragraphIndent; // convert and use the +0.5 to go to nearest integer so that the 0.5 added below ensures sharp lines x = int(d->viewConverter->documentToViewX(x) + d->offset + 0.5); const int bottom = d->ruler->height(); polygon.clear(); polygon << QPointF(x+6.5, bottom - 0.5) << QPointF(x+0.5, bottom - 8.5) << QPointF(x-5.5, bottom - 0.5) << QPointF(x+5.5, bottom - 0.5); painter->drawPolygon(polygon); // Draw end-indent or paragraph indent if mode is rightToLeft qreal diff; if (d->rightToLeft) diff = d->viewConverter->documentToViewX(d->effectiveActiveRangeEnd() - d->paragraphIndent) + d->offset - x; else diff = d->viewConverter->documentToViewX(d->effectiveActiveRangeEnd() - d->endIndent) + d->offset - x; polygon.translate(diff, 0); painter->drawPolygon(polygon); } QSize HorizontalPaintingStrategy::sizeHint() { // assumes that digits for the number only use glyphs which do not go below the baseline const QFontMetrics fm(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)); const int digitsHeight = fm.ascent() + 1; // +1 for baseline const int minimum = digitsHeight + fullStepMarkerLength + 2*measurementTextAboveBelowMargin; return QSize(0, minimum); } QRectF VerticalPaintingStrategy::drawBackground(const KReportRuler::Private *d, QPainter *painter) { lengthInPixel = d->viewConverter->documentToViewY(d->rulerLength); QRectF rectangle; rectangle.setX(0); rectangle.setY(qMax(0, d->offset)); rectangle.setWidth(d->ruler->width() - 1.0); rectangle.setHeight(qMin(qreal(d->ruler->height() - 1.0 - rectangle.y()), (d->offset >= 0) ? lengthInPixel : lengthInPixel + d->offset)); QRectF activeRangeRectangle; activeRangeRectangle.setX(rectangle.x() + 1); activeRangeRectangle.setY(qMax(rectangle.y() + 1, d->viewConverter->documentToViewY(d->effectiveActiveRangeStart()) + d->offset)); activeRangeRectangle.setWidth(rectangle.width() - 2); activeRangeRectangle.setBottom(qMin(rectangle.bottom() - 1, d->viewConverter->documentToViewY(d->effectiveActiveRangeEnd()) + d->offset)); painter->setPen(d->ruler->palette().color(QPalette::Mid)); painter->drawRect(rectangle); if(d->effectiveActiveRangeStart() != d->effectiveActiveRangeEnd()) painter->fillRect(activeRangeRectangle, d->ruler->palette().brush(QPalette::Base)); if(d->showSelectionBorders) { // Draw first selection border if(d->firstSelectionBorder > 0) { qreal border = d->viewConverter->documentToViewY(d->firstSelectionBorder) + d->offset; painter->drawLine(QPointF(rectangle.x() + 1, border), QPointF(rectangle.right() - 1, border)); } // Draw second selection border if(d->secondSelectionBorder > 0) { qreal border = d->viewConverter->documentToViewY(d->secondSelectionBorder) + d->offset; painter->drawLine(QPointF(rectangle.x() + 1, border), QPointF(rectangle.right() - 1, border)); } } return rectangle; } void VerticalPaintingStrategy::drawMeasurements(const KReportRuler::Private *d, QPainter *painter, const QRectF &rectangle) { qreal numberStep = d->numberStepForUnit(); // number step in unit int numberStepPixel = qRound(d->viewConverter->documentToViewY( d->unit.fromUserValue(numberStep))); if (numberStepPixel <= 0) return; const QFont font = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont); const QFontMetrics fontMetrics(font); painter->setFont(font); // Calc the longest text length int textLength = 0; for(int i = 0; i < lengthInPixel; i += numberStepPixel) { int number = qRound((i / numberStepPixel) * numberStep); textLength = qMax(textLength, fontMetrics.width(QString::number(number))); } textLength += 4; // Add some padding if (numberStepPixel == 0 || numberStep == 0) return; // Change number step so all digits will fit while(textLength > numberStepPixel) { numberStepPixel += numberStepPixel; numberStep += numberStep; } // Calc the first number step const int start = d->offset < 0 ? qAbs(d->offset) : 0; // make a little hack so rulers shows correctly inversed number aligned int stepCount = (start / numberStepPixel) + 1; int halfStepCount = (start / qRound(numberStepPixel * 0.5)) + 1; int quarterStepCount = (start / qRound(numberStepPixel * 0.25)) + 1; const QPen numberPen(d->ruler->palette().color(QPalette::Text)); const QPen markerPen(d->ruler->palette().color(QPalette::Inactive, QPalette::Text)); painter->setPen(markerPen); if(d->offset > 0) painter->translate(0, d->offset); const int len = qRound(rectangle.height()) + start; int nextStep = qRound(d->viewConverter->documentToViewY( d->unit.fromUserValue(numberStep * stepCount))); int nextHalfStep = qRound(d->viewConverter->documentToViewY(d->unit.fromUserValue( numberStep * 0.5 * halfStepCount))); int nextQuarterStep = qRound(d->viewConverter->documentToViewY(d->unit.fromUserValue( numberStep * 0.25 * quarterStepCount))); int pos = 0; for(int i = start; i < len; ++i) { pos = i - start; if(i == nextStep) { painter->save(); painter->translate(rectangle.right()-fullStepMarkerLength, pos); if(pos != 0) painter->drawLine(QPointF(0, 0), QPointF(fullStepMarkerLength-1, 0)); painter->rotate(-90); int number = qRound(stepCount * numberStep); QString numberText = QString::number(number); painter->setPen(numberPen); painter->drawText(QPointF(-fontMetrics.width(numberText) / 2.0, -measurementTextAboveBelowMargin), numberText); painter->restore(); ++stepCount; nextStep = qRound(d->viewConverter->documentToViewY( d->unit.fromUserValue(numberStep * stepCount))); ++halfStepCount; nextHalfStep = qRound(d->viewConverter->documentToViewY(d->unit.fromUserValue( numberStep * 0.5 * halfStepCount))); ++quarterStepCount; nextQuarterStep = qRound(d->viewConverter->documentToViewY(d->unit.fromUserValue( numberStep * 0.25 * quarterStepCount))); } else if(i == nextHalfStep) { if(pos != 0) painter->drawLine(QPointF(rectangle.right() - halfStepMarkerLength, pos), QPointF(rectangle.right() - 1, pos)); ++halfStepCount; nextHalfStep = qRound(d->viewConverter->documentToViewY(d->unit.fromUserValue( numberStep * 0.5 * halfStepCount))); ++quarterStepCount; nextQuarterStep = qRound(d->viewConverter->documentToViewY(d->unit.fromUserValue( numberStep * 0.25 * quarterStepCount))); } else if(i == nextQuarterStep) { if(pos != 0) painter->drawLine(QPointF(rectangle.right() - quarterStepMarkerLength, pos), QPointF(rectangle.right() - 1, pos)); ++quarterStepCount; nextQuarterStep = qRound(d->viewConverter->documentToViewY(d->unit.fromUserValue( numberStep * 0.25 * quarterStepCount))); } } // Draw the mouse indicator const int mouseCoord = d->mouseCoordinate - start; - if (d->selected == KReportRuler::Private::None || d->selected == KReportRuler::Private::HotSpot) { + if (d->selected == KReportRuler::Private::Selection::None + || d->selected == KReportRuler::Private::Selection::HotSpot) + { const qreal left = rectangle.left() + 1; const qreal right = rectangle.right() -1; - if (d->selected == KReportRuler::Private::None && d->showMousePosition && mouseCoord > 0 && mouseCoord < rectangle.height() ) + if (d->selected == KReportRuler::Private::Selection::None && d->showMousePosition + && mouseCoord > 0 && mouseCoord < rectangle.height()) + { painter->drawLine(QPointF(left, mouseCoord), QPointF(right, mouseCoord)); + } foreach (const KReportRuler::Private::HotSpotData & hp, d->hotspots) { const qreal y = d->viewConverter->documentToViewY(hp.position) + d->offset; painter->drawLine(QPointF(left, y), QPointF(right, y)); } } } QSize VerticalPaintingStrategy::sizeHint() { // assumes that digits for the number only use glyphs which do not go below the baseline const QFontMetrics fm(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)); const int digitsHeight = fm.ascent() + 1; // +1 for baseline const int minimum = digitsHeight + fullStepMarkerLength + 2*measurementTextAboveBelowMargin; return QSize(minimum, 0); } void HorizontalDistancesPaintingStrategy::drawDistanceLine(const KReportRuler::Private *d, QPainter *painter, qreal start, qreal end) { // Don't draw too short lines if (qMax(start, end) - qMin(start, end) < 1) return; painter->save(); painter->translate(d->offset, d->ruler->height() / 2); painter->setPen(d->ruler->palette().color(QPalette::Text)); painter->setBrush(d->ruler->palette().color(QPalette::Text)); QLineF line(QPointF(d->viewConverter->documentToViewX(start), 0), QPointF(d->viewConverter->documentToViewX(end), 0)); QPointF midPoint = line.pointAt(0.5); // Draw the label text const QFont font = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont); const QFontMetrics fontMetrics(font); QString label = d->unit.toUserStringValue( d->viewConverter->viewToDocumentX(line.length())) + QLatin1String("") + d->unit.symbol(); QPointF labelPosition = QPointF(midPoint.x() - fontMetrics.width(label)/2, midPoint.y() + fontMetrics.ascent()/2); painter->setFont(font); painter->drawText(labelPosition, label); // Draw the arrow lines qreal arrowLength = (line.length() - fontMetrics.width(label)) / 2 - 2; arrowLength = qMax(qreal(0.0), arrowLength); QLineF startArrow(line.p1(), line.pointAt(arrowLength / line.length())); QLineF endArrow(line.p2(), line.pointAt(1.0 - arrowLength / line.length())); painter->drawLine(startArrow); painter->drawLine(endArrow); // Draw the arrow heads QPolygonF arrowHead; arrowHead << line.p1() << QPointF(line.x1()+3, line.y1()-3) << QPointF(line.x1()+3, line.y1()+3); painter->drawPolygon(arrowHead); arrowHead.clear(); arrowHead << line.p2() << QPointF(line.x2()-3, line.y2()-3) << QPointF(line.x2()-3, line.y2()+3); painter->drawPolygon(arrowHead); painter->restore(); } void HorizontalDistancesPaintingStrategy::drawMeasurements(const KReportRuler::Private *d, QPainter *painter, const QRectF&) { QList points; points << 0.0; points << d->effectiveActiveRangeStart() + d->paragraphIndent + d->firstLineIndent; points << d->effectiveActiveRangeStart() + d->paragraphIndent; points << d->effectiveActiveRangeEnd() - d->endIndent; points << d->effectiveActiveRangeStart(); points << d->effectiveActiveRangeEnd(); points << d->rulerLength; qSort(points.begin(), points.end()); QListIterator i(points); i.next(); while (i.hasNext() && i.hasPrevious()) { drawDistanceLine(d, painter, i.peekPrevious(), i.peekNext()); i.next(); } } KReportRuler::Private::Private(KReportRuler *parent, const KReportZoomHandler &zoomHandler, Qt::Orientation o) : unit(KReportUnit(KReportUnit::Point)), orientation(o), viewConverter(&zoomHandler), offset(0), rulerLength(0), activeRangeStart(0), activeRangeEnd(0), activeOverrideRangeStart(0), activeOverrideRangeEnd(0), mouseCoordinate(-1), showMousePosition(0), showSelectionBorders(false), firstSelectionBorder(0), secondSelectionBorder(0), showIndents(false), firstLineIndent(0), paragraphIndent(0), endIndent(0), showTabs(false), relativeTabs(false), tabMoved(false), originalIndex(-1), currentIndex(0), tabDistance(0.0), rightToLeft(false), - selected(None), + selected(Selection::None), selectOffset(0), tabChooser(nullptr), normalPaintingStrategy(o == Qt::Horizontal ? (PaintingStrategy*)new HorizontalPaintingStrategy() : (PaintingStrategy*)new VerticalPaintingStrategy()), distancesPaintingStrategy((PaintingStrategy*)new HorizontalDistancesPaintingStrategy()), paintingStrategy(normalPaintingStrategy), ruler(parent) { } KReportRuler::Private::~Private() { delete normalPaintingStrategy; delete distancesPaintingStrategy; } qreal KReportRuler::Private::numberStepForUnit() const { switch(unit.type()) { case KReportUnit::Inch: case KReportUnit::Centimeter: case KReportUnit::Decimeter: case KReportUnit::Millimeter: return 1.0; case KReportUnit::Pica: case KReportUnit::Cicero: return 10.0; case KReportUnit::Point: default: return 100.0; } } qreal KReportRuler::Private::doSnapping(qreal value) const { qreal numberStep = unit.fromUserValue(numberStepForUnit()/4.0); return numberStep * qRound(value / numberStep); } KReportRuler::Private::Selection KReportRuler::Private::selectionAtPosition(const QPoint & pos, int *selectOffset ) { const int height = ruler->height(); if (rightToLeft) { int x = int(viewConverter->documentToViewX(effectiveActiveRangeEnd() - firstLineIndent - paragraphIndent) + offset); if (pos.x() >= x - 8 && pos.x() <= x +8 && pos.y() < height / 2) { if (selectOffset) *selectOffset = x - pos.x(); - return KReportRuler::Private::FirstLineIndent; + return KReportRuler::Private::Selection::FirstLineIndent; } x = int(viewConverter->documentToViewX(effectiveActiveRangeEnd() - paragraphIndent) + offset); if (pos.x() >= x - 8 && pos.x() <= x +8 && pos.y() > height / 2) { if (selectOffset) *selectOffset = x - pos.x(); - return KReportRuler::Private::ParagraphIndent; + return KReportRuler::Private::Selection::ParagraphIndent; } x = int(viewConverter->documentToViewX(effectiveActiveRangeStart() + endIndent) + offset); if (pos.x() >= x - 8 && pos.x() <= x + 8) { if (selectOffset) *selectOffset = x - pos.x(); - return KReportRuler::Private::EndIndent; + return KReportRuler::Private::Selection::EndIndent; } } else { int x = int(viewConverter->documentToViewX(effectiveActiveRangeStart() + firstLineIndent + paragraphIndent) + offset); if (pos.x() >= x -8 && pos.x() <= x + 8 && pos.y() < height / 2) { if (selectOffset) *selectOffset = x - pos.x(); - return KReportRuler::Private::FirstLineIndent; + return KReportRuler::Private::Selection::FirstLineIndent; } x = int(viewConverter->documentToViewX(effectiveActiveRangeStart() + paragraphIndent) + offset); if (pos.x() >= x - 8 && pos.x() <= x + 8 && pos.y() > height/2) { if (selectOffset) *selectOffset = x - pos.x(); - return KReportRuler::Private::ParagraphIndent; + return KReportRuler::Private::Selection::ParagraphIndent; } x = int(viewConverter->documentToViewX(effectiveActiveRangeEnd() - endIndent) + offset); if (pos.x() >= x - 8 && pos.x() <= x + 8) { if (selectOffset) *selectOffset = x - pos.x(); - return KReportRuler::Private::EndIndent; + return KReportRuler::Private::Selection::EndIndent; } } - return KReportRuler::Private::None; + return KReportRuler::Private::Selection::None; } int KReportRuler::Private::hotSpotIndex(const QPoint & pos) { for(int counter = 0; counter < hotspots.count(); counter++) { bool hit; if (orientation == Qt::Horizontal) hit = qAbs(viewConverter->documentToViewX(hotspots[counter].position) - pos.x() + offset) < 3; else hit = qAbs(viewConverter->documentToViewY(hotspots[counter].position) - pos.y() + offset) < 3; if (hit) return counter; } return -1; } qreal KReportRuler::Private::effectiveActiveRangeStart() const { if (activeOverrideRangeStart != activeOverrideRangeEnd) { return activeOverrideRangeStart; } else { return activeRangeStart; } } qreal KReportRuler::Private::effectiveActiveRangeEnd() const { if (activeOverrideRangeStart != activeOverrideRangeEnd) { return activeOverrideRangeEnd; } else { return activeRangeEnd; } } void KReportRuler::Private::emitTabChanged() { KReportRuler::Tab tab; if (currentIndex >= 0) tab = tabs[currentIndex]; emit ruler->tabChanged(originalIndex, currentIndex >= 0 ? &tab : nullptr); } KReportRuler::KReportRuler(QWidget* parent, Qt::Orientation orientation, const KReportZoomHandler &zoomHandler) : QWidget(parent) , d(new KReportRuler::Private(this, zoomHandler, orientation)) { setMouseTracking( true ); } KReportRuler::~KReportRuler() { delete d; } KReportUnit KReportRuler::unit() const { return d->unit; } void KReportRuler::setUnit(const KReportUnit &unit) { d->unit = unit; update(); } qreal KReportRuler::rulerLength() const { return d->rulerLength; } Qt::Orientation KReportRuler::orientation() const { return d->orientation; } void KReportRuler::setOffset(int offset) { d->offset = offset; update(); } void KReportRuler::setRulerLength(qreal length) { d->rulerLength = length; update(); } void KReportRuler::paintEvent(QPaintEvent* event) { QPainter painter(this); painter.setClipRegion(event->region()); painter.save(); QRectF rectangle = d->paintingStrategy->drawBackground(d, &painter); painter.restore(); painter.save(); d->paintingStrategy->drawMeasurements(d, &painter, rectangle); painter.restore(); if (d->showIndents) { painter.save(); d->paintingStrategy->drawIndents(d, &painter); painter.restore(); } d->paintingStrategy->drawTabs(d, &painter); } QSize KReportRuler::minimumSizeHint() const { return d->paintingStrategy->sizeHint(); } QSize KReportRuler::sizeHint() const { return d->paintingStrategy->sizeHint(); } void KReportRuler::setActiveRange(qreal start, qreal end) { d->activeRangeStart = start; d->activeRangeEnd = end; update(); } void KReportRuler::setOverrideActiveRange(qreal start, qreal end) { d->activeOverrideRangeStart = start; d->activeOverrideRangeEnd = end; update(); } void KReportRuler::updateMouseCoordinate(int coordinate) { if(d->mouseCoordinate == coordinate) return; d->mouseCoordinate = coordinate; update(); } void KReportRuler::setShowMousePosition(bool show) { d->showMousePosition = show; update(); } void KReportRuler::setRightToLeft(bool isRightToLeft) { d->rightToLeft = isRightToLeft; update(); } void KReportRuler::setShowIndents(bool show) { d->showIndents = show; update(); } void KReportRuler::setFirstLineIndent(qreal indent) { d->firstLineIndent = indent; if (d->showIndents) { update(); } } void KReportRuler::setParagraphIndent(qreal indent) { d->paragraphIndent = indent; if (d->showIndents) { update(); } } void KReportRuler::setEndIndent(qreal indent) { d->endIndent = indent; if (d->showIndents) { update(); } } qreal KReportRuler::firstLineIndent() const { return d->firstLineIndent; } qreal KReportRuler::paragraphIndent() const { return d->paragraphIndent; } qreal KReportRuler::endIndent() const { return d->endIndent; } QWidget *KReportRuler::tabChooser() { if ((d->tabChooser == nullptr) && (d->orientation == Qt::Horizontal)) { d->tabChooser = new RulerTabChooser(parentWidget()); d->tabChooser->setShowTabs(d->showTabs); } return d->tabChooser; } void KReportRuler::setShowSelectionBorders(bool show) { d->showSelectionBorders = show; update(); } void KReportRuler::updateSelectionBorders(qreal first, qreal second) { d->firstSelectionBorder = first; d->secondSelectionBorder = second; if(d->showSelectionBorders) update(); } void KReportRuler::setShowTabs(bool show) { if (d->showTabs == show) { return; } d->showTabs = show; if (d->tabChooser) { d->tabChooser->setShowTabs(show); } update(); } void KReportRuler::setRelativeTabs(bool relative) { d->relativeTabs = relative; if (d->showTabs) { update(); } } void KReportRuler::updateTabs(const QList &tabs, qreal tabDistance) { d->tabs = tabs; d->tabDistance = tabDistance; if (d->showTabs) { update(); } } QList KReportRuler::tabs() const { QList answer = d->tabs; qSort(answer.begin(), answer.end(), compareTabs); return answer; } void KReportRuler::setPopupActionList(const QList &popupActionList) { d->popupActions = popupActionList; } QList KReportRuler::popupActionList() const { return d->popupActions; } void KReportRuler::mousePressEvent ( QMouseEvent* ev ) { d->tabMoved = false; - d->selected = KReportRuler::Private::None; + d->selected = KReportRuler::Private::Selection::None; if (ev->button() == Qt::RightButton && !d->popupActions.isEmpty()) QMenu::exec(d->popupActions, ev->globalPos()); if (ev->button() != Qt::LeftButton) { ev->ignore(); return; } QPoint pos = ev->pos(); if (d->showTabs) { int i = 0; int x; foreach (const Tab & t, d->tabs) { if (d->rightToLeft) { x = d->viewConverter->documentToViewX(d->effectiveActiveRangeEnd() - (d->relativeTabs ? d->paragraphIndent : 0) - t.position) + d->offset; } else { x = d->viewConverter->documentToViewX(d->effectiveActiveRangeStart() + (d->relativeTabs ? d->paragraphIndent : 0) + t.position) + d->offset; } if (pos.x() >= x-6 && pos.x() <= x+6) { - d->selected = KReportRuler::Private::Tab; + d->selected = KReportRuler::Private::Selection::Tab; d->selectOffset = x - pos.x(); d->currentIndex = i; break; } i++; } d->originalIndex = d->currentIndex; } - if (d->selected == KReportRuler::Private::None) + if (d->selected == KReportRuler::Private::Selection::None) d->selected = d->selectionAtPosition(ev->pos(), &d->selectOffset); - if (d->selected == KReportRuler::Private::None) { + if (d->selected == KReportRuler::Private::Selection::None) { int hotSpotIndex = d->hotSpotIndex(ev->pos()); if (hotSpotIndex >= 0) { - d->selected = KReportRuler::Private::HotSpot; + d->selected = KReportRuler::Private::Selection::HotSpot; update(); } } - if (d->showTabs && d->selected == KReportRuler::Private::None) { + if (d->showTabs && d->selected == KReportRuler::Private::Selection::None) { // still haven't found something so let assume the user wants to add a tab qreal tabpos; if (d->rightToLeft) { tabpos = d->viewConverter->viewToDocumentX(pos.x() - d->offset) + d->effectiveActiveRangeEnd() + (d->relativeTabs ? d->paragraphIndent : 0); } else { tabpos = d->viewConverter->viewToDocumentX(pos.x() - d->offset) - d->effectiveActiveRangeStart() - (d->relativeTabs ? d->paragraphIndent : 0); } Tab t(tabpos, d->tabChooser ? d->tabChooser->type() : d->rightToLeft ? QTextOption::RightTab : QTextOption::LeftTab); d->tabs.append(t); d->selectOffset = 0; - d->selected = KReportRuler::Private::Tab; + d->selected = KReportRuler::Private::Selection::Tab; d->currentIndex = d->tabs.count() - 1; d->originalIndex = -1; // new! update(); } if (d->orientation == Qt::Horizontal && (ev->modifiers() & Qt::ShiftModifier) && - (d->selected == KReportRuler::Private::FirstLineIndent || - d->selected == KReportRuler::Private::ParagraphIndent || - d->selected == KReportRuler::Private::Tab || - d->selected == KReportRuler::Private::EndIndent)) + (d->selected == KReportRuler::Private::Selection::FirstLineIndent || + d->selected == KReportRuler::Private::Selection::ParagraphIndent || + d->selected == KReportRuler::Private::Selection::Tab || + d->selected == KReportRuler::Private::Selection::EndIndent)) d->paintingStrategy = d->distancesPaintingStrategy; - if (d->selected != KReportRuler::Private::None) + if (d->selected != KReportRuler::Private::Selection::None) emit aboutToChange(); } void KReportRuler::mouseReleaseEvent ( QMouseEvent* ev ) { ev->accept(); - if (d->selected == KReportRuler::Private::Tab) { + if (d->selected == KReportRuler::Private::Selection::Tab) { if (d->originalIndex >= 0 && !d->tabMoved) { int type = d->tabs[d->currentIndex].type; type++; if (type > 3) type = 0; d->tabs[d->currentIndex].type = static_cast (type); update(); } d->emitTabChanged(); } - else if( d->selected != KReportRuler::Private::None) + else if( d->selected != KReportRuler::Private::Selection::None) emit indentsChanged(true); else ev->ignore(); d->paintingStrategy = d->normalPaintingStrategy; - d->selected = KReportRuler::Private::None; + d->selected = KReportRuler::Private::Selection::None; } void KReportRuler::mouseMoveEvent ( QMouseEvent* ev ) { QPoint pos = ev->pos(); qreal activeLength = d->effectiveActiveRangeEnd() - d->effectiveActiveRangeStart(); switch (d->selected) { - case KReportRuler::Private::FirstLineIndent: + case KReportRuler::Private::Selection::FirstLineIndent: if (d->rightToLeft) d->firstLineIndent = d->effectiveActiveRangeEnd() - d->paragraphIndent - d->viewConverter->viewToDocumentX(pos.x() + d->selectOffset - d->offset); else d->firstLineIndent = d->viewConverter->viewToDocumentX(pos.x() + d->selectOffset - d->offset) - d->effectiveActiveRangeStart() - d->paragraphIndent; if( ! (ev->modifiers() & Qt::ShiftModifier)) { d->firstLineIndent = d->doSnapping(d->firstLineIndent); d->paintingStrategy = d->normalPaintingStrategy; } else { if (d->orientation == Qt::Horizontal) d->paintingStrategy = d->distancesPaintingStrategy; } emit indentsChanged(false); break; - case KReportRuler::Private::ParagraphIndent: + case KReportRuler::Private::Selection::ParagraphIndent: if (d->rightToLeft) d->paragraphIndent = d->effectiveActiveRangeEnd() - d->viewConverter->viewToDocumentX(pos.x() + d->selectOffset - d->offset); else d->paragraphIndent = d->viewConverter->viewToDocumentX(pos.x() + d->selectOffset - d->offset) - d->effectiveActiveRangeStart(); if( ! (ev->modifiers() & Qt::ShiftModifier)) { d->paragraphIndent = d->doSnapping(d->paragraphIndent); d->paintingStrategy = d->normalPaintingStrategy; } else { if (d->orientation == Qt::Horizontal) d->paintingStrategy = d->distancesPaintingStrategy; } if (d->paragraphIndent + d->endIndent > activeLength) d->paragraphIndent = activeLength - d->endIndent; emit indentsChanged(false); break; - case KReportRuler::Private::EndIndent: + case KReportRuler::Private::Selection::EndIndent: if (d->rightToLeft) d->endIndent = d->viewConverter->viewToDocumentX(pos.x() + d->selectOffset - d->offset) - d->effectiveActiveRangeStart(); else d->endIndent = d->effectiveActiveRangeEnd() - d->viewConverter->viewToDocumentX(pos.x() + d->selectOffset - d->offset); if (!(ev->modifiers() & Qt::ShiftModifier)) { d->endIndent = d->doSnapping(d->endIndent); d->paintingStrategy = d->normalPaintingStrategy; } else { if (d->orientation == Qt::Horizontal) d->paintingStrategy = d->distancesPaintingStrategy; } if (d->paragraphIndent + d->endIndent > activeLength) d->endIndent = activeLength - d->paragraphIndent; emit indentsChanged(false); break; - case KReportRuler::Private::Tab: + case KReportRuler::Private::Selection::Tab: d->tabMoved = true; if (d->currentIndex < 0) { // tab is deleted. if (ev->pos().y() < height()) { // reinstante it. d->currentIndex = d->tabs.count(); d->tabs.append(d->deletedTab); } else { break; } } if (d->rightToLeft) d->tabs[d->currentIndex].position = d->effectiveActiveRangeEnd() - d->viewConverter->viewToDocumentX(pos.x() + d->selectOffset - d->offset); else d->tabs[d->currentIndex].position = d->viewConverter->viewToDocumentX(pos.x() + d->selectOffset - d->offset) - d->effectiveActiveRangeStart(); if (!(ev->modifiers() & Qt::ShiftModifier)) d->tabs[d->currentIndex].position = d->doSnapping(d->tabs[d->currentIndex].position); if (d->tabs[d->currentIndex].position < 0) d->tabs[d->currentIndex].position = 0; if (d->tabs[d->currentIndex].position > activeLength) d->tabs[d->currentIndex].position = activeLength; if (ev->pos().y() > height() + OutsideRulerThreshold ) { // moved out of the ruler, delete it. d->deletedTab = d->tabs.takeAt(d->currentIndex); d->currentIndex = -1; // was that a temporary added tab? if ( d->originalIndex == -1 ) emit guideLineCreated(d->orientation, d->orientation == Qt::Horizontal ? d->viewConverter->viewToDocumentY(ev->pos().y()) : d->viewConverter->viewToDocumentX(ev->pos().x())); } d->emitTabChanged(); break; - case KReportRuler::Private::HotSpot: + case KReportRuler::Private::Selection::HotSpot: qreal newPos; if (d->orientation == Qt::Horizontal) newPos= d->viewConverter->viewToDocumentX(pos.x() - d->offset); else newPos= d->viewConverter->viewToDocumentY(pos.y() - d->offset); d->hotspots[d->currentIndex].position = newPos; emit hotSpotChanged(d->hotspots[d->currentIndex].id, newPos); break; - case KReportRuler::Private::None: + case KReportRuler::Private::Selection::None: d->mouseCoordinate = (d->orientation == Qt::Horizontal ? pos.x() : pos.y()) - d->offset; int hotSpotIndex = d->hotSpotIndex(pos); if (hotSpotIndex >= 0) { setCursor(QCursor( d->orientation == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor )); break; } unsetCursor(); KReportRuler::Private::Selection selection = d->selectionAtPosition(pos); QString text; switch(selection) { - case KReportRuler::Private::FirstLineIndent: text = tr("First line indent"); break; - case KReportRuler::Private::ParagraphIndent: text = tr("Left indent"); break; - case KReportRuler::Private::EndIndent: text = tr("Right indent"); break; - case KReportRuler::Private::None: + case KReportRuler::Private::Selection::FirstLineIndent: text = tr("First line indent"); break; + case KReportRuler::Private::Selection::ParagraphIndent: text = tr("Left indent"); break; + case KReportRuler::Private::Selection::EndIndent: text = tr("Right indent"); break; + case KReportRuler::Private::Selection::None: if (ev->buttons() & Qt::LeftButton) { if (d->orientation == Qt::Horizontal && ev->pos().y() > height() + OutsideRulerThreshold) emit guideLineCreated(d->orientation, d->viewConverter->viewToDocumentY(ev->pos().y())); else if (d->orientation == Qt::Vertical && ev->pos().x() > width() + OutsideRulerThreshold) emit guideLineCreated(d->orientation, d->viewConverter->viewToDocumentX(ev->pos().x())); } break; default: break; } setToolTip(text); } update(); } void KReportRuler::clearHotSpots() { if (d->hotspots.isEmpty()) return; d->hotspots.clear(); update(); } void KReportRuler::setHotSpot(qreal position, int id) { int hotspotCount = d->hotspots.count(); for (int i = 0; i < hotspotCount; ++i) { KReportRuler::Private::HotSpotData & hs = d->hotspots[i]; if (hs.id == id) { hs.position = position; update(); return; } } // not there yet, then insert it. KReportRuler::Private::HotSpotData hs; hs.position = position; hs.id = id; d->hotspots.append(hs); } bool KReportRuler::removeHotSpot(int id) { QList::Iterator iter = d->hotspots.begin(); while(iter != d->hotspots.end()) { if (iter->id == id) { d->hotspots.erase(iter); update(); return true; } } return false; } diff --git a/src/wrtembed/KReportSectionEditor.cpp b/src/wrtembed/KReportSectionEditor.cpp index bbfdcb0a..d4785a7f 100644 --- a/src/wrtembed/KReportSectionEditor.cpp +++ b/src/wrtembed/KReportSectionEditor.cpp @@ -1,536 +1,536 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * Copyright (C) 2012 by Friedrich W. H. Kossebau (kossebau@kde.org) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportSectionEditor.h" #include "KReportDesigner.h" #include "KReportSection.h" #include "KReportDesignerSectionDetail.h" #include "KReportDetailGroupSectionDialog.h" #include "KReportDesignerSectionDetailGroup.h" #include #include #include #include enum { KeyRole = Qt::UserRole }; // KReportDesigner currently prepends an empty key/fieldname pair to the list // of fields, possibly to offer the option to have report elements not yet // bound to fields static inline bool isEditorHelperField(const QString &key) { return key.isEmpty(); } /* * Constructs a SectionEditor as a child of 'parent'. * * The dialog will by default be modeless, unless you set 'modal' to * true to construct a modal dialog. */ KReportSectionEditor::KReportSectionEditor(KReportDesigner* designer) : QDialog(designer) { Q_ASSERT(designer); m_reportDesigner = designer; m_reportSectionDetail = m_reportDesigner->detailSection(); //! @todo check section editor //setButtons(Close); //setCaption(tr("Section Editor")); QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Close); QVBoxLayout* mainLayout = new QVBoxLayout(this); QPushButton* closeButton = buttonBox->button(QDialogButtonBox::Close); closeButton->setDefault(true); closeButton->setShortcut(Qt::CTRL | Qt::Key_Return); connect(buttonBox, SIGNAL(rejected()), this, SLOT(accept())); QWidget *widget = new QWidget(this); m_ui.setupUi(widget); m_btnAdd = new QPushButton(QIcon::fromTheme(QLatin1String("list-add")), tr("Add..."), this); m_ui.lGroupSectionsButtons->addWidget(m_btnAdd); m_btnEdit = new QPushButton(QIcon::fromTheme(QLatin1String("document-edit")), tr("Edit..."), this); m_ui.lGroupSectionsButtons->addWidget(m_btnEdit); m_btnRemove = new QPushButton(QIcon::fromTheme(QLatin1String("list-remove")), tr("Delete"), this); m_ui.lGroupSectionsButtons->addWidget(m_btnRemove); m_btnMoveUp = new QPushButton(QIcon::fromTheme(QLatin1String("arrow-up")), tr("Move Up"), this); m_ui.lGroupSectionsButtons->addWidget(m_btnMoveUp); m_btnMoveDown = new QPushButton(QIcon::fromTheme(QLatin1String("arrow-down")), tr("Move Down"), this); m_ui.lGroupSectionsButtons->addWidget(m_btnMoveDown); m_ui.lGroupSectionsButtons->addStretch(); mainLayout->addWidget(widget); mainLayout->addWidget(buttonBox); //setMainWidget(widget); // signals and slots connections connect(m_ui.cbReportHeader, SIGNAL(toggled(bool)), this, SLOT(cbReportHeader_toggled(bool))); connect(m_ui.cbReportFooter, SIGNAL(toggled(bool)), this, SLOT(cbReportFooter_toggled(bool))); connect(m_ui.cbHeadFirst, SIGNAL(toggled(bool)), this, SLOT(cbHeadFirst_toggled(bool))); connect(m_ui.cbHeadLast, SIGNAL(toggled(bool)), this, SLOT(cbHeadLast_toggled(bool))); connect(m_ui.cbHeadEven, SIGNAL(toggled(bool)), this, SLOT(cbHeadEven_toggled(bool))); connect(m_ui.cbHeadOdd, SIGNAL(toggled(bool)), this, SLOT(cbHeadOdd_toggled(bool))); connect(m_ui.cbFootFirst, SIGNAL(toggled(bool)), this, SLOT(cbFootFirst_toggled(bool))); connect(m_ui.cbFootLast, SIGNAL(toggled(bool)), this, SLOT(cbFootLast_toggled(bool))); connect(m_ui.cbFootEven, SIGNAL(toggled(bool)), this, SLOT(cbFootEven_toggled(bool))); connect(m_ui.cbFootOdd, SIGNAL(toggled(bool)), this, SLOT(cbFootOdd_toggled(bool))); connect(m_ui.cbHeadAny, SIGNAL(toggled(bool)), this, SLOT(cbHeadAny_toggled(bool))); connect(m_ui.cbFootAny, SIGNAL(toggled(bool)), this, SLOT(cbFootAny_toggled(bool))); connect(m_ui.lbGroups, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(updateButtonsForItem(QListWidgetItem*))); connect(m_ui.lbGroups, SIGNAL(currentRowChanged(int)), this, SLOT(updateButtonsForRow(int))); connect(m_btnAdd, SIGNAL(clicked(bool)), this, SLOT(btnAdd_clicked())); connect(m_btnEdit, SIGNAL(clicked(bool)), this, SLOT(btnEdit_clicked())); connect(m_btnRemove, SIGNAL(clicked(bool)), this, SLOT(btnRemove_clicked())); connect(m_btnMoveUp, SIGNAL(clicked(bool)), this, SLOT(btnMoveUp_clicked())); connect(m_btnMoveDown, SIGNAL(clicked(bool)), this, SLOT(brnMoveDown_clicked())); // set all the properties - m_ui.cbReportHeader->setChecked(m_reportDesigner->section(KReportSectionData::ReportHeader)); - m_ui.cbReportFooter->setChecked(m_reportDesigner->section(KReportSectionData::ReportFooter)); + m_ui.cbReportHeader->setChecked(m_reportDesigner->section(KReportSectionData::Type::ReportHeader)); + m_ui.cbReportFooter->setChecked(m_reportDesigner->section(KReportSectionData::Type::ReportFooter)); - m_ui.cbHeadFirst->setChecked(m_reportDesigner->section(KReportSectionData::PageHeaderFirst)); - m_ui.cbHeadOdd->setChecked(m_reportDesigner->section(KReportSectionData::PageHeaderOdd)); - m_ui.cbHeadEven->setChecked(m_reportDesigner->section(KReportSectionData::PageHeaderEven)); - m_ui.cbHeadLast->setChecked(m_reportDesigner->section(KReportSectionData::PageHeaderLast)); - m_ui.cbHeadAny->setChecked(m_reportDesigner->section(KReportSectionData::PageHeaderAny)); + m_ui.cbHeadFirst->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageHeaderFirst)); + m_ui.cbHeadOdd->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageHeaderOdd)); + m_ui.cbHeadEven->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageHeaderEven)); + m_ui.cbHeadLast->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageHeaderLast)); + m_ui.cbHeadAny->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageHeaderAny)); - m_ui.cbFootFirst->setChecked(m_reportDesigner->section(KReportSectionData::PageFooterFirst)); - m_ui.cbFootOdd->setChecked(m_reportDesigner->section(KReportSectionData::PageFooterOdd)); - m_ui.cbFootEven->setChecked(m_reportDesigner->section(KReportSectionData::PageFooterEven)); - m_ui.cbFootLast->setChecked(m_reportDesigner->section(KReportSectionData::PageFooterLast)); - m_ui.cbFootAny->setChecked(m_reportDesigner->section(KReportSectionData::PageFooterAny)); + m_ui.cbFootFirst->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageFooterFirst)); + m_ui.cbFootOdd->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageFooterOdd)); + m_ui.cbFootEven->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageFooterEven)); + m_ui.cbFootLast->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageFooterLast)); + m_ui.cbFootAny->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageFooterAny)); // now set the rw value if (m_reportSectionDetail) { const QStringList columnNames = m_reportDesigner->fieldNames(); const QStringList keys = m_reportDesigner->fieldKeys(); for (int i = 0; i < m_reportSectionDetail->groupSectionCount(); ++i) { const QString key = m_reportSectionDetail->groupSection(i)->column(); const int idx = keys.indexOf(key); const QString columnName = columnNames.value(idx); QListWidgetItem *item = new QListWidgetItem(columnName); item->setData(KeyRole, key); m_ui.lbGroups->addItem(item); } } if (m_ui.lbGroups->count() == 0) { } else { m_ui.lbGroups->setCurrentItem(m_ui.lbGroups->item(0)); } updateButtonsForItem(m_ui.lbGroups->currentItem()); updateAddButton(); updateButtonsForRow(m_ui.lbGroups->currentRow()); } /* * Destroys the object and frees any allocated resources */ KReportSectionEditor::~KReportSectionEditor() { // no need to delete child widgets, Qt does it all for us } void KReportSectionEditor::cbReportHeader_toggled(bool yes) { if (m_reportDesigner) { if (yes) { - m_reportDesigner->insertSection(KReportSectionData::ReportHeader); + m_reportDesigner->insertSection(KReportSectionData::Type::ReportHeader); } else { - m_reportDesigner->removeSection(KReportSectionData::ReportHeader); + m_reportDesigner->removeSection(KReportSectionData::Type::ReportHeader); } } } void KReportSectionEditor::cbReportFooter_toggled(bool yes) { if (m_reportDesigner) { if (yes) { - m_reportDesigner->insertSection(KReportSectionData::ReportFooter); + m_reportDesigner->insertSection(KReportSectionData::Type::ReportFooter); } else { - m_reportDesigner->removeSection(KReportSectionData::ReportFooter); + m_reportDesigner->removeSection(KReportSectionData::Type::ReportFooter); } } } void KReportSectionEditor::cbHeadFirst_toggled(bool yes) { if (m_reportDesigner) { if (yes) { - m_reportDesigner->insertSection(KReportSectionData::PageHeaderFirst); + m_reportDesigner->insertSection(KReportSectionData::Type::PageHeaderFirst); } else { - m_reportDesigner->removeSection(KReportSectionData::PageHeaderFirst); + m_reportDesigner->removeSection(KReportSectionData::Type::PageHeaderFirst); } } } void KReportSectionEditor::cbHeadLast_toggled(bool yes) { if (m_reportDesigner) { if (yes) { - m_reportDesigner->insertSection(KReportSectionData::PageHeaderLast); + m_reportDesigner->insertSection(KReportSectionData::Type::PageHeaderLast); } else { - m_reportDesigner->removeSection(KReportSectionData::PageHeaderLast); + m_reportDesigner->removeSection(KReportSectionData::Type::PageHeaderLast); } } } void KReportSectionEditor::cbHeadEven_toggled(bool yes) { if (m_reportDesigner) { if (yes) { - m_reportDesigner->insertSection(KReportSectionData::PageHeaderEven); + m_reportDesigner->insertSection(KReportSectionData::Type::PageHeaderEven); } else { - m_reportDesigner->removeSection(KReportSectionData::PageHeaderEven); + m_reportDesigner->removeSection(KReportSectionData::Type::PageHeaderEven); } } } void KReportSectionEditor::cbHeadOdd_toggled(bool yes) { if (m_reportDesigner) { if (yes) { - m_reportDesigner->insertSection(KReportSectionData::PageHeaderOdd); + m_reportDesigner->insertSection(KReportSectionData::Type::PageHeaderOdd); } else { - m_reportDesigner->removeSection(KReportSectionData::PageHeaderOdd); + m_reportDesigner->removeSection(KReportSectionData::Type::PageHeaderOdd); } } } void KReportSectionEditor::cbFootFirst_toggled(bool yes) { if (m_reportDesigner) { if (yes) { - m_reportDesigner->insertSection(KReportSectionData::PageFooterFirst); + m_reportDesigner->insertSection(KReportSectionData::Type::PageFooterFirst); } else { - m_reportDesigner->removeSection(KReportSectionData::PageFooterFirst); + m_reportDesigner->removeSection(KReportSectionData::Type::PageFooterFirst); } } } void KReportSectionEditor::cbFootLast_toggled(bool yes) { if (m_reportDesigner) { if (yes) { - m_reportDesigner->insertSection(KReportSectionData::PageFooterLast); + m_reportDesigner->insertSection(KReportSectionData::Type::PageFooterLast); } else { - m_reportDesigner->removeSection(KReportSectionData::PageFooterLast); + m_reportDesigner->removeSection(KReportSectionData::Type::PageFooterLast); } } } void KReportSectionEditor::cbFootEven_toggled(bool yes) { if (m_reportDesigner) { if (yes) { - m_reportDesigner->insertSection(KReportSectionData::PageFooterEven); + m_reportDesigner->insertSection(KReportSectionData::Type::PageFooterEven); } else { - m_reportDesigner->removeSection(KReportSectionData::PageFooterEven); + m_reportDesigner->removeSection(KReportSectionData::Type::PageFooterEven); } } } void KReportSectionEditor::cbFootOdd_toggled(bool yes) { if (m_reportDesigner) { if (yes) { - m_reportDesigner->insertSection(KReportSectionData::PageFooterOdd); + m_reportDesigner->insertSection(KReportSectionData::Type::PageFooterOdd); } else { - m_reportDesigner->removeSection(KReportSectionData::PageFooterOdd); + m_reportDesigner->removeSection(KReportSectionData::Type::PageFooterOdd); } } } bool KReportSectionEditor::editDetailGroup(KReportDesignerSectionDetailGroup * rsdg) { KReportDetailGroupSectionDialog * dgsd = new KReportDetailGroupSectionDialog(this); // add the current column and all columns not yet used for groups const QStringList keys = m_reportDesigner->fieldKeys(); const QStringList columnNames = m_reportDesigner->fieldNames(); // in case of to-be-added group that column needs to be added to the used const QSet usedColumns = groupingColumns() << rsdg->column(); // if the current column is not among the keys, something is broken. // for now just simply select no column in the combobox, achieved by -1 int indexOfCurrentColumn = -1; for (int i = 0; i < keys.count(); ++i) { const QString &key = keys.at(i); // skip any editor helper fields if (isEditorHelperField(key)) { continue; } // already used? if (usedColumns.contains(key)) { // and not the one of the group? if (key != rsdg->column()) { continue; } // remember index indexOfCurrentColumn = dgsd->cbColumn->count(); } dgsd->cbColumn->insertItem( i, columnNames.value(i), key); } dgsd->cbColumn->setCurrentIndex(indexOfCurrentColumn); dgsd->cbSort->addItem(tr("Ascending"), Qt::AscendingOrder); dgsd->cbSort->addItem(tr("Descending"), Qt::DescendingOrder); dgsd->cbSort->setCurrentIndex(dgsd->cbSort->findData(rsdg->sort())); dgsd->breakAfterFooter->setChecked(rsdg->pageBreak() == KReportDesignerSectionDetailGroup::PageBreak::AfterGroupFooter); dgsd->cbHead->setChecked(rsdg->groupHeaderVisible()); dgsd->cbFoot->setChecked(rsdg->groupFooterVisible()); const bool isOkayed = (dgsd->exec() == QDialog::Accepted); if (isOkayed) { const QString newColumn = dgsd->cbColumn->itemData(dgsd->cbColumn->currentIndex()).toString(); const QString oldColumn = rsdg->column(); if (newColumn != oldColumn) { rsdg->setColumn(newColumn); } rsdg->setGroupHeaderVisible(dgsd->cbHead->isChecked()); rsdg->setGroupFooterVisible(dgsd->cbFoot->isChecked()); const KReportDesignerSectionDetailGroup::PageBreak pageBreak = dgsd->breakAfterFooter->isChecked() ? KReportDesignerSectionDetailGroup::PageBreak::AfterGroupFooter : KReportDesignerSectionDetailGroup::PageBreak::None; rsdg->setPageBreak(pageBreak); const Qt::SortOrder sortOrder = static_cast(dgsd->cbSort->itemData(dgsd->cbSort->currentIndex()).toInt()); rsdg->setSort(sortOrder); } delete dgsd; return isOkayed; } QString KReportSectionEditor::columnName(const QString &column) const { const QStringList keys = m_reportDesigner->fieldKeys(); const QStringList columnNames = m_reportDesigner->fieldNames(); return columnNames.at(keys.indexOf(column)); } QSet KReportSectionEditor::groupingColumns() const { QSet result; for (int i = 0; i < m_ui.lbGroups->count(); ++i) { result.insert(m_ui.lbGroups->item(i)->data(KeyRole).toString()); } return result; } void KReportSectionEditor::cbHeadAny_toggled(bool yes) { if (m_reportDesigner) { if (yes) { - m_reportDesigner->insertSection(KReportSectionData::PageHeaderAny); + m_reportDesigner->insertSection(KReportSectionData::Type::PageHeaderAny); } else { - m_reportDesigner->removeSection(KReportSectionData::PageHeaderAny); + m_reportDesigner->removeSection(KReportSectionData::Type::PageHeaderAny); } } } void KReportSectionEditor::cbFootAny_toggled(bool yes) { if (m_reportDesigner) { if (yes) { - m_reportDesigner->insertSection(KReportSectionData::PageFooterAny); + m_reportDesigner->insertSection(KReportSectionData::Type::PageFooterAny); } else { - m_reportDesigner->removeSection(KReportSectionData::PageFooterAny); + m_reportDesigner->removeSection(KReportSectionData::Type::PageFooterAny); } } } void KReportSectionEditor::btnEdit_clicked() { if (m_reportSectionDetail) { const int idx = m_ui.lbGroups->currentRow(); if (idx < 0) { return; } KReportDesignerSectionDetailGroup * rsdg = m_reportSectionDetail->groupSection(idx); if (editDetailGroup(rsdg)) { // update name in list m_ui.lbGroups->item(idx)->setText(columnName(rsdg->column())); } } } void KReportSectionEditor::btnAdd_clicked() { if (m_reportSectionDetail) { // lets add a new section // search for unused column QString column; const QStringList keys = m_reportDesigner->fieldKeys(); const QSet columns = groupingColumns(); foreach(const QString &key, keys) { // skip any editor helper fields if (isEditorHelperField(key)) { continue; } if (! columns.contains(key)) { column = key; break; } } // should not happen, but we do not really know if m_reportDesigner is in sync if (column.isEmpty()) { return; } // create new group, have it edited and add it, if not cancelled KReportDesignerSectionDetailGroup * rsdg = new KReportDesignerSectionDetailGroup(column, m_reportSectionDetail, m_reportSectionDetail); if (editDetailGroup(rsdg)) { // append to group sections m_reportSectionDetail->insertGroupSection(m_reportSectionDetail->groupSectionCount(), rsdg); // add to combobox const QString column = rsdg->column(); QListWidgetItem *item = new QListWidgetItem(columnName(column)); item->setData(KeyRole, column); m_ui.lbGroups->addItem(item); m_ui.lbGroups->setCurrentRow(m_ui.lbGroups->count() - 1); updateAddButton(); } else { delete rsdg; } } } void KReportSectionEditor::btnRemove_clicked() { if (m_reportSectionDetail) { const int index = m_ui.lbGroups->currentRow(); if (index != -1) { QListWidgetItem *item = m_ui.lbGroups->takeItem(index); delete item; m_reportSectionDetail->removeGroupSection(index, true); // a field got usable, so make sure add button is available again m_btnAdd->setEnabled(true); // workaround for at least Qt 4.8.1, which does not emit the proper // currentRowChanged signal on deletion of the first element updateButtonsForRow(m_ui.lbGroups->currentRow()); } } } void KReportSectionEditor::btnMoveUp_clicked() { if (m_reportSectionDetail) { int idx = m_ui.lbGroups->currentRow(); if (idx <= 0) return; QString s = m_ui.lbGroups->currentItem()->text(); m_ui.lbGroups->takeItem(idx); m_ui.lbGroups->insertItem(idx - 1, s); m_ui.lbGroups->setCurrentRow(idx - 1, QItemSelectionModel::ClearAndSelect); KReportDesignerSectionDetailGroup * rsdg = m_reportSectionDetail->groupSection(idx); bool showgh = rsdg->groupHeaderVisible(); bool showgf = rsdg->groupFooterVisible(); m_reportSectionDetail->removeGroupSection(idx); m_reportSectionDetail->insertGroupSection(idx - 1, rsdg); rsdg->setGroupHeaderVisible(showgh); rsdg->setGroupFooterVisible(showgf); } } void KReportSectionEditor::brnMoveDown_clicked() { if (m_reportSectionDetail) { int idx = m_ui.lbGroups->currentRow(); if (idx == (int)(m_ui.lbGroups->count() - 1)) return; QString s = m_ui.lbGroups->currentItem()->text(); m_ui.lbGroups->takeItem(idx); m_ui.lbGroups->insertItem (idx + 1, s); m_ui.lbGroups->setCurrentRow(idx + 1, QItemSelectionModel::ClearAndSelect); KReportDesignerSectionDetailGroup * rsdg = m_reportSectionDetail->groupSection(idx); bool showgh = rsdg->groupHeaderVisible(); bool showgf = rsdg->groupFooterVisible(); m_reportSectionDetail->removeGroupSection(idx); m_reportSectionDetail->insertGroupSection(idx + 1, rsdg); rsdg->setGroupHeaderVisible(showgh); rsdg->setGroupFooterVisible(showgf); } } void KReportSectionEditor::updateButtonsForItem(QListWidgetItem* currentItem) { const bool isItemSelected = (currentItem != 0); m_btnEdit->setEnabled(isItemSelected); m_btnRemove->setEnabled(isItemSelected); } void KReportSectionEditor::updateButtonsForRow(int row) { const bool enableMoveUpButton = (row > 0); const bool enableMoveDownButton = (0 <= row) && (row+1 < m_ui.lbGroups->count()); m_btnMoveUp->setEnabled(enableMoveUpButton); m_btnMoveDown->setEnabled(enableMoveDownButton); } void KReportSectionEditor::updateAddButton() { // search for unused column bool foundUnusedColumn = false; const QStringList keys = m_reportDesigner->fieldKeys(); const QSet columns = groupingColumns(); foreach(const QString &key, keys) { // skip any editor helper fields if (isEditorHelperField(key)) { continue; } if (! columns.contains(key)) { foundUnusedColumn = true; break; } } m_btnAdd->setEnabled(foundUnusedColumn); } diff --git a/src/wrtembed/KReportZoomHandler_p.cpp b/src/wrtembed/KReportZoomHandler_p.cpp index e77c2552..bea8492a 100644 --- a/src/wrtembed/KReportZoomHandler_p.cpp +++ b/src/wrtembed/KReportZoomHandler_p.cpp @@ -1,169 +1,169 @@ /* This file is part of the KDE project Copyright (C) 2001-2005 David Faure Copyright (C) 2006 Thomas Zander Copyright (C) 2010 KO GmbH This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "KReportZoomHandler_p.h" #include "KReportUnit.h" // for POINT_TO_INCH #include "KReportUtils_p.h" #include #include KReportZoomHandler::KReportZoomHandler() - : m_zoomMode(KReportZoomMode::ZOOM_CONSTANT) + : m_zoomType(KReportZoomMode::Type::Constant) , m_resolutionX(0) , m_resolutionY(0) , m_zoomedResolutionX(0) , m_zoomedResolutionY(0) , m_zoomLevel(1.0) { setZoom(1.0); - setZoomMode( KReportZoomMode::ZOOM_CONSTANT ); + setZoomMode(KReportZoomMode::Type::Constant); setDpi(KReportPrivate::dpiX(), KReportPrivate::dpiY()); } KReportZoomHandler::~KReportZoomHandler() { } void KReportZoomHandler::setResolutionToStandard() { setDpi(KReportPrivate::dpiX(), KReportPrivate::dpiY()); } void KReportZoomHandler::setDpi(int dpiX, int dpiY) { setResolution(POINT_TO_INCH(static_cast(dpiX)), POINT_TO_INCH(static_cast(dpiY))); } void KReportZoomHandler::setResolution( qreal resolutionX, qreal resolutionY ) { m_resolutionX = resolutionX; m_resolutionY = resolutionY; if (qFuzzyCompare(m_resolutionX, 1)) m_resolutionX = 1; if (qFuzzyCompare(m_resolutionY, 1)) m_resolutionY = 1; m_zoomedResolutionX = zoom() * resolutionX; m_zoomedResolutionY = zoom() * resolutionY; } void KReportZoomHandler::setZoomedResolution( qreal zoomedResolutionX, qreal zoomedResolutionY ) { // zoom() doesn't matter, it's only used in setZoom() to calculated the zoomed resolutions // Here we know them. The whole point of this method is to allow a different zoom factor // for X and for Y, as can be useful for e.g. fullscreen kpresenter presentations. m_zoomedResolutionX = zoomedResolutionX; m_zoomedResolutionY = zoomedResolutionY; } void KReportZoomHandler::setZoom( qreal zoom ) { if (qFuzzyCompare(zoom, qreal(0.0)) || qFuzzyCompare(zoom, qreal(1.0))) { zoom = 1.0; } m_zoomLevel = zoom; if( zoom == 1.0 ) { m_zoomedResolutionX = m_resolutionX; m_zoomedResolutionY = m_resolutionY; } else { m_zoomedResolutionX = zoom * m_resolutionX; m_zoomedResolutionY = zoom * m_resolutionY; } } QPointF KReportZoomHandler::documentToView( const QPointF &documentPoint ) const { return QPointF( zoomItX( documentPoint.x() ), zoomItY( documentPoint.y() )); } QPointF KReportZoomHandler::viewToDocument( const QPointF &viewPoint ) const { return QPointF( unzoomItX( viewPoint.x() ), unzoomItY( viewPoint.y() ) ); } QRectF KReportZoomHandler::documentToView( const QRectF &documentRect ) const { QRectF r (zoomItX( documentRect.x() ), zoomItY( documentRect.y() ), zoomItX( documentRect.width() ), zoomItY( documentRect.height() ) ); return r; } QRectF KReportZoomHandler::viewToDocument( const QRectF &viewRect ) const { QRectF r ( unzoomItX( viewRect.x() ), unzoomItY( viewRect.y()), unzoomItX( viewRect.width() ), unzoomItY( viewRect.height() ) ); return r; } QSizeF KReportZoomHandler::documentToView( const QSizeF &documentSize ) const { return QSizeF( zoomItX( documentSize.width() ), zoomItY( documentSize.height() ) ); } QSizeF KReportZoomHandler::viewToDocument( const QSizeF &viewSize ) const { return QSizeF( unzoomItX( viewSize.width() ), unzoomItY( viewSize.height() ) ); } qreal KReportZoomHandler::documentToViewX( qreal documentX ) const { return zoomItX( documentX ); } qreal KReportZoomHandler::documentToViewY( qreal documentY ) const { return zoomItY( documentY ); } qreal KReportZoomHandler::viewToDocumentX( qreal viewX ) const { return unzoomItX( viewX ); } qreal KReportZoomHandler::viewToDocumentY( qreal viewY ) const { return unzoomItY( viewY ); } void KReportZoomHandler::zoom(qreal *zoomX, qreal *zoomY) const { *zoomX = zoomItX(100.0) / 100.0; *zoomY = zoomItY(100.0) / 100.0; } qreal KReportZoomHandler::zoom() const { return m_zoomLevel; } diff --git a/src/wrtembed/KReportZoomHandler_p.h b/src/wrtembed/KReportZoomHandler_p.h index 8dd32313..8368eb98 100644 --- a/src/wrtembed/KReportZoomHandler_p.h +++ b/src/wrtembed/KReportZoomHandler_p.h @@ -1,233 +1,234 @@ /* This file is part of the KDE project Copyright (C) 2001-2005 David Faure Copyright (C) 2006, 2009 Thomas Zander This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KREPORTZOOMHANDLER_H #define KREPORTZOOMHANDLER_H #include "KReportZoomMode_p.h" class QPointF; class QRectF; class QSizeF; /** * This class handles the zooming and DPI stuff (conversions between * postscript pt values and pixels). If the internal data of your * document does not work with postscript points (for instance raster * image pixels), you need to some additional converting yourself. * * An instance of KReportZoomHandler operates at a given zoom and resolution * so there is usually one instance of KReportZoomHandler per view. */ class KReportZoomHandler { public: KReportZoomHandler(); ~KReportZoomHandler(); /** * @return the conversion factor between document and view, that * includes the zoom and also the DPI setting. */ inline qreal zoomedResolutionX() const { return m_zoomedResolutionX; } /** * @return the conversion factor between document and view, that * includes the zoom and also the DPI setting. */ inline qreal zoomedResolutionY() const { return m_zoomedResolutionY; } inline qreal resolutionX() const { return m_resolutionX; } inline qreal resolutionY() const { return m_resolutionY; } /** * Zoom factor for X. Equivalent to zoomedResolutionX()/resolutionX() */ inline qreal zoomFactorX() const { return m_zoomedResolutionX / m_resolutionX; } /** * Zoom factor for Y. Equivalent to zoomedResolutionY()/resolutionY() */ inline qreal zoomFactorY() const { return m_zoomedResolutionY / m_resolutionY; } /** * Set resolution expressed in dots-per-inch */ void setDpi(int dpiX, int dpiY); /** * Set a resolution for X and Y of the output device. * The zoom factor is not changed. * * This number should be the result of: * POINT_TO_INCH(static_cast(DOTS_PER_INCH)) */ void setResolution(qreal resolutionX, qreal resolutionY); /** * Set the resolution for X and Y to the display values reported by KGlobal. * The zoom factor is not changed. */ void setResolutionToStandard( ); /** * Set the zoomed resolution for X and Y. * Compared to the setZoom... methods, this allows to set a different * zoom factor for X and for Y. */ void setZoomedResolution(qreal zoomedResolutionX, qreal zoomedResolutionY); /** * Change the zoom level, keeping the resolution unchanged. * @param zoom the zoom factor (e.g. 1.0 for 100%) */ void setZoom(qreal zoom); /** - * Change the zoom mode - * @param zoomMode the zoom mode. + * Change the zoom type + * @param zoomType the zoom type. */ - inline void setZoomMode(KReportZoomMode::Mode zoomMode) { m_zoomMode = zoomMode; } + inline void setZoomMode(KReportZoomMode::Type zoomType) { m_zoomType = zoomType; } /** * @return the global zoom factor (e.g. 100 for 100%). * Only use this to display to the user, don't use in calculations */ inline int zoomInPercent() const { return qRound(zoom() * 100); } + /** - * @return the global zoom mode (e.g. KReportZoomMode::ZOOM_WIDTH). + * @return the global zoom type (e.g. KReportZoomMode::Type::Width). * use this to determine how to zoom */ - KReportZoomMode::Mode zoomMode() const { return m_zoomMode; } + KReportZoomMode::Type zoomType() const { return m_zoomType; } // Input: pt. Output: pixels. Resolution and zoom are applied. inline qreal zoomItX(qreal z) const { return m_zoomedResolutionX * z; } inline qreal zoomItY(qreal z) const { return m_zoomedResolutionY * z ; } // Input: pixels. Output: pt. inline qreal unzoomItX(qreal x) const { return x / m_zoomedResolutionX; } inline qreal unzoomItY(qreal y) const { return y / m_zoomedResolutionY; } /** * Convert a coordinate in pt to pixels. * @param documentPoint the point in the document coordinate system of a KoShape. */ QPointF documentToView(const QPointF &documentPoint) const; /** * Convert a coordinate in pixels to pt. * @param viewPoint the point in the coordinate system of the widget, or window. */ QPointF viewToDocument(const QPointF &viewPoint) const; /** * Convert a rectangle in pt to pixels. * @param documentRect the rect in the document coordinate system of a KoShape. */ QRectF documentToView(const QRectF &documentRect) const; /** * Convert a rectangle in pixels to pt. * @param viewRect the rect in the coordinate system of the widget, or window. */ QRectF viewToDocument(const QRectF &viewRect) const; /** * Convert a size in pt to pixels. * @param documentSize the size in pt. * @return the size in pixels. */ QSizeF documentToView(const QSizeF &documentSize) const; /** * Convert a size in pixels to pt. * @param viewSize the size in pixels. * @return the size in pt. */ QSizeF viewToDocument(const QSizeF &viewSize) const; /** * Convert a single x coordinate in pt to pixels. * @param documentX the x coordinate in pt. * @return the x coordinate in pixels. */ qreal documentToViewX(qreal documentX) const; /** * Convert a single y coordinate in pt to pixels. * @param documentY the y coordinate in pt. * @return the y coordinate in pixels. */ qreal documentToViewY(qreal documentY) const; /** * Convert a single x coordinate in pixels to pt. * @param viewX the x coordinate in pixels. * @return the x coordinate in pt. */ qreal viewToDocumentX(qreal viewX) const; /** * Convert a single y coordinate in pixels to pt. * @param viewY the y coordinate in pixels. * @return the y coordinate in pt. */ qreal viewToDocumentY(qreal viewY) const; /** * Get the zoom levels of the individual x and y axis. Copy them to the pointer parameters. * @param zoomX a pointer to a qreal which will be modified to set the horizontal zoom. * @param zoomY a pointer to a qreal which will be modified to set the vertical zoom. */ void zoom(qreal *zoomX, qreal *zoomY) const; /** * Return the current zoom level. 1.0 is 100%. */ qreal zoom() const; private: - KReportZoomMode::Mode m_zoomMode; + KReportZoomMode::Type m_zoomType; qreal m_resolutionX; qreal m_resolutionY; qreal m_zoomedResolutionX; qreal m_zoomedResolutionY; qreal m_zoomLevel; // 1.0 is 100% }; #endif diff --git a/src/wrtembed/KReportZoomMode_p.cpp b/src/wrtembed/KReportZoomMode_p.cpp index 007eb8d1..e0e8398a 100644 --- a/src/wrtembed/KReportZoomMode_p.cpp +++ b/src/wrtembed/KReportZoomMode_p.cpp @@ -1,93 +1,93 @@ /* This file is part of the KDE project Copyright (C) 2005 Johannes Schaub Copyright (C) 2011 Arjen Hiemstra This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KReportZoomMode_p.h" #include -const char* const KReportZoomMode::modes[] = +namespace{ +static const char* const s_types[] = { QT_TRANSLATE_NOOP("KReportZoomMode", "%1%"), QT_TRANSLATE_NOOP("KReportZoomMode", "Fit Page Width"), QT_TRANSLATE_NOOP("KReportZoomMode", "Fit Page"), nullptr, QT_TRANSLATE_NOOP("KReportZoomMode", "Actual Pixels"), nullptr, nullptr, nullptr, QT_TRANSLATE_NOOP("KReportZoomMode", "Fit Text Width") }; -qreal KReportZoomMode::minimumZoomValue = 0.2; -qreal KReportZoomMode::maximumZoomValue = 5.0; +qreal s_minimumZoomValue = 0.2; +qreal s_maximumZoomValue = 5.0; +} -QString KReportZoomMode::toString(Mode mode) +QString KReportZoomMode::toString(Type type) { - return QCoreApplication::translate("KReportZoomMode", modes[mode]); + return tr(s_types[static_cast(type)]); } -KReportZoomMode::Mode KReportZoomMode::toMode(const QString& mode) +KReportZoomMode::Type KReportZoomMode::toType(const QString& string) { - if(mode == QCoreApplication::translate("KReportZoomMode", modes[ZOOM_WIDTH])) - return ZOOM_WIDTH; - else - if(mode == QCoreApplication::translate("KReportZoomMode", modes[ZOOM_PAGE])) - return ZOOM_PAGE; - else - if(mode == QCoreApplication::translate("KReportZoomMode", modes[ZOOM_PIXELS])) - return ZOOM_PIXELS; - else - if(mode == QCoreApplication::translate("KReportZoomMode", modes[ZOOM_TEXT])) - return ZOOM_TEXT; - else - return ZOOM_CONSTANT; - // we return ZOOM_CONSTANT else because then we can pass '10%' or '15%' - // or whatever, it's automatically converted. ZOOM_CONSTANT is - // changeable, whereas all other zoom modes (non-constants) are normal - // text like "Fit to xxx". they let the view grow/shrink according - // to windowsize, hence the term 'non-constant' + if(string == toString(Type::Width)) { + return Type::Width; + } else if (string == toString(Type::Page)) { + return Type::Page; + } else if (string == toString(Type::Pixels)) { + return Type::Pixels; + } else if (string == toString(Type::Text)) { + return Type::Text; + } else { + // we return Constant else because then we can pass '10%' or '15%' + // or whatever, it's automatically converted. Constant is + // changeable, whereas all other zoom modes (non-constants) are normal + // text like "Fit to xxx". they let the view grow/shrink according + // to windowsize, hence the term 'non-constant' + return Type::Constant; + } } qreal KReportZoomMode::minimumZoom() { - return minimumZoomValue; + return s_minimumZoomValue; } qreal KReportZoomMode::maximumZoom() { - return maximumZoomValue; + return s_maximumZoomValue; } qreal KReportZoomMode::clampZoom(qreal zoom) { - return qMin(maximumZoomValue, qMax(minimumZoomValue, zoom)); + return qMin(s_maximumZoomValue, qMax(s_minimumZoomValue, zoom)); } void KReportZoomMode::setMinimumZoom(qreal zoom) { Q_ASSERT(zoom > 0.0f); - minimumZoomValue = zoom; + s_minimumZoomValue = zoom; } void KReportZoomMode::setMaximumZoom(qreal zoom) { Q_ASSERT(zoom > 0.0f); - maximumZoomValue = zoom; + s_maximumZoomValue = zoom; } diff --git a/src/wrtembed/KReportZoomMode_p.h b/src/wrtembed/KReportZoomMode_p.h index 79e3a136..c440dedf 100644 --- a/src/wrtembed/KReportZoomMode_p.h +++ b/src/wrtembed/KReportZoomMode_p.h @@ -1,106 +1,98 @@ /* This file is part of the KDE project Copyright (C) 2005 Johannes Schaub Copyright (C) 2011 Arjen Hiemstra This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef _KREPORTZOOMMODE_H_ #define _KREPORTZOOMMODE_H_ -#include +#include #include "kreport_export.h" /** * The ZoomMode container */ class KReportZoomMode { + Q_DECLARE_TR_FUNCTIONS(KReportZoomMode) public: - enum Mode + enum class Type { - ZOOM_CONSTANT = 0, ///< zoom x % - ZOOM_WIDTH = 1, ///< zoom pagewidth - ZOOM_PAGE = 2, ///< zoom to pagesize - ZOOM_PIXELS = 4, ///< zoom to actual pixels - ZOOM_TEXT = 8 ///< zoom to actual pixels + Constant, ///< zoom x % + Width, ///< zoom pagewidth + Page, ///< zoom to pagesize + Pixels, ///< zoom to actual pixels + Text ///< zoom to text }; - Q_DECLARE_FLAGS(Modes, Mode) + /// \param type name + /// \return type converted + static Type toType(const QString &string); - /// \param mode the mode name - /// \return the to Mode converted QString \c mode - static Mode toMode(const QString& mode); + /// \return QString converted and translated for type + static QString toString(Type type); - /// \return the to QString converted and translated Mode \c mode - static QString toString(Mode mode); - - /// \param mode the mode name + /// \param type name /// \return true if \c mode isn't dependent on windowsize static bool isConstant(const QString& mode) - { return toMode(mode) == ZOOM_CONSTANT; } + { return toType(mode) == Type::Constant; } /** * Return the minimum zoom possible for documents. * * \return The minimum zoom possible. */ static qreal minimumZoom(); /** * Return the maximum zoom possible for documents. * * \return The maximum zoom possible. */ static qreal maximumZoom(); /** * Clamp the zoom value so that mimimumZoom <= zoom <= maximumZoom. * * \param zoom The value to clamp. * * \return minimumZoom if zoom < minimumZoom, maximumZoom if zoom > * maximumZoom, zoom if otherwise. */ static qreal clampZoom(qreal zoom); /** * Set the minimum zoom possible for documents. * * Note that after calling this, any existing KoZoomAction instances * should be recreated. * * \param zoom The minimum zoom to use. */ static void setMinimumZoom(qreal zoom); /** * Set the maximum zoom possible for documents. * * Note that after calling this, any existing KoZoomAction instances * should be recreated. * * \param zoom The maximum zoom to use. */ static void setMaximumZoom(qreal zoom); - -private: - static const char * const modes[]; - static qreal minimumZoomValue; - static qreal maximumZoomValue; }; -Q_DECLARE_OPERATORS_FOR_FLAGS(KReportZoomMode::Modes) - #endif