~ubuntu-branches/ubuntu/precise/kalzium/precise

« back to all changes in this revision

Viewing changes to libscience/chemicaldataobject.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Philip Muškovac
  • Date: 2011-07-03 12:28:58 UTC
  • Revision ID: james.westby@ubuntu.com-20110703122858-q1yyxncs89e4w0hs
Tags: upstream-4.6.90+repack
Import upstream version 4.6.90+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2005 by Carsten Niehaus                                 *
 
3
 *   cniehaus@kde.org                                                      *
 
4
 *                                                                         *
 
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.                                   *
 
9
 *                                                                         *
 
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.                          *
 
14
 *                                                                         *
 
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
 ***************************************************************************/
 
20
 
 
21
#include "chemicaldataobject.h"
 
22
#include <kunitconversion/converter.h>
 
23
#include <kdebug.h>
 
24
 
 
25
#include <QLatin1String>
 
26
 
 
27
class ChemicalDataObjectPrivate : public QSharedData
 
28
{
 
29
public:
 
30
    ChemicalDataObjectPrivate();
 
31
    ~ChemicalDataObjectPrivate();
 
32
 
 
33
    QVariant m_value;
 
34
    QVariant m_errorValue;
 
35
    ChemicalDataObject::BlueObelisk m_type;
 
36
    int m_unit;
 
37
};
 
38
 
 
39
//########################
 
40
ChemicalDataObjectPrivate::ChemicalDataObjectPrivate()
 
41
        : QSharedData()
 
42
{
 
43
}
 
44
 
 
45
ChemicalDataObjectPrivate::~ChemicalDataObjectPrivate()
 
46
{
 
47
}
 
48
//##############
 
49
 
 
50
ChemicalDataObject::ChemicalDataObject( const QVariant& v, BlueObelisk type, const QVariant& errorValue )
 
51
        : d(new ChemicalDataObjectPrivate)
 
52
{
 
53
    d->m_value = v;
 
54
    d->m_errorValue = errorValue;
 
55
    d->m_type = type;
 
56
    d->m_unit = KUnitConversion::NoUnit;
 
57
}
 
58
 
 
59
ChemicalDataObject::ChemicalDataObject()
 
60
        : d(new ChemicalDataObjectPrivate)
 
61
{
 
62
    d->m_errorValue = QVariant();
 
63
    d->m_unit = KUnitConversion::NoUnit;
 
64
}
 
65
 
 
66
ChemicalDataObject::ChemicalDataObject(const ChemicalDataObject &other)
 
67
        : d(other.d)
 
68
{
 
69
}
 
70
 
 
71
ChemicalDataObject::~ChemicalDataObject()
 
72
{
 
73
}
 
74
 
 
75
ChemicalDataObject& ChemicalDataObject::operator=(const ChemicalDataObject &other)
 
76
{
 
77
    d = other.d;
 
78
    return *this;
 
79
}
 
80
 
 
81
bool ChemicalDataObject::operator==( const int v ) const
 
82
{
 
83
    if ( d->m_value.type() != QVariant::Int )
 
84
        return false;
 
85
 
 
86
    return d->m_value.toInt() == v;
 
87
}
 
88
 
 
89
bool ChemicalDataObject::operator==( const bool v ) const
 
90
{
 
91
    if ( d->m_value.type() != QVariant::Bool )
 
92
        return false;
 
93
 
 
94
    return d->m_value.toBool() == v;
 
95
}
 
96
 
 
97
bool ChemicalDataObject::operator==( const double v ) const
 
98
{
 
99
    if ( d->m_value.type() != QVariant::Double )
 
100
        return false;
 
101
 
 
102
    return d->m_value.toDouble() == v;
 
103
}
 
104
 
 
105
bool ChemicalDataObject::operator==( const QString& v ) const
 
106
{
 
107
    if ( d->m_value.type() != QVariant::String )
 
108
        return false;
 
109
 
 
110
    return d->m_value.toString() == v;
 
111
}
 
112
 
 
113
bool ChemicalDataObject::operator==(const ChemicalDataObject &other) const
 
114
{
 
115
    return d == other.d;
 
116
}
 
117
 
 
118
bool ChemicalDataObject::operator!=(const ChemicalDataObject &other) const
 
119
{
 
120
    return d != other.d;
 
121
}
 
122
 
 
123
QString ChemicalDataObject::valueAsString() const
 
124
{
 
125
    return d->m_value.toString();
 
126
}
 
127
 
 
128
ChemicalDataObject::BlueObelisk ChemicalDataObject::type() const
 
129
{
 
130
    return d->m_type;
 
131
}
 
132
 
 
133
QVariant ChemicalDataObject::value() const
 
134
{
 
135
    return d->m_value;
 
136
}
 
137
 
 
138
QVariant ChemicalDataObject::errorValue() const
 
139
{
 
140
    return d->m_errorValue;
 
141
}
 
142
 
 
143
void ChemicalDataObject::setUnit( int unit )
 
144
{
 
145
    d->m_unit = unit;
 
146
}
 
147
 
 
148
int ChemicalDataObject::unit() const
 
149
{
 
150
    return d->m_unit;
 
151
}
 
152
 
 
153
void ChemicalDataObject::setData( const QVariant& v )
 
154
{
 
155
    d->m_value = v;
 
156
}
 
157
 
 
158
void ChemicalDataObject::setErrorValue( const QVariant& v )
 
159
{
 
160
    d->m_errorValue = v;
 
161
}
 
162
 
 
163
void ChemicalDataObject::setType( BlueObelisk type )
 
164
{
 
165
    d->m_type = type;
 
166
}
 
167
 
 
168
void ChemicalDataObject::setType( int type )
 
169
{
 
170
    d->m_type = ( ChemicalDataObject::BlueObelisk ) type;
 
171
}
 
172
 
 
173
QString ChemicalDataObject::unitAsString() const
 
174
{
 
175
    return KUnitConversion::Converter().unit(d->m_unit).data()->symbol();
 
176
}