Marble

GeoDataObject.cpp
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2007 Murad Tagirov <[email protected]>
9 // Copyright 2008 Jens-Michael Hoffmann <[email protected]>
10 //
11 
12 #include "GeoDataObject.h"
13 
14 #include <QtGlobal>
15 #include <QDataStream>
16 #include <QFileInfo>
17 #include <QUrl>
18 
19 #include "GeoDataDocument.h"
20 
21 #include "GeoDataTypes.h"
22 
23 
24 namespace Marble
25 {
26 
27 class GeoDataObjectPrivate
28 {
29  public:
30  GeoDataObjectPrivate()
31  : m_id(),
32  m_targetId(),
33  m_parent(nullptr)
34  {
35  }
36 
37  QString m_id;
38  QString m_targetId;
39  GeoDataObject *m_parent;
40 };
41 
42 GeoDataObject::GeoDataObject()
43  : GeoNode(), Serializable(),
44  d( new GeoDataObjectPrivate() )
45 {
46 }
47 
48 GeoDataObject::GeoDataObject( GeoDataObject const & other )
49  : GeoNode(), Serializable( other ),
50  d( new GeoDataObjectPrivate( *other.d ) )
51 {
52 }
53 
54 GeoDataObject & GeoDataObject::operator=( const GeoDataObject & rhs )
55 {
56  *d = *rhs.d;
57  return *this;
58 }
59 
60 GeoDataObject::~GeoDataObject()
61 {
62  delete d;
63 }
64 
66 {
67  return d->m_parent;
68 }
69 
71 {
72  return d->m_parent;
73 }
74 
76 {
77  d->m_parent = parent;
78 }
79 
81 {
82  return d->m_id;
83 }
84 
85 void GeoDataObject::setId( const QString& value )
86 {
87  d->m_id = value;
88 }
89 
91 {
92  return d->m_targetId;
93 }
94 
95 void GeoDataObject::setTargetId( const QString& value )
96 {
97  d->m_targetId = value;
98 }
99 
100 QString GeoDataObject::resolvePath( const QString &relativePath ) const
101 {
102  QUrl const url( relativePath );
103  QFileInfo const fileInfo( url.path() );
104  if ( url.isRelative() && fileInfo.isRelative() ) {
105  GeoDataDocument const * document = dynamic_cast<GeoDataDocument const*>( this );
106  if ( document ) {
107  QString const baseUri = document->baseUri();
108  QFileInfo const documentRoot = baseUri.isEmpty() ? document->fileName() : baseUri;
109  QFileInfo const absoluteImage(documentRoot.absolutePath() + QLatin1Char('/') + url.path());
110  return absoluteImage.absoluteFilePath();
111  } else if ( d->m_parent ) {
112  return d->m_parent->resolvePath( relativePath );
113  }
114  }
115 
116  return relativePath;
117 }
118 
119 void GeoDataObject::pack( QDataStream& stream ) const
120 {
121  stream << d->m_id;
122  stream << d->m_targetId;
123 }
124 
126 {
127  stream >> d->m_id;
128  stream >> d->m_targetId;
129 }
130 
131 bool GeoDataObject::equals(const GeoDataObject &other) const
132 {
133  return d->m_id == other.d->m_id && d->m_targetId == other.d->m_targetId;
134 }
135 
136 }
void setTargetId(const QString &value)
set a new targetId of this object
void unpack(QDataStream &steam) override
Reimplemented from Serializable.
A container for Features, Styles and in the future Schemas.
Binds a QML item to a specific geodetic location in screen coordinates.
A base class for all geodata objects.
Definition: GeoDataObject.h:48
virtual bool equals(const GeoDataObject &other) const
Compares the value of id and targetId of the two objects.
void setParent(GeoDataObject *parent)
Sets the parent of the object.
QString baseUri() const
The URI relative paths should be resolved against.
void pack(QDataStream &stream) const override
Reimplemented from Serializable.
QString absoluteFilePath() const const
bool isEmpty() const const
QString path(QUrl::ComponentFormattingOptions options) const const
QString targetId() const
Get the targetId of the object to be replaced.
const GeoDataObject * parent() const
Provides the parent of the object in GeoDataContainers.
QString id() const
Get the id of the object.
void setId(const QString &value)
Set the id of the object.
QString fileName() const
The filename of the document.
bool isRelative() const const
QString absolutePath() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Aug 10 2020 23:24:43 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.