Skip to content

Commit

Permalink
Tidy Athlete Preferences
Browse files Browse the repository at this point in the history
.. too many things on one page
.. also deprecated 'bio' since its not used anywhere
  • Loading branch information
liversedge committed Oct 12, 2015
1 parent f6e8bad commit b198b54
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 124 deletions.
10 changes: 8 additions & 2 deletions src/ConfigDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ ConfigDialog::ConfigDialog(QDir _home, Zones *_zones, Context *context) :
pagesWidget->addWidget(athlete);

// units change on general affects units used on entry in athlete pages
connect (general->generalPage->unitCombo, SIGNAL(currentIndexChanged(int)), athlete->athletePage, SLOT(unitChanged(int)));
connect (general->generalPage->unitCombo, SIGNAL(currentIndexChanged(int)), athlete->athletePhysPage, SLOT(unitChanged(int)));

password = new PasswordConfig(_home, _zones, context);
HelpWhatsThis *passwordHelp = new HelpWhatsThis(password);
Expand Down Expand Up @@ -301,10 +301,14 @@ AthleteConfig::AthleteConfig(QDir home, Zones *zones, Context *context) :
home(home), zones(zones), context(context)
{
// the widgets
athletePage = new RiderPage(this, context);
athletePage = new AboutRiderPage(this, context);
HelpWhatsThis *athleteHelp = new HelpWhatsThis(athletePage);
athletePage->setWhatsThis(athleteHelp->getWhatsThisText(HelpWhatsThis::Preferences_Athlete_About));

athletePhysPage = new RiderPhysPage(this, context);
HelpWhatsThis *athletePhysHelp = new HelpWhatsThis(athletePhysPage);
athletePhysPage->setWhatsThis(athleteHelp->getWhatsThisText(HelpWhatsThis::Preferences_Athlete_About_Phys));

zonePage = new ZonePage(context);
HelpWhatsThis *zoneHelp = new HelpWhatsThis(zonePage);
zonePage->setWhatsThis(zoneHelp->getWhatsThisText(HelpWhatsThis::Preferences_Athlete_TrainingZones_Power));
Expand All @@ -328,6 +332,7 @@ AthleteConfig::AthleteConfig(QDir home, Zones *zones, Context *context) :

QTabWidget *tabs = new QTabWidget(this);
tabs->addTab(athletePage, tr("About"));
tabs->addTab(athletePhysPage, tr("Measures"));
tabs->addTab(zonePage, tr("Power Zones"));
tabs->addTab(hrZonePage, tr("Heartrate Zones"));
tabs->addTab(paceZonePage, tr("Pace Zones"));
Expand All @@ -341,6 +346,7 @@ qint32 AthleteConfig::saveClicked()
qint32 state = 0;

state |= athletePage->saveClicked();
state |= athletePhysPage->saveClicked();
state |= zonePage->saveClicked();
state |= hrZonePage->saveClicked();
state |= paceZonePage->saveClicked();
Expand Down
3 changes: 2 additions & 1 deletion src/ConfigDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class AthleteConfig : public QWidget

public:
AthleteConfig(QDir home, Zones *zones, Context *context);
RiderPage *athletePage;
AboutRiderPage *athletePage;
RiderPhysPage *athletePhysPage;

public slots:
qint32 saveClicked();
Expand Down
1 change: 1 addition & 0 deletions src/HelpWhatsThis.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ Q_OBJECT

Preferences_General,
Preferences_Athlete_About,
Preferences_Athlete_About_Phys,
Preferences_Athlete_TrainingZones_Power,
Preferences_Athlete_TrainingZones_HR,
Preferences_Athlete_TrainingZones_Pace,
Expand Down
233 changes: 132 additions & 101 deletions src/Pages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ CredentialsPage::saveClicked()
//
// About me
//
RiderPage::RiderPage(QWidget *parent, Context *context) : QWidget(parent), context(context)
AboutRiderPage::AboutRiderPage(QWidget *parent, Context *context) : QWidget(parent), context(context)
{
QVBoxLayout *all = new QVBoxLayout(this);
QGridLayout *grid = new QGridLayout;
Expand All @@ -903,15 +903,6 @@ RiderPage::RiderPage(QWidget *parent, Context *context) : QWidget(parent), conte
QLabel *nicklabel = new QLabel(tr("Nickname"));
QLabel *doblabel = new QLabel(tr("Date of Birth"));
QLabel *sexlabel = new QLabel(tr("Sex"));
QLabel *biolabel = new QLabel(tr("Bio"));

QString weighttext = QString(tr("Weight (%1)")).arg(context->athlete->useMetricUnits ? tr("kg") : tr("lb"));
weightlabel = new QLabel(weighttext);

QString heighttext = QString(tr("Height (%1)")).arg(context->athlete->useMetricUnits ? tr("cm") : tr("in"));
heightlabel = new QLabel(heighttext);

wbaltaulabel = new QLabel(tr("W'bal tau (s)"));

nickname = new QLineEdit(this);
nickname->setText(appsettings->cvalue(context->athlete->cyclist, GC_NICKNAME, "").toString());
Expand All @@ -929,27 +920,6 @@ RiderPage::RiderPage(QWidget *parent, Context *context) : QWidget(parent), conte
// is language independent (and for once the code is easier!)
sex->setCurrentIndex(appsettings->cvalue(context->athlete->cyclist, GC_SEX).toInt());

weight = new QDoubleSpinBox(this);
weight->setMaximum(999.9);
weight->setMinimum(0.0);
weight->setDecimals(1);
weight->setValue(appsettings->cvalue(context->athlete->cyclist, GC_WEIGHT).toDouble() * (context->athlete->useMetricUnits ? 1.0 : LB_PER_KG));

height = new QDoubleSpinBox(this);
height->setMaximum(999.9);
height->setMinimum(0.0);
height->setDecimals(1);
height->setValue(appsettings->cvalue(context->athlete->cyclist, GC_HEIGHT).toDouble() * (context->athlete->useMetricUnits ? 100.0 : 100.0/CM_PER_INCH));

wbaltau = new QSpinBox(this);
wbaltau->setMinimum(30);
wbaltau->setMaximum(1200);
wbaltau->setSingleStep(10);
wbaltau->setValue(appsettings->cvalue(context->athlete->cyclist, GC_WBALTAU, 300).toInt());

bio = new QTextEdit(this);
bio->setText(appsettings->cvalue(context->athlete->cyclist, GC_BIO).toString());

if (QFileInfo(context->athlete->home->config().canonicalPath() + "/" + "avatar.png").exists())
avatar = QPixmap(context->athlete->home->config().canonicalPath() + "/" + "avatar.png");
else
Expand Down Expand Up @@ -1026,30 +996,6 @@ RiderPage::RiderPage(QWidget *parent, Context *context) : QWidget(parent), conte
connect(wheelSizeEdit, SIGNAL(textEdited(QString)), this, SLOT(resetWheelSize()));


//
// Performance manager
//

perfManSTSLabel = new QLabel(tr("STS average (days)"));
perfManLTSLabel = new QLabel(tr("LTS average (days)"));
perfManSTSavgValidator = new QIntValidator(1,21,this);
perfManLTSavgValidator = new QIntValidator(7,56,this);

// get config or set to defaults
QVariant perfManSTSVal = appsettings->cvalue(context->athlete->cyclist, GC_STS_DAYS);
if (perfManSTSVal.isNull() || perfManSTSVal.toInt() == 0) perfManSTSVal = 7;
QVariant perfManLTSVal = appsettings->cvalue(context->athlete->cyclist, GC_LTS_DAYS);
if (perfManLTSVal.isNull() || perfManLTSVal.toInt() == 0) perfManLTSVal = 42;

perfManSTSavg = new QLineEdit(perfManSTSVal.toString(),this);
perfManSTSavg->setValidator(perfManSTSavgValidator);
perfManLTSavg = new QLineEdit(perfManLTSVal.toString(),this);
perfManLTSavg->setValidator(perfManLTSavgValidator);

showSBToday = new QCheckBox(tr("PMC Stress Balance Today"), this);
showSBToday->setChecked(appsettings->cvalue(context->athlete->cyclist, GC_SB_TODAY).toInt());


//
// Auto Backup
//
Expand All @@ -1072,37 +1018,22 @@ RiderPage::RiderPage(QWidget *parent, Context *context) : QWidget(parent), conte
grid->addWidget(nicklabel, 0, 0, alignment);
grid->addWidget(doblabel, 1, 0, alignment);
grid->addWidget(sexlabel, 2, 0, alignment);
grid->addWidget(weightlabel, 3, 0, alignment);
grid->addWidget(heightlabel, 4, 0, alignment);
grid->addWidget(wbaltaulabel, 5, 0, alignment);

grid->addWidget(nickname, 0, 1, alignment);
grid->addWidget(dob, 1, 1, alignment);
grid->addWidget(sex, 2, 1, alignment);
grid->addWidget(weight, 3, 1, alignment);
grid->addWidget(height, 4, 1, alignment);
grid->addWidget(wbaltau, 5, 1, alignment);


grid->addWidget(crankLengthLabel, 6, 0, alignment);
grid->addWidget(crankLengthCombo, 6, 1, alignment);
grid->addWidget(wheelSizeLabel, 7, 0, alignment);
grid->addLayout(wheelSizeLayout, 7, 1, 1, 2, alignment);
grid->addWidget(perfManSTSLabel, 8, 0, alignment);
grid->addWidget(perfManSTSavg, 8, 1, alignment);
grid->addWidget(perfManLTSLabel, 9, 0, alignment);
grid->addWidget(perfManLTSavg, 9, 1, alignment);
grid->addWidget(showSBToday, 10, 1, alignment);
grid->addWidget(autoBackupFolderLabel, 11,0, alignment);
grid->addWidget(autoBackupFolder, 11, 1, alignment);
grid->addWidget(autoBackupFolderBrowse, 11, 2, alignment);
grid->addWidget(autoBackupPeriodLabel, 12, 0,alignment);
grid->addWidget(autoBackupPeriod, 12, 1, alignment);

grid->addWidget(biolabel, 13, 0, alignment);
grid->addWidget(bio, 14, 0, 1, 3);

grid->addWidget(avatarButton, 0, 1, 5, 2, Qt::AlignRight|Qt::AlignVCenter);

grid->addWidget(crankLengthLabel, 4, 0, alignment);
grid->addWidget(crankLengthCombo, 4, 1, alignment);
grid->addWidget(wheelSizeLabel, 5, 0, alignment);
grid->addLayout(wheelSizeLayout, 5, 1, 1, 2, alignment);
grid->addWidget(autoBackupFolderLabel, 7,0, alignment);
grid->addWidget(autoBackupFolder, 7, 1, alignment);
grid->addWidget(autoBackupFolderBrowse, 7, 2, alignment);
grid->addWidget(autoBackupPeriodLabel, 8, 0,alignment);
grid->addWidget(autoBackupPeriod, 8, 1, alignment);

grid->addWidget(avatarButton, 0, 1, 4, 2, Qt::AlignRight|Qt::AlignVCenter);
all->addLayout(grid);
all->addStretch();

Expand All @@ -1113,18 +1044,14 @@ RiderPage::RiderPage(QWidget *parent, Context *context) : QWidget(parent), conte
// care about tracking as it is used by metrics

// height and weight as stored (always metric)
b4.height = appsettings->cvalue(context->athlete->cyclist, GC_HEIGHT).toDouble();
b4.weight = appsettings->cvalue(context->athlete->cyclist, GC_WEIGHT).toDouble();
b4.wheel = wheelSize;
b4.crank = crankLengthCombo->currentIndex();
b4.lts = perfManLTSVal.toInt();
b4.sts = perfManSTSVal.toInt();

connect (avatarButton, SIGNAL(clicked()), this, SLOT(chooseAvatar()));
}

void
RiderPage::chooseAvatar()
AboutRiderPage::chooseAvatar()
{
QString filename = QFileDialog::getOpenFileName(this, tr("Choose Picture"),
"", tr("Images (*.png *.jpg *.bmp)"));
Expand All @@ -1136,7 +1063,7 @@ RiderPage::chooseAvatar()
}
}

void RiderPage::chooseAutoBackupFolder()
void AboutRiderPage::chooseAutoBackupFolder()
{
// did the user type something ? if not, get it from the Settings
QString path = autoBackupFolder->text();
Expand All @@ -1148,7 +1075,7 @@ void RiderPage::chooseAutoBackupFolder()
}

void
RiderPage::unitChanged(int currentIndex)
RiderPhysPage::unitChanged(int currentIndex)
{
if (currentIndex == 0) {
QString weighttext = QString(tr("Weight (%1)")).arg(tr("kg"));
Expand All @@ -1171,42 +1098,33 @@ RiderPage::unitChanged(int currentIndex)
}

void
RiderPage::calcWheelSize()
AboutRiderPage::calcWheelSize()
{
int diameter = WheelSize::calcPerimeter(rimSizeCombo->currentIndex(), tireSizeCombo->currentIndex());
if (diameter>0)
wheelSizeEdit->setText(QString("%1").arg(diameter));
}

void
RiderPage::resetWheelSize()
AboutRiderPage::resetWheelSize()
{
rimSizeCombo->setCurrentIndex(0);
tireSizeCombo->setCurrentIndex(0);
}

qint32
RiderPage::saveClicked()
AboutRiderPage::saveClicked()
{
appsettings->setCValue(context->athlete->cyclist, GC_NICKNAME, nickname->text());
appsettings->setCValue(context->athlete->cyclist, GC_DOB, dob->date());
appsettings->setCValue(context->athlete->cyclist, GC_WEIGHT, weight->value() * (context->athlete->useMetricUnits ? 1.0 : KG_PER_LB));
appsettings->setCValue(context->athlete->cyclist, GC_HEIGHT, height->value() * (context->athlete->useMetricUnits ? 1.0/100.0 : CM_PER_INCH/100.0));
appsettings->setCValue(context->athlete->cyclist, GC_WBALTAU, wbaltau->value());


appsettings->setCValue(context->athlete->cyclist, GC_SEX, sex->currentIndex());
appsettings->setCValue(context->athlete->cyclist, GC_BIO, bio->toPlainText());
avatar.save(context->athlete->home->config().canonicalPath() + "/" + "avatar.png", "PNG");

appsettings->setCValue(context->athlete->cyclist, GC_CRANKLENGTH, crankLengthCombo->currentText());
appsettings->setCValue(context->athlete->cyclist, GC_WHEELSIZE, wheelSizeEdit->text().toInt());

// Performance Manager
appsettings->setCValue(context->athlete->cyclist, GC_STS_DAYS, perfManSTSavg->text());
appsettings->setCValue(context->athlete->cyclist, GC_LTS_DAYS, perfManLTSavg->text());
appsettings->setCValue(context->athlete->cyclist, GC_SB_TODAY, (int) showSBToday->isChecked());

// Auto Backup
appsettings->setCValue(context->athlete->cyclist, GC_AUTOBACKUP_FOLDER, autoBackupFolder->text());
appsettings->setCValue(context->athlete->cyclist, GC_AUTOBACKUP_PERIOD, autoBackupPeriod->value());
Expand All @@ -1219,6 +1137,119 @@ RiderPage::saveClicked()
b4.crank != crankLengthCombo->currentIndex() )
state += CONFIG_GENERAL;

return state;
}

//
// About me - physiology settings
//
RiderPhysPage::RiderPhysPage(QWidget *parent, Context *context) : QWidget(parent), context(context)
{
QVBoxLayout *all = new QVBoxLayout(this);
QGridLayout *grid = new QGridLayout;
#ifdef Q_OS_MAX
setContentsMargins(10,10,10,10);
grid->setSpacing(5);
all->setSpacing(5);
#endif

QString weighttext = QString(tr("Weight (%1)")).arg(context->athlete->useMetricUnits ? tr("kg") : tr("lb"));
weightlabel = new QLabel(weighttext);

QString heighttext = QString(tr("Height (%1)")).arg(context->athlete->useMetricUnits ? tr("cm") : tr("in"));
heightlabel = new QLabel(heighttext);

wbaltaulabel = new QLabel(tr("W'bal tau (s)"));

weight = new QDoubleSpinBox(this);
weight->setMaximum(999.9);
weight->setMinimum(0.0);
weight->setDecimals(1);
weight->setValue(appsettings->cvalue(context->athlete->cyclist, GC_WEIGHT).toDouble() * (context->athlete->useMetricUnits ? 1.0 : LB_PER_KG));

height = new QDoubleSpinBox(this);
height->setMaximum(999.9);
height->setMinimum(0.0);
height->setDecimals(1);
height->setValue(appsettings->cvalue(context->athlete->cyclist, GC_HEIGHT).toDouble() * (context->athlete->useMetricUnits ? 100.0 : 100.0/CM_PER_INCH));

wbaltau = new QSpinBox(this);
wbaltau->setMinimum(30);
wbaltau->setMaximum(1200);
wbaltau->setSingleStep(10);
wbaltau->setValue(appsettings->cvalue(context->athlete->cyclist, GC_WBALTAU, 300).toInt());

//
// Performance manager
//

perfManSTSLabel = new QLabel(tr("STS average (days)"));
perfManLTSLabel = new QLabel(tr("LTS average (days)"));
perfManSTSavgValidator = new QIntValidator(1,21,this);
perfManLTSavgValidator = new QIntValidator(7,56,this);

// get config or set to defaults
QVariant perfManSTSVal = appsettings->cvalue(context->athlete->cyclist, GC_STS_DAYS);
if (perfManSTSVal.isNull() || perfManSTSVal.toInt() == 0) perfManSTSVal = 7;
QVariant perfManLTSVal = appsettings->cvalue(context->athlete->cyclist, GC_LTS_DAYS);
if (perfManLTSVal.isNull() || perfManLTSVal.toInt() == 0) perfManLTSVal = 42;

perfManSTSavg = new QLineEdit(perfManSTSVal.toString(),this);
perfManSTSavg->setValidator(perfManSTSavgValidator);
perfManLTSavg = new QLineEdit(perfManLTSVal.toString(),this);
perfManLTSavg->setValidator(perfManLTSavgValidator);

showSBToday = new QCheckBox(tr("PMC Stress Balance Today"), this);
showSBToday->setChecked(appsettings->cvalue(context->athlete->cyclist, GC_SB_TODAY).toInt());

Qt::Alignment alignment = Qt::AlignLeft|Qt::AlignVCenter;

grid->addWidget(weightlabel, 1, 0, alignment);
grid->addWidget(heightlabel, 2, 0, alignment);
grid->addWidget(wbaltaulabel, 3, 0, alignment);

grid->addWidget(weight, 1, 1, alignment);
grid->addWidget(height, 2, 1, alignment);
grid->addWidget(wbaltau, 3, 1, alignment);


grid->addWidget(perfManSTSLabel, 4, 0, alignment);
grid->addWidget(perfManSTSavg, 4, 1, alignment);
grid->addWidget(perfManLTSLabel, 5, 0, alignment);
grid->addWidget(perfManLTSavg, 5, 1, alignment);
grid->addWidget(showSBToday, 6, 1, alignment);

all->addLayout(grid);
all->addStretch();

// save initial values for things we care about
// note we don't worry about age or sex at this point
// since they are not used, nor the W'bal tau used in
// the realtime code. This is limited to stuff we
// care about tracking as it is used by metrics

// height and weight as stored (always metric)
b4.height = appsettings->cvalue(context->athlete->cyclist, GC_HEIGHT).toDouble();
b4.weight = appsettings->cvalue(context->athlete->cyclist, GC_WEIGHT).toDouble();
b4.lts = perfManLTSVal.toInt();
b4.sts = perfManSTSVal.toInt();
}

qint32
RiderPhysPage::saveClicked()
{
appsettings->setCValue(context->athlete->cyclist, GC_WEIGHT, weight->value() * (context->athlete->useMetricUnits ? 1.0 : KG_PER_LB));
appsettings->setCValue(context->athlete->cyclist, GC_HEIGHT, height->value() * (context->athlete->useMetricUnits ? 1.0/100.0 : CM_PER_INCH/100.0));
appsettings->setCValue(context->athlete->cyclist, GC_WBALTAU, wbaltau->value());


// Performance Manager
appsettings->setCValue(context->athlete->cyclist, GC_STS_DAYS, perfManSTSavg->text());
appsettings->setCValue(context->athlete->cyclist, GC_LTS_DAYS, perfManLTSavg->text());
appsettings->setCValue(context->athlete->cyclist, GC_SB_TODAY, (int) showSBToday->isChecked());

qint32 state=0;

// PMC constants changed ?
if(b4.lts != perfManLTSavg->text().toInt() ||
b4.sts != perfManSTSavg->text().toInt())
Expand Down
Loading

0 comments on commit b198b54

Please sign in to comment.