File indexing completed on 2024-05-12 04:43:22

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2007-2008 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 #ifndef SCRIPTINGKRSCRIPTREPORT_H
0018 #define SCRIPTINGKRSCRIPTREPORT_H
0019 
0020 #include <QObject>
0021 #include <QtQml/QJSValue>
0022 #include <QMap>
0023 
0024 class KReportDocument;
0025 
0026 namespace Scripting
0027 {
0028 
0029 
0030 /**
0031  @brief Report object user scripting API.
0032 
0033  Contains methods for a report object which can be called by user scripts. \n
0034 
0035  Example: \n
0036  \code
0037  function report()
0038  {
0039   this.OnOpen = function()
0040   {
0041    debug.print("Report opened!");
0042   }
0043  }
0044  reportname.initialize(new report())
0045  \endcode
0046 */
0047 class Report : public QObject
0048 {
0049     Q_OBJECT
0050 public:
0051     explicit Report(KReportDocument*);
0052 
0053     ~Report() override;
0054 
0055 public Q_SLOTS:
0056     //! @return the title of the report as a string
0057     QString title() const;
0058 
0059     //! @return the name of the report as a string
0060     QString name() const;
0061 
0062     //! @return the record source (data source, table, query etc) as a string
0063     QString recordSource() const;
0064 
0065     //! @return an object in the report given its name, or NULL
0066     QObject* objectByName(const QString &);
0067 
0068     //! @return a section in the report given its name, or NULL
0069     QObject* sectionByName(const QString &);
0070 
0071 
0072     //! Assigns a user object to this report
0073     void initialize(const QJSValue &val);
0074 
0075     //! Executed when the report is opened.  If a handler exists for this in the user object it is called.
0076     void eventOnOpen();
0077 
0078     //! Executed when the report is complete.  If a handler exists for this in the user object it is called.
0079     void eventOnComplete();
0080 
0081     //! Executed when a new page is created.  If a handler exists for this in the user object it is called.
0082     void eventOnNewPage();
0083 
0084 private:
0085     KReportDocument *m_reportData;
0086     QJSValue m_scriptObject;
0087     QMap<QString, QObject*> m_scriptObjMap;
0088 };
0089 
0090 }
0091 
0092 #endif