EHM DAL 0.2.3
Data abstraction layer for Eastside Hockey Manager
Loading...
Searching...
No Matches
ehm_dal::tables::AbstractTable Class Referenceabstract

The Table class represents a database table and provides access to rows of data. More...

#include <abstract_table.h>

Inheritance diagram for ehm_dal::tables::AbstractTable:

Public Types

enum class  ParentTableRelationshipType : qint8 { TableDoesNotHaveAnyParent , ParentTableHasChildIdField , ChildTableHasParentIdField }
 
- Public Types inherited from ehm_dal::tables::AbstractBaseModel
enum class  AbstractTableModelType : quint8 { AbstractClass , GameTable , GameChildTable , GameChildTreeTable }
 

Public Member Functions

 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.
 
void addChildItem (const qint32 parent_row_id, std::shared_ptr< ehm_dal::schema::AbstractTableItem > item, const ehm_dal::tables::TableIndex child_table)
 
QVariant childData (const QModelIndex &index, qint32 role, ehm_dal::column_data::ColumnData *column_data, const ehm_dal::tables::TableIndex child_table)
 
qint32 childItemId (const qint32 parent_row_id, const ehm_dal::tables::TableIndex child_table) const
 
virtual qint32 childRowCount (const qint32 parent_row_id, const ehm_dal::tables::TableIndex child_table) const
 
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)
 
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.
 
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 string much match the text to constitute a match.
 
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-string search.
 
std::vector< ehm_dal::data_types::PointerfindAll (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::PointerfindAll (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 much match the text to constitute a match.
 
std::vector< ehm_dal::data_types::PointerfindAllContains (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-string search.
 
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 isValidRow (const qint32 row_id) const
 
QString text (const qint32 row) const
 
qint32 rowCount (const QModelIndex &parent=QModelIndex()) const override
 Returns the number of rows in the table.
 
std::shared_ptr< ehm_dal::schema::AbstractTableItempointer (const qint32 row)
 Returns a shared pointer to the selected row of the table.
 
const TableAttributesattributes () const
 
bool init ()
 Initialises the table.
 
bool moveRows (const QModelIndex &source_parent, qint32 source_row, qint32 count, const QModelIndex &destination_parent, qint32 destination_child) override
 
qint32 parentRowId (const QModelIndex &index) const
 
virtual std::shared_ptr< ehm_dal::tables::AbstractTableparentTable () const
 
virtual ParentTableRelationshipType parentTableRelationship () const
 
virtual void setParentTable (const std::shared_ptr< ehm_dal::tables::AbstractTable > parent_table, const ParentTableRelationshipType relationship)
 
bool removeRows (qint32 row, qint32 count, const QModelIndex &parent=QModelIndex()) override
 
bool setData (const QModelIndex &index, const QVariant &value, qint32 role=Qt::EditRole) override
 
- Public Member Functions inherited from ehm_dal::tables::AbstractBaseModel
 AbstractBaseModel (ehm_dal::column_data::ColumnData *column_data=new ehm_dal::column_data::ColumnData(), QObject *parent=nullptr)
 
ehm_dal::column_data::ColumnDatacolumnData ()
 Returns the ehm_dal::column_data::ColumnData.
 
ehm_dal::column_data::ColumnDataconstColumnData () const
 
qint32 columnCount (const QModelIndex &parent=QModelIndex()) const override
 Returns the number of columns in the table.
 
qint32 size () const
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 Returns the item flags for the given index.
 
QVariant headerData (qint32 section, Qt::Orientation orientation, qint32 role=Qt::DisplayRole) const override
 Returns the data for the given role and section in the header with the specified orientation. For horizontal headers, the section number corresponds to the column number. Similarly, for vertical headers, the section number corresponds to the row number.
 
std::unique_ptr< QSortFilterProxyModel > proxy ()
 
virtual QString modelName () const
 
virtual constexpr AbstractTableModelType modelType () const
 

Protected Attributes

TableAttributes table_attributes_
 
std::vector< std::shared_ptr< ehm_dal::schema::AbstractTableItem > > data_
 

Additional Inherited Members

- Protected Member Functions inherited from ehm_dal::tables::AbstractBaseModel
bool emitModifiedColumns (const qint32 row, const std::vector< qint32 > &modified_columns, const QList< qint32 > &modified_roles=QList< qint32 >())
 

Detailed Description

The Table class represents a database table and provides access to rows of data.

Access to each row of data is via QModelIndex. Table inherits from QAbstractTableModel and is there compatible with Qt's Model/View framework.

Constructor & Destructor Documentation

◆ AbstractTable()

ehm_dal::tables::AbstractTable::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.

Parameters
table_nameName of the table
table_idehm_dal::tables::TableIndex (aka id) of the table
table_typeehm_dal::tables::TableType of table
column_dataTable column data

Member Function Documentation

◆ data()

QVariant ehm_dal::tables::AbstractTable::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.

Parameters
indexIndex of the selected row and column
roleItem data role. Qt::DisplayRole and Qt::EditRole are the most frequently used
Returns
a QVariant containing a copy of the data.

◆ find() [1/2]

ehm_dal::data_types::Pointer ehm_dal::tables::AbstractTable::find ( const qint32  value,
const quint16  column 
)

Finds the first row which has a value in the chosen column matching value.

Parameters
valueTarget value
columnTarget column to search
Returns
a Pointer to the search result. A null Pointer indicates that no match was found.

◆ find() [2/2]

ehm_dal::data_types::Pointer ehm_dal::tables::AbstractTable::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 string much match the text to constitute a match.

Parameters
textTarget text
columnTarget column to search
csCase sensitivity
Returns
a Pointer to the search result. A null Pointer indicates that no match was found.

◆ findAll() [1/2]

std::vector< ehm_dal::data_types::Pointer > ehm_dal::tables::AbstractTable::findAll ( const qint32  value,
const quint16  column 
)

Finds all rows which have a value in the chosen column matching value.

Parameters
valueTarget value
columnTarget column to search
Returns
a vector of Pointers to each search result. An empty vector indicates that no match was found.

◆ findAll() [2/2]

std::vector< ehm_dal::data_types::Pointer > ehm_dal::tables::AbstractTable::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 much match the text to constitute a match.

Parameters
textTarget text
columnTarget column to search
csCase sensitivity
Returns
a vector of Pointers to each search result. An empty vector indicates that no match was found.

◆ findAllContains()

std::vector< ehm_dal::data_types::Pointer > ehm_dal::tables::AbstractTable::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-string search.

Parameters
textTargettext
columnTarget column to search
csCase sensitivity
Returns
a vector of Pointers to each search result. An empty vector indicates that no match was found.

◆ findContains()

ehm_dal::data_types::Pointer ehm_dal::tables::AbstractTable::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-string search.

Parameters
textTarget text
columnTarget column to search
csCase sensitivity
Returns
a Pointer to the search result. A null Pointer indicates that no match was found.

◆ init()

bool ehm_dal::tables::AbstractTable::init ( )

Initialises the table.

Returns
whether initialisation took place

◆ pointer()

std::shared_ptr< ehm_dal::schema::AbstractTableItem > ehm_dal::tables::AbstractTable::pointer ( const qint32  row)

Returns a shared pointer to the selected row of the table.

Parameters
rowTable row
Returns
shared_ptr to the selected row of the table

◆ read()

bool ehm_dal::tables::AbstractTable::read ( QDataStream &  in)

Reads the table data from a QDataStream (wrapper for AbstractTable::readStream).

Parameters
in
Returns
whether parsing was successful.

◆ readData()

bool ehm_dal::tables::AbstractTable::readData ( QByteArray *  data)

Reads the table data from a QByteArray.

Parameters
in
Returns
whether parsing was successful.

◆ rowCount()

qint32 ehm_dal::tables::AbstractTable::rowCount ( const QModelIndex &  parent = QModelIndex()) const
override

Returns the number of rows in the table.

Parameters
parentNot used
Returns
the row count.