KReport

KReportScriptSection.cpp
1 /* This file is part of the KDE project
2  * Copyright (C) 2007-2008 by Adam Pigg ([email protected])
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #include "KReportScriptSection.h"
18 
19 #include "KReportScriptLine.h"
20 #include "KReportItemBase.h"
21 #include "KReportPluginManager.h"
22 #include "KReportPluginInterface.h"
23 #include "KReportItemLine.h"
24 #include "KReportSectionData.h"
25 #include "kreport_debug.h"
26 
27 namespace Scripting
28 {
29 Section::Section(KReportSectionData* sec)
30 {
31  m_section = sec;
32  m_scriptObject = 0;
33 }
34 
35 
36 Section::~Section()
37 {
38 }
39 
40 QColor Section::backgroundColor() const
41 {
42  return m_section->backgroundColor();
43 }
44 
45 void Section::setBackgroundColor(const QColor &c)
46 {
47  m_section->setBackgroundColor(c);
48 }
49 
50 qreal Section::height() const
51 {
52  return m_section->height();
53 }
54 
55 void Section::setHeight(qreal h)
56 {
57  m_section->setHeight(h);
58 }
59 
60 QString Section::name() const
61 {
62  return m_section->objectName();
63 }
64 
65 QObject* Section::objectByNumber(int i)
66 {
67  if (m_section->object(i)->typeName() == QLatin1String("line")) {
68  return new Scripting::Line(dynamic_cast<KReportItemLine*>(m_section->object(i)));
69  }
70  else {
71  KReportPluginManager* manager = KReportPluginManager::self();
72  KReportPluginInterface *plugin = manager->plugin(m_section->object(i)->typeName());
73  if (plugin) {
74  QObject *obj = plugin->createScriptInstance(m_section->object(i));
75  if (obj) {
76  return obj;
77  }
78  }
79  else {
80  kreportWarning() << "Encountered unknown node while parsing section: " << m_section->object(i)->typeName();
81  }
82  }
83 
84  return new QObject();
85 }
86 
87 QObject* Section::objectByName(const QString& n)
88 {
89  for (int i = 0; i < m_section->objects().count(); ++i) {
90  if (m_section->object(i)->entityName() == n) {
91  return objectByNumber(i);
92  }
93  }
94  return nullptr;
95 }
96 
97 void Section::initialize(const QJSValue &s)
98 {
99  m_scriptObject = s;
100 }
101 
102 void Section::eventOnRender()
103 {
104  if (m_scriptObject.isObject() && m_scriptObject.hasProperty(QLatin1String("OnRender")))
105  m_scriptObject.property(QLatin1String("OnRender")).call();
106 }
107 }
Line item script interface.
KReportSectionData is used to store the information about a specific report section.
Manager class for finding and loading available plugins.
Field item script interface.
QJSValue property(const QString &name) const const
QJSValue call(const QJSValueList &args)
An interface for plugins delivering KReport elements.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 04:17:37 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.