File indexing completed on 2024-04-28 03:50:32

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2011 Dennis Nienhüser <nienhueser@kde.org>
0004 //
0005 
0006 #include "OsmPlacemark.h"
0007 #include "DatabaseQuery.h"
0008 
0009 namespace Marble {
0010 
0011 OsmPlacemark::OsmPlacemark() : m_regionId( 0 ),
0012     m_category( UnknownCategory ),
0013     m_longitude( 0.0 ), m_latitude( 0.0 )
0014 {
0015     // nothing to do
0016 }
0017 
0018 OsmPlacemark::OsmCategory OsmPlacemark::category() const
0019 {
0020     return m_category;
0021 }
0022 
0023 void OsmPlacemark::setCategory( OsmCategory category )
0024 {
0025     m_category = category;
0026 }
0027 
0028 QString OsmPlacemark::name() const
0029 {
0030     return m_name;
0031 }
0032 
0033 void OsmPlacemark::setName( const QString &name )
0034 {
0035     m_name = name;
0036 }
0037 
0038 QString OsmPlacemark::houseNumber() const
0039 {
0040     return m_houseNumber;
0041 }
0042 
0043 void OsmPlacemark::setHouseNumber( const QString &houseNumber )
0044 {
0045     m_houseNumber = houseNumber;
0046 }
0047 
0048 int OsmPlacemark::regionId() const
0049 {
0050     return m_regionId;
0051 }
0052 
0053 void OsmPlacemark::setRegionId( int id )
0054 {
0055     m_regionId = id;
0056 }
0057 
0058 QString OsmPlacemark::additionalInformation() const
0059 {
0060     return m_additionalInformation;
0061 }
0062 
0063 void OsmPlacemark::setAdditionalInformation( const QString &name )
0064 {
0065     m_additionalInformation = name;
0066 }
0067 
0068 qreal OsmPlacemark::longitude() const
0069 {
0070     return m_longitude;
0071 }
0072 
0073 void OsmPlacemark::setLongitude( qreal longitude )
0074 {
0075     m_longitude = longitude;
0076 }
0077 
0078 qreal OsmPlacemark::latitude() const
0079 {
0080     return m_latitude;
0081 }
0082 
0083 void OsmPlacemark::setLatitude( qreal latitude )
0084 {
0085     m_latitude = latitude;
0086 }
0087 
0088 
0089 bool OsmPlacemark::operator<( const OsmPlacemark &other) const
0090 {
0091     if ( name() != other.name() ) {
0092         return name() < other.name();
0093     }
0094 
0095     if ( additionalInformation() != other.additionalInformation() ) {
0096         return additionalInformation() < other.additionalInformation();
0097     }
0098 
0099     if ( houseNumber() != other.houseNumber() ) {
0100         return houseNumber() < other.houseNumber();
0101     }
0102 
0103     if ( regionId() != other.regionId() ) {
0104         return regionId() < other.regionId();
0105     }
0106 
0107     if ( longitude() != other.longitude() ) {
0108         return longitude() < other.longitude();
0109     }
0110 
0111     return latitude() < other.latitude();
0112 }
0113 
0114 bool OsmPlacemark::operator==( const OsmPlacemark &other ) const
0115 {
0116     return m_regionId == other.m_regionId &&
0117            m_category == other.m_category &&
0118            m_longitude == other.m_longitude &&
0119            m_latitude == other.m_latitude &&
0120            m_name == other.m_name &&
0121            m_houseNumber == other.m_houseNumber &&
0122            m_additionalInformation == other.m_additionalInformation;
0123 }
0124 
0125 qreal OsmPlacemark::matchScore( const DatabaseQuery* query ) const
0126 {
0127     qreal score = 0.0;
0128 
0129     if ( query && query->resultFormat() == DatabaseQuery::AddressFormat ) {
0130         if ( !query->region().isEmpty() ) {
0131             if ( m_additionalInformation.compare( query->region(), Qt::CaseInsensitive ) == 0 ) {
0132                 score += 2.0;
0133             } else if ( m_additionalInformation.startsWith( query->region(), Qt::CaseInsensitive ) ) {
0134                 score += 0.5;
0135             }
0136         }
0137 
0138         if ( !query->houseNumber().isEmpty() ) {
0139             if ( m_houseNumber.compare( query->houseNumber(), Qt::CaseInsensitive ) == 0 ) {
0140                 score += 1.0;
0141             } else if ( m_houseNumber.startsWith( query->houseNumber(), Qt::CaseInsensitive ) ) {
0142                 score += 0.5;
0143             }
0144         }
0145 
0146         if ( !query->street().isEmpty() ) {
0147             if ( m_name.compare( query->street(), Qt::CaseInsensitive ) == 0 ) {
0148                 score += 2.0;
0149             } else if ( m_name.startsWith( query->street(), Qt::CaseInsensitive ) ) {
0150                 score += 0.5;
0151             }
0152         }
0153     }
0154 
0155     return score;
0156 }
0157 
0158 }