diff --git a/Graphs/gSummaryChart.cpp b/Graphs/gSummaryChart.cpp index ff6cbcac..ff6f3972 100644 --- a/Graphs/gSummaryChart.cpp +++ b/Graphs/gSummaryChart.cpp @@ -73,6 +73,8 @@ void SummaryChart::SetDay(Day * nullday) for (int i=0;imachine_type()!=m_machinetype) continue; + for (int s=0;ssize();s++) { tmp=(*day)[s]->hours(); m_values[dn][s]=tmp; diff --git a/daily.cpp b/daily.cpp index fe7ca149..f2a9d8de 100644 --- a/daily.cpp +++ b/daily.cpp @@ -15,6 +15,7 @@ #include #include #include +#include //#include //#include @@ -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); } diff --git a/daily.h b/daily.h index 2d176415..4f401c65 100644 --- a/daily.h +++ b/daily.h @@ -47,6 +47,7 @@ public: QDate getDate() { return previous_date; } void PrintReport(); + void UnitsChanged(); private slots: diff --git a/daily.ui b/daily.ui index 4a63c028..27760d36 100644 --- a/daily.ui +++ b/daily.ui @@ -248,7 +248,7 @@ - 3 + 2 true @@ -531,23 +531,7 @@ - - - - 50 - - - Qt::Horizontal - - - QSlider::TicksAbove - - - 5 - - - - + @@ -569,7 +553,7 @@ - + @@ -585,28 +569,51 @@ + + + + + 0 + 0 + + + + Weight + + + + + + + 399.990000000000009 + + + + + + + 50 + + + Qt::Horizontal + + + QSlider::TicksAbove + + + 5 + + + + + + + + + + - - - - - 0 - 0 - - - - Weight - - - - - - - 399.990000000000009 - - - diff --git a/newprofile.cpp b/newprofile.cpp index f5d203ac..418b56a8 100644 --- a/newprofile.cpp +++ b/newprofile.cpp @@ -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(); - prof["Units"]=ui->heightCombo->currentText(); + 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