diff --git a/src/common/KReportAsyncItemBase.h b/src/common/KReportAsyncItemBase.h index c0450b4c..1dd128bb 100644 --- a/src/common/KReportAsyncItemBase.h +++ b/src/common/KReportAsyncItemBase.h @@ -1,42 +1,45 @@ /* This file is part of the KDE project Copyright (C) 2011 Adam Pigg 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef KREPORTASYNCITEMBASE_H #define KREPORTASYNCITEMBASE_H #include "KReportItemBase.h" +/*! + * @brief Base class for items that are drawn asyncronously due to unknown loading times. + */ class KREPORT_EXPORT KReportAsyncItemBase : public KReportItemBase { Q_OBJECT public: KReportAsyncItemBase(); ~KReportAsyncItemBase(); int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) override = 0; virtual QVariant realItemData(const QVariant& itemData) const; Q_SIGNALS: void finishedRendering(); - + private: class Private; Private * const d; }; #endif // KREPORTASYNCITEMBASE_H diff --git a/src/common/KReportDataSource.h b/src/common/KReportDataSource.h index 01504fed..4761af6c 100644 --- a/src/common/KReportDataSource.h +++ b/src/common/KReportDataSource.h @@ -1,129 +1,135 @@ /* This file is part of the KDE project * Copyright (C) 2007-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 . */ #ifndef KREPORTDATA_H #define KREPORTDATA_H #include #include #include "kreport_export.h" #include "config-kreport.h" -/** @brief Abstraction of report data source -*/ +/*! + * @brief Abstraction of report data source. + * + * A data source provides data to the report engine, usually from a + * database, but could also be implemented for text and other file formats + */ class KREPORT_EXPORT KReportDataSource { public: KReportDataSource(); virtual ~KReportDataSource(); - //! Describes sorting for single field - /*! By default the order is ascending. */ + /*! + * @brief Describes sorting for single field, + * By default the order is ascending. + */ class KREPORT_EXPORT SortedField { public: SortedField(); SortedField(const SortedField& other); ~SortedField(); SortedField& operator=(const SortedField &other); bool operator==(const SortedField &other) const; bool operator!=(const SortedField &other) const; void setField(const QString &field); void setOrder(Qt::SortOrder order); QString field() const; Qt::SortOrder order() const; private: class Private; Private * const d; }; //! Open the dataset virtual bool open() = 0; //! Close the dataset virtual bool close() = 0; //! Move to the next record virtual bool moveNext() = 0; //! Move to the previous record virtual bool movePrevious() = 0; //! Move to the first record virtual bool moveFirst() = 0; //! Move to the last record virtual bool moveLast() = 0; //! Return the current position in the dataset virtual qint64 at() const = 0; //! Return the total number of records virtual qint64 recordCount() const = 0; //! Return the index number of the field given by nane field virtual int fieldNumber(const QString &field) const = 0; //! Return the list of field names virtual QStringList fieldNames() const = 0; //! Return the list of field keys. Returns fieldNames() by default virtual QStringList fieldKeys() const; //! Return the value of the field at the given position for the current record virtual QVariant value(int pos) const = 0; //! Return the value of the field fir the given name for the current record virtual QVariant value(const QString &field) const = 0; //! Return the name of this source virtual QString sourceName() const; //! @return the class name of this source virtual QString sourceClass() const; //! Sets the sorting for the data //! Should be called before open() so that the data source can be edited accordingly //! Default impl does nothing virtual void setSorting(const QList &sorting); //! Adds a condition to the data source virtual void addCondition(const QString &field, const QVariant &value, const QString& relation = QLatin1String("=")); //! Return a list of data source names available for this data source //! Works after the source is opened virtual QStringList dataSourceNames() const = 0; //! Return data source caption for specified @a dataSourceName //! It is possibly translated. As such it is suitable for use in GUIs. //! Default implementation just returns @a dataSourceName. virtual QString dataSourceCaption(const QString &dataSourceName) const; //! Creates a new instance with data source. Default implementation returns @c nullptr. //! @a source is implementation-specific identifier. //! Owner of the returned pointer is the caller. virtual KReportDataSource* create(const QString &source) const Q_REQUIRED_RESULT; private: Q_DISABLE_COPY(KReportDataSource) class Private; Private * const d; }; #endif diff --git a/src/common/KReportDesign.h b/src/common/KReportDesign.h index 883a011b..c05492ec 100644 --- a/src/common/KReportDesign.h +++ b/src/common/KReportDesign.h @@ -1,152 +1,152 @@ /* This file is part of the KDE project * 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_H #define KREPORTDESIGN_H #include "kreport_export.h" #include "config-kreport.h" #include "KReportSection.h" #include class QPageSize; class QMarginsF; class QPageLayout; class KReportElement; //! The KReportDesignReadStatus represents status of reading a report design in .kreport format. /*! It is used by KReportDesign::setContent(). */ class KREPORT_EXPORT KReportDesignReadingStatus { public: //! Creates an empty status object. /*! For empty status objects isError() returns false. */ KReportDesignReadingStatus(); ~KReportDesignReadingStatus(); KReportDesignReadingStatus(const KReportDesignReadingStatus &other); KReportDesignReadingStatus& operator=(const KReportDesignReadingStatus &other); - + //! @return true if the status is error. //! Equivalent of errorLineNumber() >= 0 && errorColumnNumber() >= 0. bool isError() const; - + //! Error message suitable for displaying to the user, translated. QString errorMessage() const; - - //! Detailed error message, partially translated. + + //! Detailed error message, partially translated. QString errorDetails() const; - + //! Line number (counting from 0) in which the error occured. -1 if there is no error. - int errorLineNumber() const; - + int errorLineNumber() const; + //! Column number (counting from 0) in which the error occured. -1 if there is no error. int errorColumnNumber() const; - + void setErrorMessage(const QString& msg); void setErrorDetails(const QString& details); void setErrorLineNumber(int line); void setErrorColumnNumber(int column); - + private: class Private; - Private * const d; + Private * const d; }; //! Sends information about the reading status @a status to debug output @a dbg. KREPORT_EXPORT QDebug operator<<(QDebug dbg, const KReportDesignReadingStatus& status); -//! The KReportDesign class represents a report design in .kreport format +//! @brief The KReportDesign class represents a report design in .kreport format class KREPORT_EXPORT KReportDesign { Q_DECLARE_TR_FUNCTIONS(KReportDesign) public: KReportDesign(); ~KReportDesign(); //! Reads the XML document in .kreport format from the string @a text //! @return true if the content was successfully parsed //! On failure false is returned and if @a status is provided, it is updated accordingly. bool setContent(const QString &text, KReportDesignReadingStatus *status = nullptr); //! Converts the report document back to its textual representation. QString toString(int indent = 1) const; //! @return title for this design QString title() const; //! Sets title for this design to @a title void setTitle(const QString &title); //! @return page layout for this design QPageLayout pageLayout() const; //! Sets the page layout to @a pageLayout //! @note Calling this method does not alter page layouts of existing KReportDesign objects. void setPageLayout(const QPageLayout &pageLayout); //! @return true if this design has section defined of type @a type bool hasSection(KReportSection::Type type) const; //! @return section of type @a type KReportSection section(KReportSection::Type type) const; //! Add section @a section. Previous section of the same type is removed from this design. void addSection(const KReportSection §ion); //! Creates and returns report element of type @a typeName //! On success @a errorMessage is cleared, on failure it is set to a nonempty value. KReportElement createElement(const QString &typeName, QString *errorMessage); //! @return default page layout that is used for creating new report designs /*! Attributes that are specified in the design format: - margins: by default equal to equivalent of 1cm in points (QPageLayout::Point). - mode: by default QPageLayout::StandardMode - orientation: by default QPageLayout::Portrait - pageSize: by default equal to default page size of the default printer (QPrinterInfo::defaultPrinter().defaultPageSize()). If there is no default printer, A4 size is used. Passing invalid page size restores defaults explained in documentation of QPageLayout defaultPageLayout(). @todo For KDE Plasma use information from the Locale by using readConfigNumEntry("PageSize", QPrinter::A4, m_pageSize, QPrinter::PageSize) from KLocalePrivate::initFormat() (klocale_kde.cpp) Other attributes are ignored by the design format. In particular units for margins and pageSize are always QPageLayout::Point. */ static QPageLayout defaultPageLayout(); //! Sets default page layout to @a pageLayout //! This information is used when a new report design is created. static void setDefaultPageLayout(const QPageLayout &pageLayout); #ifdef KREPORT_SCRIPTING //! @return text of the script program QString script() const; #endif private: Q_DISABLE_COPY(KReportDesign) class Private; Private * const d; }; #endif // KREPORTDESIGN_H diff --git a/src/common/KReportDocument.h b/src/common/KReportDocument.h index 73c09676..72f9e028 100644 --- a/src/common/KReportDocument.h +++ b/src/common/KReportDocument.h @@ -1,112 +1,115 @@ /* 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 -/** -*/ +/*! + * @brief Top level report document definition. + * A KReportDocment defines the design of a document, and is composed of multiple + * sections. + */ 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 type */ KReportSectionData* section(KReportSectionData::Type type) const; /** \return a sectiondata given its name */ 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; void setName(const QString&n); QString name() const; QString title() const; QPageLayout pageLayout() const; - + QString pageSize(); void setPageSize(const QString &size); -private: +private: 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/KReportItemBase.h b/src/common/KReportItemBase.h index fdb84e77..a9c3ee4a 100644 --- a/src/common/KReportItemBase.h +++ b/src/common/KReportItemBase.h @@ -1,183 +1,174 @@ /* This file is part of the KDE project * Copyright (C) 2007-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 . */ #ifndef KREPORTITEMBASE_H #define KREPORTITEMBASE_H #include "config-kreport.h" #include "kreport_export.h" #include "KReportUnit.h" #include #include #include class OROPage; class OROSection; class KReportDataSource; class KReportLineStyle; #ifdef KREPORT_SCRIPTING class KReportScriptHandler; #else #define KReportScriptHandler void #endif class KProperty; class KPropertySet; class QDomElement; class KReportTextStyleData { public: QFont font; Qt::Alignment alignment; QColor backgroundColor; QColor foregroundColor; int backgroundOpacity; }; -/* -class KReportLineStyle -{ -public: - int weight; - QColor lineColor; - Qt::PenStyle style; -}; -*/ - -/** -*/ +/*! + * @brief Base class for items that are drawn syncronously. + */ class KREPORT_EXPORT KReportItemBase : public QObject { Q_OBJECT public: KReportItemBase(); ~KReportItemBase() override; /** @brief Return the item type as a string. Required by all items @return Item type */ virtual QString typeName() const = 0; /** @brief Render the item into a primitive which is used by the second stage renderer @return the height required by the object */ virtual int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script); /** @brief Render a complex item that uses a sub query as a data source @return the height required by the object */ virtual int renderReportData(OROPage *page, OROSection *section, const QPointF &offset, KReportDataSource *dataSource, KReportScriptHandler *script); /** @brief Override if the item supports a simple data source, such as a field @return The field name or expression for the data source */ virtual QString itemDataSource() const; /** @brief Override if the item uses a sub query and linked fields, such as a chart or sub-report @return True if uses a sub query */ virtual bool supportsSubQuery() const; KPropertySet* propertySet(); const KPropertySet* propertySet() const; void setEntityName(const QString& n); QString entityName() const; KReportUnit unit() const; //! Sets unit to @a a and converts values of position and size property from the old //! unit to new if needed. virtual void setUnit(const KReportUnit &u); /** * @brief Return the size in points */ QSizeF size() const; /** * @brief Return the position in points */ QPointF position() const; /** * @brief Sets position for the element * @param ptPos Position in points */ void setPosition(const QPointF &ptPos); /** * @brief Sets size for the element * @param ptSize Size in points */ void setSize(const QSizeF &ptSize); /** * @brief Return the z-value in points */ qreal z() const; /** * @brief Sets the z-value for the element * @param z Z-value in points */ void setZ(qreal z); //! Helper function mapping to screen units (pixels), @a ptPos is in points static QPointF scenePosition(const QPointF &ptPos); //! Helper function mapping to screen units (pixels), @a ptSize is in points static QSizeF sceneSize(const QSizeF &ptSize); - + //! Helper function mapping from screen units to points, @a pos is in pixels static QPointF positionFromScene(const QPointF &pos); //! Helper function mapping from screen units to points, @a size is in pixels static QSizeF sizeFromScene(const QSizeF &size); protected: virtual void createProperties() = 0; bool parseReportRect(const QDomElement &elem); static bool parseReportTextStyleData(const QDomElement &, KReportTextStyleData*); static bool parseReportLineStyleData(const QDomElement &, KReportLineStyle*); KProperty *nameProperty(); QString oldName() const; void setOldName(const QString &old); Q_SLOT virtual void propertyChanged(KPropertySet &s, KProperty &p); private: Q_DISABLE_COPY(KReportItemBase) class Private; Private * const d; Q_SLOT void aboutToDeleteProperty(KPropertySet& set, KProperty& property); }; #endif diff --git a/src/common/KReportPluginInterface.h b/src/common/KReportPluginInterface.h index 58cce89c..9b25b8a5 100644 --- a/src/common/KReportPluginInterface.h +++ b/src/common/KReportPluginInterface.h @@ -1,80 +1,82 @@ /* This file is part of the KDE project Copyright (C) 2010 by Adam Pigg (adam@piggz.co.uk) 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 Library 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 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 KREPORTPLUGININTERFACE_H #define KREPORTPLUGININTERFACE_H #include "config-kreport.h" #include "kreport_export.h" #include "KReportElement.h" #include class QGraphicsScene; class QDomNode; class QDomElement; class KReportPluginMetaData; class KReportDesignReadingStatus; class KReportDesigner; class KReportItemBase; //! Implementation of report plugin's entry point #define KREPORT_PLUGIN_FACTORY(class_name, name) \ K_PLUGIN_FACTORY_WITH_JSON(class_name ## Factory, name, registerPlugin();) -//! An interface for plugins delivering KReport elements +/*! + * @brief An interface for plugins delivering KReport elements. + */ class KREPORT_EXPORT KReportPluginInterface : public QObject { Q_OBJECT public: explicit KReportPluginInterface(QObject *parent = nullptr, const QVariantList &args = QVariantList()); ~KReportPluginInterface() override; virtual QObject* createDesignerInstance(KReportDesigner *designer, QGraphicsScene * scene, const QPointF &pos) = 0; virtual QObject* createDesignerInstance(const QDomNode &element, KReportDesigner *designer, QGraphicsScene *scene) = 0; virtual QObject* createRendererInstance(const QDomNode &element) = 0; virtual KReportElement createElement(); virtual bool loadElement(KReportElement *el, const QDomElement &dom, KReportDesignReadingStatus *status); #ifdef KREPORT_SCRIPTING virtual QObject* createScriptInstance(KReportItemBase* item) = 0; #endif //! @return information about the plugin const KReportPluginMetaData* metaData() const; private: friend class KReportPluginEntry; void setMetaData(KReportPluginMetaData* metaData); Q_DISABLE_COPY(KReportPluginInterface) class Private; Private * const d; }; #endif // KREPORTPLUGININTERFACE_H diff --git a/src/common/KReportPluginManager.h b/src/common/KReportPluginManager.h index d0783c25..a8c4efcf 100644 --- a/src/common/KReportPluginManager.h +++ b/src/common/KReportPluginManager.h @@ -1,64 +1,67 @@ /* This file is part of the KDE project Copyright (C) 2010 by Adam Pigg (adam@piggz.co.uk) 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 Library 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 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 KREPORTPLUGINMANAGER_H #define KREPORTPLUGINMANAGER_H #include "config-kreport.h" #include "kreport_export.h" #include #include class KReportPluginMetaData; class KReportPluginInterface; class QStringList; class QAction; class QString; +/*! + * @brief Manager class for finding and loading available plugins + */ class KREPORT_EXPORT KReportPluginManager : public QObject { Q_OBJECT public: static KReportPluginManager* self(); QStringList pluginIds() const; const KReportPluginMetaData *pluginMetaData(const QString& id) const; KReportPluginInterface* plugin(const QString& id) const; QList createActions(QObject *parent) Q_REQUIRED_RESULT; private: // class for access to the constructor friend class KReportPluginManagerSingleton; KReportPluginManager(); ~KReportPluginManager() override; Q_DISABLE_COPY(KReportPluginManager) class Private; Private *const d; }; #endif // KREPORTPLUGINMANAGER_H diff --git a/src/common/KReportPluginMetaData.h b/src/common/KReportPluginMetaData.h index 0d6df8c5..f5f2f460 100644 --- a/src/common/KReportPluginMetaData.h +++ b/src/common/KReportPluginMetaData.h @@ -1,63 +1,65 @@ /* This file is part of the KDE project Copyright (C) 2010 by Adam Pigg (adam@piggz.co.uk) 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 Library 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 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 KREPORTPLUGININFO_H #define KREPORTPLUGININFO_H #include #include "kreport_export.h" -//! Information about a KReport plugin. +/*! + * @brief Information about a KReport plugin. + */ class KREPORT_EXPORT KReportPluginMetaData : public KPluginMetaData { public: ~KReportPluginMetaData(); //! @return internal name of the plugin, a shortcut of pluginId() QString id() const; //! @return priority of the plugin //! Useful for user interfaces such as tool boxes. int priority() const; //! @return true if this plugin is built-in, i.e. has been provided by the KReport //! framework itself, not by a plugin file. bool isBuiltIn() const; //! @return true if this plugin is static, i.e. is compiled-in. bool isStatic() const; protected: explicit KReportPluginMetaData(const QJsonObject &metaData); explicit KReportPluginMetaData(const QPluginLoader &loader); void setBuiltIn(bool set); void setStatic(bool set); friend class KReportPluginEntry; private: Q_DISABLE_COPY(KReportPluginMetaData) class Private; Private * const d; }; #endif // KREPORTPLUGININFO_H diff --git a/src/common/KReportRenderObjects.h b/src/common/KReportRenderObjects.h index 2ef50771..5ef49d4a 100644 --- a/src/common/KReportRenderObjects.h +++ b/src/common/KReportRenderObjects.h @@ -1,462 +1,460 @@ /* 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 -// + +/*! + * @brief Represents 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 + * + * @param section 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. -// +/*! + * @brief Represents a single page in a document and may contain zero or more + * OROPrimitive objects all of which represent some form of mark to be 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 -// + +/*! + * @brief Represents a single 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::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. -// +/*! + * @brief 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. -// +/*! + * @brief 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. -// +/*! + * @brief 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 -// +/*! + * @brief Defines an image. + * An image is a bitmap. + */ 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 -// +/*! + * @brief Defines a picture. + * A picture is different to an image, in that it is drawn using commands. + */ 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 -// + +/*! + * @brief Defines a 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 -// +/*! + * @brief Defines an ellipse. + */ 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; }; +/*! + * @brief Defines checkbox. + */ class KREPORT_EXPORT OROCheckBox : public OROPrimitive { public: 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/KReportUnit.h b/src/common/KReportUnit.h index 3be141da..5ea4a02c 100644 --- a/src/common/KReportUnit.h +++ b/src/common/KReportUnit.h @@ -1,341 +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) -/** - * %KReport stores everything in pt (using "qreal") internally. + +/*! + * @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; //! Equal to convertToPoint(), use convertToPoint() instead for clarity inline qreal fromUserValue(const QString &value, bool *ok = 0) 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/items/label/KReportLabelElement.shared.h b/src/items/label/KReportLabelElement.shared.h index f9ad7185..9244588b 100644 --- a/src/items/label/KReportLabelElement.shared.h +++ b/src/items/label/KReportLabelElement.shared.h @@ -1,72 +1,75 @@ /* 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 KREPORTLABELELEMENT_H #define KREPORTLABELELEMENT_H #include "KReportElement.h" #include "KReportLineStyle.h" #include -//! @brief The KReportLabelElement class represents a label element of a report design +/*! + * @brief The KReportLabelElement class represents a label element of a report design + * @warning This API is currently private. + */ class KREPORT_EXPORT KReportLabelElement : public KReportElement //SDC: explicit operator== virtual_dtor { public: /*! @getter @return element's name. @setter Sets the element's name to @a name. */ QString text; //SDC: /*! @getter @return element's font. @setter Sets the element's font to @a font. */ QFont font; //SDC: /*! @getter @return element's text alignment. Default value is Qt::AlignLeft|Qt::AlignVCenter. @setter Sets the element's text alignment to @a alignment. */ Qt::Alignment alignment; //SDC: default=Qt::AlignLeft|Qt::AlignVCenter /*! @getter @return element's border style. @setter Sets the element's border style to @a borderStyle. */ KReportLineStyle borderStyle; //SDC: //! Constructs a label with text @a text. explicit KReportLabelElement(const QString &text) : KReportElement(new Data) { setText(text); } }; #endif // KREPORTLABELELEMENT_H diff --git a/src/renderer/KReportPage.h b/src/renderer/KReportPage.h index 9db3f208..7b71ef06 100644 --- a/src/renderer/KReportPage.h +++ b/src/renderer/KReportPage.h @@ -1,58 +1,58 @@ /* 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 . */ #ifndef KREPORTPAGE_H #define KREPORTPAGE_H #include "kreport_export.h" #include #include class ORODocument; -/** - Provides a widget that renders a specific page of - and ORODocument - The widget is sized to the document size in pixels. -*/ +/*! + * @brief Provides a widget that renders a specific page of + * an ORODocument + * The widget is sized to the document size in pixels + */ class KREPORT_EXPORT KReportPage : public QObject, public QGraphicsRectItem { Q_OBJECT public: KReportPage(QWidget *parent, ORODocument *document); ~KReportPage() override; //! Renders page @a page (counted from 1). void renderPage(int page); public Q_SLOTS: void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override; void pageUpdated(int pageNo); private Q_SLOTS: void renderCurrentPage(); private: Q_DISABLE_COPY(KReportPage) class Private; Private * const d; }; #endif diff --git a/src/renderer/KReportPreRenderer.h b/src/renderer/KReportPreRenderer.h index 57d62345..6012fba1 100644 --- a/src/renderer/KReportPreRenderer.h +++ b/src/renderer/KReportPreRenderer.h @@ -1,87 +1,86 @@ /* 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 KREPORTPRERENDERER_H #define KREPORTPRERENDERER_H #include "config-kreport.h" #include "kreport_export.h" #include #ifdef KREPORT_SCRIPTING class KReportScriptHandler; class KReportScriptSource; #else #define KReportScriptHandler void #endif class KReportPreRendererPrivate; class ORODocument; class KReportDataSource; class KReportDocument; class QDomElement; -// -// ORPreRender -// This class takes a report definition and prerenders the result to -// an ORODocument that can be used to pass to any number of renderers. -// +/*! + * @brief Takes a report definition and prerenders the result to + * an ORODocument that can be used to pass to any number of renderers. + */ class KREPORT_EXPORT KReportPreRenderer : public QObject { Q_OBJECT public: explicit KReportPreRenderer(const QDomElement& document); ~KReportPreRenderer() override; //! Sets data source to @a data, takes ownership void setDataSource(KReportDataSource* dataSource); #ifdef KREPORT_SCRIPTING //!Sets the script source to @a source, does NOT take ownership as it may be an application window void setScriptSource(KReportScriptSource* source); KReportScriptHandler *scriptHandler(); void registerScriptObject(QObject *obj, const QString &name); #endif bool generateDocument(); ORODocument *document(); /** @brief Set the name of the report so that it can be used internally by the script engine */ void setName(const QString &); bool isValid() const; const KReportDocument *reportData() const; Q_SIGNALS: void groupChanged(const QMap &groupData); void finishedAllASyncItems(); private: bool setDocument(const QDomElement &document); Q_DISABLE_COPY(KReportPreRenderer) KReportPreRendererPrivate *const d; }; #endif // KREPORTPRERENDERER_H diff --git a/src/renderer/KReportRendererBase.h b/src/renderer/KReportRendererBase.h index b4eef63e..ecb60d90 100644 --- a/src/renderer/KReportRendererBase.h +++ b/src/renderer/KReportRendererBase.h @@ -1,84 +1,93 @@ /* This file is part of the KDE project Copyright (C) 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 Library 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 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 KREPORTRENDERERBASE_H #define KREPORTRENDERERBASE_H #include #include "kreport_export.h" class QPainter; class QPrinter; class ORODocument; -//! Context for executing rendering. +/*! + * @bref Context for executing rendering. + */ class KREPORT_EXPORT KReportRendererContext { public: KReportRendererContext(); ~KReportRendererContext(); - + void setUrl(const QUrl& url); void setPainter(QPainter* painter); void setPrinter(QPrinter* printer); - + QPrinter *printer(); QPainter *painter(); QPrinter *printer() const; QPainter *painter() const; - + QUrl url() const; - + private: Q_DISABLE_COPY(KReportRendererContext) class Private; Private * const d; }; -//! Base class for report renderers. +/*! + * @brief Base class for report renderers. + * + * A renderer combines the report design with + * data to produce a visual output + */ class KREPORT_EXPORT KReportRendererBase { public: KReportRendererBase(); virtual ~KReportRendererBase(); //! Render the page of the given document within the given context. //! If page == -1, renders the entire document. virtual bool render(const KReportRendererContext& context, ORODocument *document, int page = -1) = 0; }; -//! Factory for creating renderers -//! @todo make it use plugins +/*! + * @brief Factory for creating renderers + * @todo make it use plugins + */ class KREPORT_EXPORT KReportRendererFactory { public: KReportRendererFactory(); ~KReportRendererFactory(); - + KReportRendererBase* createInstance(const QString& key); - + private: Q_DISABLE_COPY(KReportRendererFactory) class Private; Private * const d; }; #endif // KREPORTRENDERERBASE_H diff --git a/src/renderer/KReportView.h b/src/renderer/KReportView.h index 9f850d23..b48e1f2c 100644 --- a/src/renderer/KReportView.h +++ b/src/renderer/KReportView.h @@ -1,67 +1,66 @@ /* This file is part of the KDE project Copyright (C) 2015 by Adam Pigg (adam@piggz.co.uk) 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.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 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 KREPORTVIEW_H #define KREPORTVIEW_H #include #include "kreport_export.h" class ORODocument; class QAbstractScrollArea; /** * @brief Provides a simple widget for viewing a rendered report on screen - * */ class KREPORT_EXPORT KReportView : public QWidget { Q_OBJECT public: explicit KReportView(QWidget *parent); ~KReportView() override; void moveToFirstPage(); void moveToLastPage(); void moveToNextPage(); void moveToPreviousPage(); //! Moves to page @a page (counted from 1) //! @since 3.1 void moveToPage(int page); //! @return number of current page (counted from 1) int currentPage() const; int pageCount() const; void refreshCurrentPage(); void setDocument(ORODocument* doc); QAbstractScrollArea* scrollArea(); private: Q_DISABLE_COPY(KReportView) class Private; Private * const d; }; #endif diff --git a/src/renderer/scripting/KReportGroupTracker.h b/src/renderer/scripting/KReportGroupTracker.h index 739e19b5..e434e05a 100644 --- a/src/renderer/scripting/KReportGroupTracker.h +++ b/src/renderer/scripting/KReportGroupTracker.h @@ -1,19 +1,22 @@ #ifndef KREPORTGROUPTRACKER_H #define KREPORTGROUPTRACKER_H #include #include "kreport_export.h" +/*! + * @brief Keeps track of groups as the data for the group changes + */ class KREPORT_EXPORT KReportGroupTracker : public QObject { Q_OBJECT protected: KReportGroupTracker() {} ~KReportGroupTracker() override{} public: Q_SLOT virtual void setGroupData(const QMap &groupData) = 0; }; #endif // KREPORTGROUPTRACKER_H diff --git a/src/renderer/scripting/KReportScriptHandler.h b/src/renderer/scripting/KReportScriptHandler.h index c6934739..c214e817 100644 --- a/src/renderer/scripting/KReportScriptHandler.h +++ b/src/renderer/scripting/KReportScriptHandler.h @@ -1,78 +1,84 @@ /* 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 . */ #ifndef KRSCRIPTHANDLER_H #define KRSCRIPTHANDLER_H #include "kreport_export.h" #include "config-kreport.h" #ifdef KREPORT_SCRIPTING #include "KReportScriptConstants.h" #include "KReportDataSource.h" #include class KReportScriptDebug; class KReportScriptDraw; class KReportSectionData; class QJSEngine; class KReportDocument; class OROPage; class KReportScriptSource; namespace Scripting { class Report; class Section; } +/*! + * @brief Handles scripting during report rendering. + * + * The script handler loads scriptable objects, and executes + * appropriate script code during report rendering + */ class KREPORT_EXPORT KReportScriptHandler : public QObject { Q_OBJECT public: KReportScriptHandler(const KReportDataSource *reportDataSource, KReportScriptSource *scriptSource, KReportDocument* reportDocument); ~KReportScriptHandler() override; QVariant evaluate(const QString&); void displayErrors(); QJSValue registerScriptObject(QObject*, const QString&); bool trigger(); public Q_SLOTS: void slotEnteredSection(KReportSectionData*, OROPage*, QPointF); void slotEnteredGroup(const QString&, const QVariant&); void slotExitedGroup(const QString&, const QVariant&); void setPageNumber(int p); void setPageTotal(int t); void newPage(); Q_SIGNALS: void groupChanged(const QMap &groupData); private: //! @todo KEXI3 QString where(); Q_DISABLE_COPY(KReportScriptHandler) class Private; Private * const d; }; #else // !KREPORT_SCRIPTING #define KReportScriptHandler void #endif #endif diff --git a/src/renderer/scripting/KReportScriptSource.h b/src/renderer/scripting/KReportScriptSource.h index 613111f7..216f0fd4 100644 --- a/src/renderer/scripting/KReportScriptSource.h +++ b/src/renderer/scripting/KReportScriptSource.h @@ -1,41 +1,45 @@ /* This file is part of the KDE project * Copyright (C) 2017 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 KREPORTSCRIPTSOURCE_H #define KREPORTSCRIPTSOURCE_H #include #include #include "kreport_export.h" -/** @brief Abstraction of report script source -*/ +/*! + * @brief Abstraction of report script source. + * + * A script source is implemented by the source + * application to provide scripts to the report. + */ class KREPORT_EXPORT KReportScriptSource { public: virtual ~KReportScriptSource(); //! Allow the implementation to return a list of possible scripts virtual QStringList scriptList() const = 0; //! Allow the implementation to return some script code based on a specific script name //! as set in the report virtual QString scriptCode(const QString& script) const = 0; }; #endif diff --git a/src/wrtembed/KReportDesigner.cpp b/src/wrtembed/KReportDesigner.cpp index 28c80485..68134da5 100644 --- a/src/wrtembed/KReportDesigner.cpp +++ b/src/wrtembed/KReportDesigner.cpp @@ -1,1693 +1,1693 @@ /* 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 "KReportDesign_p.h" #include "KReportDesignerItemLine.h" #include "KReportDesignerSection.h" #include "KReportDesignerSectionDetail.h" #include "KReportDesignerSectionDetailGroup.h" #include "KReportDesignerSectionScene.h" #include "KReportDesignerSectionView.h" #include "KReportPageSize.h" #include "KReportPluginInterface.h" #include "KReportPluginManager.h" #include "KReportPluginMetaData.h" #include "KReportPropertiesButton.h" #include "KReportRuler_p.h" #include "KReportSection.h" #include "KReportSectionEditor.h" #include "KReportUtils.h" #include "KReportUtils_p.h" #include "KReportZoomHandler_p.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 #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 = MouseAction::None; } virtual ~ReportWriterSectionData() { } 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: explicit Private(KReportDesigner *designer); ~Private() { delete dataSource; } void init(const QDomElement *xml); void updateCurrentUnit() { QString u = unit->value().toString(); KReportUnit newUnit = KReportUnit(KReportUnit::symbolToType(u)); if (newUnit.isValid()) { currentUnit = newUnit; } else { currentUnit = DEFAULT_UNIT; } if (u == QLatin1String("dm")) { gridDivisions->setOption("max", 100); } else { gridDivisions->setOption("max", 10); if (gridDivisions->value().toInt() > 10) { gridDivisions->setValue(10, KProperty::ValueOption::IgnoreOld); } } } #ifdef KREPORT_SCRIPTING void updateScripts(); #endif KReportDesigner * const q; 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 *customPageSize; KProperty *leftMargin; KProperty *rightMargin; KProperty *topMargin; KProperty *bottomMargin; KProperty *showGrid; KProperty *gridDivisions; KProperty *gridSnap; KProperty *labelType; #ifdef KREPORT_SCRIPTING KProperty *script; #endif KReportUnit currentUnit; //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 private: void loadXml(const QDomElement &data); }; KReportDesigner::Private::Private(KReportDesigner *designer) : q(designer), currentUnit(DEFAULT_UNIT_TYPE) { } // (must be init() instead of ctor because we are indirectly depending on initialized KReportDesigner::d here) void KReportDesigner::Private::init(const QDomElement *xml) { KReportPluginManager::self(); // this loads icons early enough q->createProperties(); q->createActions(); grid = new QGridLayout(q); grid->setSpacing(0); grid->setMargin(0); grid->setColumnStretch(1, 1); grid->setRowStretch(1, 1); grid->setSizeConstraint(QLayout::SetFixedSize); vboxlayout = new QVBoxLayout(); vboxlayout->setSpacing(0); vboxlayout->setMargin(0); vboxlayout->setSizeConstraint(QLayout::SetFixedSize); //Create nice rulers hruler = new KReportRuler(nullptr, Qt::Horizontal, zoomHandler); hruler->setUnit(DEFAULT_UNIT); pageButton = new KReportPropertiesButton; grid->addWidget(pageButton, 0, 0); grid->addWidget(hruler, 0, 1); grid->addLayout(vboxlayout, 1, 0, 1, 2); pageButton->setMaximumSize(QSize(19, 22)); pageButton->setMinimumSize(QSize(19, 22)); if (!xml) { detail = new KReportDesignerSectionDetail(q); vboxlayout->insertWidget(0, detail); } connect(pageButton, &KReportPropertiesButton::released, q, &KReportDesigner::slotPageButton_Pressed); emit q->pagePropertyChanged(set); connect(&set, &KPropertySet::propertyChanged, q, &KReportDesigner::slotPropertyChanged); if (xml) { loadXml(*xml); } set.clearModifiedFlags(); q->changeSet(&set); } void KReportDesigner::Private::loadXml(const QDomElement &data) { if (data.tagName() != QLatin1String("report:content")) { // arg we got an xml file but not one i know of kreportWarning() << "root element was not "; } //kreportDebug() << data.text(); 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")) { q->setReportTitle(it.firstChild().nodeValue()); #ifdef KREPORT_SCRIPTING } else if (n == QLatin1String("report:script")) { originalInterpreter = it.toElement().attribute(QLatin1String("report:script-interpreter"), QLatin1String("javascript")); if (originalInterpreter.isEmpty()) { originalInterpreter = QLatin1String("javascript"); } originalScript = it.firstChild().nodeValue(); script->setValue(originalScript); if (originalInterpreter != QLatin1String("javascript") && originalInterpreter != QLatin1String("qtscript")) { QString msg = tr("This report contains scripts of type \"%1\". " "Only scripts written in JavaScript language are " "supported. To prevent losing the scripts, their type " "and content will not be changed unless you change these scripts." ).arg(originalInterpreter); QMessageBox::warning(q, tr("Unsupported Script Type"), msg); } #endif } else if (n == QLatin1String("report:grid")) { showGrid->setValue(it.toElement().attribute(QLatin1String("report:grid-visible"), QString::number(1)).toInt() != 0); gridSnap->setValue(it.toElement().attribute(QLatin1String("report:grid-snap"), QString::number(1)).toInt() != 0); gridDivisions->setValue(it.toElement().attribute(QLatin1String("report:grid-divisions"), QString::number(4)).toInt()); unit->setValue(it.toElement().attribute(QLatin1String("report:page-unit"), DEFAULT_UNIT_STRING)); updateCurrentUnit(); } //! @todo Load page options else if (n == QLatin1String("report:page-style")) { QString pagetype = it.firstChild().nodeValue(); if (pagetype == QLatin1String("predefined")) { pageSize->setValue(it.toElement().attribute(QLatin1String("report:page-size"), QLatin1String("A4"))); } else if (pagetype == QLatin1String("custom")) { pageSize->setValue(QLatin1String("Custom")); customPageSize->setValue(QSizeF(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-width"), QLatin1String(""))), KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-height"), QLatin1String(""))))); } else if (pagetype == QLatin1String("label")) { //! @todo } rightMargin->setValue(currentUnit.convertFromPoint( KReportUnit::parseValue(it.toElement().attribute( QLatin1String("fo:margin-right"), DEFAULT_PAGE_MARGIN_STRING)))); leftMargin->setValue(currentUnit.convertFromPoint( KReportUnit::parseValue(it.toElement().attribute( QLatin1String("fo:margin-left"), DEFAULT_PAGE_MARGIN_STRING)))); topMargin->setValue(currentUnit.convertFromPoint( KReportUnit::parseValue(it.toElement().attribute( QLatin1String("fo:margin-top"), DEFAULT_PAGE_MARGIN_STRING)))); bottomMargin->setValue(currentUnit.convertFromPoint( KReportUnit::parseValue(it.toElement().attribute( QLatin1String("fo:margin-bottom"), DEFAULT_PAGE_MARGIN_STRING)))); 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")) { const QString sectiontype = KReportUtils::readSectionTypeNameAttribute(sec.toElement()); if (q->section(KReportSectionData::sectionTypeFromString(sectiontype)) == nullptr) { q->insertSection(KReportSectionData::sectionTypeFromString(sectiontype)); q->section(KReportSectionData::sectionTypeFromString(sectiontype))->initFromXML(sec); } } else if (sn == QLatin1String("report:detail")) { KReportDesignerSectionDetail * rsd = new KReportDesignerSectionDetail(q); rsd->initFromXML(&sec); q->setDetail(rsd); } } else { kreportWarning() << "Encountered an unknown Element: " << n; } } } } else { kreportWarning() << "Encountered a child node of root that is not an Element"; } } updateScripts(); emit q->reportDataChanged(); q->slotPropertyChanged(set, *unit); // set unit for all items q->setModified(false); } #ifdef KREPORT_SCRIPTING void KReportDesigner::Private::updateScripts() { if (scriptSource) { QStringList sl = scriptSource->scriptList(); sl.prepend(QString()); // prepend "none" script->setListData(sl, sl); } } #endif // ---- KReportDesigner::KReportDesigner(QWidget * parent) : QWidget(parent), d(new Private(this)) { d->init(nullptr); } KReportDesigner::KReportDesigner(QWidget *parent, const QDomElement &data) : QWidget(parent), d(new Private(this)) { d->init(&data); } KReportDesigner::~KReportDesigner() { delete d; } ///The saving code 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->currentUnit.convertToPoint(d->customPageSize->value().toSizeF().width())); KReportUtils::setAttribute( &pagestyle, QLatin1String("report:custom-page-height"), d->currentUnit.convertToPoint(d->customPageSize->value().toSizeF().height())); } 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->currentUnit.convertToPoint(d->topMargin->value().toDouble())); KReportUtils::setAttribute( &pagestyle, QLatin1String("fo:margin-bottom"), d->currentUnit.convertToPoint(d->bottomMargin->value().toDouble())); KReportUtils::setAttribute( &pagestyle, QLatin1String("fo:margin-right"), d->currentUnit.convertToPoint(d->rightMargin->value().toDouble())); KReportUtils::setAttribute( &pagestyle, QLatin1String("fo:margin-left"), d->currentUnit.convertToPoint(d->leftMargin->value().toDouble())); content.appendChild(pagestyle); QDomElement body = doc.createElement(QLatin1String("report:body")); QDomElement domsection; 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(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::Type type) const { KReportDesignerSection *sec; switch (type) { case KReportSectionData::Type::PageHeaderAny: sec = d->pageHeaderAny; break; case KReportSectionData::Type::PageHeaderEven: sec = d->pageHeaderEven; break; case KReportSectionData::Type::PageHeaderOdd: sec = d->pageHeaderOdd; break; case KReportSectionData::Type::PageHeaderFirst: sec = d->pageHeaderFirst; break; case KReportSectionData::Type::PageHeaderLast: sec = d->pageHeaderLast; break; case KReportSectionData::Type::PageFooterAny: sec = d->pageFooterAny; break; case KReportSectionData::Type::PageFooterEven: sec = d->pageFooterEven; break; case KReportSectionData::Type::PageFooterOdd: sec = d->pageFooterOdd; break; case KReportSectionData::Type::PageFooterFirst: sec = d->pageFooterFirst; break; case KReportSectionData::Type::PageFooterLast: sec = d->pageFooterLast; break; case KReportSectionData::Type::ReportHeader: sec = d->reportHeader; break; 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::Type type) { KReportDesignerSection* sec = section(type); if (sec) { delete sec; switch (type) { case KReportSectionData::Type::PageHeaderAny: d->pageHeaderAny = nullptr; break; case KReportSectionData::Type::PageHeaderEven: sec = d->pageHeaderEven = nullptr; break; case KReportSectionData::Type::PageHeaderOdd: d->pageHeaderOdd = nullptr; break; case KReportSectionData::Type::PageHeaderFirst: d->pageHeaderFirst = nullptr; break; case KReportSectionData::Type::PageHeaderLast: d->pageHeaderLast = nullptr; break; case KReportSectionData::Type::PageFooterAny: d->pageFooterAny = nullptr; break; case KReportSectionData::Type::PageFooterEven: d->pageFooterEven = nullptr; break; case KReportSectionData::Type::PageFooterOdd: d->pageFooterOdd = nullptr; break; case KReportSectionData::Type::PageFooterFirst: d->pageFooterFirst = nullptr; break; case KReportSectionData::Type::PageFooterLast: d->pageFooterLast = nullptr; break; case KReportSectionData::Type::ReportHeader: d->reportHeader = nullptr; break; case KReportSectionData::Type::ReportFooter: d->reportFooter = nullptr; break; default: sec = nullptr; } setModified(true); adjustSize(); } } void KReportDesigner::insertSection(KReportSectionData::Type type) { KReportDesignerSection* sec = section(type); if (!sec) { int idx = 0; for (int i = static_cast(KReportSectionData::Type::PageHeaderFirst); i <= static_cast(type); ++i) { if (section(static_cast(i))) idx++; } if (type > KReportSectionData::Type::ReportHeader) idx++; //kreportDebug() << idx; KReportDesignerSection *rs = createSection(); d->vboxlayout->insertWidget(idx, rs); switch (type) { case KReportSectionData::Type::PageHeaderAny: rs->setTitle(tr("Page Header (Any)")); d->pageHeaderAny = rs; break; case KReportSectionData::Type::PageHeaderEven: rs->setTitle(tr("Page Header (Even)")); d->pageHeaderEven = rs; break; case KReportSectionData::Type::PageHeaderOdd: rs->setTitle(tr("Page Header (Odd)")); d->pageHeaderOdd = rs; break; case KReportSectionData::Type::PageHeaderFirst: rs->setTitle(tr("Page Header (First)")); d->pageHeaderFirst = rs; break; case KReportSectionData::Type::PageHeaderLast: rs->setTitle(tr("Page Header (Last)")); d->pageHeaderLast = rs; break; case KReportSectionData::Type::PageFooterAny: rs->setTitle(tr("Page Footer (Any)")); d->pageFooterAny = rs; break; case KReportSectionData::Type::PageFooterEven: rs->setTitle(tr("Page Footer (Even)")); d->pageFooterEven = rs; break; case KReportSectionData::Type::PageFooterOdd: rs->setTitle(tr("Page Footer (Odd)")); d->pageFooterOdd = rs; break; case KReportSectionData::Type::PageFooterFirst: rs->setTitle(tr("Page Footer (First)")); d->pageFooterFirst = rs; break; case KReportSectionData::Type::PageFooterLast: rs->setTitle(tr("Page Footer (Last)")); d->pageFooterLast = rs; break; case KReportSectionData::Type::ReportHeader: rs->setTitle(tr("Report Header")); d->reportHeader = rs; break; case KReportSectionData::Type::ReportFooter: rs->setTitle(tr("Report Footer")); d->reportFooter = rs; break; //These sections cannot be inserted this way 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() { 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")); KPropertyListData *listData = new KPropertyListData(KReportPageSize::pageFormatKeys(), KReportPageSize::pageFormatNames()); QVariant defaultKey = KReportPageSize::pageSizeKey(KReportPageSize::defaultSize()); d->pageSize = new KProperty("page-size", listData, defaultKey, tr("Page Size")); d->customPageSize = new KProperty("custom-page-size", DEFAULT_CUSTOM_PAGE_SIZE, tr("Custom Page Size"), tr("Custom Page Size"), KProperty::SizeF); d->customPageSize->setOption("suffix", d->currentUnit.symbol()); listData = new KPropertyListData({ QLatin1String("portrait"), QLatin1String("landscape") }, QVariantList{ tr("Portrait"), tr("Landscape") }); d->orientation = new KProperty("print-orientation", listData, QLatin1String("portrait"), tr("Page Orientation")); QList types(KReportUnit::allTypes()); types.removeOne(KReportUnit::Type::Pixel); listData = new KPropertyListData(KReportUnit::symbols(types), KReportUnit::descriptions(types)); d->unit = new KProperty("page-unit", listData, DEFAULT_UNIT_STRING, 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->gridDivisions->setOption("min", 1); d->gridDivisions->setOption("max", 10); d->leftMargin = new KProperty("margin-left", pageUnit().convertFromPoint(KReportUnit::parseValue(DEFAULT_PAGE_MARGIN_STRING)), tr("Left Margin"), tr("Left Margin"), KProperty::Double); d->rightMargin = new KProperty("margin-right", pageUnit().convertFromPoint(KReportUnit::parseValue(DEFAULT_PAGE_MARGIN_STRING)), tr("Right Margin"), tr("Right Margin"), KProperty::Double); d->topMargin = new KProperty("margin-top", pageUnit().convertFromPoint(KReportUnit::parseValue(DEFAULT_PAGE_MARGIN_STRING)), tr("Top Margin"), tr("Top Margin"), KProperty::Double); d->bottomMargin = new KProperty("margin-bottom", pageUnit().convertFromPoint(KReportUnit::parseValue(DEFAULT_PAGE_MARGIN_STRING)), tr("Bottom Margin"), tr("Bottom Margin"), KProperty::Double); d->leftMargin->setOption("suffix", d->currentUnit.symbol()); d->rightMargin->setOption("suffix", d->currentUnit.symbol()); d->topMargin->setOption("suffix", d->currentUnit.symbol()); d->bottomMargin->setOption("suffix", d->currentUnit.symbol()); d->set.addProperty(d->title); d->set.addProperty(d->pageSize); d->set.addProperty(d->customPageSize); 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); recalculateMaxMargins(); #ifdef KREPORT_SCRIPTING d->script = new KProperty("script", new KPropertyListData, QVariant(), tr("Object Script")); d->set.addProperty(d->script); #endif } /** @brief Handle property changes */ void KReportDesigner::slotPropertyChanged(KPropertySet &s, KProperty &p) { const QSignalBlocker blocker(s); setModified(true); QByteArray propertyName = p.name(); if (propertyName == "page-unit") { const KReportUnit oldUnit = d->currentUnit; d->updateCurrentUnit(); d->hruler->setUnit(pageUnit()); // convert values d->leftMargin->setValue(KReportUnit::convertFromUnitToUnit( d->leftMargin->value().toDouble(), oldUnit, d->currentUnit), KProperty::ValueOption::IgnoreOld); d->rightMargin->setValue(KReportUnit::convertFromUnitToUnit( d->rightMargin->value().toDouble(), oldUnit, d->currentUnit), KProperty::ValueOption::IgnoreOld); d->topMargin->setValue(KReportUnit::convertFromUnitToUnit(d->topMargin->value().toDouble(), oldUnit, d->currentUnit), KProperty::ValueOption::IgnoreOld); d->bottomMargin->setValue(KReportUnit::convertFromUnitToUnit( d->bottomMargin->value().toDouble(), oldUnit, d->currentUnit), KProperty::ValueOption::IgnoreOld); d->customPageSize->setValue( KReportUnit::convertFromUnitToUnit(d->customPageSize->value().toSizeF(), oldUnit, d->currentUnit), KProperty::ValueOption::IgnoreOld); d->leftMargin->setOption("suffix", d->currentUnit.symbol()); d->rightMargin->setOption("suffix", d->currentUnit.symbol()); d->topMargin->setOption("suffix", d->currentUnit.symbol()); d->bottomMargin->setOption("suffix", d->currentUnit.symbol()); d->customPageSize->setOption("suffix", d->currentUnit.symbol()); } else if (propertyName.startsWith("margin-") || propertyName == "page-size" || propertyName == "custom-page-size") { recalculateMaxMargins(); } emit pagePropertyChanged(s); } void KReportDesigner::slotPageButton_Pressed() { #ifdef KREPORT_SCRIPTING d->updateScripts(); 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 { QSize pageSizePx; int pageWidth; if (d->set.property("page-size").value().toString() == QLatin1String("Custom")) { KReportUnit unit = pageUnit(); QSizeF customSize = d->currentUnit.convertToPoint(d->set.property("custom-page-size").value().toSizeF()); QPageLayout layout(QPageSize(customSize, QPageSize::Point, QString(), QPageSize::ExactMatch), d->set.property("print-orientation").value().toString() == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape, QMarginsF(0,0,0,0)); pageSizePx = layout.fullRectPixels(KReportPrivate::dpiX()).size(); } else { QPageLayout layout = QPageLayout( QPageSize(KReportPageSize::pageSize(d->set.property("page-size").value().toString())), d->set.property("print-orientation").value().toString() == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape, QMarginsF(0,0,0,0)); pageSizePx = layout.fullRectPixels(KReportPrivate::dpiX()).size(); } pageWidth = pageSizePx.width(); pageWidth = pageWidth - KReportUnit::convertFromUnitToUnit(d->set.property("margin-left").value().toDouble(), pageUnit(), KReportUnit(KReportUnit::Type::Inch)) * KReportPrivate::dpiX(); pageWidth = pageWidth - KReportUnit::convertFromUnitToUnit(d->set.property("margin-right").value().toDouble(), pageUnit(), KReportUnit(KReportUnit::Type::Inch)) * KReportPrivate::dpiX(); return pageWidth; } QSize KReportDesigner::pageSizePt() const { QSize pageSizePt; if (d->set.property("page-size").value().toString() == QLatin1String("Custom")) { KReportUnit unit = pageUnit(); QSizeF customSize = d->currentUnit.convertToPoint(d->set.property("custom-page-size").value().toSizeF()); QPageLayout layout(QPageSize(customSize, QPageSize::Point, QString(), QPageSize::ExactMatch), d->set.property("print-orientation").value().toString() == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape, QMarginsF(0,0,0,0)); pageSizePt = layout.fullRectPoints().size(); } else { QPageLayout layout = QPageLayout( QPageSize(KReportPageSize::pageSize(d->set.property("page-size").value().toString())), d->set.property("print-orientation").value().toString() == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape, QMarginsF(0,0,0,0)); pageSizePt = layout.fullRectPoints().size(); } return pageSizePt; } 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); } } KReportUnit KReportDesigner::pageUnit() const { return d->currentUnit; } 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::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) { KPropertySet *set = baseReportItem->propertySet(); KReportDesigner::addMetaProperties(set, classString, iconName); set->clearModifiedFlags(); changeSet(set); if (v && v->designer()) { v->designer()->setModified(true); } emit itemInserted(d->sectionData.itemToInsert); } } 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) + if (set == &d->set) d->pageButton->setCheckState(Qt::Checked); else d->pageButton->setCheckState(Qt::Unchecked); - if (d->itemSet != s) { - d->itemSet = s; + if (d->itemSet != set) { + d->itemSet = set; emit propertySetChanged(); } } // // Actions // void KReportDesigner::slotItem(const QString &entity) { //kreportDebug() << entity; 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::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::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))); } new_obj->propertySet()->clearModifiedFlags(); 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::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 = static_cast(KReportSectionData::Type::PageHeaderFirst); i <= static_cast(KReportSectionData::Type::PageFooterAny); 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 = static_cast(KReportSectionData::Type::PageHeaderFirst); i <= static_cast(KReportSectionData::Type::PageFooterAny); 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); } void KReportDesigner::recalculateMaxMargins() { QSize pageSize = pageSizePt(); d->leftMargin->setOption("max", d->currentUnit.convertFromPoint(pageSize.width() - d->currentUnit.convertToPoint(d->rightMargin->value().toReal()) - SMALLEST_PAGE_SIZE_PT)); d->rightMargin->setOption("max", d->currentUnit.convertFromPoint(pageSize.width() - d->currentUnit.convertToPoint(d->leftMargin->value().toReal())- SMALLEST_PAGE_SIZE_PT)); d->topMargin->setOption("max", d->currentUnit.convertFromPoint(pageSize.height() - d->currentUnit.convertToPoint(d->bottomMargin->value().toReal())- SMALLEST_PAGE_SIZE_PT)); d->bottomMargin->setOption("max", d->currentUnit.convertFromPoint(pageSize.height() - d->currentUnit.convertToPoint(d->topMargin->value().toReal())- SMALLEST_PAGE_SIZE_PT)); } diff --git a/src/wrtembed/KReportDesigner.h b/src/wrtembed/KReportDesigner.h index 3bfb479e..404c8fd4 100644 --- a/src/wrtembed/KReportDesigner.h +++ b/src/wrtembed/KReportDesigner.h @@ -1,359 +1,359 @@ /* 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 -// + +/*! + * @brief 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 + @param parent 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 + @param parent QWidget parent + @param desc Report structure XML element */ - KReportDesigner(QWidget *parent, const QDomElement &data); + KReportDesigner(QWidget *parent, const QDomElement &desc); /** @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 + @param type KReportSectionData::Section enum value of the section to return @return Pointer to report section object, or 0 if no section exists */ 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 + @param type KReportSectionData::Section enum value of the section to return */ 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 + @param type KReportSectionData::Section enum value of the section to return */ 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 &); + void setReportTitle(const QString &title); /** @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); + void sectionContextMenuEvent(KReportDesignerSectionScene *scene, QGraphicsSceneContextMenuEvent * event); /** @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 *); + void changeSet(KPropertySet *set); /** @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 + @param name 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); void resizeEvent(QResizeEvent * event) override; //Properties void createProperties(); unsigned int selectionCount() const; void setSectionCursor(const QCursor&); void unsetSectionCursor(); void createActions(); QSize pageSizePt() const; void recalculateMaxMargins(); 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/KReportDesignerItemBase.h b/src/wrtembed/KReportDesignerItemBase.h index 6fb38ed6..47e824fd 100644 --- a/src/wrtembed/KReportDesignerItemBase.h +++ b/src/wrtembed/KReportDesignerItemBase.h @@ -1,87 +1,87 @@ /* 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 . */ /* * This file contains all the Report Entity classes. Each one is a * derivative of ReportEntity, which in turn is derived from QCanvasItem. */ #ifndef KREPORTDESIGNERITEMBASE_H #define KREPORTDESIGNERITEMBASE_H #include #include "KReportItemBase.h" class QDomDocument; class QDomElement; class KReportDesigner; -// -// ReportEntity -// +/*! + * @brief Base class for report items used within the designer GUI. +*/ class KREPORT_EXPORT KReportDesignerItemBase { public: virtual ~KReportDesignerItemBase(); static void buildXML(QGraphicsItem * item, QDomDocument *doc, QDomElement *parent); virtual void buildXML(QDomDocument *doc, QDomElement *parent) = 0; static void buildXMLRect(QDomDocument *doc, QDomElement *entity, KReportItemBase *i); static void buildXMLTextStyle(QDomDocument *doc, QDomElement *entity, const KReportTextStyleData &ts); static void buildXMLLineStyle(QDomDocument *doc, QDomElement *entity, const KReportLineStyle &ls); virtual KReportDesignerItemBase* clone() = 0; virtual void move(const QPointF&) = 0; KReportDesigner* designer() const; void setDesigner(KReportDesigner* rd); static void addPropertyAsAttribute(QDomElement* e, KProperty* p); protected: explicit KReportDesignerItemBase(KReportDesigner *r, KReportItemBase *); QString dataSourceAndObjectTypeName(const QString &dataSource, const QString &objectTypeName) const; /** * @brief Updates the text that is shown for the item in the report designer * If itemDataSource is set then it is preferred over itemStaticValue * itemType is appended to the end of the text * * @param itemDataSource source field property * @param itemStaticValue value property * @param itemType type of item * @return void */ - void updateRenderText(const QString &itemDataSource, const QString &itemStaticValue, const QString &itemType); + void updateRenderText(const QString &itemDataSource, const QString &itemStaticValue, const QString &itemType); KReportItemBase *item() const; - + void setRenderText(const QString &text); QString renderText() const; private: Q_DISABLE_COPY(KReportDesignerItemBase) class Private; Private * const d; }; #endif diff --git a/src/wrtembed/KReportDesignerItemRectBase.h b/src/wrtembed/KReportDesignerItemRectBase.h index 18edfed9..c69c1dac 100644 --- a/src/wrtembed/KReportDesignerItemRectBase.h +++ b/src/wrtembed/KReportDesignerItemRectBase.h @@ -1,84 +1,85 @@ /* 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; -/** +/*! + * @brief Base class for rectangular report items used within the designer GUI. */ 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: enum class SceneRectFlag { UpdateProperty, DontUpdateProperty }; 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; int dpiX() const; int dpiY() const; private: Q_DISABLE_COPY(KReportDesignerItemRectBase) int grabHandle(const QPointF &pos); QPointF properPressPoint(const KReportDesigner &d) const; class Private; Private * const d; }; #endif diff --git a/src/wrtembed/KReportDesignerSection.h b/src/wrtembed/KReportDesignerSection.h index 924f4043..a01dd6a8 100644 --- a/src/wrtembed/KReportDesignerSection.h +++ b/src/wrtembed/KReportDesignerSection.h @@ -1,91 +1,90 @@ /* 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) 2014 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 __REPORTSECTION_H__ #define __REPORTSECTION_H__ #include #include "kreport_export.h" // forward declarations class QDomNode; class QDomDocument; class QDomElement; class QGraphicsItem; typedef QList QGraphicsItemList; class KPropertySet; class KProperty; class KReportDesigner; class KReportZoomHandler; -// -// Class ReportSection -// -// This class is the base to all Report Section's visual representation. -// It contains the basic data and interface that all the sections need to work. -// +/*! + * @brief This class is the base to all Report Section's visual representation. + * + * Contains the basic data and interface that all the sections need to work. + */ class KREPORT_EXPORT KReportDesignerSection : public QWidget { Q_OBJECT public: ~KReportDesignerSection() override; void setTitle(const QString & s); void buildXML(QDomDocument *doc, QDomElement *section); void initFromXML(const QDomNode & section); QSize sizeHint() const override; /** * @brief Return the items in the section * Only return top-level items ... ie, items with no parent item * because child items are not full report-items, they are implementation * details of a report item and do not need to be counted individually * * @return QGraphicsItemList */ QGraphicsItemList items() const; void setSectionCursor(const QCursor&); void unsetSectionCursor(); protected Q_SLOTS: void slotResizeBarDragged(int delta, bool changeSet = true); protected: explicit KReportDesignerSection(KReportDesigner * rptdes, const KReportZoomHandler &zoomHandler); private Q_SLOTS: void slotPageOptionsChanged(KPropertySet &); void slotSceneClicked(); void slotPropertyChanged(KPropertySet &, KProperty &); private: Q_DISABLE_COPY(KReportDesignerSection) class Private; Private * const d; friend class KReportDesigner; friend class KReportDesignerSectionTitle; }; #endif diff --git a/src/wrtembed/KReportDesignerSectionDetail.h b/src/wrtembed/KReportDesignerSectionDetail.h index 03adeb30..6bb16902 100644 --- a/src/wrtembed/KReportDesignerSectionDetail.h +++ b/src/wrtembed/KReportDesignerSectionDetail.h @@ -1,74 +1,75 @@ /* 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 KREPORTDESIGNERSECTIONDETAIL_H #define KREPORTDESIGNERSECTIONDETAIL_H #include #include "kreport_export.h" class QDomNode; class QDomElement; class QDomDocument; class KReportDesignerSection; class KReportDesigner; class KReportDesignerSectionDetailGroup; -/** +/*! + * @brief The central detail section which contains the bulk of the report */ class KREPORT_EXPORT KReportDesignerSectionDetail : public QWidget { Q_OBJECT public: explicit KReportDesignerSectionDetail(KReportDesigner * rptdes); ~KReportDesignerSectionDetail() override; enum class PageBreak { None, AtEnd }; void setPageBreak(PageBreak pageBreak); PageBreak pageBreak() const; KReportDesignerSection * detailSection() const; void buildXML(QDomDocument *doc, QDomElement *section); void initFromXML(QDomNode *node); KReportDesigner * reportDesigner() const; int groupSectionCount() const; KReportDesignerSectionDetailGroup * groupSection(int i) const; void insertGroupSection(int idx, KReportDesignerSectionDetailGroup * rsd); int indexOfGroupSection(const QString & column) const; void removeGroupSection(int idx, bool del = false); QSize sizeHint() const override; void setSectionCursor(const QCursor&); void unsetSectionCursor(); private: Q_DISABLE_COPY(KReportDesignerSectionDetail) class Private; Private * const d; }; #endif diff --git a/src/wrtembed/KReportDesignerSectionDetailGroup.h b/src/wrtembed/KReportDesignerSectionDetailGroup.h index d6e353f8..6a195bc7 100644 --- a/src/wrtembed/KReportDesignerSectionDetailGroup.h +++ b/src/wrtembed/KReportDesignerSectionDetailGroup.h @@ -1,78 +1,79 @@ /* 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 KREPORTDESIGNERSECTIONDETAILGROUP_H #define KREPORTDESIGNERSECTIONDETAILGROUP_H #include #include "kreport_export.h" class QDomElement; class QDomDocument; class QString; class QWidget; class KReportDesignerSection; class KReportDesignerSectionDetail; -/** +/*! + * @brief A section group allows a header and footer to be used for a particular report field */ class KREPORT_EXPORT KReportDesignerSectionDetailGroup : public QObject { Q_OBJECT public: KReportDesignerSectionDetailGroup(const QString &column, KReportDesignerSectionDetail *rsd, QWidget *parent = nullptr); ~KReportDesignerSectionDetailGroup() override; enum class PageBreak { None, AfterGroupFooter, BeforeGroupHeader }; void setColumn(const QString &); QString column() const; void setGroupHeaderVisible(bool yes = true); bool groupHeaderVisible() const; void setGroupFooterVisible(bool yes = true); bool groupFooterVisible() const; void setPageBreak(PageBreak); PageBreak pageBreak() const; void setSort(Qt::SortOrder); Qt::SortOrder sort(); KReportDesignerSection * groupHeader() const; KReportDesignerSection * groupFooter() const; void buildXML(QDomDocument *doc, QDomElement *section) const; void initFromXML( const QDomElement &element ); private: Q_DISABLE_COPY(KReportDesignerSectionDetailGroup) class Private; Private * const d; }; #endif