File indexing completed on 2024-04-21 03:41:37
0001 /* 0002 SPDX-FileCopyrightText: 2009 Kashyap R Puranik <kashthealien@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef CONCCALCULATOR_H 0008 #define CONCCALCULATOR_H 0009 0010 #include "kalzium_debug.h" 0011 0012 #include <KUnitConversion/UnitCategory> 0013 0014 #include <kalziumdataobject.h> 0015 #include <prefs.h> 0016 0017 #include "ui_concCalculator.h" 0018 0019 // This is required for the unit conversion library 0020 using namespace KUnitConversion; 0021 0022 // Enumeration for type of error used in the error() function 0023 enum ERROR_TYPE_CONC { 0024 RESET_CONC_MESSAGE = 0, 0025 PERCENTAGE, 0026 DENSITY_ZERO, 0027 MASS_ZERO, 0028 VOLUME_ZERO, 0029 MOLES_ZERO, 0030 MOLAR_MASS_ZERO, 0031 EQT_MASS_ZERO, 0032 MOLAR_SOLVENT_ZERO, 0033 EQTS_ZERO, 0034 CONC_ZERO, 0035 SOLVENT_VOLUME_ZERO, 0036 SOLVENT_MASS_ZERO, 0037 SOLVENT_MOLES_ZERO, 0038 INSUFFICIENT_DATA_EQT, 0039 INSUFFICIENT_DATA_MOLE, 0040 INSUFFICIENT_DATA_MOLES, 0041 INSUFFICIENT_DATA_SOLVENT 0042 }; 0043 0044 // enumeration for the mode of calculation in the setMode(int) function 0045 enum MODE_CALCULATION_CONC { AMT_SOLUTE = 0, MOLAR_MASS, EQT_MASS, AMT_SOLVENT, MOLAR_MASS_SOLVENT, CONCENTRATION }; 0046 0047 /* 0048 * This class implements the concentration calculator. This widget performs basic 0049 * calculations like calculation of molarity, mass percentages etc. 0050 * 0051 * @author Kashyap R Puranik 0052 */ 0053 class concCalculator : public QFrame 0054 { 0055 Q_OBJECT 0056 0057 public: 0058 /* 0059 * The constructor and destructor for the class 0060 */ 0061 explicit concCalculator(QWidget *parent = nullptr); 0062 ~concCalculator() override; 0063 0064 public Q_SLOTS: 0065 // Sub-routines involved in calculations of the unit 0066 0067 /// Calculates the amount of solute 0068 void calculateAmtSolute(); 0069 0070 /// Calculates the amount of solvent 0071 void calculateAmtSolvent(); 0072 0073 /// Calculates the molar mass 0074 void calculateMolarMass(); 0075 0076 /// Calculates the equivalent mass 0077 void calculateEqtMass(); 0078 0079 /// Calculates the calculate molar mass of the solvent 0080 void calculateMolarMassSolvent(); 0081 0082 /// calculates the concentration 0083 void calculateConcentration(); 0084 0085 // Functions (slots) that occur on changing a value 0086 // Sub routines which act as quantity change event handlers 0087 0088 /// occurs when the amount of solute is changed 0089 void amtSoluteChanged(); 0090 0091 /// occurs when the type in which amount of solute is specified is changed 0092 void amtSoluteTypeChanged(); 0093 0094 /// occurs when the amount of solvent is changed 0095 void amtSolventChanged(); 0096 0097 /// occurs when the type in which amount of solvent is specified is changed 0098 void amtSolventTypeChanged(); 0099 0100 /// occurs when the molar mass of solute is changed 0101 void molarMassChanged(double); 0102 0103 /// occurs when the equivalent mass of solute is changed 0104 void eqtMassChanged(double); 0105 0106 /// occurs when the molar mass of solvent is changed 0107 void molarMassSolventChanged(double); 0108 0109 /// occurs when the number of moles is changed 0110 void densitySoluteChanged(); 0111 0112 /// occurs when the density of solvent is changed 0113 void densitySolventChanged(); 0114 0115 /// occurs when the concentration is changed 0116 void concentrationChanged(); 0117 0118 /// occurs when any quantity is changed 0119 void calculate(); 0120 0121 /// returns volume of solvent in liters 0122 double volumeSolvent(); 0123 0124 /// returns mass of solvent in grams 0125 double massSolvent(); 0126 0127 /// returns number of moles of solvent 0128 double molesSolvent(); 0129 0130 /// returns density of solvent in grams per liter 0131 double densitySolvent(); 0132 0133 /// returns volume of solute in liters 0134 double volumeSolute(); 0135 0136 /// returns mass of solute in grams 0137 double massSolute(); 0138 0139 /// returns the number of moles of solute 0140 double molesSolute(); 0141 0142 /// returns the number of equivalents of solute 0143 double eqtsSolute(); 0144 0145 /// returns density of solute in grams per liter 0146 double densitySolute(); 0147 0148 /// Fills a Combobox with vulumina units 0149 void volumeUnitCombobox(QComboBox *comboBox); 0150 0151 /// Fills a Combobox with mass units 0152 void massUnitCombobox(QComboBox *comboBox); 0153 0154 /// Performs initialisation of the class. 0155 void init(); 0156 0157 /* 0158 * This function is called when an error occurs 0159 * @param mode indicates the mode of error 0160 * Refer ERROR_MODE_CONC for various modes 0161 */ 0162 void error(int); 0163 0164 /* 0165 * This function is called when the mode is changed 0166 * @param indicates the mode of calculation. 0167 * Refer MODE_CALCULATION_CONC for various modes 0168 */ 0169 void setMode(int); 0170 0171 private: 0172 Ui::concCalculator ui; // The user interface 0173 0174 Value m_amtSolute; // amount of solute 0175 Value m_amtSolvent; // amount of solvent 0176 double m_molesSolute; // amount of solute in moles 0177 double m_molesSolvent; // amount of solvent in moles 0178 double m_molarMass; // molar mass of solute 0179 double m_eqtMass; // equivalent mass of solute 0180 double m_molarMassSolvent; // molar mass of solvent 0181 Value m_densitySolute; // density of solute 0182 Value m_densitySolvent; // density of the solvent 0183 double m_concentration; // concentration of the solution 0184 0185 int m_mode; // specifies the mode of calculation 0186 }; 0187 0188 #endif // CONCCALCULATOR_H