KItinerary

uic9183ticketlayout.h
1/*
2 SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "kitinerary_export.h"
10#include "uic9183block.h"
11#include "uic9183utils.h"
12
13#include <QExplicitlySharedDataPointer>
14#include <QMetaType>
15#include <QSize>
16
17
18namespace KItinerary {
19
20class Uic9183Block;
21class Uic9183TicketLayoutPrivate;
22
23/** Low-level field entries in a U_TLAY block.
24 * For most uses, the high-level API to retrieve assembled text (Uic9183TicketLayout::text())
25 * is probably preferable to this.
26 */
27class KITINERARY_EXPORT Uic9183TicketLayoutField
28{
29 Q_GADGET
30 UIC_NUM_PROPERTY(row, 0 + m_offset, 2)
31 UIC_NUM_PROPERTY(column, 2 + m_offset, 2)
32 UIC_NUM_PROPERTY(height, 4 + m_offset, 2)
33 UIC_NUM_PROPERTY(width, 6 + m_offset, 2)
34 UIC_NUM_PROPERTY(format, 8 + m_offset, 1)
35 /** Size of the text content. */
36 UIC_NUM_PROPERTY(size, 9 + m_offset, 4)
37 UIC_STR_PROPERTY(text, 13 + m_offset, size())
38
39 Q_PROPERTY(bool isNull READ isNull STORED false)
40 Q_PROPERTY(KItinerary::Uic9183TicketLayoutField next READ next STORED false)
41public:
43 /** Create a new U_TLAY field starting at @p offset in @p block.
44 * @param size The size of the remaining U_TLAY field array (not just this field!).
45 */
46 Uic9183TicketLayoutField(const Uic9183Block &block, int offset);
47
48 /** Returns @true if this is an empty field, e.g. when iterating beyond the last one. */
49 bool isNull() const;
50
51 /** Returns the next field object, or a null one if there isn't one. */
52 Uic9183TicketLayoutField next() const;
53
54private:
55 Uic9183Block m_data;
56 int m_offset;
57};
58
59
60/** Parser for a U_TLAY block in a UIC 918-3 ticket container, such as a ERA TLB ticket.
61 * @see ERA TAP TSI TD B.12 Digital Security Elements For Rail Passenger Ticketing - ยง10 TLB - Ticket Layout Barcode
62 */
63class KITINERARY_EXPORT Uic9183TicketLayout
64{
65 Q_GADGET
66 /** Ticket type (e.g. RCT2). */
67 Q_PROPERTY(QString type READ type)
68 Q_PROPERTY(QSize size READ size)
69 Q_PROPERTY(KItinerary::Uic9183TicketLayoutField firstField READ firstField STORED false)
70public:
72 /** Parse U_TLAY ticket layout block in @p data.
73 * It's the callers responsibility to ensure @p data outlives this instance, the data
74 * is not copied.
75 * @param block A UIC 918.3 U_TLAY data block
76 */
81
82 /** Returns whether this is a valid U_TLAY layout block. */
83 bool isValid() const;
84
85 /** Type of the ticket layout. */
86 QString type() const;
87
88 /** Returns the text in the given coordinates.
89 * @note @p row and @p column are 0-based unlike the U_TLAY spec, which is 1-based!
90 */
91 Q_INVOKABLE QString text(int row, int column, int width, int height) const;
92
93 /** The size of the layout, as width and height in layout coordinates. */
94 QSize size() const;
95
96 /** Low-level field iteration access.
97 * Prefer text() over this to avoid doing your own text layout assembly.
98 */
99 Uic9183TicketLayoutField firstField() const;
100
101 /** All fields covering the given area. */
102 std::vector<Uic9183TicketLayoutField> fields(int row, int column, int width, int height) const;
103 /** All fields contained in the given area. */
104 std::vector<Uic9183TicketLayoutField> containedFields(int row, int column, int width, int height) const;
105
106 static constexpr const char RecordId[] = "U_TLAY";
107private:
109};
110
111}
A data block from a UIC 918.3 ticket.
Low-level field entries in a U_TLAY block.
Parser for a U_TLAY block in a UIC 918-3 ticket container, such as a ERA TLB ticket.
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:28:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.