diff --git a/src/common/KReportItemBase.cpp b/src/common/KReportItemBase.cpp index 065bcc38..0fe14170 100644 --- a/src/common/KReportItemBase.cpp +++ b/src/common/KReportItemBase.cpp @@ -1,298 +1,298 @@ /* 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 "KReportItemBase.h" #include "KReportUtils.h" #include "KReportUtils_p.h" #include #include #include #include class Q_DECL_HIDDEN KReportItemBase::Private { public: Private(); ~Private(); void setUnit(const KReportUnit& u, bool force) { if (!force && unit == u) { return; } const QSignalBlocker blocker(set); KReportUnit oldunit = unit; unit = u; // convert values if (positionProperty) { positionProperty->setValue(KReportUnit::convertFromUnitToUnit( positionProperty->value().toPointF(), oldunit, u), KProperty::ValueOption::IgnoreOld); positionProperty->setOption("suffix", u.symbol()); } if (sizeProperty) { sizeProperty->setValue( KReportUnit::convertFromUnitToUnit(sizeProperty->value().toSizeF(), oldunit, u), KProperty::ValueOption::IgnoreOld); sizeProperty->setOption("suffix", u.symbol()); } } KPropertySet *set; KProperty *nameProperty; KProperty *sizeProperty; KProperty *positionProperty; - KProperty *dataSourceProperty = 0; + KProperty *dataSourceProperty = nullptr; QString oldName; qreal z = 0; KReportUnit unit; }; KReportItemBase::Private::Private() { set = new KPropertySet(); nameProperty = new KProperty("name", QString(), tr("Name"), tr("Object Name")); nameProperty->setValueSyncPolicy(KProperty::ValueSyncPolicy::FocusOut); positionProperty = new KProperty("position", QPointF(), QCoreApplication::translate("ItemPosition", "Position")); sizeProperty = new KProperty("size", QSizeF(), QCoreApplication::translate("ItemSize", "Size")); setUnit(DEFAULT_UNIT, true); set->addProperty(nameProperty); set->addProperty(positionProperty); set->addProperty(sizeProperty); } KReportItemBase::Private::~Private() { delete set; } KReportItemBase::KReportItemBase() : d(new Private()) { connect(propertySet(), &KPropertySet::propertyChanged, this, &KReportItemBase::propertyChanged); connect(propertySet(), &KPropertySet::aboutToDeleteProperty, this, &KReportItemBase::aboutToDeleteProperty); } KReportItemBase::~KReportItemBase() { delete d; } void KReportItemBase::createDataSourceProperty() { if (d->dataSourceProperty) { return; } d->dataSourceProperty = new KProperty("item-data-source", new KPropertyListData, QVariant(), tr("Data Source")); d->dataSourceProperty->setOption("extraValueAllowed", true); d->set->addProperty(d->dataSourceProperty); } bool KReportItemBase::parseReportTextStyleData(const QDomElement & elemSource, KReportTextStyleData *ts) { return KReportUtils::parseReportTextStyleData(elemSource, ts); } bool KReportItemBase::parseReportLineStyleData(const QDomElement & elemSource, KReportLineStyle *ls) { return KReportUtils::parseReportLineStyleData(elemSource, ls); } bool KReportItemBase::parseReportRect(const QDomElement & elemSource) { const QRectF r(KReportUtils::readRectAttributes(elemSource, DEFAULT_ELEMENT_RECT_PT)); setPosition(r.topLeft()); setSize(r.size()); return true; } KReportUnit KReportItemBase::unit() const { return d->unit; } void KReportItemBase::setUnit(const KReportUnit& u) { d->setUnit(u, false); } int KReportItemBase::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler* script) { Q_UNUSED(page) Q_UNUSED(section) Q_UNUSED(offset) Q_UNUSED(data) Q_UNUSED(script) return 0; } int KReportItemBase::renderReportData(OROPage *page, OROSection *section, const QPointF &offset, KReportDataSource *dataSource, KReportScriptHandler* script) { Q_UNUSED(page) Q_UNUSED(section) Q_UNUSED(offset) Q_UNUSED(dataSource) Q_UNUSED(script) return 0; } QString KReportItemBase::itemDataSource() const { return d->dataSourceProperty ? d->dataSourceProperty->value().toString() : QString(); } void KReportItemBase::setItemDataSource(const QString& source) { if (d->dataSourceProperty && d->dataSourceProperty->value() != source) { d->dataSourceProperty->setValue(source); } } KPropertySet* KReportItemBase::propertySet() { return d->set; } bool KReportItemBase::supportsSubQuery() const { return false; } QString KReportItemBase::entityName() const { return d->nameProperty->value().toString(); } void KReportItemBase::setEntityName(const QString& n) { d->nameProperty->setValue(n); } KProperty* KReportItemBase::nameProperty() { return d->nameProperty; } QString KReportItemBase::oldName() const { return d->oldName; } void KReportItemBase::setOldName(const QString& old) { d->oldName = old; } KProperty* KReportItemBase::dataSourceProperty() { return d->dataSourceProperty; } QPointF KReportItemBase::position() const { return d->unit.convertToPoint(d->positionProperty->value().toPointF()); } QSizeF KReportItemBase::size() const { return d->unit.convertToPoint(d->sizeProperty->value().toSizeF()); } const KPropertySet * KReportItemBase::propertySet() const { return d->set; } QPointF KReportItemBase::scenePosition(const QPointF &ptPos) { const qreal x = POINT_TO_INCH(ptPos.x()) * KReportPrivate::dpiX(); const qreal y = POINT_TO_INCH(ptPos.y()) * KReportPrivate::dpiY(); return QPointF(x, y); } QSizeF KReportItemBase::sceneSize(const QSizeF &ptSize) { const qreal w = POINT_TO_INCH(ptSize.width()) * KReportPrivate::dpiX(); const qreal h = POINT_TO_INCH(ptSize.height()) * KReportPrivate::dpiY(); return QSizeF(w, h); } qreal KReportItemBase::z() const { return d->z; } void KReportItemBase::setZ(qreal z) { d->z = z; } void KReportItemBase::setPosition(const QPointF& ptPos) { d->positionProperty->setValue(d->unit.convertFromPoint(ptPos)); } void KReportItemBase::setSize(const QSizeF &ptSize) { d->sizeProperty->setValue(d->unit.convertFromPoint(ptSize)); } QPointF KReportItemBase::positionFromScene(const QPointF& pos) { const qreal x = INCH_TO_POINT(pos.x() / KReportPrivate::dpiX()); const qreal y = INCH_TO_POINT(pos.y() / KReportPrivate::dpiY()); return QPointF(x, y); } QSizeF KReportItemBase::sizeFromScene(const QSizeF& size) { qreal w = INCH_TO_POINT(size.width() / KReportPrivate::dpiX()); qreal h = INCH_TO_POINT(size.height() / KReportPrivate::dpiY()); return QSizeF(w, h); } void KReportItemBase::propertyChanged(KPropertySet& s, KProperty& p) { Q_UNUSED(s) Q_UNUSED(p) } void KReportItemBase::aboutToDeleteProperty(KPropertySet& set, KProperty& property) { Q_UNUSED(set) if (property.name() == "size") { d->sizeProperty = nullptr; } else if (property.name() == "position") { d->positionProperty = nullptr; } } diff --git a/src/common/KReportUnit.h b/src/common/KReportUnit.h index 5ea4a02c..58430d1b 100644 --- a/src/common/KReportUnit.h +++ b/src/common/KReportUnit.h @@ -1,344 +1,344 @@ /* This file is part of the KDE project Copyright (C) 1998 1999 Reginald Stadlbauer Copyright (C) 1998 1999 Torben Weis Copyright (C) 2004 Nicolas GOUTTE Copyright (C) 2010 Thomas Zander Copyright (C) 2012 Friedrich W. H. Kossebau Copyright (C) 2017 Jarosław Staniek 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 KREPORTUNIT_H #define KREPORTUNIT_H #include // for floor #include #include #include #include #include "kreport_export.h" // 1 inch ^= 72 pt // 1 inch ^= 25.399956 mm (-pedantic ;p) // 1 pt = 1/12 pi // 1 pt ^= 0.0077880997 cc // 1 cc = 12 dd // Note: I don't use division but multiplication with the inverse value // because it's faster ;p (Werner) #define POINT_TO_MM(px) qreal((px)*0.352777167) #define MM_TO_POINT(mm) qreal((mm)*2.83465058) #define POINT_TO_CM(px) qreal((px)*0.0352777167) #define CM_TO_POINT(cm) qreal((cm)*28.3465058) #define POINT_TO_DM(px) qreal((px)*0.00352777167) #define DM_TO_POINT(dm) qreal((dm)*283.465058) #define POINT_TO_INCH(px) qreal((px)*0.01388888888889) #define INCH_TO_POINT(inch) qreal((inch)*72.0) #define MM_TO_INCH(mm) qreal((mm)*0.039370147) #define INCH_TO_MM(inch) qreal((inch)*25.399956) #define POINT_TO_PI(px) qreal((px)*0.083333333) #define POINT_TO_CC(px) qreal((px)*0.077880997) #define PI_TO_POINT(pi) qreal((pi)*12) #define CC_TO_POINT(cc) qreal((cc)*12.840103) /*! * @brief Converts between different units * * KReportUnit stores everything in pt (using "qreal") internally. * When displaying a value to the user, the value is converted to the user's unit * of choice, and rounded to a reasonable precision to avoid 0.999999 * * For implementing the selection of a unit type in the UI use the allTypes() method. * it ensure the same order of the unit types in all places, with the order not * bound to the order in the enum so ABI-compatible extension is possible. */ class KREPORT_EXPORT KReportUnit { Q_DECLARE_TR_FUNCTIONS(KReportUnit) public: /** Length units supported by %KReport. */ enum class Type { Invalid, Millimeter, Centimeter, Decimeter, Inch, Pica, Cicero, Point, ///< Postscript point, 1/72th of an Inco Pixel, Last = Pixel ///< internal }; /** * @brief Constructs invalid unit * * @since 3.1 */ KReportUnit(); /** Construct unit with given type and factor. */ explicit KReportUnit(Type type, qreal factor = 1.0); KReportUnit(const KReportUnit &other); ~KReportUnit(); /// Assigns specified type and factor 1.0 to the object /// @param unit Type of unit KReportUnit& operator=(Type type); KReportUnit& operator=(const KReportUnit& other); bool operator!=(const KReportUnit &other) const; bool operator==(const KReportUnit &other) const; /** * @brief Returns true if type of this unit is valid * * @since 3.1 */ bool isValid() const; /** * @brief Returns list of all supported types (without Invalid) * * @since 3.1 */ static QList allTypes(); /** Returns the type of this unit */ KReportUnit::Type type() const; /** * @brief Returns (translated) description string for type of this unit * * @since 3.1 */ QString description() const; /** * @brief Returns (translated) description string for given unit type * * @since 3.1 */ static QString description(KReportUnit::Type type); /** * @brief Returns the list of (translated) description strings for given list of types * * @since 3.1 */ static QStringList descriptions(const QList &types); void setFactor(qreal factor); qreal factor() const; /** * Prepare ptValue to be displayed in pt * This method will round to 0.001 precision */ static inline qreal toPoint(qreal ptValue) { // No conversion, only rounding (to 0.001 precision) return floor(ptValue * 1000.0) / 1000.0; } /** * Prepare ptValue to be displayed in mm * This method will round to 0.0001 precision, use POINT_TO_MM() for lossless conversion. */ static inline qreal toMillimeter(qreal ptValue) { // "mm" values are rounded to 0.0001 millimeters return floor(POINT_TO_MM(ptValue) * 10000.0) / 10000.0; } /** * Prepare ptValue to be displayed in cm * This method will round to 0.0001 precision, use POINT_TO_CM() for lossless conversion. */ static inline qreal toCentimeter(qreal ptValue) { return floor(POINT_TO_CM(ptValue) * 10000.0) / 10000.0; } /** * Prepare ptValue to be displayed in dm * This method will round to 0.0001 precision, use POINT_TO_DM() for lossless conversion. */ static inline qreal toDecimeter(qreal ptValue) { return floor(POINT_TO_DM(ptValue) * 10000.0) / 10000.0; } /** * Prepare ptValue to be displayed in inch * This method will round to 0.00001 precision, use POINT_TO_INCH() for lossless conversion. */ static inline qreal toInch(qreal ptValue) { // "in" values are rounded to 0.00001 inches return floor(POINT_TO_INCH(ptValue) * 100000.0) / 100000.0; } /** * Prepare ptValue to be displayed in pica * This method will round to 0.00001 precision, use POINT_TO_PI() for lossless conversion. */ static inline qreal toPica(qreal ptValue) { // "pi" values are rounded to 0.00001 inches return floor(POINT_TO_PI(ptValue) * 100000.0) / 100000.0; } /** * Prepare ptValue to be displayed in cicero * This method will round to 0.00001 precision, use POINT_TO_CC() for lossless conversion. */ static inline qreal toCicero(qreal ptValue) { // "cc" values are rounded to 0.00001 inches return floor(POINT_TO_CC(ptValue) * 100000.0) / 100000.0; } /** * convert the given value directly from one unit to another with high accuracy */ static qreal convertFromUnitToUnit(qreal value, const KReportUnit &fromUnit, const KReportUnit &toUnit, qreal factor = 1.0); /** * convert the given value directly from one unit to another with high accuracy */ static QPointF convertFromUnitToUnit(const QPointF &value, const KReportUnit &fromUnit, const KReportUnit &toUnit); /** * convert the given value directly from one unit to another with high accuracy */ static QSizeF convertFromUnitToUnit(const QSizeF &value, const KReportUnit &fromUnit, const KReportUnit &toUnit); /** * This method is the one to use to display a value in a dialog * \return the value @p ptValue converted to unit and rounded, ready to be displayed */ qreal toUserValue(qreal ptValue) const; /** * Convert the value @p ptValue to a given unit @p unit * Unlike KReportUnit::ptToUnit the return value remains unrounded, so that it can be used in complex calculation * \return the converted value */ static qreal ptToUnit(qreal ptValue, const KReportUnit &unit); /// This method is the one to use to display a value in a dialog /// @return the value @p ptValue converted the unit and rounded, ready to be displayed QString toUserStringValue(qreal ptValue) const; //! @return the value converted to points with high accuracy qreal convertToPoint(qreal value) const; //! @return the value converted from points to the actual unit with high accuracy qreal convertFromPoint(qreal ptValue) const; //! @return the value converted from points to the actual unit with high accuracy QPointF convertFromPoint(const QPointF &ptValue) const; //! @return the value converted from points to the actual unit with high accuracy QSizeF convertFromPoint(const QSizeF &ptValue) const; //! Equal to convertToPoint(), use convertToPoint() instead for clarity inline qreal fromUserValue(qreal value) const { return convertToPoint(value); } /// @return the value converted to points with high accuracy QPointF convertToPoint(const QPointF &value) const; /// @return the value converted to points with high accuracy QSizeF convertToPoint(const QSizeF &value) const; /// @return the value converted to points with high accuracy /// @param value value entered by the user /// @param ok if set, the pointed bool is set to true if the value could be /// converted to a qreal, and to false otherwise. /// @return the value converted to points for internal use - qreal convertToPoint(const QString &value, bool *ok = 0) const; + qreal convertToPoint(const QString &value, bool *ok = nullptr) const; //! Equal to convertToPoint(), use convertToPoint() instead for clarity - inline qreal fromUserValue(const QString &value, bool *ok = 0) const { + inline qreal fromUserValue(const QString &value, bool *ok = nullptr) const { return convertToPoint(value, ok); } //! Returns the symbol string of given unit type //! Symbol for Invalid type is empty string. static QString symbol(KReportUnit::Type type); //! Returns the symbol string of the unit //! Symbol for Invalid type is empty string. QString symbol() const; /** * Equal to symbol(): returns the symbol string of the unit. */ inline QString toString() const { return symbol(); } /** * @brief Returns a unit symbol string to type * * @param symbol symbol to convert, must be lowercase * @return Invalid type for unsupported symbol * * @since 3.1 */ static KReportUnit::Type symbolToType(const QString &symbol); /** * @brief Returns the list of unit symbols for the given types * * @since 3.1 */ static QStringList symbols(const QList &types); /// Parses common %KReport and ODF values, like "10cm", "5mm" to pt. /// If no unit is specified, pt is assumed. /// @a defaultVal is in Points static qreal parseValue(const QString &value, qreal defaultVal = 0.0); /// parse an angle to its value in degrees /// @a defaultVal is in degrees static qreal parseAngle(const QString &value, qreal defaultVal = 0.0); private: class Private; Private * const d; }; #ifndef QT_NO_DEBUG_STREAM KREPORT_EXPORT QDebug operator<<(QDebug, const KReportUnit &); #endif Q_DECLARE_METATYPE(KReportUnit) #endif diff --git a/src/wrtembed/KReportSectionEditor.cpp b/src/wrtembed/KReportSectionEditor.cpp index d4785a7f..b5d1aa88 100644 --- a/src/wrtembed/KReportSectionEditor.cpp +++ b/src/wrtembed/KReportSectionEditor.cpp @@ -1,536 +1,535 @@ /* 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::Type::ReportHeader)); m_ui.cbReportFooter->setChecked(m_reportDesigner->section(KReportSectionData::Type::ReportFooter)); 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::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::Type::ReportHeader); } else { m_reportDesigner->removeSection(KReportSectionData::Type::ReportHeader); } } } void KReportSectionEditor::cbReportFooter_toggled(bool yes) { if (m_reportDesigner) { if (yes) { m_reportDesigner->insertSection(KReportSectionData::Type::ReportFooter); } else { m_reportDesigner->removeSection(KReportSectionData::Type::ReportFooter); } } } void KReportSectionEditor::cbHeadFirst_toggled(bool yes) { if (m_reportDesigner) { if (yes) { m_reportDesigner->insertSection(KReportSectionData::Type::PageHeaderFirst); } else { m_reportDesigner->removeSection(KReportSectionData::Type::PageHeaderFirst); } } } void KReportSectionEditor::cbHeadLast_toggled(bool yes) { if (m_reportDesigner) { if (yes) { m_reportDesigner->insertSection(KReportSectionData::Type::PageHeaderLast); } else { m_reportDesigner->removeSection(KReportSectionData::Type::PageHeaderLast); } } } void KReportSectionEditor::cbHeadEven_toggled(bool yes) { if (m_reportDesigner) { if (yes) { m_reportDesigner->insertSection(KReportSectionData::Type::PageHeaderEven); } else { m_reportDesigner->removeSection(KReportSectionData::Type::PageHeaderEven); } } } void KReportSectionEditor::cbHeadOdd_toggled(bool yes) { if (m_reportDesigner) { if (yes) { m_reportDesigner->insertSection(KReportSectionData::Type::PageHeaderOdd); } else { m_reportDesigner->removeSection(KReportSectionData::Type::PageHeaderOdd); } } } void KReportSectionEditor::cbFootFirst_toggled(bool yes) { if (m_reportDesigner) { if (yes) { m_reportDesigner->insertSection(KReportSectionData::Type::PageFooterFirst); } else { m_reportDesigner->removeSection(KReportSectionData::Type::PageFooterFirst); } } } void KReportSectionEditor::cbFootLast_toggled(bool yes) { if (m_reportDesigner) { if (yes) { m_reportDesigner->insertSection(KReportSectionData::Type::PageFooterLast); } else { m_reportDesigner->removeSection(KReportSectionData::Type::PageFooterLast); } } } void KReportSectionEditor::cbFootEven_toggled(bool yes) { if (m_reportDesigner) { if (yes) { m_reportDesigner->insertSection(KReportSectionData::Type::PageFooterEven); } else { m_reportDesigner->removeSection(KReportSectionData::Type::PageFooterEven); } } } void KReportSectionEditor::cbFootOdd_toggled(bool yes) { if (m_reportDesigner) { if (yes) { m_reportDesigner->insertSection(KReportSectionData::Type::PageFooterOdd); } else { 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::Type::PageHeaderAny); } else { m_reportDesigner->removeSection(KReportSectionData::Type::PageHeaderAny); } } } void KReportSectionEditor::cbFootAny_toggled(bool yes) { if (m_reportDesigner) { if (yes) { m_reportDesigner->insertSection(KReportSectionData::Type::PageFooterAny); } else { 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); + const bool isItemSelected = currentItem; 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); }