EHM DAL 0.2.5
Data abstraction layer for Eastside Hockey Manager
Loading...
Searching...
No Matches
attribute.h
1#pragma once
2
3// Application headers
4#include "include/data_types/data_type.h"
5
10template<class T>
11class Attribute : public DataType<T>
12{
13public:
14 Attribute(const T value = 0);
15
16 // Set data
17 // CRASH making DataType:: setData() a virtual function appears to corrupt the vtable
18 // TODO consider how to implement Attribute::setData in light of the above crash given that
19 // attributes need to have a lowerLimit() and an upperLimit()
20 // void setData(const QVariant &value, const qint32 role = Qt::EditRole) override;
21
22private:
23 inline virtual constexpr T lowerLimit() const { return static_cast<T>(0); }
24 inline virtual constexpr T upperLimit() const { return static_cast<T>(20); }
25};
26
27/* ========================= */
28/* Attribute (0-20) */
29/* ========================= */
30
31template<class T>
32Attribute<T>::Attribute(const T value)
33 : DataType<T>(value)
34{}
35
36/* ================= */
37/* Set Data */
38/* ================= */
39/*
40template<class T>
41void Attribute<T>::setData(const QVariant &value, const qint32 role)
42{
43 if (role != Qt::EditRole)
44 return;
45
46 // Convert to qint64 to ensure the underlying value is not truncated
47 const auto new_value{static_cast<T>(value.toLongLong())};
48
49 if (new_value < lowerLimit())
50 this->setValue(lowerLimit());
51 else if (new_value > upperLimit())
52 this->setValue(upperLimit());
53 else
54 this->setValue(new_value);
55}
56*/
57} // namespace ehm_dal::data_types
The Attribute class is a template class for attribute-like values with lower and upper limit values.
Definition: attribute.h:12
The DataType class is a template class for all C++ integral and floating point data types.
Definition: data_type.h:21
T value() const
Returns the raw value which can otherwise be accessed via QVariant data(const qint32 role).
Definition: data_type.h:45
namespace ehm_dal::data_types
Definition: attribute.h:6