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

KDE's Doxygen guidelines are available online.