File indexing completed on 2022-11-29 12:50:41

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 NUCLEARCALCULATOR_H
0008 #define NUCLEARCALCULATOR_H
0009 
0010 #include "kalzium_debug.h"
0011 
0012 #include <KUnitConversion/Converter>
0013 #include <KUnitConversion/UnitCategory>
0014 
0015 #include "ui_nuclearCalculator.h"
0016 #include <element.h>
0017 #include <isotope.h>
0018 #include <kalziumdataobject.h>
0019 #include <prefs.h>
0020 
0021 // This is required for the unit conversion
0022 using namespace KUnitConversion;
0023 
0024 // This is the enumeration for the error type required in the error(int mode) function
0025 enum ERROR_MODE_NUKE { RESET_NUKE_MESSAGE = 0, INIT_AMT_ZERO, FINAL_AMT_ZERO, HALFLIFE_ZERO, FINAL_AMT_GREATER };
0026 
0027 // This is the enumeration for the mode of calculation in the nuclear calculator
0028 enum MODE_CALCULATION_NUKE { INIT_AMT = 0, FINAL_AMT, TIME };
0029 
0030 /*
0031  * This class implements the nuclear calculator which calculates the amount of substance,
0032  * remaining after a given time and given initial amount and so on after a radio-active decay.
0033  *
0034  * @author Kashyap R Puranik
0035  */
0036 class nuclearCalculator : public QFrame
0037 {
0038     Q_OBJECT
0039 
0040 public:
0041     explicit nuclearCalculator(QWidget *parent = nullptr);
0042     ~nuclearCalculator() override;
0043 
0044 public Q_SLOTS:
0045     /// Calculates the initial amount and updates the UI
0046     void calculateInitAmount();
0047 
0048     /// Calculates the final amount and updates the UI
0049     void calculateFinalAmount();
0050 
0051     /// Calculates the time required and updates the UI
0052     void calculateTime();
0053 
0054     /// This function is called when the element is changed
0055     void elementChanged(int index);
0056 
0057     /// This function is called when the isotope is changed
0058     void isotopeChanged(int index);
0059 
0060     /// This function is called when the halfLife is changed
0061     void halfLifeChanged();
0062 
0063     /// This function is called when any quantity is changed
0064     void calculate();
0065 
0066     /// This function is called when the initial amount is changed in the UI
0067     void initAmtChanged();
0068 
0069     /// This function is called when the final amount is changed in the UI
0070     void finalAmtChanged();
0071 
0072     /// This function is called when the time is changed in the UI
0073     void timeChanged();
0074 
0075     /// Fills a Combobox with vulumina units
0076     void timeUnitCombobox(QComboBox *comboBox);
0077 
0078     /// Fills a Combobox with mass units
0079     void massUnitCombobox(QComboBox *comboBox);
0080 
0081     /// Fetch the active unit id (KUnitConversion) from the combobox
0082     KUnitConversion::UnitId getUnitIdFromCombobox(QComboBox *comboBox);
0083 
0084     /*
0085      * This function is called when the slider in the ui is moved
0086      * @param x, is 10 times the number of halfLives
0087      * The slider is used to change the halfLife
0088      */
0089     void sliderMoved(int x);
0090 
0091     /*
0092      * This function is called when the mode is changed
0093      * @param indicates the mode of calculation.
0094      * Refer MODE_CALCULATION_NUKE for various modes
0095      */
0096     void setMode(int mode);
0097 
0098     /// This function is called during initialisation
0099     void init();
0100 
0101     /*
0102      * This function is called when an error occurs
0103      * @param mode indicates the mode of error
0104      * Refer ERROR_MODE_NUKE for various modes
0105      */
0106     void error(int mode);
0107 
0108 private:
0109     Ui::nuclearCalculator ui; // The user interface
0110 
0111     Element m_element; // Current element
0112     Isotope m_isotope; // current isotope
0113 
0114     Value m_halfLife; // The halfLife
0115     Value m_initAmount; // initial amount present
0116     Value m_finalAmount; // amount after time
0117     Value m_time; // the time involved in calculation
0118     double m_mass; // the atomic mass of the isotope
0119 
0120     int m_mode; // the mode of calculation
0121 };
0122 
0123 #endif // NUCLEARCALCULATOR_H