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

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2012 Mohammed Nafees <nafees.technocool@gmail.com>
0004 //
0005 
0006 #include "GeoDataVec2.h"
0007 
0008 #include "MarbleDebug.h"
0009 
0010 namespace Marble {
0011 
0012 class GeoDataVec2Private
0013 {
0014 public:
0015     GeoDataVec2Private();
0016 
0017     GeoDataVec2::Unit  m_xunit;
0018     GeoDataVec2::Unit  m_yunit;
0019 
0020     static GeoDataVec2::Unit  parseUnits( const QString &value );
0021 };
0022 
0023 GeoDataVec2Private::GeoDataVec2Private() :
0024     m_xunit(GeoDataVec2::Fraction), m_yunit(GeoDataVec2::Fraction)
0025 {
0026 }
0027 
0028 GeoDataVec2::GeoDataVec2() :
0029     d( new GeoDataVec2Private )
0030 {
0031 }
0032 
0033 GeoDataVec2::GeoDataVec2(qreal x, qreal y, const QString &xunits, const QString &yunits) :
0034     d( new GeoDataVec2Private )
0035 {
0036     setX( x );
0037     setY( y );
0038     d->m_xunit = GeoDataVec2Private::parseUnits( xunits );
0039     d->m_yunit = GeoDataVec2Private::parseUnits( yunits );
0040 }
0041 
0042 GeoDataVec2::Unit GeoDataVec2Private::parseUnits( const QString &value )
0043 {
0044     if (value == QLatin1String("fraction")) {
0045         return GeoDataVec2::Fraction;
0046     }
0047     if (value == QLatin1String("pixels")) {
0048         return GeoDataVec2::Pixels;
0049     }
0050     if (value == QLatin1String("insetPixels")) {
0051         return GeoDataVec2::InsetPixels;
0052     }
0053 
0054     mDebug() << "Warning: Unknown units value " << value << " - falling back to default 'fraction'";
0055     return GeoDataVec2::Fraction;
0056 }
0057 
0058 GeoDataVec2::GeoDataVec2( const Marble::GeoDataVec2 &other ) :
0059   QPointF(other), d( new GeoDataVec2Private( *other.d ) )
0060 {
0061 }
0062 
0063 GeoDataVec2 &GeoDataVec2::operator=( const GeoDataVec2 &other )
0064 {
0065     QPointF::operator=(other);
0066     *d = *other.d;
0067     return *this;
0068 }
0069 
0070 bool GeoDataVec2::operator==(const GeoDataVec2& other) const
0071 {
0072     return x() == other.x() && y() == other.y() &&
0073            d->m_xunit == other.d->m_xunit && d->m_yunit == other.d->m_yunit;
0074 }
0075 
0076 bool GeoDataVec2::operator!=(const GeoDataVec2& other) const
0077 {
0078     return !this->operator==(other);
0079 }
0080 
0081 GeoDataVec2::~GeoDataVec2()
0082 {
0083     delete d;
0084 }
0085 
0086 GeoDataVec2::Unit GeoDataVec2::xunit() const
0087 {
0088     return d->m_xunit;
0089 }
0090 
0091 void GeoDataVec2::setXunits(Unit xunit)
0092 {
0093     d->m_xunit = xunit;
0094 }
0095 
0096 GeoDataVec2::Unit GeoDataVec2::yunit() const
0097 {
0098     return d->m_yunit;
0099 }
0100 
0101 void GeoDataVec2::setYunits(Unit yunit)
0102 {
0103     d->m_yunit = yunit;
0104 }
0105 
0106 }