File indexing completed on 2024-03-24 03:44:18
0001 /* 0002 SPDX-FileCopyrightText: 2005 Carsten Niehaus <cniehaus@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "chemicaldataobject.h" 0008 0009 #include "kalzium_libscience_debug.h" 0010 0011 #include <KUnitConversion/Converter> 0012 0013 class ChemicalDataObjectPrivate : public QSharedData 0014 { 0015 public: 0016 ChemicalDataObjectPrivate(); 0017 ~ChemicalDataObjectPrivate(); 0018 0019 QVariant m_value; 0020 QVariant m_errorValue; 0021 ChemicalDataObject::BlueObelisk m_type; 0022 int m_unit; 0023 }; 0024 0025 //######################## 0026 ChemicalDataObjectPrivate::ChemicalDataObjectPrivate() 0027 : QSharedData() 0028 { 0029 } 0030 0031 ChemicalDataObjectPrivate::~ChemicalDataObjectPrivate() = default; 0032 //############## 0033 0034 ChemicalDataObject::ChemicalDataObject(const QVariant &v, BlueObelisk type, const QVariant &errorValue) 0035 : d(new ChemicalDataObjectPrivate) 0036 { 0037 d->m_value = v; 0038 d->m_errorValue = errorValue; 0039 d->m_type = type; 0040 d->m_unit = KUnitConversion::NoUnit; 0041 } 0042 0043 ChemicalDataObject::ChemicalDataObject() 0044 : d(new ChemicalDataObjectPrivate) 0045 { 0046 d->m_errorValue = QVariant(); 0047 d->m_unit = KUnitConversion::NoUnit; 0048 } 0049 0050 ChemicalDataObject::ChemicalDataObject(const ChemicalDataObject &other) = default; 0051 0052 ChemicalDataObject::~ChemicalDataObject() = default; 0053 0054 ChemicalDataObject &ChemicalDataObject::operator=(const ChemicalDataObject &other) = default; 0055 0056 bool ChemicalDataObject::operator==(const int v) const 0057 { 0058 if (d->m_value.type() != QVariant::Int) { 0059 return false; 0060 } 0061 0062 return d->m_value.toInt() == v; 0063 } 0064 0065 bool ChemicalDataObject::operator==(const bool v) const 0066 { 0067 if (d->m_value.type() != QVariant::Bool) { 0068 return false; 0069 } 0070 0071 return d->m_value.toBool() == v; 0072 } 0073 0074 bool ChemicalDataObject::operator==(const double v) const 0075 { 0076 if (d->m_value.type() != QVariant::Double) { 0077 return false; 0078 } 0079 0080 return d->m_value.toDouble() == v; 0081 } 0082 0083 bool ChemicalDataObject::operator==(const QString &v) const 0084 { 0085 if (d->m_value.type() != QVariant::String) { 0086 return false; 0087 } 0088 0089 return d->m_value.toString() == v; 0090 } 0091 0092 bool ChemicalDataObject::operator==(const ChemicalDataObject &other) const 0093 { 0094 return d == other.d; 0095 } 0096 0097 bool ChemicalDataObject::operator!=(const ChemicalDataObject &other) const 0098 { 0099 return d != other.d; 0100 } 0101 0102 QString ChemicalDataObject::valueAsString() const 0103 { 0104 return d->m_value.toString(); 0105 } 0106 0107 ChemicalDataObject::BlueObelisk ChemicalDataObject::type() const 0108 { 0109 return d->m_type; 0110 } 0111 0112 QVariant ChemicalDataObject::value() const 0113 { 0114 return d->m_value; 0115 } 0116 0117 QVariant ChemicalDataObject::errorValue() const 0118 { 0119 return d->m_errorValue; 0120 } 0121 0122 void ChemicalDataObject::setUnit(int unit) 0123 { 0124 d->m_unit = unit; 0125 } 0126 0127 int ChemicalDataObject::unit() const 0128 { 0129 return d->m_unit; 0130 } 0131 0132 void ChemicalDataObject::setData(const QVariant &v) 0133 { 0134 d->m_value = v; 0135 } 0136 0137 void ChemicalDataObject::setErrorValue(const QVariant &v) 0138 { 0139 d->m_errorValue = v; 0140 } 0141 0142 void ChemicalDataObject::setType(BlueObelisk type) 0143 { 0144 d->m_type = type; 0145 } 0146 0147 void ChemicalDataObject::setType(int type) 0148 { 0149 d->m_type = (ChemicalDataObject::BlueObelisk)type; 0150 } 0151 0152 QString ChemicalDataObject::unitAsString() const 0153 { 0154 return KUnitConversion::Converter().unit(KUnitConversion::UnitId(d->m_unit)).symbol(); 0155 }