KReport

KReportItemMaps.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#include "KReportItemMaps.h"
19#include "KReportUtils.h"
20#include "KReportRenderObjects.h"
21
22#include <KPropertyListData>
23#include <KPropertySet>
24
25#include <QStringList>
26
27#include <sys/socket.h>
28
29#define myDebug() if (0) kDebug(44021)
30
31//! @todo replace with ReportItemMaps(const QDomNode &element = QDomNode())
32KReportItemMaps::KReportItemMaps()
33{
34 createProperties();
35}
36
37KReportItemMaps::KReportItemMaps(const QDomNode &element)
38 : KReportItemMaps()
39{
40 nameProperty()->setValue(KReportUtils::readNameAttribute(element.toElement()));
41 setItemDataSource(element.toElement().attribute(QLatin1String("report:item-data-source")));
42 setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble());
43 m_latitudeProperty->setValue(element.toElement().attribute(QLatin1String("report:latitude")).toDouble());
44 m_longitudeProperty->setValue(element.toElement().attribute(QLatin1String("report:longitude")).toDouble());
45 m_zoomProperty->setValue(element.toElement().attribute(QLatin1String("report:zoom")).toInt());
46 QString themeId(element.toElement().attribute(QLatin1String("report:theme")));
47 themeId = themeId.isEmpty() ? m_themeManager.mapThemeIds()[0] : themeId;
48 m_themeProperty->setValue(themeId);
49
50 parseReportRect(element.toElement());
51}
52
53KReportItemMaps::~KReportItemMaps()
54{
55}
56
57void KReportItemMaps::createProperties()
58{
59 createDataSourceProperty();
60
61 m_latitudeProperty = new KProperty("latitude", 0.0, tr("Latitude"), QString(), KProperty::Double);
62 m_latitudeProperty->setOption("min", -90);
63 m_latitudeProperty->setOption("max", 90);
64 m_latitudeProperty->setOption("suffix", QString::fromUtf8("°"));
65 m_latitudeProperty->setOption("precision", 7);
66
67 m_longitudeProperty = new KProperty("longitude", 0.0, tr("Longitude"), QString(), KProperty::Double);
68 m_longitudeProperty->setOption("min", -180);
69 m_longitudeProperty->setOption("max", 180);
70 m_longitudeProperty->setOption("suffix", QString::fromUtf8("°"));
71 m_longitudeProperty->setOption("precision", 7);
72
73 m_zoomProperty = new KProperty("zoom", 1000, tr("Zoom") );
74 m_zoomProperty->setOption("min", 0);
75 m_zoomProperty->setOption("max", 4000);
76 m_zoomProperty->setOption("step", 100);
77 m_zoomProperty->setOption("slider", true);
78
79 QStringList mapThemIds(m_themeManager.mapThemeIds());
80
81 m_themeProperty = new KProperty("theme", new KPropertyListData(mapThemIds, mapThemIds),
82 QVariant(mapThemIds[1]), tr("Theme"));
83
84 if (mapThemIds.contains(QLatin1String("earth/srtm/srtm.dgml"))) {
85 m_themeProperty->setValue(QLatin1String("earth/srtm/srtm.dgml"),
86 KProperty::ValueOption::IgnoreOld);
87 }
88
89 propertySet()->addProperty(m_latitudeProperty);
90 propertySet()->addProperty(m_longitudeProperty);
91 propertySet()->addProperty(m_zoomProperty);
92 propertySet()->addProperty(m_themeProperty);
93}
94
95QString KReportItemMaps::typeName() const
96{
97 return QLatin1String("maps");
98}
99
100int KReportItemMaps::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset,
101 const QVariant &data, KReportScriptHandler *script)
102{
103 Q_UNUSED(script)
104
105 deserializeData(data);
106 m_pageId = page;
107 m_sectionId = section;
108 m_offset = offset;
109
110
111 m_oroPicture = new OROPicture();
112 m_oroPicture->setPosition(scenePosition(position()) + m_offset);
113 m_oroPicture->setSize(sceneSize(size()));
114
115 if (m_pageId) {
116 m_pageId->insertPrimitive(m_oroPicture);
117 }
118
119 if (m_sectionId) {
120 OROPicture *i2 = dynamic_cast<OROPicture*>(m_oroPicture->clone());
121 if (i2) {
122 i2->setPosition(scenePosition(position()));
123 }
124 }
125
126 m_mapRenderer.renderJob(this);
127
128 return 0; //Item doesn't stretch the section height
129}
130
131void KReportItemMaps::deserializeData(const QVariant& serialized)
132{
133 //kreportpluginDebug() << "Map data for this record is" << serialized;
134 QStringList dataList = serialized.toString().split(QLatin1Char(';'));
135 if (dataList.size() == 3) {
136 m_latitude = dataList[0].toDouble();
137 m_longtitude = dataList[1].toDouble();
138 m_zoom = dataList[2].toInt();
139 } else {
140 m_latitude = m_latitudeProperty->value().toReal();
141 m_longtitude = m_longitudeProperty->value().toReal();
142 m_zoom = m_zoomProperty->value().toInt();
143 }
144}
145
146void KReportItemMaps::renderFinished()
147{
148 emit finishedRendering();
149}
150
151OROPicture* KReportItemMaps::oroImage()
152{
153 return m_oroPicture;
154}
155
156qreal KReportItemMaps::longtitude() const
157{
158 return m_longtitude;
159}
160
161qreal KReportItemMaps::latitude() const
162{
163 return m_latitude;
164}
165
166int KReportItemMaps::zoom() const
167{
168 return m_zoom;
169}
170
171QString KReportItemMaps::themeId() const
172{
173 return m_themeProperty->value().toString();
174}
175
176QVariant KReportItemMaps::realItemData(const QVariant& itemData) const
177{
178 double lat, lon;
179 int zoom;
180
181 QStringList dataList = itemData.toString().split(QLatin1Char(';'));
182
183 if (dataList.size() == 3) {
184 lat = dataList[0].toDouble();
185 lon = dataList[1].toDouble();
186 zoom = dataList[2].toInt();
187 } else if (dataList.size() == 2) {
188 lat = dataList[0].toDouble();
189 lon = dataList[1].toDouble();
190 zoom = m_zoomProperty->value().toInt();
191 } else {
192 lat = m_latitudeProperty->value().toReal();
193 lon = m_longitudeProperty->value().toReal();
194 zoom = m_zoomProperty->value().toInt();
195 }
196
197 if (m_longDataSetFromScript) {
198 lon = m_longtitude;
199 }
200 if (m_latDataSetFromScript) {
201 lat = m_latitude;
202 }
203 if (m_zoomDataSetFromScript) {
204 zoom = m_zoom;
205 }
206 return QString(QLatin1String("%1;%2;%3")).arg(lat).arg(lon).arg(zoom);
207}
void addProperty(KProperty *property, const QByteArray &group="common")
QVariant value() const
bool setValue(const QVariant &value, ValueOptions options=ValueOptions())
void setOption(const char *name, const QVariant &val)
static QPointF scenePosition(const QPointF &ptPos)
Helper function mapping to screen units (pixels), ptPos is in points.
QPointF position() const
Return the position in points.
static QSizeF sceneSize(const QSizeF &ptSize)
Helper function mapping to screen units (pixels), ptSize is in points.
QSizeF size() const
Return the size in points.
QStringList mapThemeIds() const
Represents a single page in a document and may contain zero or more OROPrimitive objects all of which...
Defines a picture. A picture is different to an image, in that it is drawn using commands.
Represents a single a single row in a document and may contain zero or more OROPrimitives.
QAction * zoom(const QObject *recvr, const char *slot, QObject *parent)
QString attribute(const QString &name, const QString &defValue) const const
QDomElement toElement() const const
qsizetype size() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(Args &&... args) const const
QString fromUtf8(QByteArrayView str)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
int toInt(bool *ok) const const
qreal toReal(bool *ok) const const
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.