Files
QTeletextMaker/pagebase.cpp

123 lines
2.8 KiB
C++
Raw Permalink Normal View History

2020-09-11 12:06:06 +01:00
/*
2022-12-31 21:19:15 +00:00
* Copyright (C) 2020-2023 Gavin MacGregor
2020-09-11 12:06:06 +01:00
*
* This file is part of QTeletextMaker.
*
* QTeletextMaker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QTeletextMaker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QTeletextMaker. If not, see <https://www.gnu.org/licenses/>.
*/
#include <QByteArray>
#include "pagebase.h"
PageBase::PageBase()
{
// We use nullptrs to keep track of allocated packets, so initialise them this way
2020-12-15 19:44:39 +00:00
for (int i=0; i<26; i++)
m_displayPackets[i] = nullptr;
for (int i=0; i<4; i++)
for (int j=0; j<16; j++)
m_designationPackets[i][j] = nullptr;
2020-09-11 12:06:06 +01:00
for (int i=PageBase::C4ErasePage; i<=PageBase::C14NOS; i++)
2020-12-15 19:44:39 +00:00
m_controlBits[i] = false;
2020-09-16 20:49:52 +01:00
}
2020-09-11 12:06:06 +01:00
PageBase::~PageBase()
{
2020-12-15 19:44:39 +00:00
for (int i=0; i<26; i++)
if (m_displayPackets[i] != nullptr)
delete m_displayPackets[i];
for (int i=0; i<4; i++)
for (int j=0; j<16; j++)
if (m_designationPackets[i][j] != nullptr)
delete m_designationPackets[i][j];
2020-09-11 12:06:06 +01:00
}
2020-12-06 17:57:05 +00:00
bool PageBase::isEmpty() const
{
2020-12-15 19:44:39 +00:00
for (int i=0; i<26; i++)
if (m_displayPackets[i] != nullptr)
2020-12-06 17:57:05 +00:00
return false;
2020-12-15 19:44:39 +00:00
for (int i=0; i<4; i++)
for (int j=0; j<16; j++)
if (m_designationPackets[i][j] != nullptr)
return false;
2020-12-06 17:57:05 +00:00
return true;
}
2020-12-15 19:44:39 +00:00
QByteArray PageBase::packet(int i) const
{
2020-12-15 19:44:39 +00:00
if (m_displayPackets[i] == nullptr)
return QByteArray(); // Blank result
2020-12-15 19:44:39 +00:00
return *m_displayPackets[i];
2020-09-16 20:49:52 +01:00
}
2020-12-15 19:44:39 +00:00
QByteArray PageBase::packet(int i, int j) const
2020-09-16 20:49:52 +01:00
{
2020-12-15 19:44:39 +00:00
if (m_designationPackets[i-26][j] == nullptr)
return QByteArray(); // Blank result
2020-09-16 20:49:52 +01:00
2020-12-15 19:44:39 +00:00
return *m_designationPackets[i-26][j];
}
2020-09-11 12:06:06 +01:00
2020-12-15 19:44:39 +00:00
bool PageBase::setPacket(int i, QByteArray packetContents)
2020-09-11 12:06:06 +01:00
{
2020-12-15 19:44:39 +00:00
if (m_displayPackets[i] == nullptr)
m_displayPackets[i] = new QByteArray(40, 0x00);
*m_displayPackets[i] = packetContents;
2020-12-15 19:44:39 +00:00
return true;
2020-09-16 20:49:52 +01:00
}
2020-12-15 19:44:39 +00:00
bool PageBase::setPacket(int i, int j, QByteArray packetContents)
2020-09-16 20:49:52 +01:00
{
2020-12-15 19:44:39 +00:00
if (m_designationPackets[i-26][j] == nullptr)
m_designationPackets[i-26][j] = new QByteArray(40, 0x00);
*m_designationPackets[i-26][j] = packetContents;
return true;
}
2020-12-15 19:44:39 +00:00
/*
2020-12-15 19:44:39 +00:00
bool PageBase::deletePacket(int i)
{
2020-12-15 19:44:39 +00:00
if (m_displayPackets[i] != nullptr) {
delete m_displayPackets[i];
m_displayPackets[i] = nullptr;
}
2020-09-16 20:49:52 +01:00
2020-12-15 19:44:39 +00:00
return true;
2020-09-16 20:49:52 +01:00
}
2020-12-15 19:44:39 +00:00
bool PageBase::deletePacket(int i)
2020-09-16 20:49:52 +01:00
{
2020-12-15 19:44:39 +00:00
if (m_designationPackets[i-26][j] != nullptr) {
delete m_designationPackets[i-26][j];
m_designationPackets[i-26][j] = nullptr;
}
2020-09-11 12:06:06 +01:00
return true;
}
*/
2020-12-15 19:44:39 +00:00
bool PageBase::setControlBit(int bitNumber, bool active)
{
m_controlBits[bitNumber] = active;
return true;
}