KReport

KReportScriptReport.cpp
1 /* This file is part of the KDE project
2  * Copyright (C) 2001-2007 by OpenMFG, LLC ([email protected])
3  * Copyright (C) 2007-2008 by Adam Pigg ([email protected])
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 
28 namespace Scripting
29 {
30 
32 {
33  m_reportData = r;
34  m_scriptObject = 0;
35 }
36 
37 
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 
100 void Report::initialize(const QJSValue &val)
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, and is composed of multiple sections.
QString title() const
QObject * sectionByName(const QString &)
bool contains(const Key &key) const const
bool hasProperty(const QString &name) const const
QString name() const
bool isObject() const const
void eventOnComplete()
Executed when the report is complete. If a handler exists for this in the user object it is called...
QJSValue call(const QJSValueList &args)
QObject * objectByName(const QString &)
Line item script interface.
QList< KReportItemBase * > objects() const
QJSValue property(const QString &name) const const
void initialize(const QJSValue &val)
Assigns a user object to this report.
virtual QString typeName() const =0
Return the item type as a string.
An interface for plugins delivering KReport elements.
~Report() override
void eventOnOpen()
Executed when the report is opened. If a handler exists for this in the user object it is called...
KReportSectionData * section(KReportSectionData::Type type) const
QString recordSource() const
void eventOnNewPage()
Executed when a new page is created. If a handler exists for this in the user object it is called...
QObject(QObject *parent)
Report(Report *p, const QString &cmd=QString())
Base class for items that are drawn syncronously.
KReportSectionData is used to store the information about a specific report section.
Manager class for finding and loading available plugins.
Field item script interface.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Dec 5 2021 22:58:27 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.