From 26751d83eee71188fd5501c557e47d504e79aae8 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Fri, 6 Feb 2009 21:24:13 +0000 Subject: [PATCH] Move the half baked code that guesses whether to default on metric or imperial units in only one place (instead of thousands of slightly different copies). Functionally equivalent. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28380 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Length.cpp | 20 ++++++++++++++++++++ src/Length.h | 3 +++ src/frontends/qt4/GuiBox.cpp | 4 +--- src/frontends/qt4/GuiDocument.cpp | 24 ++---------------------- src/frontends/qt4/GuiExternal.cpp | 22 +++------------------- src/frontends/qt4/GuiGraphics.cpp | 19 +++++-------------- src/frontends/qt4/GuiHSpace.cpp | 4 +--- src/frontends/qt4/GuiTabular.cpp | 10 +--------- src/frontends/qt4/GuiTabular.h | 2 -- src/frontends/qt4/GuiVSpace.cpp | 4 +--- 10 files changed, 37 insertions(+), 75 deletions(-) diff --git a/src/Length.cpp b/src/Length.cpp index c6e46066af..e248d7c4f4 100644 --- a/src/Length.cpp +++ b/src/Length.cpp @@ -276,6 +276,26 @@ int Length::inBP() const } +Length::UNIT Length::defaultUnit() +{ + // FIXME user a proper pref, since we should get rid of + // default_papersize in lyxrc. + UNIT u = Length::CM; + switch (lyxrc.default_papersize) { + case PAPER_USLETTER: + case PAPER_USLEGAL: + case PAPER_USEXECUTIVE: + u = Length::IN; + break; + default: + break; + } + + return u; +} + + + bool operator==(Length const & l1, Length const & l2) { return l1.value() == l2.value() && l1.unit() == l2.unit(); diff --git a/src/Length.h b/src/Length.h index cc2caf78ac..11b591dcb8 100644 --- a/src/Length.h +++ b/src/Length.h @@ -92,6 +92,9 @@ public: /// return the value in Big Postscript points. int inBP() const; + /// return the default unit (centimeter or inch) + static UNIT defaultUnit(); + friend bool isValidLength(std::string const & data, Length * result); private: diff --git a/src/frontends/qt4/GuiBox.cpp b/src/frontends/qt4/GuiBox.cpp index ff4fb6f334..38ff0074c3 100644 --- a/src/frontends/qt4/GuiBox.cpp +++ b/src/frontends/qt4/GuiBox.cpp @@ -17,7 +17,6 @@ #include "FuncRequest.h" #include "LengthCombo.h" #include "Length.h" -#include "LyXRC.h" // to set the default length values #include "qt_helpers.h" #include "Validator.h" @@ -265,8 +264,7 @@ void GuiBox::updateContents() halignCO->setEnabled(!ibox); setSpecial(ibox); - Length::UNIT default_unit = - (lyxrc.default_papersize > 3) ? Length::CM : Length::IN; + Length::UNIT const default_unit = Length::defaultUnit(); lengthToWidgets(widthED, widthUnitsLC, (params_.width).asString(), default_unit); diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 77d8b5fa41..1363065e3d 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -34,7 +34,7 @@ #include "Language.h" #include "LaTeXFeatures.h" #include "Layout.h" -#include "LyXRC.h" // defaultUnit +#include "LyXRC.h" #include "ModuleList.h" #include "OutputParams.h" #include "PDFOptions.h" @@ -1832,27 +1832,7 @@ void GuiDocument::applyView() void GuiDocument::paramsToDialog() { // set the default unit - Length::UNIT defaultUnit = Length::CM; - switch (lyxrc.default_papersize) { - case PAPER_DEFAULT: break; - - case PAPER_USLETTER: - case PAPER_USLEGAL: - case PAPER_USEXECUTIVE: - defaultUnit = Length::IN; - break; - - case PAPER_A3: - case PAPER_A4: - case PAPER_A5: - case PAPER_B3: - case PAPER_B4: - case PAPER_B5: - defaultUnit = Length::CM; - break; - case PAPER_CUSTOM: - break; - } + Length::UNIT const defaultUnit = Length::defaultUnit(); // preamble preambleModule->update(bp_, id()); diff --git a/src/frontends/qt4/GuiExternal.cpp b/src/frontends/qt4/GuiExternal.cpp index d5c14b8d7d..bd23cd5b70 100644 --- a/src/frontends/qt4/GuiExternal.cpp +++ b/src/frontends/qt4/GuiExternal.cpp @@ -349,22 +349,6 @@ void GuiExternal::widthUnitChanged() } -static Length::UNIT defaultUnit() -{ - Length::UNIT default_unit = Length::CM; - switch (lyxrc.default_papersize) { - case PAPER_USLETTER: - case PAPER_USLEGAL: - case PAPER_USEXECUTIVE: - default_unit = Length::IN; - break; - default: - break; - } - return default_unit; -} - - static void setRotation(QLineEdit & angleED, QComboBox & originCO, external::RotationData const & data) { @@ -401,11 +385,11 @@ static void setSize(QLineEdit & widthED, LengthCombo & widthUnitCO, widthUnitCO.setCurrentItem("scale"); } else lengthToWidgets(&widthED, &widthUnitCO, - data.width.asString(), defaultUnit()); + data.width.asString(), Length::defaultUnit()); string const h = data.height.zero() ? string() : data.height.asString(); - Length::UNIT default_unit = data.width.zero() ? - defaultUnit() : data.width.unit(); + Length::UNIT const default_unit = data.width.zero() ? + Length::defaultUnit() : data.width.unit(); lengthToWidgets(&heightED, &heightUnitCO, h, default_unit); heightED.setEnabled(!using_scale); diff --git a/src/frontends/qt4/GuiGraphics.cpp b/src/frontends/qt4/GuiGraphics.cpp index 0ca3ebb55c..d44d17a4b4 100644 --- a/src/frontends/qt4/GuiGraphics.cpp +++ b/src/frontends/qt4/GuiGraphics.cpp @@ -540,16 +540,7 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) } // set the right default unit - Length::UNIT unitDefault = Length::CM; - switch (lyxrc.default_papersize) { - case PAPER_USLETTER: - case PAPER_USLEGAL: - case PAPER_USEXECUTIVE: - unitDefault = Length::IN; - break; - default: - break; - } + Length::UNIT const defaultUnit = Length::defaultUnit(); //lyxerr << bufferFilepath(); string const name = @@ -642,9 +633,9 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) groupCO->blockSignals(false); if (igp.width.value() == 0) - lengthToWidgets(Width, widthUnit, _(autostr), unitDefault); + lengthToWidgets(Width, widthUnit, _(autostr), defaultUnit); else - lengthToWidgets(Width, widthUnit, igp.width, unitDefault); + lengthToWidgets(Width, widthUnit, igp.width, defaultUnit); bool const widthChecked = !Width->text().isEmpty() && Width->text() != qt_(autostr); @@ -655,9 +646,9 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) widthUnit->setEnabled(widthChecked); if (igp.height.value() == 0) - lengthToWidgets(Height, heightUnit, _(autostr), unitDefault); + lengthToWidgets(Height, heightUnit, _(autostr), defaultUnit); else - lengthToWidgets(Height, heightUnit, igp.height, unitDefault); + lengthToWidgets(Height, heightUnit, igp.height, defaultUnit); bool const heightChecked = !Height->text().isEmpty() && Height->text() != qt_(autostr); diff --git a/src/frontends/qt4/GuiHSpace.cpp b/src/frontends/qt4/GuiHSpace.cpp index 1967c2431d..63bccc5ff1 100644 --- a/src/frontends/qt4/GuiHSpace.cpp +++ b/src/frontends/qt4/GuiHSpace.cpp @@ -16,7 +16,6 @@ #include "qt_helpers.h" #include "Validator.h" -#include "LyXRC.h" #include "Spacing.h" #include "FuncRequest.h" @@ -248,8 +247,7 @@ static void setWidgetsFromHSpace(InsetSpaceParams const & params, fillPattern->setCurrentIndex(pattern); keep->setChecked(protect); - Length::UNIT default_unit = - (lyxrc.default_papersize > 3) ? Length::CM : Length::IN; + Length::UNIT const default_unit = Length::defaultUnit(); if (item == (params.math ? 9 : 7)) lengthToWidgets(value, unit, params.length, default_unit); else diff --git a/src/frontends/qt4/GuiTabular.cpp b/src/frontends/qt4/GuiTabular.cpp index 67e7b1dd50..b2dee188bf 100644 --- a/src/frontends/qt4/GuiTabular.cpp +++ b/src/frontends/qt4/GuiTabular.cpp @@ -23,7 +23,6 @@ #include "BufferView.h" #include "Cursor.h" #include "FuncRequest.h" -#include "LyXRC.h" #include "insets/InsetTabular.h" @@ -639,8 +638,7 @@ void GuiTabular::updateContents() bool const isReadonly = bc().policy().isReadOnly(); specialAlignmentED->setEnabled(!isReadonly); - Length::UNIT default_unit = - useMetricUnits() ? Length::CM : Length::IN; + Length::UNIT const default_unit = Length::defaultUnit(); borderDefaultRB->setChecked(!tabular_.use_booktabs); booktabsRB->setChecked(tabular_.use_booktabs); @@ -996,12 +994,6 @@ void GuiTabular::set(Tabular::Feature f, string const & arg) } -bool GuiTabular::useMetricUnits() const -{ - return lyxrc.default_papersize > PAPER_USEXECUTIVE; -} - - void GuiTabular::setSpecial(string const & special) { if (tabular_.isMultiColumn(getActiveCell())) diff --git a/src/frontends/qt4/GuiTabular.h b/src/frontends/qt4/GuiTabular.h index f6e1e21618..185bb800bd 100644 --- a/src/frontends/qt4/GuiTabular.h +++ b/src/frontends/qt4/GuiTabular.h @@ -91,8 +91,6 @@ private: /// Tabular::idx_type getActiveCell() const; - /// return true if units should default to metric - bool useMetricUnits() const; /// set a parameter void set(Tabular::Feature, std::string const & arg = std::string()); diff --git a/src/frontends/qt4/GuiVSpace.cpp b/src/frontends/qt4/GuiVSpace.cpp index f9deb6d757..995393a979 100644 --- a/src/frontends/qt4/GuiVSpace.cpp +++ b/src/frontends/qt4/GuiVSpace.cpp @@ -21,7 +21,6 @@ #include "qt_helpers.h" #include "Validator.h" -#include "LyXRC.h" // to set the default length values #include "Spacing.h" #include "FuncRequest.h" @@ -114,8 +113,7 @@ static void setWidgetsFromVSpace(VSpace const & space, spacing->setCurrentIndex(item); keep->setChecked(space.keep()); - Length::UNIT default_unit = - (lyxrc.default_papersize > 3) ? Length::CM : Length::IN; + Length::UNIT const default_unit = Length::defaultUnit(); bool const custom_vspace = space.kind() == VSpace::LENGTH; if (custom_vspace) { value->setEnabled(true);