KReport

KReportScriptReport.cpp
1/* This file is part of the KDE project
2 * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
3 * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 */
18#include "KReportScriptReport.h"
19#include "KReportDocument.h"
20#include "KReportItemBase.h"
21#include "KReportPluginManager.h"
22#include "KReportPluginInterface.h"
23#include "KReportScriptLine.h"
24#include "KReportScriptSection.h"
25#include "KReportItemLine.h"
26#include "kreport_debug.h"
27
28namespace Scripting
29{
30
31Report::Report(KReportDocument *r)
32{
33 m_reportData = r;
34 m_scriptObject = 0;
35}
36
37
38Report::~Report()
39{
40
41}
42
44{
45 return m_reportData->title();
46}
47
49{
50 return m_reportData->name();
51}
52
54{
55 return m_reportData->query();
56}
57
59{
60 if (m_scriptObjMap.contains(n)) {
61 return m_scriptObjMap[n];
62 }
63
64 QList<KReportItemBase *>obs = m_reportData->objects();
65 foreach(KReportItemBase *o, obs) {
66 if (o->entityName() == n) {
67
68 if (o->typeName() == QLatin1String("line")) {
69 return new Scripting::Line(dynamic_cast<KReportItemLine*>(o));
70 }
71 else {
72 KReportPluginManager* manager = KReportPluginManager::self();
73 KReportPluginInterface *plugin = manager->plugin(o->typeName());
74 if (plugin) {
75 QObject *obj = plugin->createScriptInstance(o);
76 if (obj) {
77 m_scriptObjMap[n] = obj;
78 return obj;
79 }
80 }
81 else {
82 kreportWarning() << "Encountered unknown node while parsing section: " << o->typeName();
83 }
84 }
85 }
86 }
87 return nullptr;
88}
89
91{
92 KReportSectionData *sec = m_reportData->section(n);
93 if (sec) {
94 return new Scripting::Section(sec);
95 } else {
96 return new QObject();
97 }
98}
99
101{
102 m_scriptObject = val;
103}
104
106{
107 if (m_scriptObject.isObject() && m_scriptObject.hasProperty(QLatin1String("OnOpen")))
108 m_scriptObject.property(QLatin1String("OnOpen")).call();
109}
110
112{
113 if (m_scriptObject.isObject() && m_scriptObject.hasProperty(QLatin1String("OnComlete")))
114 m_scriptObject.property(QLatin1String("OnComplete")).call();
115}
116
118{
119 if (m_scriptObject.isObject() && m_scriptObject.hasProperty(QLatin1String("OnNewPage")))
120 m_scriptObject.property(QLatin1String("OnNewPage")).call();
121}
122
123}
Top level report document definition. A KReportDocment defines the design of a document,...
QList< KReportItemBase * > objects() const
KReportSectionData * section(KReportSectionData::Type type) const
Base class for items that are drawn syncronously.
virtual QString typeName() const =0
Return the item type as a string.
An interface for plugins delivering KReport elements.
Manager class for finding and loading available plugins.
KReportSectionData is used to store the information about a specific report section.
Line item script interface.
void initialize(const QJSValue &val)
Assigns a user object to this report.
void eventOnNewPage()
Executed when a new page is created. If a handler exists for this in the user object it is called.
QString recordSource() const
void eventOnOpen()
Executed when the report is opened. If a handler exists for this in the user object it is called.
void eventOnComplete()
Executed when the report is complete. If a handler exists for this in the user object it is called.
QObject * objectByName(const QString &)
QObject * sectionByName(const QString &)
Field item script interface.
QJSValue call(const QJSValueList &args) const const
bool hasProperty(const QString &name) const const
bool isObject() const const
QJSValue property(const QString &name) const const
bool contains(const Key &key) const const
QObject(QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:31 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.