Marble

GeoDataObject.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2007 Murad Tagirov <[email protected]>
4 // SPDX-FileCopyrightText: 2008 Jens-Michael Hoffmann <[email protected]>
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 
19 namespace Marble
20 {
21 
22 class 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 
37 GeoDataObject::GeoDataObject()
38  : GeoNode(), Serializable(),
39  d( new GeoDataObjectPrivate() )
40 {
41 }
42 
43 GeoDataObject::GeoDataObject( GeoDataObject const & other )
44  : GeoNode(), Serializable( other ),
45  d( new GeoDataObjectPrivate( *other.d ) )
46 {
47 }
48 
49 GeoDataObject & GeoDataObject::operator=( const GeoDataObject & rhs )
50 {
51  *d = *rhs.d;
52  return *this;
53 }
54 
55 GeoDataObject::~GeoDataObject()
56 {
57  delete d;
58 }
59 
61 {
62  return d->m_parent;
63 }
64 
66 {
67  return d->m_parent;
68 }
69 
71 {
72  d->m_parent = parent;
73 }
74 
76 {
77  return d->m_id;
78 }
79 
80 void GeoDataObject::setId( const QString& value )
81 {
82  d->m_id = value;
83 }
84 
86 {
87  return d->m_targetId;
88 }
89 
90 void GeoDataObject::setTargetId( const QString& value )
91 {
92  d->m_targetId = value;
93 }
94 
95 QString 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 
114 void GeoDataObject::pack( QDataStream& stream ) const
115 {
116  stream << d->m_id;
117  stream << d->m_targetId;
118 }
119 
121 {
122  stream >> d->m_id;
123  stream >> d->m_targetId;
124 }
125 
126 bool 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 }
QString id() const
Get the id of the object.
void setTargetId(const QString &value)
set a new targetId of this object
QString targetId() const
Get the targetId of the object to be replaced.
QString baseUri() const
The URI relative paths should be resolved against.
A base class for all geodata objects.
Definition: GeoDataObject.h:43
bool isEmpty() const const
void setParent(GeoDataObject *parent)
Sets the parent of the object.
A container for Features, Styles and in the future Schemas.
void pack(QDataStream &stream) const override
Reimplemented from Serializable.
Binds a QML item to a specific geodetic location in screen coordinates.
void setId(const QString &value)
Set the id of the object.
virtual bool equals(const GeoDataObject &other) const
Compares the value of id and targetId of the two objects.
const GeoDataObject * parent() const
Provides the parent of the object in GeoDataContainers.
QString absolutePath() const const
void unpack(QDataStream &steam) override
Reimplemented from Serializable.
QString fileName() const
The filename of the document.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Aug 13 2022 03:55:43 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.