KReport

KReportDesignerItemMaps.cpp
1/*
2 * Copyright (C) 2007-2016 by Adam Pigg (adam@piggz.co.uk)
3 * Copyright (C) 2011-2015 by Radoslaw Wicik (radoslaw@wicik.pl)
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
32void 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
44KReportDesignerItemMaps::KReportDesignerItemMaps(KReportDesigner *rw, QGraphicsScene *scene, const QPointF &pos)
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
53KReportDesignerItemMaps::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
60KReportDesignerItemMaps* KReportDesignerItemMaps::clone()
61{
64 QDomNode n;
65 buildXML(&d, &e);
66 n = e.firstChild();
67 return new KReportDesignerItemMaps(n, designer(), nullptr);
68}
69
70KReportDesignerItemMaps::~KReportDesignerItemMaps()
71{
72 // do we need to clean anything up?
73}
74
75void 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
95void 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
113void 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}
QVariant value() const
bool setValue(const QVariant &value, ValueOptions options=ValueOptions())
QByteArray name() const
void setListData(const QStringList &keys, const QStringList &names)
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
KOSM_EXPORT const char * typeName(Type type)
QCA_EXPORT void init()
QByteArray toLower() const const
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)
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 fillRect(const QRect &rectangle, QGradient::Preset preset)
const QPen & pen() const const
void setPen(Qt::PenStyle style)
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 13 2024 11:50:02 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.