• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kalzium/libscience

  • sources
  • kde-4.12
  • kdeedu
  • kalzium
  • libscience
element.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2003, 2004, 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 "element.h"
22 #include <kdebug.h>
23 #include <kunitconversion/converter.h>
24 
25 
26 Element::Element()
27 {
28 }
29 
30 QVariant Element::dataAsVariant( ChemicalDataObject::BlueObelisk type ) const
31 {
32  foreach( const ChemicalDataObject &o, dataList ) {
33  if ( o.type() == type )
34  return o.value();
35  }
36  return QVariant();
37 }
38 
39 QVariant Element::dataAsVariant(ChemicalDataObject::BlueObelisk type, int unit) const
40 {
41  foreach( const ChemicalDataObject &o, dataList ) {
42  if ( o.type() == type ) {
43  if ( unit == KUnitConversion::NoUnit )
44  return o.value();
45  KUnitConversion::Value data( o.value().toDouble(), o.unit() );
46  return QVariant( data.convertTo(unit).number() );
47  }
48  }
49  return QVariant();
50 }
51 
52 QString Element::dataAsString(ChemicalDataObject::BlueObelisk type) const
53 {
54  return dataAsVariant(type).toString();
55 }
56 
57 QString Element::dataAsString(ChemicalDataObject::BlueObelisk type, int unit) const
58 {
59  return dataAsVariant(type, unit).toString();
60 }
61 
62 QString Element::dataAsStringWithUnit(ChemicalDataObject::BlueObelisk type, int unit) const
63 {
64  QString valueAndUnit( QString::number( dataAsVariant( type, unit).toDouble(), 'g', 4 ) );
65 
66  if (valueAndUnit.isEmpty())
67  return QString();
68 
69  valueAndUnit.append(" ");
70  valueAndUnit.append( KUnitConversion::Converter().unit( unit ).data()->symbol() );
71  return valueAndUnit;
72 }
73 
74 Element::~Element()
75 {
76 }
77 
78 void Element::addData( const ChemicalDataObject& o )
79 {
80  dataList.append( o );
81 }
82 
83 void Element::addData( const QVariant& value, ChemicalDataObject::BlueObelisk type )
84 {
85  ChemicalDataObject tmp( value, type );
86  dataList.append( tmp );
87 }
Element::data
QList< ChemicalDataObject > data() const
Definition: element.h:90
element.h
ChemicalDataObject::unit
int unit() const
Definition: chemicaldataobject.cpp:148
ChemicalDataObject::type
BlueObelisk type() const
Definition: chemicaldataobject.cpp:128
Element::Element
Element()
Definition: element.cpp:26
Element::~Element
virtual ~Element()
Definition: element.cpp:74
ChemicalDataObject
A ChemicalDataObject is an object which contains information about a chemical element.
Definition: chemicaldataobject.h:38
Element::dataAsVariant
QVariant dataAsVariant(ChemicalDataObject::BlueObelisk type) const
Definition: element.cpp:30
ChemicalDataObject::BlueObelisk
BlueObelisk
The BlueObelisk-project defines in their XML file the dataset with the names of the enum plus "bo:"...
Definition: chemicaldataobject.h:47
Element::dataAsStringWithUnit
QString dataAsStringWithUnit(ChemicalDataObject::BlueObelisk type, int unit) const
Definition: element.cpp:62
Element::dataAsString
QString dataAsString(ChemicalDataObject::BlueObelisk type) const
Definition: element.cpp:52
Element::addData
void addData(const ChemicalDataObject &o)
Add the ChemicalDataObject o to this Element.
Definition: element.cpp:78
ChemicalDataObject::value
QVariant value() const
Every ChemicalDataObject contains one data.
Definition: chemicaldataobject.cpp:133
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:31 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalzium/libscience

Skip menu "kalzium/libscience"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal