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"
16#include <QAbstractTableModel>
40 const QString &table_name,
46 void addChildItem(
const qint32 parent_row_id,
47 std::shared_ptr<ehm_dal::schema::AbstractTableItem> item,
49 QVariant childData(
const QModelIndex &index,
53 qint32 childItemId(
const qint32 parent_row_id,
55 virtual qint32 childRowCount(
const qint32 parent_row_id,
57 bool setChildData(
const QModelIndex &index,
58 const QVariant &value,
60 std::vector<qint32> &modified_columns,
70 bool read(QDataStream &in);
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(
125 const quint16 column,
126 const Qt::CaseSensitivity cs = Qt::CaseInsensitive);
137 const quint16 column,
138 const Qt::CaseSensitivity cs = Qt::CaseInsensitive);
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;
157 qint32
rowCount(
const QModelIndex &parent = QModelIndex())
const override;
165 std::shared_ptr<ehm_dal::schema::AbstractTableItem>
pointer(
const qint32 row);
168 const TableAttributes *attributes()
const {
return &table_attributes_; }
179 bool moveRows(
const QModelIndex &source_parent,
182 const QModelIndex &destination_parent,
183 qint32 destination_child)
override;
186 enum class ParentTableRelationshipType : qint8 {
187 TableDoesNotHaveAnyParent,
188 ParentTableHasChildIdField,
189 ChildTableHasParentIdField
191 qint32 parentRowId(
const QModelIndex &index)
const;
192 inline virtual std::shared_ptr<ehm_dal::tables::AbstractTable> parentTable()
const
196 inline virtual ParentTableRelationshipType parentTableRelationship()
const
198 return ParentTableRelationshipType::TableDoesNotHaveAnyParent;
200 inline virtual void setParentTable(
201 const std::shared_ptr<ehm_dal::tables::AbstractTable> parent_table,
202 const ParentTableRelationshipType relationship)
204 Q_UNUSED(parent_table)
205 Q_UNUSED(relationship)
210 bool removeRows(qint32 row, qint32 count,
const QModelIndex &parent = QModelIndex())
override;
213 bool setData(
const QModelIndex &index,
214 const QVariant &value,
215 qint32 role = Qt::EditRole)
override;
219 TableAttributes table_attributes_;
220 std::vector<std::shared_ptr<ehm_dal::schema::AbstractTableItem>> data_;
223 bool is_initialised_{
false};
230 virtual bool readStream(QDataStream &in) = 0;
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