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

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2012 Mohammed Nafees <nafees.technocool@gmail.com>
0004 //
0005 
0006 #include "GeoDataListStyle.h"
0007 #include "GeoDataTypes.h"
0008 #include "GeoDataItemIcon.h"
0009 #include "MarbleDirs.h"
0010 
0011 #include <QDataStream>
0012 
0013 namespace Marble
0014 {
0015 
0016 class GeoDataListStylePrivate
0017 {
0018 public:
0019     GeoDataListStylePrivate();
0020 
0021     GeoDataListStyle::ListItemType m_listItemType;
0022     QColor m_bgColor;
0023 
0024     QVector<GeoDataItemIcon*> m_vector;
0025 };
0026 
0027 GeoDataListStylePrivate::GeoDataListStylePrivate() :
0028     m_listItemType( GeoDataListStyle::Check ),
0029     m_bgColor( Qt::white )
0030 {
0031 }
0032 
0033 GeoDataListStyle::GeoDataListStyle() :
0034     d( new GeoDataListStylePrivate )
0035 {
0036 }
0037 
0038 GeoDataListStyle::GeoDataListStyle( const Marble::GeoDataListStyle &other ) :
0039     GeoDataObject( other ), d( new GeoDataListStylePrivate( *other.d ) )
0040 {
0041 }
0042 
0043 GeoDataListStyle &GeoDataListStyle::operator=( const GeoDataListStyle &other )
0044 {
0045     GeoDataObject::operator=(other);
0046     *d = *other.d;
0047     return *this;
0048 }
0049 
0050 bool GeoDataListStyle::operator==( const GeoDataListStyle &other ) const
0051 {
0052     if ( !GeoDataObject::equals( other ) ||
0053          d->m_bgColor != other.d->m_bgColor ||
0054          d->m_listItemType != other.d->m_listItemType ||
0055          d->m_vector.size() != other.d->m_vector.size() )
0056     {
0057         return false;
0058     }
0059 
0060     QVector<GeoDataItemIcon*>::const_iterator begin = d->m_vector.constBegin();
0061     QVector<GeoDataItemIcon*>::const_iterator end = d->m_vector.constEnd();
0062     QVector<GeoDataItemIcon*>::const_iterator otherBegin = other.d->m_vector.constBegin();
0063 
0064     for( ; begin != end; ++begin, ++otherBegin ) {
0065         if ( **begin != **otherBegin ) {
0066             return false;
0067         }
0068     }
0069 
0070     return true;
0071 }
0072 
0073 bool GeoDataListStyle::operator!=( const GeoDataListStyle &other ) const
0074 {
0075     return !this->operator==( other );
0076 }
0077 
0078 GeoDataListStyle::~GeoDataListStyle()
0079 {
0080     delete d;
0081 }
0082 
0083 const char *GeoDataListStyle::nodeType() const
0084 {
0085     return GeoDataTypes::GeoDataListStyleType;
0086 }
0087 
0088 GeoDataListStyle::ListItemType GeoDataListStyle::listItemType() const
0089 {
0090     return d->m_listItemType;
0091 }
0092 
0093 void GeoDataListStyle::setListItemType(ListItemType type)
0094 {
0095     d->m_listItemType = type;
0096 }
0097 
0098 QColor GeoDataListStyle::backgroundColor() const
0099 {
0100     return d->m_bgColor;
0101 }
0102 
0103 void GeoDataListStyle::setBackgroundColor( const QColor &color )
0104 {
0105     d->m_bgColor = color;
0106 }
0107 
0108 QVector<GeoDataItemIcon*> GeoDataListStyle::itemIconList() const
0109 {
0110     return d->m_vector;
0111 }
0112 
0113 GeoDataItemIcon* GeoDataListStyle::child( int i )
0114 {
0115     return d->m_vector.at(i);
0116 }
0117 
0118 const GeoDataItemIcon* GeoDataListStyle::child( int i ) const
0119 {
0120     return d->m_vector.at(i);
0121 }
0122 
0123 int GeoDataListStyle::childPosition( const GeoDataItemIcon* object ) const
0124 {
0125     return d->m_vector.indexOf( const_cast<GeoDataItemIcon *>( object ) );
0126 }
0127 
0128 void GeoDataListStyle::append( GeoDataItemIcon *other )
0129 {
0130     other->setParent( this );
0131     d->m_vector.append( other );
0132 }
0133 
0134 
0135 void GeoDataListStyle::remove( int index )
0136 {
0137     d->m_vector.remove( index );
0138 }
0139 
0140 int GeoDataListStyle::size() const
0141 {
0142     return d->m_vector.size();
0143 }
0144 
0145 GeoDataItemIcon& GeoDataListStyle::at( int pos )
0146 {
0147     return *(d->m_vector[ pos ]);
0148 }
0149 
0150 const GeoDataItemIcon& GeoDataListStyle::at( int pos ) const
0151 {
0152     return *(d->m_vector.at( pos ));
0153 }
0154 
0155 GeoDataItemIcon& GeoDataListStyle::last()
0156 {
0157     return *(d->m_vector.last());
0158 }
0159 
0160 const GeoDataItemIcon& GeoDataListStyle::last() const
0161 {
0162     return *(d->m_vector.last());
0163 }
0164 
0165 GeoDataItemIcon& GeoDataListStyle::first()
0166 {
0167     return *(d->m_vector.first());
0168 }
0169 
0170 const GeoDataItemIcon& GeoDataListStyle::first() const
0171 {
0172     return *(d->m_vector.first());
0173 }
0174 
0175 void GeoDataListStyle::clear()
0176 {
0177     qDeleteAll(d->m_vector);
0178     d->m_vector.clear();
0179 }
0180 
0181 QVector<GeoDataItemIcon*>::Iterator GeoDataListStyle::begin()
0182 {
0183     return d->m_vector.begin();
0184 }
0185 
0186 QVector<GeoDataItemIcon*>::Iterator GeoDataListStyle::end()
0187 {
0188     return d->m_vector.end();
0189 }
0190 
0191 QVector<GeoDataItemIcon*>::ConstIterator GeoDataListStyle::constBegin() const
0192 {
0193     return d->m_vector.constBegin();
0194 }
0195 
0196 QVector<GeoDataItemIcon*>::ConstIterator GeoDataListStyle::constEnd() const
0197 {
0198     return d->m_vector.constEnd();
0199 }
0200 
0201 void GeoDataListStyle::pack( QDataStream& stream ) const
0202 {
0203     GeoDataObject::pack( stream );
0204     stream << d->m_vector.count();
0205 
0206     for ( QVector <GeoDataItemIcon*>::const_iterator iterator = d->m_vector.constBegin();
0207           iterator != d->m_vector.constEnd();
0208           ++iterator )
0209     {
0210         const GeoDataItemIcon *itemIcon = *iterator;
0211         itemIcon->pack( stream );
0212     }
0213 }
0214 
0215 void GeoDataListStyle::unpack( QDataStream& stream )
0216 {
0217     GeoDataObject::unpack( stream );
0218 
0219     int count;
0220     stream >> count;
0221 
0222     int featureId;
0223     stream >> featureId;
0224 
0225     GeoDataItemIcon *itemIcon = new GeoDataItemIcon;
0226     itemIcon->unpack( stream );
0227     d->m_vector.append( itemIcon );
0228 }
0229 
0230 }