4#include "include/column_data/column_data.h"
5#include "include/database/database_version.h"
6#include "include/tables/abstract_table.h"
17template<
class T_ColumnData>
18concept ColumnData = std::derived_from<T_ColumnData, ehm_dal::column_data::ColumnData>
19 || std::is_same_v<ehm_dal::column_data::ColumnData, T_ColumnData>;
21template<
class T_AbstractTableItem, ColumnData T_ColumnData = ehm_dal::column_data::ColumnData>
33 bool insertRows(qint32 row, qint32 count,
const QModelIndex &parent = QModelIndex())
override;
36 inline QString modelName()
const override {
return QStringLiteral(
"Game standard table"); }
37 inline constexpr AbstractBaseModel::AbstractTableModelType modelType()
const override
39 return AbstractBaseModel::AbstractTableModelType::GameTable;
43 inline virtual qsizetype junkDataPrefixSize()
const {
return junk_data_prefix_.size(); }
48 QByteArray junk_data_prefix_;
56template<
class T_AbstractTableItem, ColumnData T_ColumnData>
57GameTable<T_AbstractTableItem, T_ColumnData>::GameTable(
const QString &table_name,
60 : AbstractTable(table_name, table_id, table_type, new T_ColumnData())
67template<
class T_AbstractTableItem, ColumnData T_ColumnData>
71 const auto junk_data_prefix_size{junkDataPrefixSize()};
72 if (junk_data_prefix_size > 0) {
73 junk_data_prefix_.resize(junk_data_prefix_size);
74 in.readRawData(junk_data_prefix_.data(), junk_data_prefix_size);
79 const auto record_count{table_attributes_.readTableHeader(in)};
83 qDebug().noquote() << QStringLiteral(
"Reading table:") << table_attributes_.name()
84 << QString(
"-> %L1 record(s)").arg(record_count);
87 for (quint32 i = 0; i < record_count; ++i) {
88 auto item{std::make_unique<T_AbstractTableItem>()};
89 item->read(in, database_version);
91 data_.emplace_back(std::move(item));
95 qWarning().noquote() << QStringLiteral(
"%L1 error(s) encountered when reading %2")
97 .arg(table_attributes_.name());
99 return error_count == 0;
106template<
class T_AbstractTableItem, ColumnData T_ColumnData>
109 const QModelIndex &parent)
111 if (count <= 0 || row < 0 || row >
static_cast<qint32
>(this->data_.size()))
114 beginInsertRows(parent, row, row + count - 1);
116 for (
int i = 0; i < count; ++i) {
117 auto new_item{std::make_shared<T_AbstractTableItem>()};
118 new_item->alloc(
static_cast<qint32
>(this->data_.size()));
119 this->data_.insert(this->data_.begin() + row, std::move(new_item));
The DatabaseVersion class represents the database version number.
Definition: database_version.h:12
The Table class represents a database table and provides access to rows of data.
Definition: abstract_table.h:29
Definition: game_table.h:23
bool readStream(QDataStream &in) override
Reads the table data from a QDataStream.
Definition: game_table.h:68
The GameTable class is a template sub-class of Table and is intended for use as a database table.
Definition: game_table.h:18
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