From d2e133fa62d6b36f2ffafdd917685d716b2aed67 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Thu, 8 Sep 2011 19:50:05 +1000 Subject: [PATCH] Added Preferences->Profile form, made preferences only save data if pressed OK --- SleepLib/profiles.cpp | 2 +- mainwindow.cpp | 3 +- preferencesdialog.cpp | 62 ++++++++-- preferencesdialog.h | 15 ++- preferencesdialog.ui | 270 +++++++++++++++++++++++++++++++++++++++++- 5 files changed, 329 insertions(+), 23 deletions(-) diff --git a/SleepLib/profiles.cpp b/SleepLib/profiles.cpp index 469d7623..607cc255 100644 --- a/SleepLib/profiles.cpp +++ b/SleepLib/profiles.cpp @@ -329,7 +329,7 @@ Profile *Create(QString name,QString realname,QString password) prof->Open(); profiles[name]=prof; prof->Set("Username",name); - prof->Set("Realname",realname); + //prof->Set("Realname",realname); if (!password.isEmpty()) prof->Set("Password",SHA1(password)); prof->Set("DataFolder","{home}/Profiles/{Username}"); diff --git a/mainwindow.cpp b/mainwindow.cpp index d673cb8e..978cc7bf 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -381,6 +381,7 @@ void MainWindow::on_action_Preferences_triggered() PreferencesDialog pd(this); if (pd.exec()==PreferencesDialog::Accepted) { qDebug() << "Preferences Accepted"; + pd.Save(); } } @@ -396,7 +397,7 @@ void MainWindow::on_actionEnable_Multithreading_toggled(bool checked) { pref["EnableMultithreading"]=checked; if (checked) { - qDebug() << "This feature is disabled due to it currently being useless."; + qDebug() << "Multithreading feature is disabled due to it currently being useless."; } } diff --git a/preferencesdialog.cpp b/preferencesdialog.cpp index 65cec9ff..d55a65b7 100644 --- a/preferencesdialog.cpp +++ b/preferencesdialog.cpp @@ -1,6 +1,5 @@ #include #include -#include "SleepLib/profiles.h" #include "preferencesdialog.h" #include "ui_preferencesdialog.h" #include "SleepLib/machine_common.h" @@ -11,6 +10,27 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) : { ui->setupUi(this); + QString prof=pref["Profile"].toString(); + profile=Profiles::Get(prof); + + ui->firstNameEdit->setText((*profile)["FirstName"].toString()); + ui->lastNameEdit->setText((*profile)["LastName"].toString()); + ui->addressEdit->clear(); + ui->addressEdit->appendPlainText((*profile)["Address"].toString()); + ui->emailEdit->setText((*profile)["EmailAddress"].toString()); + ui->phoneEdit->setText((*profile)["Phone"].toString()); + bool gender=(*profile)["Gender"].toBool(); + if (gender) ui->genderMale->setChecked(true); else ui->genderFemale->setChecked(true); + + bool ok; + ui->heightEdit->setValue((*profile)["Height"].toDouble(&ok)); + ui->dobEdit->setDate((*profile)["DOB"].toDate()); + int i=ui->unitCombo->findText((*profile)["UnitSystem"].toString()); + ui->unitCombo->setCurrentIndex(i); + + int i=ui->timeZoneCombo->findText((*profile)["TimeZone"].toString()); + ui->timeZoneCombo->setCurrentIndex(i); + if (pref.Exists("DaySplitTime")) { QTime t=pref["DaySplitTime"].toTime(); ui->timeEdit->setTime(t); @@ -74,6 +94,16 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) : row++; } } + ui->profileTab->setTabOrder(ui->firstNameEdit,ui->lastNameEdit); + ui->profileTab->setTabOrder(ui->lastNameEdit,ui->addressEdit); + ui->profileTab->setTabOrder(ui->addressEdit,ui->genderMale); + ui->profileTab->setTabOrder(ui->genderMale,ui->genderFemale); + ui->profileTab->setTabOrder(ui->genderFemale,ui->dobEdit); + ui->profileTab->setTabOrder(ui->dobEdit,ui->heightEdit); + ui->profileTab->setTabOrder(ui->heightEdit,ui->phoneEdit); + ui->profileTab->setTabOrder(ui->phoneEdit,ui->timeZoneCombo); + ui->profileTab->setTabOrder(ui->timeZoneCombo,ui->emailEdit); + ui->profileTab->setTabOrder(ui->emailEdit,ui->unitCombo); } @@ -100,28 +130,40 @@ void PreferencesDialog::on_eventTable_doubleClicked(const QModelIndex &index) } } -void PreferencesDialog::on_timeEdit_editingFinished() +void PreferencesDialog::Save() { + (*profile)["FirstName"]=ui->firstNameEdit->text(); + (*profile)["LastName"]=ui->lastNameEdit->text(); + (*profile)["Gender"]=ui->genderMale->isChecked(); + (*profile)["Height"]=ui->heightEdit->value(); + (*profile)["DOB"]=ui->dobEdit->date(); + (*profile)["EmailAddress"]=ui->emailEdit->text(); + (*profile)["Phone"]=ui->phoneEdit->text(); + (*profile)["Address"]=ui->addressEdit->toPlainText(); + (*profile)["UnitSystem"]=ui->unitCombo->currentText(); + (*profile)["TimeZone"]=ui->timeZoneCombo->currentText(); + + pref["CombineCloserSessions"]=ui->combineSlider->value(); + pref["IgnoreShorterSessions"]=ui->IgnoreSlider->value(); + + pref["MemoryHog"]=ui->memoryHogCheckbox->isChecked(); pref["DaySplitTime"]=ui->timeEdit->time(); + + profile->Save(); + pref.Save(); } -void PreferencesDialog::on_memoryHogCheckbox_toggled(bool checked) -{ - pref["MemoryHog"]=checked; -} -void PreferencesDialog::on_combineSlider_valueChanged(int position) +void PreferencesDialog::on_combineSlider_sliderMoved(int position) { if (position>0) { ui->combineLCD->display(position); } else ui->combineLCD->display(tr("OFF")); - pref["CombineCloserSessions"]=position; } -void PreferencesDialog::on_IgnoreSlider_valueChanged(int position) +void PreferencesDialog::on_IgnoreSlider_sliderMoved(int position) { if (position>0) { ui->IgnoreLCD->display(position); } else ui->IgnoreLCD->display(tr("OFF")); - pref["IgnoreShorterSessions"]=position; } diff --git a/preferencesdialog.h b/preferencesdialog.h index 25b412c3..e54a5997 100644 --- a/preferencesdialog.h +++ b/preferencesdialog.h @@ -9,6 +9,8 @@ #include #include +#include "SleepLib/profiles.h" + namespace Ui { class PreferencesDialog; } @@ -20,17 +22,14 @@ class PreferencesDialog : public QDialog public: explicit PreferencesDialog(QWidget *parent = 0); ~PreferencesDialog(); - + void Save(); +protected: + Profile * profile; private slots: void on_eventTable_doubleClicked(const QModelIndex &index); + void on_combineSlider_sliderMoved(int position); - void on_timeEdit_editingFinished(); - - void on_memoryHogCheckbox_toggled(bool checked); - - void on_combineSlider_valueChanged(int value); - - void on_IgnoreSlider_valueChanged(int value); + void on_IgnoreSlider_sliderMoved(int position); private: Ui::PreferencesDialog *ui; diff --git a/preferencesdialog.ui b/preferencesdialog.ui index 2730d881..372ec88d 100644 --- a/preferencesdialog.ui +++ b/preferencesdialog.ui @@ -9,8 +9,8 @@ 0 0 - 501 - 292 + 491 + 299 @@ -29,8 +29,272 @@ - 0 + 1 + + + &Profile + + + + + + + + Address: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + Phone: + + + + + + + + + + + + + 1 + 0 + + + + + + + + + + + + + First Name: + + + + + + + + + + Email: + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + true + + + + + + + + + + + Gender: + + + + + + + + + + 1 + 0 + + + + Male + + + + + + + + 1 + 0 + + + + Female + + + + + + + + + D.O.B.: + + + + + + + + 1 + 0 + + + + You don't have to if you don't want. Some nifty calculations may need it. + + + d/MM/yyyy + + + + + + + Height: + + + + + + + + 1 + 0 + + + + Used in BMI calculations + + + 40.000000000000000 + + + 299.990000000000009 + + + + + + + + + + 1 + 0 + + + + + + + + + + Last Name: + + + + + + + + The Moon + + + + + Jupiter + + + + + Ursa Minor + + + + + Yo Momma! + + + + + + + + Time Zone: + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Metric + + + + + Dark Ages + + + + + + + + Unit System: + + + + + + + &Sessions