4#include "include/database/pointer/pointer_flags.h"
17template<
typename T_IdDataType,
typename T_TableIndex,
typename T_Table>
33 in.readRawData(
reinterpret_cast<char *
>(&
data.id_),
sizeof(T_IdDataType));
40 out.writeRawData(
reinterpret_cast<char *
>(&
id),
sizeof(T_IdDataType));
76 QVariant
data(
const qint32 role)
const;
84 virtual QVariant
data(
const qint32 column,
const qint32 role)
const;
88 inline virtual T_IdDataType
id()
const {
return id_; }
95 inline T_IdDataType
idBuffer()
const {
return id_; }
106 virtual QString
text()
const;
120 virtual std::shared_ptr<T_Table>
table() = 0;
124 T_TableIndex
tableId()
const {
return table_id_; }
128 inline bool operator==(
const AbstractPointer &rhs)
const {
return id() == rhs.id(); }
129 inline auto operator<=>(
const qint32 &rhs)
const {
return id() <=> rhs; }
130 inline bool operator==(
const qint32 &rhs)
const {
return id() == rhs; }
134 Q_DECL_DEPRECATED
void set(
const QVariant &value,
const qint32 role)
143 virtual void setData(
const QVariant &value,
const qint32 role);
151 bool setData(
const qint32 column,
const QVariant &value,
const qint32 role);
157 inline void setId(
const qint32
id) { id_ =
static_cast<T_IdDataType
>(
id); }
164template<
typename T_IdDataType,
typename T_TableIndex,
typename T_Table>
165AbstractPointer<T_IdDataType, T_TableIndex, T_Table>::AbstractPointer()
168template<
typename T_IdDataType,
typename T_TableIndex,
typename T_Table>
170 const T_IdDataType record_id)
172 , table_id_(table_id)
179template<
typename T_IdDataType,
typename T_TableIndex,
typename T_Table>
183 case Qt::DisplayRole:
192template<
typename T_IdDataType,
typename T_TableIndex,
typename T_Table>
196 return constTable()->index(
id(), column).data(role);
199template<
typename T_IdDataType,
typename T_TableIndex,
typename T_Table>
202 return constTable()->index(
id(), 2).data(Qt::DisplayRole).toString();
210template<
typename T_IdDataType,
typename T_TableIndex,
typename T_Table>
214 return constTable()->attributes()->name();
216 return QStringLiteral(
"[No table]");
224template<
typename T_IdDataType,
typename T_TableIndex,
typename T_Table>
228 if (role == Qt::EditRole)
229 id_ =
static_cast<T_IdDataType
>(value.toInt());
233template<
typename T_IdDataType,
typename T_TableIndex,
typename T_Table>
235 const QVariant &value,
238 const auto index{table()->index(
id(), column)};
239 return table()->setData(index, value, role);
The AbstractPointer class represents a pointer to a table item.
Definition: abstract_pointer.h:19
virtual void setData(const QVariant &value, const qint32 role)
Sets the role data for the item at index to value.
Definition: abstract_pointer.h:225
virtual std::shared_ptr< T_Table > constTable() const =0
Returns a read-only pointer to the table pointed to.
QVariant data(const qint32 role) const
Returns the data stored under the given role. Qt::DisplayRole returns the item's display text and Qt:...
Definition: abstract_pointer.h:180
bool isValidTable() const
Returns whether or not the AbstractPointer has been set to a table.
Definition: abstract_pointer.h:64
virtual QString text() const
Returns the display text of the item.
Definition: abstract_pointer.h:200
virtual std::shared_ptr< T_Table > table()=0
Returns a pointer to the table pointed to.
virtual T_IdDataType id() const
Returns the item index pointed to.
Definition: abstract_pointer.h:88
bool isPointer() const
Returns whether or not the AbstractPointer has been set to an item index.
Definition: abstract_pointer.h:56
qint32 columnCount() const
Returns the number of columns in the table pointed to.
Definition: abstract_pointer.h:48
T_TableIndex tableId() const
Returns the table id of the table pointed to.
Definition: abstract_pointer.h:124
bool isValidPointer() const
Returns whether or not the AbstractPointer has been set to an item index and to a table.
Definition: abstract_pointer.h:60
QString description() const
Returns the table name of the item.
Definition: abstract_pointer.h:211
T_IdDataType parentItemId() const
parentItemId returns the buffered id which is generally only useful when first initialising the links...
Definition: abstract_pointer.h:102
T_IdDataType idBuffer() const
idBuffer returns the buffered id which is generally only useful when first initialising the links bet...
Definition: abstract_pointer.h:95
bool isNone() const
Returns whether or not the AbstractPointer is set to ehm_dal::data_types::PointerFlags::NULL_POINTER.
Definition: abstract_pointer.h:52
namespace ehm_dal::data_types
Definition: attribute.h:6
@ NULL_POINTER
Definition: pointer_flags.h:9