EHM DAL 0.2.3
Data abstraction layer for Eastside Hockey Manager
Loading...
Searching...
No Matches
pointer.h
1#pragma once
2
3// Application headers
4#include "include/database/pointer/pointer_flags.h"
5#include "include/database/pointer/private/abstract_pointer.h"
6#include "include/tables/abstract_table.h"
7#include "include/tables/table_index.h"
8
9// Qt headers
10class QDataStream;
11#include <memory>
12
13namespace ehm_dal::data_types {
14
15// --- Database/AbstractTableItem record pointer --- //
20 AbstractPointer<qint32, ehm_dal::tables::TableIndex, ehm_dal::tables::AbstractTable>
21{
22public:
23 Pointer();
25 const qint32 record_id = PointerFlags::NULL_POINTER);
26 virtual ~Pointer();
27
28 // File i/o
33 void readFromShort(QDataStream &in);
38 void writeToShort(QDataStream &out) const;
39
40 // Get data - pointer
42 QVariant data(const qint32 column, qint32 role) const override;
43 qint32 id() const override;
44 QString text() const override;
45
46 // Get data - table
47 std::shared_ptr<ehm_dal::tables::AbstractTable> constTable() const override;
48 std::shared_ptr<ehm_dal::tables::AbstractTable> table() override;
49
50 // Initialisation
55 virtual void init();
56
57 // Set data
58 void setData(const QVariant &value, const qint32 role) override;
59
60private:
61 std::weak_ptr<ehm_dal::schema::AbstractTableItem> ptr_;
62
63 // File i/o
64 friend QDataStream &operator>>(QDataStream &in, Pointer &data);
65 friend QDataStream &operator<<(QDataStream &out, const Pointer &data);
66
67 // Initialisation
68 void initPointer();
69};
70
71// File i/o
72QDataStream &operator>>(QDataStream &in, Pointer &data);
73QDataStream &operator<<(QDataStream &out, const Pointer &data);
74
75} // namespace ehm_dal::data_types
76
77
The AbstractPointer class represents a pointer to a table item.
Definition: abstract_pointer.h:19
QVariant data(const qint32 role) const
Returns the data stored under the given role. Qt::DisplayRole returns the item's display text and Qt:...
Definition: abstract_pointer.h:180
The Pointer class represents a pointer to a table item.
Definition: pointer.h:21
void readFromShort(QDataStream &in)
Reads a qint16 as the Pointer value.
virtual void init()
Initialise/connect the Pointer to the item to be pointed to. This need only be done once.
void writeToShort(QDataStream &out) const
Writes the Pointer value as a qint16.
namespace ehm_dal::data_types
Definition: attribute.h:6
@ NULL_POINTER
Definition: pointer_flags.h:9
TableIndex
The TableIndex enum represents the id number of each table within the database.
Definition: table_index.h:14