File indexing completed on 2024-05-12 03:50:15

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2007 Murad Tagirov <tmurad@gmail.com>
0004 // SPDX-FileCopyrightText: 2008 Jens-Michael Hoffmann <jensmh@gmx.de>
0005 //
0006 
0007 #include "GeoDataObject.h"
0008 
0009 #include <QtGlobal>
0010 #include <QDataStream>
0011 #include <QFileInfo>
0012 #include <QUrl>
0013 
0014 #include "GeoDataDocument.h"
0015 
0016 #include "GeoDataTypes.h"
0017 
0018 
0019 namespace Marble
0020 {
0021 
0022 class GeoDataObjectPrivate
0023 {
0024   public:
0025     GeoDataObjectPrivate()
0026         : m_id(),
0027           m_targetId(),
0028           m_parent(nullptr)
0029     {
0030     }
0031 
0032     QString  m_id;
0033     QString  m_targetId;
0034     GeoDataObject *m_parent;
0035 };
0036 
0037 GeoDataObject::GeoDataObject()
0038     : GeoNode(), Serializable(),
0039       d( new GeoDataObjectPrivate() )
0040 {
0041 }
0042 
0043 GeoDataObject::GeoDataObject( GeoDataObject const & other )
0044     : GeoNode(), Serializable( other ),
0045       d( new GeoDataObjectPrivate( *other.d ) )
0046 {
0047 }
0048 
0049 GeoDataObject & GeoDataObject::operator=( const GeoDataObject & rhs )
0050 {
0051     *d = *rhs.d;
0052     return *this;
0053 }
0054 
0055 GeoDataObject::~GeoDataObject()
0056 {
0057     delete d;
0058 }
0059 
0060 const GeoDataObject *GeoDataObject::parent() const
0061 {
0062     return d->m_parent;
0063 }
0064 
0065 GeoDataObject *GeoDataObject::parent()
0066 {
0067     return d->m_parent;
0068 }
0069 
0070 void GeoDataObject::setParent(GeoDataObject *parent)
0071 {
0072     d->m_parent = parent;
0073 }
0074 
0075 QString GeoDataObject::id() const
0076 {
0077     return d->m_id;
0078 }
0079 
0080 void GeoDataObject::setId( const QString& value )
0081 {
0082     d->m_id = value;
0083 }
0084 
0085 QString GeoDataObject::targetId() const
0086 {
0087     return d->m_targetId;
0088 }
0089 
0090 void GeoDataObject::setTargetId( const QString& value )
0091 {
0092     d->m_targetId = value;
0093 }
0094 
0095 QString GeoDataObject::resolvePath( const QString &relativePath ) const
0096 {
0097     QUrl const url( relativePath );
0098     QFileInfo const fileInfo( url.path() );
0099     if ( url.isRelative() && fileInfo.isRelative() ) {
0100         GeoDataDocument const * document = dynamic_cast<GeoDataDocument const*>( this );
0101         if ( document ) {
0102             QString const baseUri = document->baseUri();
0103             QFileInfo const documentRoot = baseUri.isEmpty() ? document->fileName() : baseUri;
0104             QFileInfo const absoluteImage(documentRoot.absolutePath() + QLatin1Char('/') + url.path());
0105             return absoluteImage.absoluteFilePath();
0106         } else if ( d->m_parent ) {
0107             return d->m_parent->resolvePath( relativePath );
0108         }
0109     }
0110 
0111     return relativePath;
0112 }
0113 
0114 void GeoDataObject::pack( QDataStream& stream ) const
0115 {
0116     stream << d->m_id;
0117     stream << d->m_targetId;
0118 }
0119 
0120 void GeoDataObject::unpack( QDataStream& stream )
0121 {
0122     stream >> d->m_id;
0123     stream >> d->m_targetId;
0124 }
0125 
0126 bool GeoDataObject::equals(const GeoDataObject &other) const
0127 {
0128     return d->m_id == other.d->m_id && d->m_targetId == other.d->m_targetId;
0129 }
0130 
0131 }