EHM DAL 0.2.5
Data abstraction layer for Eastside Hockey Manager
Loading...
Searching...
No Matches
abstract_table.h
1#pragma once
2
3// Application headers
4#include "include/schema/abstract_id_table_item.h"
5#include "include/tables/private/abstract_base_model.h"
6#include "include/tables/table_attributes.h"
7#include "include/tables/table_index.h"
8#include "include/tables/table_type.h"
9
10// Application headers
11namespace ehm_dal::data_types {
12class Pointer;
13}
14
15// Qt headers
16#include <QAbstractTableModel>
17#include <QString>
18#include <memory>
19#include <vector>
20
21namespace ehm_dal::tables {
22
23// --- Table base class --- //
29{
30 // NOTE: Insert rows, delete rows and move rows functions are entirely untested
31public:
40 const QString &table_name,
41 const ehm_dal::tables::TableIndex table_id,
42 const ehm_dal::tables::TableType table_type,
44 const qint16 minimum_supported_database_version = TableAttributes::NO_DATABASE_VERSION);
45
46 // Child data
47 void addChildItem(const qint32 parent_row_id,
48 std::shared_ptr<ehm_dal::schema::AbstractIdTableItem> item,
49 const ehm_dal::tables::TableIndex child_table);
50 QVariant childData(const QModelIndex &index,
51 qint32 role,
53 const ehm_dal::tables::TableIndex child_table);
54 qint32 childItemId(const qint32 parent_row_id,
55 const ehm_dal::tables::TableIndex child_table) const;
56 virtual qint32 childRowCount(const qint32 parent_row_id,
57 const ehm_dal::tables::TableIndex child_table) const;
58 bool setChildData(const QModelIndex &index,
59 const QVariant &value,
60 const qint32 role,
61 std::vector<qint32> &modified_columns,
63 const ehm_dal::tables::TableIndex child_table);
64
65 // File i/o
71 bool read(QDataStream &in);
77 bool readData(QByteArray *data);
78
79 // Find data
86 ehm_dal::data_types::Pointer find(const qint32 value, const quint16 column);
96 const quint16 column,
97 const Qt::CaseSensitivity cs = Qt::CaseInsensitive);
107 const quint16 column,
108 const Qt::CaseSensitivity cs = Qt::CaseInsensitive);
115 std::vector<ehm_dal::data_types::Pointer> findAll(const qint32 value, const quint16 column);
124 std::vector<ehm_dal::data_types::Pointer> findAll(
125 const QString &text,
126 const quint16 column,
127 const Qt::CaseSensitivity cs = Qt::CaseInsensitive);
136 std::vector<ehm_dal::data_types::Pointer> findAllContains(
137 const QString &text,
138 const quint16 column,
139 const Qt::CaseSensitivity cs = Qt::CaseInsensitive);
140
141 // Get data
148 QVariant data(const QModelIndex &index, qint32 role = Qt::DisplayRole) const override;
149 bool isValidRow(const qint32 row_id) const;
150 QString text(const qint32 row) const;
151
152 // Get data - counts
158 qint32 rowCount(const QModelIndex &parent = QModelIndex()) const override;
159
160 // Get data - pointers
166 std::shared_ptr<ehm_dal::schema::AbstractIdTableItem> pointer(const qint32 row);
167
168 // Get data - table attributes
169 const TableAttributes *attributes() const { return &table_attributes_; }
170
171 // Initialisation
176 bool init();
177
178 // Move data
179 //bool moveRow(const QModelIndex &sourceParent, qint32 source_row, const QModelIndex &destination_parent, qint32 destination_child) override;
180 bool moveRows(const QModelIndex &source_parent,
181 qint32 source_row,
182 qint32 count,
183 const QModelIndex &destination_parent,
184 qint32 destination_child) override;
185
186 // Parent table
187 enum class ParentTableRelationshipType : qint8 {
188 TableDoesNotHaveAnyParent,
189 ParentTableHasChildIdField,
190 ChildTableHasParentIdField
191 };
192 qint32 parentRowId(const QModelIndex &index) const;
193 inline virtual std::shared_ptr<ehm_dal::tables::AbstractTable> parentTable() const
194 {
195 return nullptr;
196 }
197 inline virtual ParentTableRelationshipType parentTableRelationship() const
198 {
199 return ParentTableRelationshipType::TableDoesNotHaveAnyParent;
200 }
201 inline virtual void setParentTable(
202 const std::shared_ptr<ehm_dal::tables::AbstractTable> parent_table,
203 const ParentTableRelationshipType relationship)
204 {
205 Q_UNUSED(parent_table)
206 Q_UNUSED(relationship)
207 return;
208 }
209
210 // Remove data
211 bool clearAll();
212 bool removeRows(qint32 row, qint32 count, const QModelIndex &parent = QModelIndex()) override;
213
214 // Set data
215 bool setData(const QModelIndex &index,
216 const QVariant &value,
217 qint32 role = Qt::EditRole) override;
218
219protected:
220 // Table data
221 TableAttributes table_attributes_;
222 std::vector<std::shared_ptr<ehm_dal::schema::AbstractIdTableItem>> data_;
223
224private:
225 bool is_initialised_{false};
226
232 virtual bool readStream(QDataStream &in) = 0;
233};
234
235} // namespace ehm_dal::tables
236
237
The ColumnData class represents a container of ehm_dal::column_data::Column and attributes relating t...
Definition: column_data.h:19
The Pointer class represents a pointer to a table item based on ID.
Definition: pointer.h:21
Definition: abstract_base_model.h:15
The Table class represents a database table and provides access to rows of data.
Definition: abstract_table.h:29
std::shared_ptr< ehm_dal::schema::AbstractIdTableItem > pointer(const qint32 row)
Returns a shared pointer to the selected row of the table.
bool init()
Initialises the table.
std::vector< ehm_dal::data_types::Pointer > findAll(const qint32 value, const quint16 column)
Finds all rows which have a value in the chosen column matching value.
std::vector< ehm_dal::data_types::Pointer > findAllContains(const QString &text, const quint16 column, const Qt::CaseSensitivity cs=Qt::CaseInsensitive)
Finds all rows which have text in the chosen column containing text. This function performs a sub-str...
ehm_dal::data_types::Pointer findContains(const QString &text, const quint16 column, const Qt::CaseSensitivity cs=Qt::CaseInsensitive)
Finds the first row which has text in the chosen column containing text. This function performs a sub...
std::vector< ehm_dal::data_types::Pointer > findAll(const QString &text, const quint16 column, const Qt::CaseSensitivity cs=Qt::CaseInsensitive)
Finds all rows which have text in the chosen column exactly matching text. The entirety of the string...
qint32 rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows in the table.
ehm_dal::data_types::Pointer find(const qint32 value, const quint16 column)
Finds the first row which has a value in the chosen column matching value.
ehm_dal::data_types::Pointer find(const QString &text, const quint16 column, const Qt::CaseSensitivity cs=Qt::CaseInsensitive)
Finds the first row which has text in the chosen column exactly matching text. The entirety of the st...
QVariant data(const QModelIndex &index, qint32 role=Qt::DisplayRole) const override
Returns the data stored under the given role for the item referred to by the index.
bool read(QDataStream &in)
Reads the table data from a QDataStream (wrapper for AbstractTable::readStream).
AbstractTable(const QString &table_name, const ehm_dal::tables::TableIndex table_id, const ehm_dal::tables::TableType table_type, ehm_dal::column_data::ColumnData *column_data=new ehm_dal::column_data::ColumnData(), const qint16 minimum_supported_database_version=TableAttributes::NO_DATABASE_VERSION)
Constructs a new database table.
bool readData(QByteArray *data)
Reads the table data from a QByteArray.
Definition: table_attributes.h:13
namespace ehm_dal::data_types
Definition: attribute.h:6
namespace ehm_dal::tables
Definition: column.h:4
TableType
The TableType enum denotes different types of database table.
Definition: table_type.h:12
TableIndex
The TableIndex enum represents the id number of each table within the database.
Definition: table_index.h:14