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"
16#include <QAbstractTableModel>
40 const QString &table_name,
44 const qint16 minimum_supported_database_version = TableAttributes::NO_DATABASE_VERSION);
47 void addChildItem(
const qint32 parent_row_id,
48 std::shared_ptr<ehm_dal::schema::AbstractIdTableItem> item,
50 QVariant childData(
const QModelIndex &index,
54 qint32 childItemId(
const qint32 parent_row_id,
56 virtual qint32 childRowCount(
const qint32 parent_row_id,
58 bool setChildData(
const QModelIndex &index,
59 const QVariant &value,
61 std::vector<qint32> &modified_columns,
71 bool read(QDataStream &in);
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(
126 const quint16 column,
127 const Qt::CaseSensitivity cs = Qt::CaseInsensitive);
138 const quint16 column,
139 const Qt::CaseSensitivity cs = Qt::CaseInsensitive);
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;
158 qint32
rowCount(
const QModelIndex &parent = QModelIndex())
const override;
166 std::shared_ptr<ehm_dal::schema::AbstractIdTableItem>
pointer(
const qint32 row);
169 const TableAttributes *attributes()
const {
return &table_attributes_; }
180 bool moveRows(
const QModelIndex &source_parent,
183 const QModelIndex &destination_parent,
184 qint32 destination_child)
override;
187 enum class ParentTableRelationshipType : qint8 {
188 TableDoesNotHaveAnyParent,
189 ParentTableHasChildIdField,
190 ChildTableHasParentIdField
192 qint32 parentRowId(
const QModelIndex &index)
const;
193 inline virtual std::shared_ptr<ehm_dal::tables::AbstractTable> parentTable()
const
197 inline virtual ParentTableRelationshipType parentTableRelationship()
const
199 return ParentTableRelationshipType::TableDoesNotHaveAnyParent;
201 inline virtual void setParentTable(
202 const std::shared_ptr<ehm_dal::tables::AbstractTable> parent_table,
203 const ParentTableRelationshipType relationship)
205 Q_UNUSED(parent_table)
206 Q_UNUSED(relationship)
212 bool removeRows(qint32 row, qint32 count,
const QModelIndex &parent = QModelIndex())
override;
215 bool setData(
const QModelIndex &index,
216 const QVariant &value,
217 qint32 role = Qt::EditRole)
override;
221 TableAttributes table_attributes_;
222 std::vector<std::shared_ptr<ehm_dal::schema::AbstractIdTableItem>> data_;
225 bool is_initialised_{
false};
232 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: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