File indexing completed on 2024-04-28 04:41:56
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2007-2010 by Adam Pigg <adam@piggz.co.uk> 0003 * Copyright (C) 2011-2015 JarosÅ‚aw Staniek <staniek@kde.org> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Lesser General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2.1 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Lesser General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Lesser General Public 0016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 0017 */ 0018 0019 #ifndef KREPORTDESIGN_H 0020 #define KREPORTDESIGN_H 0021 0022 #include "kreport_export.h" 0023 #include "config-kreport.h" 0024 #include "KReportSection.h" 0025 0026 #include <QCoreApplication> 0027 0028 class QPageSize; 0029 class QMarginsF; 0030 class QPageLayout; 0031 class KReportElement; 0032 0033 //! The KReportDesignReadStatus represents status of reading a report design in .kreport format. 0034 /*! It is used by KReportDesign::setContent(). */ 0035 class KREPORT_EXPORT KReportDesignReadingStatus 0036 { 0037 public: 0038 //! Creates an empty status object. 0039 /*! For empty status objects isError() returns false. */ 0040 KReportDesignReadingStatus(); 0041 0042 ~KReportDesignReadingStatus(); 0043 KReportDesignReadingStatus(const KReportDesignReadingStatus &other); 0044 KReportDesignReadingStatus& operator=(const KReportDesignReadingStatus &other); 0045 0046 //! @return true if the status is error. 0047 //! Equivalent of errorLineNumber() >= 0 && errorColumnNumber() >= 0. 0048 bool isError() const; 0049 0050 //! Error message suitable for displaying to the user, translated. 0051 QString errorMessage() const; 0052 0053 //! Detailed error message, partially translated. 0054 QString errorDetails() const; 0055 0056 //! Line number (counting from 0) in which the error occured. -1 if there is no error. 0057 int errorLineNumber() const; 0058 0059 //! Column number (counting from 0) in which the error occured. -1 if there is no error. 0060 int errorColumnNumber() const; 0061 0062 void setErrorMessage(const QString& msg); 0063 void setErrorDetails(const QString& details); 0064 void setErrorLineNumber(int line); 0065 void setErrorColumnNumber(int column); 0066 0067 private: 0068 class Private; 0069 Private * const d; 0070 }; 0071 0072 //! Sends information about the reading status @a status to debug output @a dbg. 0073 KREPORT_EXPORT QDebug operator<<(QDebug dbg, const KReportDesignReadingStatus& status); 0074 0075 //! @brief The KReportDesign class represents a report design in .kreport format 0076 class KREPORT_EXPORT KReportDesign 0077 { 0078 Q_DECLARE_TR_FUNCTIONS(KReportDesign) 0079 public: 0080 KReportDesign(); 0081 0082 ~KReportDesign(); 0083 0084 //! Reads the XML document in .kreport format from the string @a text 0085 //! @return true if the content was successfully parsed 0086 //! On failure false is returned and if @a status is provided, it is updated accordingly. 0087 bool setContent(const QString &text, KReportDesignReadingStatus *status = nullptr); 0088 0089 //! Converts the report document back to its textual representation. 0090 QString toString(int indent = 1) const; 0091 0092 //! @return title for this design 0093 QString title() const; 0094 0095 //! Sets title for this design to @a title 0096 void setTitle(const QString &title); 0097 0098 //! @return page layout for this design 0099 QPageLayout pageLayout() const; 0100 0101 //! Sets the page layout to @a pageLayout 0102 //! @note Calling this method does not alter page layouts of existing KReportDesign objects. 0103 void setPageLayout(const QPageLayout &pageLayout); 0104 0105 //! @return true if this design has section defined of type @a type 0106 bool hasSection(KReportSection::Type type) const; 0107 0108 //! @return section of type @a type 0109 KReportSection section(KReportSection::Type type) const; 0110 0111 //! Add section @a section. Previous section of the same type is removed from this design. 0112 void addSection(const KReportSection §ion); 0113 0114 //! Creates and returns report element of type @a typeName 0115 //! On success @a errorMessage is cleared, on failure it is set to a nonempty value. 0116 KReportElement createElement(const QString &typeName, QString *errorMessage); 0117 0118 //! @return default page layout that is used for creating new report designs 0119 /*! Attributes that are specified in the design format: 0120 - margins: by default equal to equivalent of 1cm in points (QPageLayout::Point). 0121 - mode: by default QPageLayout::StandardMode 0122 - orientation: by default QPageLayout::Portrait 0123 - pageSize: by default equal to default page size of the default printer 0124 (QPrinterInfo::defaultPrinter().defaultPageSize()). 0125 If there is no default printer, A4 size is used. 0126 Passing invalid page size restores defaults explained in 0127 documentation of QPageLayout defaultPageLayout(). 0128 @todo For KDE Plasma use information from the Locale by using 0129 readConfigNumEntry("PageSize", QPrinter::A4, m_pageSize, QPrinter::PageSize) 0130 from KLocalePrivate::initFormat() (klocale_kde.cpp) 0131 0132 Other attributes are ignored by the design format. 0133 In particular units for margins and pageSize are always QPageLayout::Point. 0134 */ 0135 static QPageLayout defaultPageLayout(); 0136 0137 //! Sets default page layout to @a pageLayout 0138 //! This information is used when a new report design is created. 0139 static void setDefaultPageLayout(const QPageLayout &pageLayout); 0140 0141 #ifdef KREPORT_SCRIPTING 0142 //! @return text of the script program 0143 QString script() const; 0144 #endif 0145 0146 private: 0147 Q_DISABLE_COPY(KReportDesign) 0148 class Private; 0149 Private * const d; 0150 }; 0151 0152 #endif // KREPORTDESIGN_H