KReport

KReportDesignerItemWeb.cpp
1 /* This file is part of the KDE project
2  Copyright Shreya Pandit <[email protected]>
3  Copyright 2011 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 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 
34 void 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 
44 KReportDesignerItemWeb::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 
53 KReportDesignerItemWeb::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 
61 KReportDesignerItemWeb *KReportDesignerItemWeb::clone()
62 {
63  QDomDocument d;
64  QDomElement e = d.createElement(QLatin1String("clone"));
65  QDomNode n;
66  buildXML(&d, &e);
67  n = e.firstChild();
68  return new KReportDesignerItemWeb(n, designer(), nullptr);
69 }
70 
71 KReportDesignerItemWeb::~KReportDesignerItemWeb() //done,compared
72 {
73  // do we need to clean anything up?
74 }
75 
76 void 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 
89 void 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 
103 void 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 }
QByteArray name() const
void setBackgroundMode(Qt::BGMode mode)
QDomNode firstChild() const const
void addItem(QGraphicsItem *item)
void drawRect(const QRectF &rectangle)
QCA_EXPORT void init()
TransparentMode
QDomElement createElement(const QString &tagName)
void drawText(const QPointF &position, const QString &text)
void setAttribute(const QString &name, const QString &value)
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.
QGraphicsScene * scene() const const
bool setValue(const QVariant &value, ValueOptions options=ValueOptions())
QDomNode appendChild(const QDomNode &newChild)
QRectF rect() const const
Base class for rectangular report items used within the designer GUI.
QVariant value() const
QPointF pos() const const
The ReportDesigner is the main widget for designing a report.
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Feb 8 2023 04:21:47 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.