diff options
author | Gehad elrobey <gehadelrobey@gmail.com> | 2014-10-17 22:46:33 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-10-20 18:04:01 -0700 |
commit | fae86eb4ceb51381e1a91e22048ee44991bebcda (patch) | |
tree | 024b5a4d30e8f33cd4f3f6ea3dbaf507e594e69d | |
parent | 71d21c375c404cd675e408689c79e9d58d315ccc (diff) | |
download | subsurface-fae86eb4ceb51381e1a91e22048ee44991bebcda.tar.gz |
HTML: Export unit preferences to settings file
Working on HTML exports to support imperial and metric units and also
custom selected units based on subsurface preferences.
User selected units is exported to settings file that will be mainly used
by listlib javascript file.
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-ui/divelogexportdialog.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/qt-ui/divelogexportdialog.cpp b/qt-ui/divelogexportdialog.cpp index 6b847a425..a0fbc50fd 100644 --- a/qt-ui/divelogexportdialog.cpp +++ b/qt-ui/divelogexportdialog.cpp @@ -17,6 +17,13 @@ #include "helpers.h" #include "statistics.h" +#define GET_UNIT(name, field, f, t) \ + v = settings.value(QString(name)); \ + if (v.isValid()) \ + field = (v.toInt() == 0) ? (t) : (f); \ + else \ + field = default_prefs.units.field + DiveLogExportDialog::DiveLogExportDialog(QWidget *parent) : QDialog(parent), ui(new Ui::DiveLogExportDialog) { @@ -149,7 +156,26 @@ void DiveLogExportDialog::exportHTMLsettings(const QString &filename) file.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&file); out << "settings = {\"fontSize\":\"" << fontSize << "\",\"fontFamily\":\"" << fontFamily << "\",\"listOnly\":\"" - << ui->exportListOnly->isChecked() << "\",\"subsurfaceNumbers\":\"" << ui->exportSubsurfaceNumber->isChecked() << "\",}"; + << ui->exportListOnly->isChecked() << "\",\"subsurfaceNumbers\":\"" << ui->exportSubsurfaceNumber->isChecked() << "\","; + //save units preferences + settings.beginGroup("Units"); + if (settings.value("unit_system").toString() == "metric") { + out << "\"unit_system\":\"Meteric\""; + } else if (settings.value("unit_system").toString() == "imperial") { + out << "\"unit_system\":\"Imperial\""; + } else { + QVariant v; + QString length, pressure, volume, temperature, weight; + GET_UNIT("length", length, "FEET", "METER"); + GET_UNIT("pressure", pressure, "PSI", "BAR"); + GET_UNIT("volume", volume, "CUFT", "LITER"); + GET_UNIT("temperature", temperature, "FAHRENHEIT", "CELSIUS"); + GET_UNIT("weight", weight, "LBS", "KG"); + out << "\"unit_system\":\"Personalize\","; + out << "\"units\":{\"depth\":\"" << length << "\",\"pressure\":\"" << pressure << "\",\"volume\":\"" << volume << "\",\"temperature\":\"" << temperature << "\",\"weight\":\"" << weight << "\"}"; + } + out << "}"; + settings.endGroup(); file.close(); } |