Added support for non-Metric weights

This commit is contained in:
Mark Watkins 2011-12-02 23:48:05 +10:00
parent b571217170
commit 61669afb06
5 changed files with 148 additions and 44 deletions

View File

@ -73,6 +73,8 @@ void SummaryChart::SetDay(Day * nullday)
for (int i=0;i<d.value().size();i++) { // for each day
day=d.value()[i];
if (!day) continue;
if (day->machine_type()!=m_machinetype) continue;
for (int s=0;s<day->size();s++) {
tmp=(*day)[s]->hours();
m_values[dn][s]=tmp;

View File

@ -15,6 +15,7 @@
#include <QResizeEvent>
#include <QScrollBar>
#include <QSpacerItem>
#include <cmath>
//#include <QPrinter>
//#include <QProgressBar>
@ -36,6 +37,7 @@
//extern QProgressBar *qprogress;
const int min_height=150;
const float ounce_convert=28.3495231;
Daily::Daily(QWidget *parent,gGraphView * shared, MainWindow *mw)
:QWidget(parent),mainwin(mw), ui(new Ui::Daily)
@ -289,6 +291,16 @@ Daily::Daily(QWidget *parent,gGraphView * shared, MainWindow *mw)
// TODO: Add preference to hide do this for Widget Haters..
//ui->calNavWidget->hide();
if (PROFILE["Units"].toString()=="metric") {
ui->ouncesSpinBox->setVisible(false);
ui->weightSpinBox->setDecimals(3);
ui->weightSpinBox->setSuffix("Kg");
} else {
ui->weightSpinBox->setSuffix("lb");
ui->weightSpinBox->setDecimals(0);
ui->ouncesSpinBox->setVisible(true);
ui->ouncesSpinBox->setSuffix("oz");
}
}
Daily::~Daily()
@ -474,6 +486,17 @@ void Daily::on_calendar_selectionChanged()
Load(ui->calendar->selectedDate());
ui->calButton->setText(ui->calendar->selectedDate().toString(Qt::TextDate));
ui->calendar->setFocus(Qt::ActiveWindowFocusReason);
if (PROFILE["Units"].toString()=="metric") {
ui->ouncesSpinBox->setVisible(false);
ui->weightSpinBox->setDecimals(3);
ui->weightSpinBox->setSuffix("Kg");
} else {
ui->weightSpinBox->setSuffix("lb");
ui->weightSpinBox->setDecimals(0);
ui->ouncesSpinBox->setVisible(true);
ui->ouncesSpinBox->setSuffix("oz");
}
}
void Daily::ResetGraphLayout()
{
@ -802,6 +825,7 @@ void Daily::Load(QDate date)
sl.append("Notes");
ui->bookmarkTable->setHorizontalHeaderLabels(sl);
ui->weightSpinBox->setValue(0);
ui->ouncesSpinBox->setValue(0);
ui->ZombieMeter->setValue(50);
Session *journal=GetJournalSession(date);
if (journal) {
@ -809,8 +833,28 @@ void Daily::Load(QDate date)
if (journal->settings.contains(Journal_Notes))
ui->JournalNotes->setHtml(journal->settings[Journal_Notes].toString());
if (journal->settings.contains("Weight"))
ui->weightSpinBox->setValue(journal->settings["Weight"].toDouble(&ok));
if (journal->settings.contains("Weight")) {
double kg=journal->settings["Weight"].toDouble(&ok);
if (PROFILE["Units"].toString()=="metric") {
ui->weightSpinBox->setDecimals(3);
ui->weightSpinBox->setValue(kg);
ui->ouncesSpinBox->setVisible(false);
ui->weightSpinBox->setSuffix("Kg");
} else {
float ounces=(kg*1000.0)/ounce_convert;
int pounds=ounces/16.0;
double oz;
double frac=modf(ounces,&oz);
ounces=(int(ounces) % 16)+frac;
ui->weightSpinBox->setValue(pounds);
ui->ouncesSpinBox->setValue(ounces);
ui->weightSpinBox->setSuffix("lb");
ui->weightSpinBox->setDecimals(0);
ui->ouncesSpinBox->setVisible(true);
ui->ouncesSpinBox->setSuffix("oz");
}
}
if (journal->settings.contains("ZombieMeter"))
ui->ZombieMeter->setValue(journal->settings["ZombieMeter"].toDouble(&ok));
@ -840,6 +884,32 @@ void Daily::Load(QDate date)
}
}
void Daily::UnitsChanged()
{
double kg;
if (PROFILE["Units"].toString()!="metric") {
kg=ui->weightSpinBox->value();
float ounces=(kg*1000.0)/ounce_convert;
int pounds=ounces/16;
float oz=fmodf(ounces,16);
ui->weightSpinBox->setValue(pounds);
ui->ouncesSpinBox->setValue(oz);
ui->weightSpinBox->setDecimals(0);
ui->weightSpinBox->setSuffix("lb");
ui->ouncesSpinBox->setVisible(true);
ui->ouncesSpinBox->setSuffix("oz");
} else {
kg=(ui->weightSpinBox->value()*(ounce_convert*16.0))+(ui->ouncesSpinBox->value()*ounce_convert);
kg/=1000.0;
ui->weightSpinBox->setDecimals(3);
ui->weightSpinBox->setValue(kg);
ui->ouncesSpinBox->setVisible(false);
ui->weightSpinBox->setSuffix("Kg");
}
}
void Daily::Unload(QDate date)
{
Session *journal=GetJournalSession(date);
@ -853,7 +923,14 @@ void Daily::Unload(QDate date)
journal->SetChanged(true);
}
if ((!journal->settings.contains("Weight") && (ui->weightSpinBox->value()>0)) || (journal->settings["Weight"].toDouble(&ok)!=ui->weightSpinBox->value())) {
journal->settings["Weight"]=ui->weightSpinBox->value();
double kg;
if (PROFILE["Units"].toString()=="metric") {
kg=ui->weightSpinBox->value();
} else {
kg=(ui->weightSpinBox->value()*(ounce_convert*16.0))+(ui->ouncesSpinBox->value()*ounce_convert);
kg/=1000.0;
}
journal->settings["Weight"]=kg;
journal->SetChanged(true);
}
if ((!journal->settings.contains("ZombieMeter") && (ui->ZombieMeter->value()!=50)) || (journal->settings["ZombieMeter"].toDouble(&ok)!=ui->ZombieMeter->value())) {
@ -888,7 +965,14 @@ void Daily::Unload(QDate date)
journal->SetChanged(true);
}
if (ui->weightSpinBox->value() > 0) {
journal->settings["Weight"]=ui->weightSpinBox->value();
double kg;
if (PROFILE["Units"].toString()=="metric") {
kg=ui->weightSpinBox->value();
} else {
kg=(ui->weightSpinBox->value()*(ounce_convert*16))+(ui->ouncesSpinBox->value()*ounce_convert);
kg/=1000.0;
}
journal->settings["Weight"]=kg;
journal->SetChanged(true);
}
if (ui->bookmarkTable->rowCount()>0) {
@ -916,6 +1000,9 @@ void Daily::Unload(QDate date)
journal->settings.erase(it);
}
}
if (journal->IsChanged()) {
mainwin->getOverview()->ReloadGraphs();
}
Machine *jm=PROFILE.GetMachine(MT_JOURNAL);
if (jm) jm->SaveSession(journal);
}

View File

@ -47,6 +47,7 @@ public:
QDate getDate() { return previous_date; }
void PrintReport();
void UnitsChanged();
private slots:

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,23 +531,7 @@
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QSlider" name="ZombieMeter">
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksAbove</enum>
</property>
<property name="tickInterval">
<number>5</number>
</property>
</widget>
</item>
<item row="0" column="2">
<item row="0" column="4">
<widget class="QLabel" name="label_10">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
@ -569,7 +553,7 @@
</property>
</widget>
</item>
<item row="0" column="1">
<item row="0" column="1" colspan="3">
<widget class="QLabel" name="label_9">
<property name="font">
<font>
@ -585,9 +569,7 @@
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_8">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
@ -600,13 +582,38 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="weightSpinBox">
<property name="maximum">
<double>399.990000000000009</double>
</property>
</widget>
</item>
<item row="1" column="0" colspan="5">
<widget class="QSlider" name="ZombieMeter">
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksAbove</enum>
</property>
<property name="tickInterval">
<number>5</number>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="ouncesSpinBox">
<property name="suffix">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>

View File

@ -12,6 +12,9 @@
#include "newprofile.h"
#include "ui_newprofile.h"
#include "mainwindow.h"
extern MainWindow *mainwin;
NewProfile::NewProfile(QWidget *parent) :
QDialog(parent),
@ -157,7 +160,11 @@ void NewProfile::on_nextButton_clicked()
prof["TimeZone"]=ui->timezoneCombo->itemData(ui->timezoneCombo->currentIndex()).toString();
prof["Country"]=ui->countryCombo->currentText();
prof["DST"]=ui->DSTcheckbox->isChecked();
if (prof["Units"].toString()!=ui->heightCombo->currentText()) {
prof["Units"]=ui->heightCombo->currentText();
mainwin->getDaily()->UnitsChanged();
}
double v=0;
if (ui->heightCombo->currentIndex()==1) {
// convert to metric