11concept Number = std::is_integral<T>::value || std::is_floating_point<T>::value;
29 QVariant
data(
const qint32 role = Qt::DisplayRole)
const;
33 inline T
value()
const {
return value_; }
59 inline auto operator<=>(
const qint32 &rhs)
const {
return value() <=> rhs; }
60 inline bool operator==(
const qint32 &rhs)
const {
return value() == rhs; }
63 Q_DECL_DEPRECATED
void set(
const QVariant &
value,
const qint32 role = Qt::EditRole);
70 void setData(
const QVariant &
value,
const qint32 role = Qt::EditRole);
83 in.readRawData(
reinterpret_cast<char *
>(&
data.value_),
sizeof(T));
86 friend QDataStream &operator<<(QDataStream &out,
const DataType<T> &
data)
88 out.writeRawData(
reinterpret_cast<const char *
>(&
data.value_),
sizeof(T));
98DataType<T>::DataType(
const T value)
110 case Qt::DisplayRole:
125 if (role == Qt::DisplayRole || role == Qt::EditRole)
126 return QLocale().toString(value_);
134 if (role != Qt::DisplayRole && role != Qt::EditRole)
137 if constexpr (std::is_floating_point_v<T>)
138 return QLocale().toString(value_,
'g', 8);
140 return QString::number(0.0);
146 return static_cast<double>(value_);
152 return static_cast<float>(value_);
163 setData(value, role);
169 if (role != Qt::EditRole)
172 if constexpr (std::is_floating_point_v<T>)
173 setValue(
static_cast<T
>(value.toDouble()));
174 else if constexpr (std::is_unsigned_v<T>)
175 setValue(
static_cast<T
>(value.toUInt()));
177 setValue(
static_cast<T
>(value.toInt()));
The DataType class is a template class for all C++ integral and floating point data types.
Definition: data_type.h:18
double toDouble() const
Returns the value as a double.
Definition: data_type.h:144
QVariant accurateDecimal(const qint32 role=Qt::DisplayRole) const
Returns the decimal value to as many decimal places as possible.
Definition: data_type.h:123
float toFloat() const
Returns the value as a float.
Definition: data_type.h:150
QVariant roundedDecimal(const qint32 role=Qt::DisplayRole) const
Returns the decimal value rounded to 8 decimal places. This is useful when converting a double to a f...
Definition: data_type.h:132
QVariant data(const qint32 role=Qt::DisplayRole) const
Returns the data stored under the given role for the item.
Definition: data_type.h:107
T value() const
Returns the raw value which can otherwise be accessed via QVariant data(const qint32 role).
Definition: data_type.h:33
void setValue(const T value)
Sets the value to value
Definition: data_type.h:75
void setData(const QVariant &value, const qint32 role=Qt::EditRole)
Sets the role data for the item at to value.
Definition: data_type.h:167
Definition: data_type.h:11
namespace ehm_dal::data_types
Definition: attribute.h:6