File indexing completed on 2024-04-21 04:41:49

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2007-2010 by Adam Pigg (adam@piggz.co.uk)
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Lesser General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2.1 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0012  * Lesser General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Lesser General Public
0015  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 
0018 #ifndef KREPORTITEMBASE_H
0019 #define KREPORTITEMBASE_H
0020 
0021 #include "config-kreport.h"
0022 #include "kreport_export.h"
0023 #include "KReportUnit.h"
0024 
0025 #include <QObject>
0026 #include <QFont>
0027 #include <QColor>
0028 
0029 class OROPage;
0030 class OROSection;
0031 class KReportDataSource;
0032 class KReportLineStyle;
0033 
0034 #ifdef KREPORT_SCRIPTING
0035 class KReportScriptHandler;
0036 #else
0037 #define KReportScriptHandler void
0038 #endif
0039 
0040 class KProperty;
0041 class KPropertySet;
0042 
0043 class QDomElement;
0044 
0045 class KReportTextStyleData
0046 {
0047 public:
0048     QFont font;
0049     Qt::Alignment alignment;
0050     QColor backgroundColor;
0051     QColor foregroundColor;
0052     int backgroundOpacity;
0053 
0054 };
0055 
0056 /*!
0057  * @brief Base class for items that are drawn syncronously.
0058  */
0059 class KREPORT_EXPORT KReportItemBase : public QObject
0060 {
0061     Q_OBJECT
0062 public:
0063 
0064     KReportItemBase();
0065     ~KReportItemBase() override;
0066 
0067     /**
0068     @brief Return the item type as a string.  Required by all items
0069     @return Item type
0070     */
0071     virtual QString typeName() const = 0;
0072 
0073     /**
0074     @brief Render the item into a primitive which is used by the second stage renderer
0075     @return the height required by the object
0076     */
0077     virtual int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script);
0078 
0079     /**
0080     @brief Render a complex item that uses a sub query as a data source
0081     @return the height required by the object
0082     */
0083     virtual int renderReportData(OROPage *page, OROSection *section, const QPointF &offset, KReportDataSource *dataSource, KReportScriptHandler *script);
0084 
0085     /**
0086     @return The field name or expression for the data source
0087     */
0088     QString itemDataSource() const;
0089 
0090     void setItemDataSource(const QString &source);
0091 
0092     /**
0093     @brief Override if the item uses a sub query and linked fields, such as a chart or sub-report
0094     @return True if uses a sub query
0095     */
0096     virtual bool supportsSubQuery() const;
0097 
0098     KPropertySet* propertySet();
0099     const KPropertySet* propertySet() const;
0100 
0101     void setEntityName(const QString& n);
0102     QString entityName() const;
0103 
0104     KReportUnit unit() const;
0105 
0106     //! Sets unit to @a a and converts values of position and size property from the old
0107     //! unit to new if needed.
0108     virtual void setUnit(const KReportUnit &u);
0109 
0110     /**
0111      * @brief Return the size in points
0112      */
0113     QSizeF size() const;
0114 
0115     /**
0116      * @brief Return the position in points
0117      */
0118     QPointF position() const;
0119 
0120     /**
0121      * @brief Sets position for the element
0122      * @param ptPos Position in points
0123      */
0124     void setPosition(const QPointF &ptPos);
0125 
0126     /**
0127      * @brief Sets size for the element
0128      * @param ptSize Size in points
0129      */
0130     void setSize(const QSizeF &ptSize);
0131 
0132     /**
0133      * @brief Return the z-value in points
0134      */
0135     qreal z() const;
0136 
0137     /**
0138      * @brief Sets the z-value for the element
0139      * @param z Z-value in points
0140      */
0141     void setZ(qreal z);
0142 
0143     //! Helper function mapping to screen units (pixels), @a ptPos is in points
0144     static QPointF scenePosition(const QPointF &ptPos);
0145 
0146     //! Helper function mapping to screen units (pixels), @a ptSize is in points
0147     static QSizeF sceneSize(const QSizeF &ptSize);
0148 
0149     //! Helper function mapping from screen units to points, @a pos is in pixels
0150     static QPointF positionFromScene(const QPointF &pos);
0151 
0152     //! Helper function mapping from screen units to points, @a size is in pixels
0153     static QSizeF sizeFromScene(const QSizeF &size);
0154 
0155 protected:
0156     virtual void createProperties() = 0;
0157     void createDataSourceProperty();
0158     bool parseReportRect(const QDomElement &elem);
0159     static bool parseReportTextStyleData(const QDomElement &, KReportTextStyleData*);
0160     static bool parseReportLineStyleData(const QDomElement &, KReportLineStyle*);
0161 
0162     KProperty *nameProperty();
0163     QString oldName() const;
0164     void setOldName(const QString &old);
0165     KProperty* dataSourceProperty();
0166 
0167     Q_SLOT virtual void propertyChanged(KPropertySet &s, KProperty &p);
0168 
0169 private:
0170     Q_DISABLE_COPY(KReportItemBase)
0171     class Private;
0172     Private * const d;
0173     Q_SLOT void aboutToDeleteProperty(KPropertySet& set, KProperty& property);
0174 
0175     friend class KReportDesignerItemRectBase;
0176 };
0177 
0178 #endif