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

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2013 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
0004 //
0005 
0006 #include "GeoDataPlaylist.h"
0007 
0008 #include "GeoDataTypes.h"
0009 
0010 namespace Marble
0011 {
0012 
0013 bool GeoDataPlaylist::operator==(const GeoDataPlaylist& other) const
0014 {
0015     if( this->m_primitives.size() != other.m_primitives.size() ){
0016         return false;
0017     }
0018     else{
0019         int index = 0;
0020         for( GeoDataTourPrimitive* m_primitive: m_primitives ){
0021             if (*m_primitive != *other.m_primitives.at(index)) {
0022                 return false;
0023             }
0024 
0025             index++;
0026         }
0027         return true;
0028     }
0029 }
0030 
0031 bool GeoDataPlaylist::operator!=(const GeoDataPlaylist& other) const
0032 {
0033     return !this->operator==(other);
0034 }
0035 
0036 const char *GeoDataPlaylist::nodeType() const
0037 {
0038     return GeoDataTypes::GeoDataPlaylistType;
0039 }
0040 
0041 GeoDataTourPrimitive* GeoDataPlaylist::primitive(int id)
0042 {
0043     if (size() <= id || id < 0) {
0044         return nullptr;
0045     }
0046     return m_primitives.at(id);
0047 }
0048 
0049 const GeoDataTourPrimitive* GeoDataPlaylist::primitive(int id) const
0050 {
0051     if (size() <= id || id < 0) {
0052         return nullptr;
0053     }
0054     return m_primitives.at(id);
0055 }
0056 
0057 void GeoDataPlaylist::addPrimitive( GeoDataTourPrimitive *primitive )
0058 {
0059     primitive->setParent( this );
0060     m_primitives.push_back( primitive );
0061 }
0062 
0063 void GeoDataPlaylist::insertPrimitive( int position, GeoDataTourPrimitive *primitive )
0064 {
0065     primitive->setParent( this );
0066     int const index = qBound( 0, position, m_primitives.size() );
0067     m_primitives.insert( index, primitive );
0068 }
0069 
0070 void GeoDataPlaylist::removePrimitiveAt(int position)
0071 {
0072     m_primitives.removeAt( position );
0073 }
0074 
0075 void GeoDataPlaylist::swapPrimitives( int positionA, int positionB )
0076 {
0077     if ( qMin( positionA, positionB ) >= 0 && qMax( positionA, positionB ) < m_primitives.size() ) {
0078 
0079 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
0080         m_primitives.swapItemsAt( positionA, positionB );
0081 #else
0082         m_primitives.swap( positionA, positionB );
0083 #endif
0084     }
0085 }
0086 
0087 int GeoDataPlaylist::size() const
0088 {
0089     return m_primitives.size();
0090 }
0091 
0092 } // namespace Marble