BMI calculations

This commit is contained in:
Mark Watkins 2011-12-03 11:05:17 +10:00
parent 42f54730e3
commit 7aabc7f4f5
4 changed files with 149 additions and 33 deletions

View File

@ -97,8 +97,8 @@ bool Session::Store(QString path)
if (eventlist.size()>0) {
s_eventfile=base+".001";
StoreEvents(s_eventfile);
} else {
qDebug() << "Trying to save empty events file";
} else { // who cares..
//qDebug() << "Trying to save empty events file";
}
//qDebug() << " Events done";
s_changed=false;

View File

@ -38,6 +38,7 @@
const int min_height=150;
const float ounce_convert=28.3495231;
const float pound_convert=ounce_convert*16;
Daily::Daily(QWidget *parent,gGraphView * shared, MainWindow *mw)
:QWidget(parent),mainwin(mw), ui(new Ui::Daily)
@ -834,6 +835,10 @@ void Daily::Load(QDate date)
ui->weightSpinBox->setValue(0);
ui->ouncesSpinBox->setValue(0);
ui->ZombieMeter->setValue(50);
ui->BMI->display(0);
ui->BMI->setVisible(false);
ui->BMIlabel->setVisible(false);
BookmarksChanged=false;
Session *journal=GetJournalSession(date);
if (journal) {
@ -862,6 +867,13 @@ void Daily::Load(QDate date)
ui->ouncesSpinBox->setVisible(true);
ui->ouncesSpinBox->setSuffix("oz");
}
double height=PROFILE["Height"].toDouble(&ok)/100.0;
if (height>0 && kg>0) {
//double bmi=kg/(height*height);
ui->BMI->setVisible(true);
ui->BMIlabel->setVisible(true);
//ui->BMI->display(bmi);
}
}
if (journal->settings.contains("ZombieMeter"))
@ -938,8 +950,22 @@ void Daily::Unload(QDate date)
kg=(ui->weightSpinBox->value()*(ounce_convert*16.0))+(ui->ouncesSpinBox->value()*ounce_convert);
kg/=1000.0;
}
journal->settings["Weight"]=kg;
journal->SetChanged(true);
double height=PROFILE["Height"].toDouble(&ok);
double bmi=(height*height)/kg;
if (kg>0) {
journal->settings["Weight"]=kg;
journal->settings["BMI"]=kg;
journal->SetChanged(true);
} else {
if (journal->settings.contains("Weight")) {
journal->settings.erase(journal->settings.find("Weight"));
journal->SetChanged(true);
}
if (journal->settings.contains("BMI")) {
journal->settings.erase(journal->settings.find("BMI"));
journal->SetChanged(true);
}
}
}
if ((!journal->settings.contains("ZombieMeter") && (ui->ZombieMeter->value()!=50)) || (journal->settings["ZombieMeter"].toDouble(&ok)!=ui->ZombieMeter->value())) {
journal->settings["ZombieMeter"]=ui->ZombieMeter->value();
@ -979,8 +1005,13 @@ void Daily::Unload(QDate date)
kg=(ui->weightSpinBox->value()*(ounce_convert*16))+(ui->ouncesSpinBox->value()*ounce_convert);
kg/=1000.0;
}
journal->settings["Weight"]=kg;
journal->SetChanged(true);
double height=PROFILE["Height"].toDouble(&ok);
double bmi=(height*height)/kg;
if (kg>0) {
journal->settings["Weight"]=kg;
journal->settings["BMI"]=bmi;
journal->SetChanged(true);
}
}
if (BookmarksChanged) {
QVariantList start;
@ -1365,3 +1396,32 @@ void Daily::on_bookmarkTable_itemChanged(QTableWidgetItem *item)
Q_UNUSED(item);
BookmarksChanged=true;
}
void Daily::on_weightSpinBox_valueChanged(double arg1)
{
bool ok;
double height=PROFILE["Height"].toDouble(&ok)/100.0;
double kg;
if (PROFILE["Units"].toString()=="metric")
kg=arg1;
else {
kg=(arg1*pound_convert) + (ui->ouncesSpinBox->value()*ounce_convert);
}
if ((height>0) && (kg>0)) {
double bmi=kg/(height * height);
ui->BMI->display(bmi);
//ui->BMI->setDigitCount(5);
//ui->BMI->setSmallDecimalPoint(true);
}
}
void Daily::on_ouncesSpinBox_valueChanged(int arg1)
{
bool ok;
double height=PROFILE["Height"].toDouble(&ok)/100.0;
double kg=(ui->weightSpinBox->value()*pound_convert) + (arg1*ounce_convert);
if ((height>0) && (kg>0)) {
double bmi=kg/(height * height);
ui->BMI->display(bmi);
//ui->BMI->setDigitCount(5);
//ui->BMI->setSmallDecimalPoint(true);
}
}

View File

@ -86,6 +86,10 @@ private slots:
void on_bookmarkTable_itemChanged(QTableWidgetItem *item);
void on_weightSpinBox_valueChanged(double arg1);
void on_ouncesSpinBox_valueChanged(int arg1);
protected:
private:
@ -126,3 +130,4 @@ private:
};
#endif // DAILY_H

105
daily.ui
View File

@ -248,7 +248,7 @@
</size>
</property>
<property name="currentIndex">
<number>3</number>
<number>2</number>
</property>
<property name="movable">
<bool>true</bool>
@ -531,29 +531,7 @@
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QLabel" name="label_10">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Awesome</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1" colspan="3">
<item row="0" column="1" colspan="7">
<widget class="QLabel" name="label_9">
<property name="font">
<font>
@ -582,14 +560,14 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="2" column="1" colspan="2">
<widget class="QDoubleSpinBox" name="weightSpinBox">
<property name="maximum">
<double>399.990000000000009</double>
</property>
</widget>
</item>
<item row="1" column="0" colspan="5">
<item row="1" column="0" colspan="9">
<widget class="QSlider" name="ZombieMeter">
<property name="value">
<number>50</number>
@ -605,13 +583,86 @@
</property>
</widget>
</item>
<item row="2" column="2">
<item row="2" column="3">
<widget class="QSpinBox" name="ouncesSpinBox">
<property name="suffix">
<string/>
</property>
</widget>
</item>
<item row="0" column="8">
<widget class="QLabel" name="label_10">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Awesome</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QLabel" name="BMIlabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>B.M.I.</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="5" colspan="2">
<widget class="QLCDNumber" name="BMI">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="smallDecimalPoint">
<bool>true</bool>
</property>
<property name="numDigits">
<number>5</number>
</property>
<property name="segmentStyle">
<enum>QLCDNumber::Flat</enum>
</property>
</widget>
</item>
<item row="2" column="7" colspan="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>