EHM DAL 0.2.5
Data abstraction layer for Eastside Hockey Manager
Loading...
Searching...
No Matches
abstract_id_table_item.h
1#pragma once
2
3// Application headers
4#include "include/schema/abstract_table_item.h"
5
6namespace ehm_dal::column_data {
7class ColumnData;
8}
9namespace ehm_dal::tables {
10enum class TableIndex : char;
11}
12
13// Qt headers
14class QDataStream;
15class QModelIndex;
16#include <QString>
17#include <QVariant>
18
19namespace ehm_dal::schema {
20
21// -- Table item/record --- //
26{
27public:
36
37 // Child data
44 virtual void addChildItem(std::shared_ptr<AbstractIdTableItem> item,
45 const ehm_dal::tables::TableIndex child_table);
54 virtual QVariant childData(const QModelIndex &index,
55 qint32 role,
57 const ehm_dal::tables::TableIndex child_table) const;
62 virtual qint32 childItemId(const ehm_dal::tables::TableIndex child_table) const;
67 virtual qint32 childRowCount(const ehm_dal::tables::TableIndex child_table) const;
78 virtual bool setChildData(const QModelIndex &index,
79 const QVariant &value,
80 const qint32 role,
81 std::vector<qint32> &modified_columns,
83 const ehm_dal::tables::TableIndex child_table);
84
85 // Get data - item attributes
90 inline qint32 id() const { return id_; }
97 QVariant id(const qint32 role);
102 virtual QString text() const = 0;
103 Q_DECL_DEPRECATED QString displayText() const { return text(); } // TODO to be deprecated
108 virtual qint32 uid() const;
109
110 // Get data
117 QVariant data(const qint32 column,
118 qint32 role,
119 ehm_dal::column_data::ColumnData *column_data) const;
126 virtual QVariant data(const QModelIndex &index,
127 qint32 role,
128 ehm_dal::column_data::ColumnData *column_data) const;
129
130 // Identifier
134 virtual QString identifier() const;
139 virtual QStringList identifierList() const;
140 // TODO implement
141 /*QString personIdentifier(const QString &first_name,
142 const QString &second_name,
143 const Date &date_of_birth) const;
144 QStringList personIdentifierList(const QString &first_name,
145 const QString &second_name,
146 const Date &date_of_birth,
147 const Year &year_of_birth) const;*/
148
149 // Initialisation
156 bool alloc(const qint32 new_id);
157
158 // Parent data
162 virtual qint32 parentItemId() const;
163
164 // Set data
174 bool setData(const qint32 column,
175 const QVariant &value,
176 qint32 role,
177 std::vector<qint32> &modified_columns,
188 virtual bool setData(const QModelIndex &index,
189 const QVariant &value,
190 qint32 role,
191 std::vector<qint32> &modified_columns,
193
194 // Validation
198 virtual void fixErrors() { return; }
199
200protected:
201 // Item attributes
202 qint32 id_; // Record id
203
204 // Operator overloading (Data stream)
205 // This is solely for the purposes of reading/writing the record id for child items
206 friend QDataStream &operator>>(QDataStream &in, AbstractIdTableItem &data);
207 friend QDataStream &operator<<(QDataStream &out, const AbstractIdTableItem &data);
208
209private:
210 // Get data
211 virtual QVariant internalData(const qint32 column, const qint32 role) const = 0;
212
213 // Set data
214 virtual bool setInternalData(const qint32 column,
215 const QVariant &value,
216 const qint32 role,
217 std::vector<qint32> &modified_columns);
218};
219
220// File i/o
221QDataStream &operator>>(QDataStream &in, ehm_dal::schema::AbstractIdTableItem &data);
222QDataStream &operator<<(QDataStream &out, const ehm_dal::schema::AbstractIdTableItem &data);
223
224} // namespace ehm_dal::schema
The ColumnData class represents a container of ehm_dal::column_data::Column and attributes relating t...
Definition: column_data.h:19
The AbstractIdTableItem class represents a row in a Table with an id field.
Definition: abstract_id_table_item.h:26
virtual qint32 uid() const
Returns the row's unique database id. Not all tables use a uid.
qint32 id() const
Returns the row id. The first row of a table is 0, the second row is 1, etc.
Definition: abstract_id_table_item.h:90
virtual qint32 childItemId(const ehm_dal::tables::TableIndex child_table) const
Returns the item id number for the child data under the related child_table.
virtual void fixErrors()
Fixes any known errors with the item. E.g. errors introduced with a prior version of EHM DAL or the E...
Definition: abstract_id_table_item.h:198
virtual qint32 childRowCount(const ehm_dal::tables::TableIndex child_table) const
Returns the number of related child items in respect of child_table.
virtual qint32 parentItemId() const
Returns the item id of the items parent item. Applies to tree structures only.
virtual QVariant childData(const QModelIndex &index, qint32 role, ehm_dal::column_data::ColumnData *column_data, const ehm_dal::tables::TableIndex child_table) const
Returns child data stored under the given role for the selected index.
QVariant id(const qint32 role)
Returns the row id in a manner compatible with QAbstractTableModel item roles. This is generally unec...
QVariant data(const qint32 column, qint32 role, ehm_dal::column_data::ColumnData *column_data) const
Returns the row's data stored under the given role for the column.
virtual QStringList identifierList() const
Returns a list of all of the item's identifiers for matching against. This includes the main identifi...
bool setData(const qint32 column, const QVariant &value, qint32 role, std::vector< qint32 > &modified_columns, ehm_dal::column_data::ColumnData *column_data)
Sets the role data for the item at column to value.
virtual bool setData(const QModelIndex &index, const QVariant &value, qint32 role, std::vector< qint32 > &modified_columns, ehm_dal::column_data::ColumnData *column_data)
Sets the role data for the item at index to value.
virtual QString text() const =0
Returns the row's display text. This provides a convenient way to obtain a simple description of the ...
virtual QString identifier() const
Returns the item's text identifier for matching against.
virtual QVariant data(const QModelIndex &index, qint32 role, ehm_dal::column_data::ColumnData *column_data) const
Returns the row's data stored under the given role for the column referred to by the index.
bool alloc(const qint32 new_id)
Initialises the table item and allocates and item id to new_id and a uid (if applicable) and then cal...
virtual void addChildItem(std::shared_ptr< AbstractIdTableItem > item, const ehm_dal::tables::TableIndex child_table)
Adds the child item item from the child_table to the present tree table. This represents a tree relat...
virtual ~AbstractIdTableItem()
Default destructor.
virtual bool setChildData(const QModelIndex &index, const QVariant &value, const qint32 role, std::vector< qint32 > &modified_columns, ehm_dal::column_data::ColumnData *column_data, const ehm_dal::tables::TableIndex child_table)
Sets the role data for the child item at index to value.
AbstractIdTableItem()
Default constructor.
The AbstractTableItem class represents a row in a Table with no primary key (id/uid) field.
Definition: abstract_table_item.h:23
namespace ehm_dal::tables
Definition: column.h:4
TableIndex
The TableIndex enum represents the id number of each table within the database.
Definition: table_index.h:14