From ed1a836e0e4c4443d8fc491b1de331ad45c0d9dd Mon Sep 17 00:00:00 2001 From: Hanna K Date: Sun, 9 Jul 2023 08:49:45 +0200 Subject: [PATCH] Add option to disable units and to interpret unrecognized symbols as variables (unknowns) to preferences (issue #87) --- src/preferencesdialog.cpp | 10 ++++++++++ src/preferencesdialog.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/preferencesdialog.cpp b/src/preferencesdialog.cpp index 48b4eee..84ff1aa 100644 --- a/src/preferencesdialog.cpp +++ b/src/preferencesdialog.cpp @@ -193,6 +193,7 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) : QDialog(parent) { BOX_G(tr("Simplified percentage calculation"), settings->simplified_percentage, simplifiedPercentageToggled(bool)); BOX_G(tr("Read precision"), settings->evalops.parse_options.read_precision != DONT_READ_PRECISION, readPrecisionToggled(bool)); BOX_G(tr("Limit implicit multiplication"), settings->evalops.parse_options.limit_implicit_multiplication, limitImplicitToggled(bool)); + BOX_G(tr("Interpret unrecognized symbols as variables"), settings->evalops.parse_options.unknowns_enabled, unknownsToggled(bool)); l2->addWidget(new QLabel(tr("Interval calculation:"), this), r, 0); combo = new QComboBox(this); combo->addItem(tr("Variance formula"), INTERVAL_CALCULATION_VARIANCE_FORMULA); @@ -264,6 +265,7 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) : QDialog(parent) { l->addStretch(1); l2 = new QGridLayout(w3); l2->setSizeConstraint(QLayout::SetFixedSize); r = 0; + BOX_G(tr("Enable units"), settings->evalops.parse_options.units_enabled, unitsToggled(bool)); BOX_G(tr("Abbreviate names"), settings->printops.abbreviate_names, abbreviateNamesToggled(bool)); BOX_G(tr("Use binary prefixes for information units"), CALCULATOR->usesBinaryPrefixes() > 0, binaryPrefixesToggled(bool)); l2->addWidget(new QLabel(tr("Automatic unit conversion:"), this), r, 0); @@ -489,6 +491,10 @@ void PreferencesDialog::exratesChanged(int i) { exratesSpin->setPrefix(str.right(index)); } } +void PreferencesDialog::unitsToggled(bool b) { + settings->evalops.parse_options.units_enabled = b; + emit expressionFormatUpdated(false); +} void PreferencesDialog::binaryPrefixesToggled(bool b) { CALCULATOR->useBinaryPrefixes(b ? 1 : 0); emit resultFormatUpdated(); @@ -584,6 +590,10 @@ void PreferencesDialog::limitImplicitToggled(bool b) { settings->printops.limit_implicit_multiplication = b; emit expressionFormatUpdated(true); } +void PreferencesDialog::unknownsToggled(bool b) { + settings->evalops.parse_options.unknowns_enabled = b; + emit expressionFormatUpdated(false); +} void PreferencesDialog::titleChanged(int i) { settings->title_type = qobject_cast(sender())->itemData(i).toInt(); emit titleTypeChanged(); diff --git a/src/preferencesdialog.h b/src/preferencesdialog.h index 1b57eea..c003082 100644 --- a/src/preferencesdialog.h +++ b/src/preferencesdialog.h @@ -53,9 +53,11 @@ class PreferencesDialog : public QDialog { void colorizeToggled(bool); void formatToggled(bool); void parsingModeChanged(int); + void unknownsToggled(bool); void temperatureCalculationChanged(int); void exratesToggled(bool); void exratesChanged(int); + void unitsToggled(bool); void binaryPrefixesToggled(bool); void readPrecisionToggled(bool); void simplifiedPercentageToggled(bool);