[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdeedu/kalzium/src/calculator
From: Etienne Rebetez <etienne.rebetez () oberwallis ! ch>
Date: 2011-03-18 20:27:59
Message-ID: 20110318202759.B83BCAC8C8 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1225252 by erebetez:
formatting code, removing redundant comments, typos
M +16 -72 gasCalculator.cpp
M +36 -45 gasCalculator.h
--- trunk/KDE/kdeedu/kalzium/src/calculator/gasCalculator.cpp #1225251:1225252
@@ -19,24 +19,16 @@
#include "gasCalculator.h"
#include "prefs.h"
-#include <kunitconversion/converter.h>
-
using namespace KUnitConversion;
gasCalculator::gasCalculator(QWidget * parent)
- : QFrame(parent)
+ : QWidget(parent)
{
ui.setupUi(this);
- /**************************************************************************/
- // Gas Calculator set up
- /**************************************************************************/
-
- // initialise the initially selected values
init();
- // Connect signals with slots
connect(ui.temp , SIGNAL(valueChanged(double)),
this, SLOT(tempChanged()));
connect(ui.temp_unit , SIGNAL(activated(int)),
@@ -67,14 +59,10 @@
this, SLOT(setMode(int)));
connect(ui.reset, SIGNAL(clicked()),
this, SLOT(init()));
- /**************************************************************************/
- // gas Calculator setup complete
- /**************************************************************************/
}
gasCalculator:: ~gasCalculator()
{
-
}
void gasCalculator::init()
@@ -92,26 +80,24 @@
QList<int> units;
units << Gram << Milligram << Kilogram << Ton;
- poulateUnitCombobox( ui.mass_unit, units );
+ populateUnitCombobox( ui.mass_unit, units );
units.clear();
units << Atmosphere << Pascal << Bar << Millibar << Torr;
- poulateUnitCombobox( ui.pressure_unit, units );
+ populateUnitCombobox( ui.pressure_unit, units );
units.clear();
units << Kelvin << Celsius << Fahrenheit;
- poulateUnitCombobox( ui.temp_unit, units );
+ populateUnitCombobox( ui.temp_unit, units );
units.clear();
units << Liter << Milliliter << CubicMeter << KUnitConversion::GallonUS;
- poulateUnitCombobox( ui.volume_unit, units );
+ populateUnitCombobox( ui.volume_unit, units );
units.clear();
units << Liter << Milliliter << CubicMeter << KUnitConversion::GallonUS;
- poulateUnitCombobox( ui.b_unit, units );
- // Setup of the UI done
+ populateUnitCombobox( ui.b_unit, units );
- // Initialise values
m_temp = Value(273.0, KUnitConversion::Kelvin);
m_molarMass = 2.016;
m_pressure = Value(1.0, KUnitConversion::Atmosphere);
@@ -120,17 +106,15 @@
m_Vand_a = 0.0;
m_Vand_b = Value(0.0, KUnitConversion::Liter);
m_vol = Value(22.4, KUnitConversion::Liter);
- // Initialisation of values done
- if (Prefs::ideal())
- {
+ if (Prefs::ideal()) {
ui.non_ideal->hide();
}
- setMode(3);
+ setMode(VOLUME);
}
-void gasCalculator::poulateUnitCombobox(QComboBox *comboBox, const QList< int > \
&unitList) +void gasCalculator::populateUnitCombobox(QComboBox *comboBox, const \
QList< int > &unitList) {
foreach( int unit, unitList) {
comboBox->addItem( \
KUnitConversion::Converter().unit(unit).data()->description(), unit); @@ -142,39 \
+126,19 @@ return comboBox->itemData( comboBox->currentIndex() ).toInt();
}
-
-/*
- Note:-
-
- Van der Val's gas equation
- ( P + n^2 a / V^2) ( V - nb ) = nRT
-
- where P - pressure
- V - Volume
- n - number of moles
- R - Universal gas constant
- T - temperature
-
- a,b - Van der Val's constants
-*/
-
-// Calculates the Pressure
void gasCalculator::calculatePressure()
{
- double pressure;
double volume = m_vol.convertTo( KUnitConversion::Liter ).number();
double temp = m_temp.convertTo( KUnitConversion::Kelvin ).number();
double b = m_Vand_b.convertTo( KUnitConversion::Liter ).number();
- pressure = m_moles * R * temp / (volume - m_moles * b) - m_moles * m_moles * \
m_Vand_a / volume / volume; + double pressure = m_moles * R * temp / (volume - \
m_moles * b) - m_moles * m_moles * m_Vand_a / volume / volume; +
m_pressure = Value(pressure, KUnitConversion::Atmosphere );
m_pressure = m_pressure.convertTo(getCurrentUnitId(ui.pressure_unit));
ui.pressure->setValue(m_pressure.number());
-
- //pressure =
}
-// Calculates the molar mass of the gas
void gasCalculator::calculateMolarMass()
{
double mass = m_mass.convertTo(KUnitConversion::Gram).number();
@@ -188,36 +152,31 @@
ui.molarMass->setValue(m_molarMass);
}
-// Calculates the Volume
void gasCalculator::calculateVol()
{
- double volume;
double pressure = m_pressure.convertTo(KUnitConversion::Atmosphere).number();
double temp = m_temp.convertTo(KUnitConversion::Kelvin).number();
double b = m_Vand_b.convertTo(KUnitConversion::Liter).number();
- volume = m_moles * R * temp / pressure + (m_moles * b);
+ double volume = m_moles * R * temp / pressure + (m_moles * b);
m_vol = Value(volume, KUnitConversion::Liter);
m_vol = m_vol.convertTo( getCurrentUnitId(ui.volume_unit) );
ui.volume->setValue(m_vol.number());
}
-// Calculates the Temperature
void gasCalculator::calculateTemp()
{
- double temp;
double volume = m_vol.convertTo(KUnitConversion::Liter).number();
double pressure = m_pressure.convertTo(KUnitConversion::Atmosphere).number();
double b = m_Vand_b.convertTo(KUnitConversion::Liter).number();
- temp = (pressure + (m_moles * m_moles * m_Vand_a / volume / volume))\
+ double temp = (pressure + (m_moles * m_moles * m_Vand_a / volume / volume))\
* (volume - m_moles * b) / m_moles / R;
m_temp = Value(temp, KUnitConversion::Kelvin);
m_temp = m_temp.convertTo( getCurrentUnitId( ui.temp_unit ) );
ui.temp->setValue(m_temp.number());
}
-// Calculates the number of moles
void gasCalculator::calculateMoles()
{
double volume = m_vol.convertTo(KUnitConversion::Liter).number();
@@ -230,16 +189,14 @@
ui.moles->setValue(m_moles);
}
-// Calculates the mass of substance
void gasCalculator::calculateMass()
{
- double mass;
double volume = m_vol.convertTo(KUnitConversion::Liter).number();
double pressure = m_pressure.convertTo(KUnitConversion::Atmosphere).number();
double temp = m_temp.convertTo(KUnitConversion::Kelvin).number();
double b = m_Vand_b.convertTo(KUnitConversion::Liter).number();
- mass = (pressure + m_moles * m_moles * m_Vand_a / volume / volume)\
+ double mass = (pressure + m_moles * m_moles * m_Vand_a / volume / volume)\
* (volume - m_moles * b) * m_molarMass / R / temp;
m_mass = Value(mass, KUnitConversion::Gram);
m_mass = m_mass.convertTo( getCurrentUnitId( ui.mass_unit ) );
@@ -247,29 +204,24 @@
}
-// Functions ( slots ) that occur on changing a value
-// occurs when the volume is changed
void gasCalculator::volChanged()
{
m_vol = Value(ui.volume->value(), getCurrentUnitId( ui.volume_unit ) );
calculate();
}
-// occurs when the temperature is changed
void gasCalculator::tempChanged()
{
m_temp = Value(ui.temp->value(), getCurrentUnitId( ui.temp_unit ) );
calculate();
}
-// occurs when the pressure is changed
void gasCalculator::pressureChanged()
{
m_pressure = Value(ui.pressure->value(), getCurrentUnitId( ui.pressure_unit ) );
calculate();
}
-// occurs when the mass is changed
void gasCalculator::massChanged()
{
m_mass = Value(ui.mass->value(), getCurrentUnitId( ui.mass_unit ) );
@@ -278,7 +230,6 @@
calculate();
}
-// occurs when the number of moles is changed
void gasCalculator::molesChanged(double value)
{
m_moles = value;
@@ -288,11 +239,10 @@
calculate();
}
-// occurs when the molar mass is changed
void gasCalculator::molarMassChanged(double value)
{
if (value == 0.0) {
- error(MOLAR_MASS_ZERO_);
+ error(GAS_MOLAR_MASS_ZERO);
return;
}
m_molarMass = value;
@@ -302,21 +252,18 @@
calculate();
}
-// occurs when the number of moles is changed
void gasCalculator::Vand_aChanged()
{
m_Vand_a = ui.a->value();
calculate();
}
-// occurs when the number of moles is changed
void gasCalculator::Vand_bChanged()
{
m_Vand_b = Value(ui.b->value(), getCurrentUnitId( ui.b_unit ) );
calculate();
}
-// occurs when the mode is changed, eg pressure to volume
void gasCalculator::setMode(int mode)
{
m_mode = mode;
@@ -347,7 +294,6 @@
calculate();
}
-// occurs when any quantity is changed
void gasCalculator::calculate()
{
error(RESET_GAS_MESSAGE);
@@ -378,7 +324,7 @@
case VOL_ZERO :
ui.error->setText(i18n("Volume cannot be zero, please enter a valid \
value.")); break;
- case MOLAR_MASS_ZERO_:
+ case GAS_MOLAR_MASS_ZERO:
ui.error->setText(i18n("Molar mass cannot be zero, please enter a non-zero \
value.")); default:
break;
@@ -386,5 +332,3 @@
}
#include "gasCalculator.moc"
-
-
--- trunk/KDE/kdeedu/kalzium/src/calculator/gasCalculator.h #1225251:1225252
@@ -20,37 +20,26 @@
#ifndef gasCalculator_H
#define gasCalculator_H
-#include <element.h>
-#include <isotope.h>
-
#include <kdebug.h>
-#include <prefs.h>
#include <kalziumdataobject.h>
#include <kunitconversion/unitcategory.h>
#include <kunitconversion/converter.h>
-#include <QComboBox>
-
#include "ui_gasCalculator.h"
// The universal Gas constant is defined here.
#define R 0.08206
-namespace KUnitConversion {
-enum UnitId;
-}
-
-// This is required for the units conversion
using namespace KUnitConversion;
-// This is the enumeration for the error type required in the error(int mode) \
function +/// This is the enumeration for the error type required in the error(int \
mode) function enum ERROR_TYPE_GAS {
RESET_GAS_MESSAGE = 0,
VOL_ZERO,
- MOLAR_MASS_ZERO_
+ GAS_MOLAR_MASS_ZERO
};
-// This is the enumeration for the mode of calculation for the gas calculator
+/// This is the enumeration for the mode of calculation for the gas calculator
enum MODE_CALCULATION_GAS {
MOLES = 0,
PRESSURE,
@@ -58,13 +47,24 @@
VOLUME
};
-/*
+/**
* This class implements the gas calculator. It performs basic calculations like
* calculation of volume given pressure, temerature, amount etc. and so on.
*
+ * Van der Val's gas equation
+ * ( P + n^2 a / V^2) ( V - nb ) = nRT
+ *
+ * where P - pressure
+ * V - Volume
+ * n - number of moles
+ * R - Universal gas constant
+ * T - temperature
+ *
+ * a,b - Van der Val's constants
+ *
* @author Kashyap R Puranik
- */
-class gasCalculator : public QFrame
+**/
+class gasCalculator : public QWidget
{
Q_OBJECT
@@ -104,16 +104,16 @@
/// This function is called when the mass is changed
void massChanged();
- /*
+ /**
* This function is called when the number of moles is changed
* @param value is the number of moles
- */
+ **/
void molesChanged(double value);
- /*
+ /**
* This function is called when the molar mass is changed
* @param value is the molar mass
- */
+ **/
void molarMassChanged(double value);
/// This function is called when Vander Val's constant a is changed
@@ -125,48 +125,39 @@
/// This function is called when any quantity is changed
void calculate();
- /*
+ /**
* This function is called when an error occurs
* @param mode indicates the mode of error
* Refer ERROR_MODE_GAS for various modes
- */
+ **/
void error(int);
- /*
+ /**
* This function is called when the mode is changed
* @param indicates the mode of calculation.
* Refer MODE_CALCULATION_GAS for various modes
- */
+ **/
void setMode(int);
- // Initialises the gasCalculator
void init();
private:
- void poulateUnitCombobox(QComboBox *comboBox, const QList<int> &unitList);
+ void populateUnitCombobox(QComboBox *comboBox, const QList<int> &unitList);
int getCurrentUnitId(QComboBox *comboBox);
- Ui::gasCalculator ui; // The user interface
+ Ui::gasCalculator ui;
- double m_moles; // Number of moles
- double m_molarMass; // molarMass
- Value m_mass; // mass
- Value m_temp; // Temperature
- Value m_pressure; // pressure
- Value m_vol; // volume
- Value m_Vand_b; // vander val's constant b
+ double m_moles;
+ double m_molarMass;
+ Value m_mass;
+ Value m_temp;
+ Value m_pressure;
+ Value m_vol;
+ Value m_Vand_b;
+ double m_Vand_a;
- QStringList m_massUnits; // mass
- QStringList m_tempUnits; // Temperature
- QStringList m_pressureUnits; // pressure
- QStringList m_volUnits; // volume
- QStringList m_Vand_bUnits;
-
- //( Unit conversion library not available for the following quantities)
- double m_Vand_a; // Vander val's constant a
-
- int m_mode; // indicates the volume that should be calculated
+ int m_mode;
};
#endif // gasCalculator_H
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic