EHM DAL 0.2.3
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_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
45 // Child data
46 void addChildItem(const qint32 parent_row_id,
47 std::shared_ptr<ehm_dal::schema::AbstractTableItem> item,
48 const ehm_dal::tables::TableIndex child_table);
49 QVariant childData(const QModelIndex &index,
50 qint32 role,
52 const ehm_dal::tables::TableIndex child_table);
53 qint32 childItemId(const qint32 parent_row_id,
54 const ehm_dal::tables::TableIndex child_table) const;
55 virtual qint32 childRowCount(const qint32 parent_row_id,
56 const ehm_dal::tables::TableIndex child_table) const;
57 bool setChildData(const QModelIndex &index,
58 const QVariant &value,
59 const qint32 role,
60 std::vector<qint32> &modified_columns,
62 const ehm_dal::tables::TableIndex child_table);
63
64 // File i/o
70 bool read(QDataStream &in);
76 bool readData(QByteArray *data);
77
78 // Find data
85 ehm_dal::data_types::Pointer find(const qint32 value, const quint16 column);
95 const quint16 column,
96 const Qt::CaseSensitivity cs = Qt::CaseInsensitive);
106 const quint16 column,
107 const Qt::CaseSensitivity cs = Qt::CaseInsensitive);
114 std::vector<ehm_dal::data_types::Pointer> findAll(const qint32 value, const quint16 column);
123 std::vector<ehm_dal::data_types::Pointer> findAll(
124 const QString &text,
125 const quint16 column,
126 const Qt::CaseSensitivity cs = Qt::CaseInsensitive);
135 std::vector<ehm_dal::data_types::Pointer> findAllContains(
136 const QString &text,
137 const quint16 column,
138 const Qt::CaseSensitivity cs = Qt::CaseInsensitive);
139
140 // Get data
147 QVariant data(const QModelIndex &index, qint32 role = Qt::DisplayRole) const override;
148 bool isValidRow(const qint32 row_id) const;
149 QString text(const qint32 row) const;
150
151 // Get data - counts
157 qint32 rowCount(const QModelIndex &parent = QModelIndex()) const override;
158
159 // Get data - pointers
165 std::shared_ptr<ehm_dal::schema::AbstractTableItem> pointer(const qint32 row);
166
167 // Get data - table attributes
168 const TableAttributes *attributes() const { return &table_attributes_; }
169
170 // Initialisation
175 bool init();
176
177 // Move data
178 //bool moveRow(const QModelIndex &sourceParent, qint32 source_row, const QModelIndex &destination_parent, qint32 destination_child) override;
179 bool moveRows(const QModelIndex &source_parent,
180 qint32 source_row,
181 qint32 count,
182 const QModelIndex &destination_parent,
183 qint32 destination_child) override;
184
185 // Parent table
186 enum class ParentTableRelationshipType : qint8 {
187 TableDoesNotHaveAnyParent,
188 ParentTableHasChildIdField,
189 ChildTableHasParentIdField
190 };
191 qint32 parentRowId(const QModelIndex &index) const;
192 inline virtual std::shared_ptr<ehm_dal::tables::AbstractTable> parentTable() const
193 {
194 return nullptr;
195 }
196 inline virtual ParentTableRelationshipType parentTableRelationship() const
197 {
198 return ParentTableRelationshipType::TableDoesNotHaveAnyParent;
199 }
200 inline virtual void setParentTable(
201 const std::shared_ptr<ehm_dal::tables::AbstractTable> parent_table,
202 const ParentTableRelationshipType relationship)
203 {
204 Q_UNUSED(parent_table)
205 Q_UNUSED(relationship)
206 return;
207 }
208
209 // Remove data
210 bool removeRows(qint32 row, qint32 count, const QModelIndex &parent = QModelIndex()) override;
211
212 // Set data
213 bool setData(const QModelIndex &index,
214 const QVariant &value,
215 qint32 role = Qt::EditRole) override;
216
217protected:
218 // Table data
219 TableAttributes table_attributes_;
220 std::vector<std::shared_ptr<ehm_dal::schema::AbstractTableItem>> data_;
221
222private:
223 bool is_initialised_{false};
224
230 virtual bool readStream(QDataStream &in) = 0;
231};
232
233} // namespace ehm_dal::tables
234
235
The ColumnData class represents a container of ehm_dal::column_data::Column and attributes relating t...
Definition: column_data.h:18
The Pointer class represents a pointer to a table item.
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
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...
std::shared_ptr< ehm_dal::schema::AbstractTableItem > pointer(const qint32 row)
Returns a shared pointer to the selected row of the table.
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...
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())
Constructs a new database table.
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).
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