KReport

KReportScriptSection.cpp
1/* This file is part of the KDE project
2 * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
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
27namespace Scripting
28{
29Section::Section(KReportSectionData* sec)
30{
31 m_section = sec;
32 m_scriptObject = 0;
33}
34
35
36Section::~Section()
37{
38}
39
40QColor Section::backgroundColor() const
41{
42 return m_section->backgroundColor();
43}
44
45void Section::setBackgroundColor(const QColor &c)
46{
47 m_section->setBackgroundColor(c);
48}
49
50qreal Section::height() const
51{
52 return m_section->height();
53}
54
55void Section::setHeight(qreal h)
56{
57 m_section->setHeight(h);
58}
59
60QString Section::name() const
61{
62 return m_section->objectName();
63}
64
65QObject* 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
87QObject* 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
97void Section::initialize(const QJSValue &s)
98{
99 m_scriptObject = s;
100}
101
102void Section::eventOnRender()
103{
104 if (m_scriptObject.isObject() && m_scriptObject.hasProperty(QLatin1String("OnRender")))
105 m_scriptObject.property(QLatin1String("OnRender")).call();
106}
107}
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.
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
QObject(QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 14 2024 11:56:05 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.