KReport

KReportDesignerItemWeb.cpp
1/* This file is part of the KDE project
2 Copyright Shreya Pandit <shreya@shreyapandit.com>
3 Copyright 2011 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 Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 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 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "KReportDesignerItemWeb.h"
22#include <KReportDesignerItemBase.h>
23#include <KReportDesigner.h>
24
25#include <KProperty>
26#include <KPropertySet>
27
28#include <QGraphicsScene>
29#include <QGraphicsSceneMouseEvent>
30#include <QDomDocument>
31#include <QPainter>
32#include "kreportplugin_debug.h"
33
34void KReportDesignerItemWeb::init(QGraphicsScene *scene)
35{
36 if (scene)
37 scene->addItem(this);
38
39 connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&)));
40
41 setZValue(z());
42}
43
44KReportDesignerItemWeb::KReportDesignerItemWeb(KReportDesigner *rw, QGraphicsScene *scene,
45 const QPointF &pos) : KReportDesignerItemRectBase(rw, this)
46{
47 Q_UNUSED(pos);
48 init(scene);
49 setSceneRect(properRect(*rw, KREPORT_ITEM_RECT_DEFAULT_WIDTH, KREPORT_ITEM_RECT_DEFAULT_WIDTH));
50 nameProperty()->setValue(designer()->suggestEntityName(typeName()));
51}
52
53KReportDesignerItemWeb::KReportDesignerItemWeb(const QDomNode &element, KReportDesigner *rw,
54 QGraphicsScene *scene)
55 : KReportItemWeb(element), KReportDesignerItemRectBase(rw, this)
56{
57 init(scene);
58 setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size()));
59}
60
61KReportDesignerItemWeb *KReportDesignerItemWeb::clone()
62{
65 QDomNode n;
66 buildXML(&d, &e);
67 n = e.firstChild();
68 return new KReportDesignerItemWeb(n, designer(), nullptr);
69}
70
71KReportDesignerItemWeb::~KReportDesignerItemWeb() //done,compared
72{
73 // do we need to clean anything up?
74}
75
76void KReportDesignerItemWeb::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
77{
78 Q_UNUSED(option);
79 Q_UNUSED(widget);
80
82 painter->drawText(rect(), 0, dataSourceAndObjectTypeName(itemDataSource(), QLatin1String("web-view")));
83
85
86 drawHandles(painter);
87}
88
89void KReportDesignerItemWeb::buildXML(QDomDocument *doc, QDomElement *parent)
90{
91 Q_UNUSED(doc);
92 Q_UNUSED(parent);
93 QDomElement entity = doc->createElement(QLatin1String("report:") + typeName());
94
95 // properties
96 addPropertyAsAttribute(&entity, dataSourceProperty());
97 addPropertyAsAttribute(&entity, nameProperty());
98 entity.setAttribute(QLatin1String("report:z-index"), zValue());
99 buildXMLRect(doc, &entity, this);
100 parent->appendChild(entity);
101}
102
103void KReportDesignerItemWeb::slotPropertyChanged(KPropertySet &s, KProperty &p)
104{
105 if (p.name() == "name") {
106 if (!designer()->isEntityNameUnique(p.value().toString(), this)) {
107 p.setValue(oldName());
108 }
109 else {
110 setOldName(p.value().toString());
111 }
112 }
113
114 KReportDesignerItemRectBase::propertyChanged(s, p);
115 if (designer()) {
116 designer()->setModified(true);
117 }
118}
QVariant value() const
bool setValue(const QVariant &value, ValueOptions options=ValueOptions())
QByteArray name() const
Base class for rectangular report items used within the designer GUI.
The ReportDesigner is the main widget for designing a report.
void setModified(bool modified)
Sets the modified status, defaulting to true for modified.
static QPointF scenePosition(const QPointF &ptPos)
Helper function mapping to screen units (pixels), ptPos is in points.
static QSizeF sceneSize(const QSizeF &ptSize)
Helper function mapping to screen units (pixels), ptSize is in points.
qreal z() const
Return the z-value in points.
QString itemDataSource() const
QString typeName(const QJsonObject &obj)
QCA_EXPORT void init()
QDomElement createElement(const QString &tagName)
void setAttribute(const QString &name, const QString &value)
QDomNode firstChild() const const
QGraphicsScene * scene() const const
void setZValue(qreal z)
qreal zValue() const const
QRectF rect() const const
void addItem(QGraphicsItem *item)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
void drawRect(const QRect &rectangle)
void drawText(const QPoint &position, const QString &text)
void setBackgroundMode(Qt::BGMode mode)
TransparentMode
QString toString() const const
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.