File indexing completed on 2024-05-12 04:43:22
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) 0003 * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) 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 #include "KReportScriptReport.h" 0019 #include "KReportDocument.h" 0020 #include "KReportItemBase.h" 0021 #include "KReportPluginManager.h" 0022 #include "KReportPluginInterface.h" 0023 #include "KReportScriptLine.h" 0024 #include "KReportScriptSection.h" 0025 #include "KReportItemLine.h" 0026 #include "kreport_debug.h" 0027 0028 namespace Scripting 0029 { 0030 0031 Report::Report(KReportDocument *r) 0032 { 0033 m_reportData = r; 0034 m_scriptObject = 0; 0035 } 0036 0037 0038 Report::~Report() 0039 { 0040 0041 } 0042 0043 QString Report::title() const 0044 { 0045 return m_reportData->title(); 0046 } 0047 0048 QString Report::name() const 0049 { 0050 return m_reportData->name(); 0051 } 0052 0053 QString Report::recordSource() const 0054 { 0055 return m_reportData->query(); 0056 } 0057 0058 QObject* Report::objectByName(const QString &n) 0059 { 0060 if (m_scriptObjMap.contains(n)) { 0061 return m_scriptObjMap[n]; 0062 } 0063 0064 QList<KReportItemBase *>obs = m_reportData->objects(); 0065 foreach(KReportItemBase *o, obs) { 0066 if (o->entityName() == n) { 0067 0068 if (o->typeName() == QLatin1String("line")) { 0069 return new Scripting::Line(dynamic_cast<KReportItemLine*>(o)); 0070 } 0071 else { 0072 KReportPluginManager* manager = KReportPluginManager::self(); 0073 KReportPluginInterface *plugin = manager->plugin(o->typeName()); 0074 if (plugin) { 0075 QObject *obj = plugin->createScriptInstance(o); 0076 if (obj) { 0077 m_scriptObjMap[n] = obj; 0078 return obj; 0079 } 0080 } 0081 else { 0082 kreportWarning() << "Encountered unknown node while parsing section: " << o->typeName(); 0083 } 0084 } 0085 } 0086 } 0087 return nullptr; 0088 } 0089 0090 QObject* Report::sectionByName(const QString &n) 0091 { 0092 KReportSectionData *sec = m_reportData->section(n); 0093 if (sec) { 0094 return new Scripting::Section(sec); 0095 } else { 0096 return new QObject(); 0097 } 0098 } 0099 0100 void Report::initialize(const QJSValue &val) 0101 { 0102 m_scriptObject = val; 0103 } 0104 0105 void Report::eventOnOpen() 0106 { 0107 if (m_scriptObject.isObject() && m_scriptObject.hasProperty(QLatin1String("OnOpen"))) 0108 m_scriptObject.property(QLatin1String("OnOpen")).call(); 0109 } 0110 0111 void Report::eventOnComplete() 0112 { 0113 if (m_scriptObject.isObject() && m_scriptObject.hasProperty(QLatin1String("OnComlete"))) 0114 m_scriptObject.property(QLatin1String("OnComplete")).call(); 0115 } 0116 0117 void Report::eventOnNewPage() 0118 { 0119 if (m_scriptObject.isObject() && m_scriptObject.hasProperty(QLatin1String("OnNewPage"))) 0120 m_scriptObject.property(QLatin1String("OnNewPage")).call(); 0121 } 0122 0123 }