7#include "uic9183ticketlayout.h"
19class Uic9183TicketLayoutPrivate :
public QSharedData
31Uic9183TicketLayoutField::Uic9183TicketLayoutField() =
default;
40Uic9183TicketLayoutField::Uic9183TicketLayoutField(
const Uic9183Block &block,
int offset)
43 const auto remainingSize = block.
contentSize() - offset;
44 if (remainingSize <= FieldHeaderSize) {
45 qCWarning(
Log) <<
"Found too small U_TLAY field:" << remainingSize;
50 if (!std::all_of(block.
content() + offset, block.
content() + offset + 8, isdigit)
51 || !std::all_of(block.
content() + offset + 9, block.
content() + offset + FieldHeaderSize, isdigit)) {
52 qCWarning(Log) <<
"Found U_TLAY field with invalid format";
57 const auto fieldSize = Uic9183Utils::readAsciiEncodedNumber(block, offset + 9, 4) + FieldHeaderSize;
59 qCWarning(Log) <<
"Found U_TLAY field with invalid size" << fieldSize << block.size();
73 const auto thisSize = size() + FieldHeaderSize;
74 const auto remaining = m_data.
contentSize() - thisSize - m_offset;
82 for (
int i = 0; i < remaining - FieldHeaderSize; ++i) {
94 const auto contentSize = d->block.contentSize();
95 if (contentSize > 8) {
106Uic9183TicketLayout::Uic9183TicketLayout()
107 : d(new Uic9183TicketLayoutPrivate)
112 : d(new Uic9183TicketLayoutPrivate)
117 std::vector<QString> out;
118 for (
auto f = d->firstField(); !f.isNull(); f = f.next()) {
119 qDebug() <<
"Field:" << f.row() << f.column() << f.width() << f.height() << f.text() << f.size();
120 out.resize(std::max<int>(f.row() + 1, out.size()));
121 out[f.row()].resize(std::max(out[f.row()].size(), f.column() + f.width() + 1), QLatin1Char(
' '));
122 out[f.row()].replace(f.column(), f.width(), f.text());
124 for (
const auto &line : out) {
131Uic9183TicketLayout::~Uic9183TicketLayout() =
default;
136 return Uic9183Utils::readUtf8String(d->block, 0, 4);
141 return !d->block.isNull() && d->block.contentSize() > 8 && d->block.version() == 1;
148 for (
int i = 0; i < height; ++i) {
152 for (
auto f = firstField(); !f.
isNull(); f = f.next()) {
154 const auto effectiveHeight = std::max(f.height(), 1);
155 if (f.row() + effectiveHeight - 1 < row || f.row() > row + height - 1) {
158 const auto effectiveFieldWidth = f.width() > 0 ? f.width() : f.size();
159 if (f.column() + effectiveFieldWidth - 1 < column || f.column() > column + width - 1) {
165 const auto content = f.text();
168 for (
int i = 0; i < lines.size(); ++i) {
169 if (f.row() + i < row) {
172 if (f.row() + i > row + height - 1) {
177 const auto offset = column - f.column();
179 s[f.row() + i - row] += lines.
at(i).mid(offset).left(width);
182 s[f.row() + i - row] += lines.
at(i);
190QSize Uic9183TicketLayout::size()
const
194 for (
auto f = firstField(); !f.
isNull(); f = f.next()) {
195 width = std::max(width, f.column() + f.width());
196 height = std::max(height, f.row() + std::max(1, f.height()));
198 return QSize(width, height);
203 std::vector<Uic9183TicketLayoutField> result;
204 for (
auto f = firstField(); !f.
isNull(); f = f.next()) {
206 const auto effectiveHeight = std::max(f.height(), 1);
207 if (f.row() + effectiveHeight - 1 < row || f.row() > row + height - 1) {
210 const auto effectiveFieldWidth = f.width() > 0 ? f.width() : f.size();
211 if (f.column() + effectiveFieldWidth - 1 < column || f.column() > column + width - 1) {
221 std::vector<Uic9183TicketLayoutField> result;
222 for (
auto f = firstField(); !f.
isNull(); f = f.next()) {
224 const auto effectiveHeight = std::max(f.height(), 1);
225 if (f.row() + effectiveHeight - 1 > row + height - 1 || f.row() < row ) {
228 const auto effectiveFieldWidth = f.width() > 0 ? f.width() : f.size();
229 if (f.column() + effectiveFieldWidth - 1 > column + width + 1 || f.column() < column) {
237#include "moc_uic9183ticketlayout.cpp"
A data block from a UIC 918.3 ticket.
int contentSize() const
Returns the size of the content data.
bool isNull() const
Checks if the block is valid or empty/default constructed.
const char * content() const
Returns the payload data (not including the block header).
Low-level field entries in a U_TLAY block.
bool isNull
Size of the text content.
Parser for a U_TLAY block in a UIC 918-3 ticket container, such as a ERA TLB ticket.
QString type
Ticket type (e.g.
bool isValid() const
Returns whether this is a valid U_TLAY layout block.
std::vector< Uic9183TicketLayoutField > fields(int row, int column, int width, int height) const
All fields covering the given area.
std::vector< Uic9183TicketLayoutField > containedFields(int row, int column, int width, int height) const
All fields contained in the given area.
Q_INVOKABLE QString text(int row, int column, int width, int height) const
Returns the text in the given coordinates.
Classes for reservation/travel data models, data extraction and data augmentation.
const_reference at(qsizetype i) const const
void push_back(parameter_type value)
void reserve(qsizetype size)
QString join(QChar separator) const const
QList< QStringView > split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const