KReport

KReportDesignerItemMaps.cpp
1 /*
2  * Copyright (C) 2007-2016 by Adam Pigg ([email protected])
3  * Copyright (C) 2011-2015 by Radoslaw Wicik ([email protected])
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 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  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "KReportDesignerItemMaps.h"
20 #include "KReportDesignerItemBase.h"
21 #include "KReportDesigner.h"
22 
23 #include <KProperty>
24 #include <KPropertySet>
25 
26 #include <QGraphicsScene>
27 #include <QGraphicsSceneMouseEvent>
28 #include <QDomDocument>
29 #include <QPainter>
30 #include "kreportplugin_debug.h"
31 
32 void KReportDesignerItemMaps::init(QGraphicsScene *scene)
33 {
34  if (scene)
35  scene->addItem(this);
36 
37  connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)),
38  this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&)));
39 
40  dataSourceProperty()->setListData(designer()->fieldKeys(), designer()->fieldNames());
41  setZValue(z());
42 }
43 
44 KReportDesignerItemMaps::KReportDesignerItemMaps(KReportDesigner *rw, QGraphicsScene *scene, const QPointF &pos)
45  : 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 KReportDesignerItemMaps::KReportDesignerItemMaps(const QDomNode &element, KReportDesigner *rw, QGraphicsScene* scene)
54  : KReportItemMaps(element), KReportDesignerItemRectBase(rw, this)
55 {
56  init(scene);
57  setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size()));
58 }
59 
60 KReportDesignerItemMaps* KReportDesignerItemMaps::clone()
61 {
62  QDomDocument d;
63  QDomElement e = d.createElement(QLatin1String("clone"));
64  QDomNode n;
65  buildXML(&d, &e);
66  n = e.firstChild();
67  return new KReportDesignerItemMaps(n, designer(), nullptr);
68 }
69 
70 KReportDesignerItemMaps::~KReportDesignerItemMaps()
71 {
72  // do we need to clean anything up?
73 }
74 
75 void KReportDesignerItemMaps::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
76 {
77  Q_UNUSED(option);
78  Q_UNUSED(widget);
79  // store any values we plan on changing so we can restore them
80  QPen p = painter->pen();
81  painter->fillRect(rect(), QColor(0xc2, 0xfc, 0xc7));//C2FCC7
82 
83  //Draw a border so user knows the object edge
84  painter->setPen(QPen(QColor(224, 224, 224)));
85  painter->drawRect(rect());
86  painter->setPen(Qt::black);
87  painter->drawText(rect(), 0, dataSourceAndObjectTypeName(itemDataSource(), QLatin1String("map")));
88 
89  drawHandles(painter);
90 
91  // restore an values before we started just in case
92  painter->setPen(p);
93 }
94 
95 void KReportDesignerItemMaps::buildXML(QDomDocument *doc, QDomElement *parent)
96 {
97  QDomElement entity = doc->createElement(QLatin1String("report:") + typeName());
98 
99  // properties
100  addPropertyAsAttribute(&entity, nameProperty());
101  addPropertyAsAttribute(&entity, dataSourceProperty());
102  addPropertyAsAttribute(&entity, m_latitudeProperty);
103  addPropertyAsAttribute(&entity, m_longitudeProperty);
104  addPropertyAsAttribute(&entity, m_zoomProperty);
105  addPropertyAsAttribute(&entity, m_themeProperty);
106  //addPropertyAsAttribute(&entity, m_resizeMode);
107  entity.setAttribute(QLatin1String("report:z-index"), z());
108  buildXMLRect(doc, &entity, this);
109 
110  parent->appendChild(entity);
111 }
112 
113 void KReportDesignerItemMaps::slotPropertyChanged(KPropertySet &s, KProperty &p)
114 {
115  //kreportpluginDebug() << p.name() << ":" << p.value();
116  if (p.name().toLower() == "name") {
117  //For some reason p.oldValue returns an empty string
118  if (!designer()->isEntityNameUnique(p.value().toString(), this)) {
119  p.setValue(oldName());
120  } else {
121  setOldName(p.value().toString());
122  }
123  }
124 
125  KReportDesignerItemRectBase::propertyChanged(s, p);
126  if (designer()) designer()->setModified(true);
127 }
QByteArray name() const
void setPen(const QColor &color)
QDomNode firstChild() const const
QByteArray toLower() const const
void addItem(QGraphicsItem *item)
void drawRect(const QRectF &rectangle)
QCA_EXPORT void init()
const QPen & pen() const const
QDomElement createElement(const QString &tagName)
void drawText(const QPointF &position, const QString &text)
void fillRect(const QRectF &rectangle, const QBrush &brush)
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.
bool setValue(const QVariant &value, ValueOptions options=ValueOptions())
QDomNode appendChild(const QDomNode &newChild)
Base class for rectangular report items used within the designer GUI.
QVariant value() 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 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.