1
/***************************************************************************
2
* Copyright (C) 2005 by Carsten Niehaus *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19
***************************************************************************/
21
#include "chemicaldataobject.h"
22
#include <kunitconversion/converter.h>
25
#include <QLatin1String>
27
class ChemicalDataObjectPrivate : public QSharedData
30
ChemicalDataObjectPrivate();
31
~ChemicalDataObjectPrivate();
34
QVariant m_errorValue;
35
ChemicalDataObject::BlueObelisk m_type;
39
//########################
40
ChemicalDataObjectPrivate::ChemicalDataObjectPrivate()
45
ChemicalDataObjectPrivate::~ChemicalDataObjectPrivate()
50
ChemicalDataObject::ChemicalDataObject( const QVariant& v, BlueObelisk type, const QVariant& errorValue )
51
: d(new ChemicalDataObjectPrivate)
54
d->m_errorValue = errorValue;
56
d->m_unit = KUnitConversion::NoUnit;
59
ChemicalDataObject::ChemicalDataObject()
60
: d(new ChemicalDataObjectPrivate)
62
d->m_errorValue = QVariant();
63
d->m_unit = KUnitConversion::NoUnit;
66
ChemicalDataObject::ChemicalDataObject(const ChemicalDataObject &other)
71
ChemicalDataObject::~ChemicalDataObject()
75
ChemicalDataObject& ChemicalDataObject::operator=(const ChemicalDataObject &other)
81
bool ChemicalDataObject::operator==( const int v ) const
83
if ( d->m_value.type() != QVariant::Int )
86
return d->m_value.toInt() == v;
89
bool ChemicalDataObject::operator==( const bool v ) const
91
if ( d->m_value.type() != QVariant::Bool )
94
return d->m_value.toBool() == v;
97
bool ChemicalDataObject::operator==( const double v ) const
99
if ( d->m_value.type() != QVariant::Double )
102
return d->m_value.toDouble() == v;
105
bool ChemicalDataObject::operator==( const QString& v ) const
107
if ( d->m_value.type() != QVariant::String )
110
return d->m_value.toString() == v;
113
bool ChemicalDataObject::operator==(const ChemicalDataObject &other) const
118
bool ChemicalDataObject::operator!=(const ChemicalDataObject &other) const
123
QString ChemicalDataObject::valueAsString() const
125
return d->m_value.toString();
128
ChemicalDataObject::BlueObelisk ChemicalDataObject::type() const
133
QVariant ChemicalDataObject::value() const
138
QVariant ChemicalDataObject::errorValue() const
140
return d->m_errorValue;
143
void ChemicalDataObject::setUnit( int unit )
148
int ChemicalDataObject::unit() const
153
void ChemicalDataObject::setData( const QVariant& v )
158
void ChemicalDataObject::setErrorValue( const QVariant& v )
163
void ChemicalDataObject::setType( BlueObelisk type )
168
void ChemicalDataObject::setType( int type )
170
d->m_type = ( ChemicalDataObject::BlueObelisk ) type;
173
QString ChemicalDataObject::unitAsString() const
175
return KUnitConversion::Converter().unit(d->m_unit).data()->symbol();