File indexing completed on 2024-06-23 08:47:21

0001 /*
0002     SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "viewstable.h"
0007 
0008 #include <QDebug>
0009 
0010 namespace Latte {
0011 namespace Data {
0012 
0013 const char *TEMPIDPREFIX = "temp:";
0014 
0015 ViewsTable::ViewsTable()
0016     : GenericTable<View>()
0017 {
0018 }
0019 
0020 ViewsTable::ViewsTable(ViewsTable &&o)
0021     : GenericTable<View>(o),
0022       isInitialized(o.isInitialized)
0023 {
0024 
0025 }
0026 
0027 ViewsTable::ViewsTable(const ViewsTable &o)
0028     : GenericTable<View>(o),
0029       isInitialized(o.isInitialized)
0030 {
0031 }
0032 
0033 //! Operators
0034 ViewsTable &ViewsTable::operator=(const ViewsTable &rhs)
0035 {
0036     m_list = rhs.m_list;
0037     isInitialized = rhs.isInitialized;
0038     return (*this);
0039 }
0040 
0041 ViewsTable &ViewsTable::operator=(ViewsTable &&rhs)
0042 {
0043     m_list = rhs.m_list;
0044     isInitialized = rhs.isInitialized;
0045     return (*this);
0046 }
0047 
0048 bool ViewsTable::operator==(const ViewsTable &rhs) const
0049 {
0050     GenericTable<View> tempView = (*this);
0051 
0052     return (isInitialized == rhs.isInitialized)
0053             && (((GenericTable<View>)*this) == ((GenericTable<View>)rhs));
0054 }
0055 
0056 bool ViewsTable::operator!=(const ViewsTable &rhs) const
0057 {
0058     return !(*this == rhs);
0059 }
0060 
0061 bool ViewsTable::hasContainmentId(const QString &cid) const
0062 {
0063     if (containsId(cid)) {
0064         return true;
0065     }
0066 
0067     for(int i=0; i<rowCount(); ++i) {
0068         if (m_list[i].subcontainments.containsId(cid)) {
0069             return true;
0070         }
0071     }
0072 
0073     return false;
0074 }
0075 
0076 ViewsTable ViewsTable::subtracted(const ViewsTable &rhs) const
0077 {
0078     ViewsTable subtract;
0079 
0080     if ((*this) == rhs) {
0081         return subtract;
0082     }
0083 
0084     for(int i=0; i<m_list.count(); ++i) {
0085         if (!rhs.containsId(m_list[i].id)) {
0086             subtract << m_list[i];
0087         }
0088     }
0089 
0090     return subtract;
0091 }
0092 
0093 ViewsTable ViewsTable::onlyOriginals() const
0094 {
0095     ViewsTable originals;
0096 
0097     for(int i=0; i<m_list.count(); ++i) {
0098         if (m_list[i].isOriginal()) {
0099             originals << m_list[i];
0100         }
0101     }
0102 
0103     return originals;
0104 }
0105 
0106 void ViewsTable::appendTemporaryView(const Data::View &view)
0107 {
0108     int maxTempId = 0;
0109 
0110     for(int i=0; i<rowCount(); ++i) {
0111         if ((*this)[i].id.startsWith(TEMPIDPREFIX)) {
0112             QString tid = (*this)[i].id;
0113             tid.remove(0, QString(TEMPIDPREFIX).count());
0114             if (tid.toInt() > maxTempId) {
0115                 maxTempId = tid.toInt();
0116             }
0117         }
0118     }
0119 
0120     Data::View newview = view;
0121     newview.id =  QString(TEMPIDPREFIX + QString::number(maxTempId+1));
0122     m_list << newview;
0123 }
0124 
0125 void ViewsTable::print()
0126 {
0127     qDebug().noquote() << "Views initialized : " + (isInitialized ? QString("true") : QString("false"));
0128     qDebug().noquote() << "aa | id | active | primary | screen | edge | alignment | maxlength | subcontainments";
0129 
0130     for(int i=0; i<rowCount(); ++i) {
0131         qDebug().noquote() << QString::number(i+1) << " | " << m_list[i];
0132     }
0133 }
0134 
0135 }
0136 }