Marble

GeoDataObject.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2007 Murad Tagirov <tmurad@gmail.com>
4// SPDX-FileCopyrightText: 2008 Jens-Michael Hoffmann <jensmh@gmx.de>
5//
6
7#include "GeoDataObject.h"
8
9#include <QDataStream>
10#include <QFileInfo>
11#include <QUrl>
12#include <QtGlobal>
13
14#include "GeoDataDocument.h"
15
16#include "GeoDataTypes.h"
17
18namespace Marble
19{
20
21class GeoDataObjectPrivate
22{
23public:
24 GeoDataObjectPrivate()
25 : m_id()
26 , m_targetId()
27 , m_parent(nullptr)
28 {
29 }
30
31 QString m_id;
32 QString m_targetId;
33 GeoDataObject *m_parent;
34};
35
36GeoDataObject::GeoDataObject()
37 : GeoNode()
38 , Serializable()
39 , d(new GeoDataObjectPrivate())
40{
41}
42
43GeoDataObject::GeoDataObject(GeoDataObject const &other)
44 : GeoNode()
45 , Serializable(other)
46 , d(new GeoDataObjectPrivate(*other.d))
47{
48}
49
50GeoDataObject &GeoDataObject::operator=(const GeoDataObject &rhs)
51{
52 *d = *rhs.d;
53 return *this;
54}
55
56GeoDataObject::~GeoDataObject()
57{
58 delete d;
59}
60
61const GeoDataObject *GeoDataObject::parent() const
62{
63 return d->m_parent;
64}
65
66GeoDataObject *GeoDataObject::parent()
67{
68 return d->m_parent;
69}
70
71void GeoDataObject::setParent(GeoDataObject *parent)
72{
73 d->m_parent = parent;
74}
75
76QString GeoDataObject::id() const
77{
78 return d->m_id;
79}
80
81void GeoDataObject::setId(const QString &value)
82{
83 d->m_id = value;
84}
85
86QString GeoDataObject::targetId() const
87{
88 return d->m_targetId;
89}
90
91void GeoDataObject::setTargetId(const QString &value)
93 d->m_targetId = value;
94}
95
96QString GeoDataObject::resolvePath(const QString &relativePath) const
97{
98 QUrl const url(relativePath);
99 QFileInfo const fileInfo(url.path());
100 if (url.isRelative() && fileInfo.isRelative()) {
101 auto const *document = dynamic_cast<GeoDataDocument const *>(this);
102 if (document) {
103 QString const baseUri = document->baseUri();
104 QFileInfo const documentRoot = QFileInfo(baseUri.isEmpty() ? document->fileName() : baseUri);
105 QFileInfo const absoluteImage(documentRoot.absolutePath() + QLatin1Char('/') + url.path());
106 return absoluteImage.absoluteFilePath();
107 } else if (d->m_parent) {
108 return d->m_parent->resolvePath(relativePath);
109 }
110 }
111
112 return relativePath;
113}
114
115void GeoDataObject::pack(QDataStream &stream) const
116{
117 stream << d->m_id;
118 stream << d->m_targetId;
119}
120
121void GeoDataObject::unpack(QDataStream &stream)
122{
123 stream >> d->m_id;
124 stream >> d->m_targetId;
125}
126
127bool GeoDataObject::equals(const GeoDataObject &other) const
128{
129 return d->m_id == other.d->m_id && d->m_targetId == other.d->m_targetId;
130}
131
132}
A container for Features, Styles and in the future Schemas.
A base class for all geodata objects.
Binds a QML item to a specific geodetic location in screen coordinates.
QString absolutePath() const const
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.