1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2013 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
4 //
5
6 #include "GeoDataPlaylist.h"
7
8 #include "GeoDataTypes.h"
9
10 namespace Marble
11 {
12
operator ==(const GeoDataPlaylist & other) const13 bool GeoDataPlaylist::operator==(const GeoDataPlaylist& other) const
14 {
15 if( this->m_primitives.size() != other.m_primitives.size() ){
16 return false;
17 }
18 else{
19 int index = 0;
20 for( GeoDataTourPrimitive* m_primitive: m_primitives ){
21 if (*m_primitive != *other.m_primitives.at(index)) {
22 return false;
23 }
24
25 index++;
26 }
27 return true;
28 }
29 }
30
operator !=(const GeoDataPlaylist & other) const31 bool GeoDataPlaylist::operator!=(const GeoDataPlaylist& other) const
32 {
33 return !this->operator==(other);
34 }
35
nodeType() const36 const char *GeoDataPlaylist::nodeType() const
37 {
38 return GeoDataTypes::GeoDataPlaylistType;
39 }
40
primitive(int id)41 GeoDataTourPrimitive* GeoDataPlaylist::primitive(int id)
42 {
43 if (size() <= id || id < 0) {
44 return nullptr;
45 }
46 return m_primitives.at(id);
47 }
48
primitive(int id) const49 const GeoDataTourPrimitive* GeoDataPlaylist::primitive(int id) const
50 {
51 if (size() <= id || id < 0) {
52 return nullptr;
53 }
54 return m_primitives.at(id);
55 }
56
addPrimitive(GeoDataTourPrimitive * primitive)57 void GeoDataPlaylist::addPrimitive( GeoDataTourPrimitive *primitive )
58 {
59 primitive->setParent( this );
60 m_primitives.push_back( primitive );
61 }
62
insertPrimitive(int position,GeoDataTourPrimitive * primitive)63 void GeoDataPlaylist::insertPrimitive( int position, GeoDataTourPrimitive *primitive )
64 {
65 primitive->setParent( this );
66 int const index = qBound( 0, position, m_primitives.size() );
67 m_primitives.insert( index, primitive );
68 }
69
removePrimitiveAt(int position)70 void GeoDataPlaylist::removePrimitiveAt(int position)
71 {
72 m_primitives.removeAt( position );
73 }
74
swapPrimitives(int positionA,int positionB)75 void GeoDataPlaylist::swapPrimitives( int positionA, int positionB )
76 {
77 if ( qMin( positionA, positionB ) >= 0 && qMax( positionA, positionB ) < m_primitives.size() ) {
78
79 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
80 m_primitives.swapItemsAt( positionA, positionB );
81 #else
82 m_primitives.swap( positionA, positionB );
83 #endif
84 }
85 }
86
size() const87 int GeoDataPlaylist::size() const
88 {
89 return m_primitives.size();
90 }
91
92 } // namespace Marble
93