File indexing completed on 2024-12-22 04:40:14

0001 /*
0002     SPDX-FileCopyrightText: 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar>
0003     SPDX-FileCopyrightText: 2010-2022 Mladen Milinkovic <max@smoothware.net>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "scripting_list.h"
0009 
0010 using namespace SubtitleComposer;
0011 
0012 Scripting::List::List(const char *contentClass, QObject *parent) :
0013     QObject(parent),
0014     m_contentClass(contentClass)
0015 {}
0016 
0017 Scripting::List::List(const QObjectList &backend, const char *contentClass, QObject *parent) :
0018     QObject(parent),
0019     m_contentClass(contentClass),
0020     m_backend(backend)
0021 {}
0022 
0023 bool
0024 Scripting::List::isEmpty() const
0025 {
0026     return m_backend.isEmpty();
0027 }
0028 
0029 int
0030 Scripting::List::length() const
0031 {
0032     return m_backend.count();
0033 }
0034 
0035 int
0036 Scripting::List::count() const
0037 {
0038     return m_backend.count();
0039 }
0040 
0041 int
0042 Scripting::List::size() const
0043 {
0044     return m_backend.size();
0045 }
0046 
0047 QObject *
0048 Scripting::List::at(int index) const
0049 {
0050     if(index < 0 || index >= m_backend.count())
0051         return 0;
0052     return m_backend.at(index);
0053 }
0054 
0055 void
0056 Scripting::List::insert(int index, QObject *object)
0057 {
0058     if(!object || index < 0 || index > m_backend.count() || strcmp(object->metaObject()->className(), m_contentClass))
0059         return;
0060     m_backend.insert(index, object);
0061 }
0062 
0063 void
0064 Scripting::List::append(QObject *object)
0065 {
0066     if(!object || strcmp(object->metaObject()->className(), m_contentClass))
0067         return;
0068     m_backend.append(object);
0069 }
0070 
0071 void
0072 Scripting::List::prepend(QObject *object)
0073 {
0074     if(object && !strcmp(object->metaObject()->className(), m_contentClass))
0075         m_backend.prepend(object);
0076 }
0077 
0078 void
0079 Scripting::List::removeFirst()
0080 {
0081     if(!m_backend.isEmpty())
0082         return m_backend.removeFirst();
0083 }
0084 
0085 void
0086 Scripting::List::removeLast()
0087 {
0088     if(!m_backend.isEmpty())
0089         m_backend.removeLast();
0090 }
0091 
0092 void
0093 Scripting::List::removeAt(int index)
0094 {
0095     if(index >= 0 && index < m_backend.count())
0096         m_backend.removeAt(index);
0097 }
0098 
0099 void
0100 Scripting::List::clear()
0101 {
0102     m_backend.clear();
0103 }
0104 
0105