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

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2012 Mohammed Nafees <nafees.technocool@gmail.com>
0004 //
0005 
0006 #include "GeoDataItemIcon.h"
0007 #include "GeoDataTypes.h"
0008 
0009 #include <QString>
0010 #include <QImage>
0011 
0012 namespace Marble
0013 {
0014 
0015 class GeoDataItemIconPrivate
0016 {
0017 public:
0018     GeoDataItemIconPrivate();
0019 
0020     GeoDataItemIcon::ItemIconStates m_state;
0021     QString m_iconPath;
0022     QImage m_icon;
0023 };
0024 
0025 GeoDataItemIconPrivate::GeoDataItemIconPrivate() :
0026     m_state(),
0027     m_iconPath(),
0028     m_icon()
0029 {
0030 }
0031 
0032 GeoDataItemIcon::GeoDataItemIcon() :
0033     d( new GeoDataItemIconPrivate )
0034 {
0035 }
0036 
0037 GeoDataItemIcon::GeoDataItemIcon( const Marble::GeoDataItemIcon &other ) :
0038     GeoDataObject(), d( new GeoDataItemIconPrivate( *other.d ) )
0039 {
0040 }
0041 
0042 GeoDataItemIcon &GeoDataItemIcon::operator=( const GeoDataItemIcon &other )
0043 {
0044     GeoDataObject::operator=( other );
0045     *d = *other.d;
0046     return *this;
0047 }
0048 
0049 bool GeoDataItemIcon::operator==( const GeoDataItemIcon& other ) const
0050 {
0051     return equals(other) &&
0052            d->m_state == other.d->m_state &&
0053            d->m_iconPath == other.d->m_iconPath &&
0054            d->m_icon == other.d->m_icon;
0055 }
0056 
0057 bool GeoDataItemIcon::operator!=( const GeoDataItemIcon& other ) const
0058 {
0059     return !this->operator==(other);
0060 }
0061 
0062 GeoDataItemIcon::~GeoDataItemIcon()
0063 {
0064     delete d;
0065 }
0066 
0067 const char *GeoDataItemIcon::nodeType() const
0068 {
0069     return GeoDataTypes::GeoDataItemIconType;
0070 }
0071 
0072 GeoDataItemIcon::ItemIconStates GeoDataItemIcon::state() const
0073 {
0074     return d->m_state;
0075 }
0076 
0077 void GeoDataItemIcon::setState(ItemIconStates state)
0078 {
0079     d->m_state = state;
0080 }
0081 
0082 void GeoDataItemIcon::setIcon( const QImage &icon )
0083 {
0084     d->m_icon = icon;
0085 }
0086 
0087 QString GeoDataItemIcon::iconPath() const
0088 {
0089     return d->m_iconPath;
0090 }
0091 
0092 void GeoDataItemIcon::setIconPath( const QString &path )
0093 {
0094     d->m_iconPath = path;
0095 }
0096 
0097 QImage GeoDataItemIcon::icon() const
0098 {
0099     if(!d->m_icon.isNull())
0100     {
0101         return d->m_icon;
0102     }
0103     else if(!d->m_iconPath.isEmpty())
0104     {
0105         d->m_icon = QImage(resolvePath(d->m_iconPath));
0106         return d->m_icon;
0107     }
0108     else
0109     {
0110         return QImage();
0111     }
0112 }
0113 
0114 }