]> git.lyx.org Git - features.git/commitdiff
Add support for number localization in the GUI (using Qt's locale facilities).
authorJürgen Spitzmüller <spitz@lyx.org>
Sun, 12 Jul 2009 15:44:26 +0000 (15:44 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Sun, 12 Jul 2009 15:44:26 +0000 (15:44 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30511 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiExternal.cpp
src/frontends/qt4/GuiGraphics.cpp
src/frontends/qt4/GuiParagraph.cpp
src/frontends/qt4/GuiPrefs.cpp
src/frontends/qt4/Validator.cpp
src/frontends/qt4/qt_helpers.cpp
src/frontends/qt4/qt_helpers.h

index c88fb7f98e5a5137e27d57aac836308b98a03a93..800a5c589873ca3a79a57c1ed572a56455593c09 100644 (file)
@@ -1877,7 +1877,7 @@ void GuiDocument::applyView()
                break;
        case 3:
                bp_.spacing().set(Spacing::Other,
-                       fromqstr(textLayoutModule->lspacingLE->text()));
+                       widgetToDoubleStr(textLayoutModule->lspacingLE));
                break;
        }
 
@@ -2201,8 +2201,8 @@ void GuiDocument::paramsToDialog()
 
        textLayoutModule->lspacingCO->setCurrentIndex(nitem);
        if (bp_.spacing().getSpace() == Spacing::Other) {
-               textLayoutModule->lspacingLE->setText(
-                       toqstr(bp_.spacing().getValueAsString()));
+               doubleToWidget(textLayoutModule->lspacingLE,
+                       bp_.spacing().getValueAsString());
        }
        setLSpacing(nitem);
 
index bd23cd5b70b427a01edc4991f13537a420957eee..c32f3edecd5ba6f33317c36408bfd3805e336ed4 100644 (file)
@@ -213,23 +213,25 @@ bool GuiExternal::activateAspectratio() const
        if (usingScale())
                return false;
 
-       string const wstr = fromqstr(widthED->text());
-       if (wstr.empty())
+       QString const wstr = widthED->text();
+       if (wstr.isEmpty())
                return false;
-       bool const wIsDbl = isStrDbl(wstr);
-       if (wIsDbl && float_equal(convert<double>(wstr), 0.0, 0.05))
+       bool wIsDbl;
+       double val = wstr.trimmed().toDouble(&wIsDbl);
+       if (wIsDbl && float_equal(val, 0.0, 0.05))
                return false;
        Length l;
-       if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
+       if (!wIsDbl && (!isValidLength(fromqstr(wstr), &l) || l.zero()))
                return false;
 
-       string const hstr = fromqstr(heightED->text());
-       if (hstr.empty())
+       QString const hstr = heightED->text();
+       if (hstr.isEmpty())
                return false;
-       bool const hIsDbl = isStrDbl(hstr);
-       if (hIsDbl && float_equal(convert<double>(hstr), 0.0, 0.05))
+       bool hIsDbl;
+       val = hstr.trimmed().toDouble(&hIsDbl);
+       if (hIsDbl && float_equal(val, 0.0, 0.05))
                return false;
-       if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
+       if (!hIsDbl && (!isValidLength(fromqstr(hstr), &l) || l.zero()))
                return false;
 
        return true;
@@ -353,7 +355,7 @@ static void setRotation(QLineEdit & angleED, QComboBox & originCO,
        external::RotationData const & data)
 {
        originCO.setCurrentIndex(int(data.origin()));
-       angleED.setText(toqstr(data.angle));
+       doubleToWidget(&angleED, data.angle);
 }
 
 
@@ -363,7 +365,7 @@ static void getRotation(external::RotationData & data,
        typedef external::RotationData::OriginType OriginType;
 
        data.origin(static_cast<OriginType>(originCO.currentIndex()));
-       data.angle = fromqstr(angleED.text());
+       data.angle = widgetToDoubleStr(&angleED);
 }
 
 
@@ -381,7 +383,7 @@ static void setSize(QLineEdit & widthED, LengthCombo & widthUnitCO,
        }
 
        if (using_scale) {
-               widthED.setText(toqstr(scale));
+               doubleToWidget(&widthED, scale);
                widthUnitCO.setCurrentItem("scale");
        } else
                lengthToWidgets(&widthED, &widthUnitCO,
@@ -408,11 +410,9 @@ static void getSize(external::ResizeData & data,
        QLineEdit const & heightED, LengthCombo const & heightUnitCO,
        QCheckBox const & aspectratioCB, bool const scaling)
 {
-       string const width = fromqstr(widthED.text());
-
        if (scaling) {
                // scaling instead of a width
-               data.scale = width;
+               data.scale = widgetToDoubleStr(&widthED);
                data.width = Length();
        } else {
                data.width = Length(widgetsToLength(&widthED, &widthUnitCO));
index 7e28a0c83a91a77f6218d9a22437d17e7c389d7f..953f8e1247991e888185dc5d05c3e93a6b4b7ca4 100644 (file)
@@ -109,49 +109,6 @@ static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
 }
 
 
-template<class Pair>
-vector<typename Pair::first_type> getFirst(vector<Pair> const & pr)
-{
-       size_t const n = pr.size();
-       vector<typename Pair::first_type> tmp(n);
-       for (size_t i = 0; i != n; ++i)
-               tmp[i] = pr[i].first;
-       return tmp;
-}
-
-
-///
-template<class Pair>
-vector<typename Pair::second_type> getSecond(vector<Pair> const & pr)
-{
-       size_t const n = pr.size();
-       vector<typename Pair::second_type> tmp(n);
-       for (size_t i = 0; i != n; ++i)
-               tmp[i] = pr[i].second;
-       return tmp;
-}
-
-
-/// The (tranlated) GUI string and it's LaTeX equivalent.
-typedef pair<docstring, string> RotationOriginPair;
-///
-vector<RotationOriginPair> getRotationOriginData()
-{
-       static vector<RotationOriginPair> data;
-       if (!data.empty())
-               return data;
-
-       data.resize(rorigin_size);
-       for (size_type i = 0; i < rorigin_size; ++i) {
-               data[i] = make_pair(_(rorigin_gui_strs[i]),
-                                   rorigin_lyx_strs[i]);
-       }
-
-       return data;
-}
-
-
-
 GuiGraphics::GuiGraphics(GuiView & lv)
        : GuiDialog(lv, "graphics", qt_("Graphics"))
 {
@@ -524,21 +481,25 @@ static int itemNumber(const vector<string> & v, string const & s)
 void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
 {
        static char const * const bb_units[] = { "bp", "cm", "mm", "in" };
+       static char const * const bb_units_gui[] = { N_("bp"), N_("cm"), N_("mm"), N_("in") };
        size_t const bb_size = sizeof(bb_units) / sizeof(bb_units[0]);
 
-       vector<string> const units = vector<string>(bb_units, bb_units + bb_size);
        lbXunit->clear();
        lbYunit->clear();
        rtXunit->clear();
        rtYunit->clear();
-       for (vector<string>::const_iterator it = units.begin();
-           it != units.end(); ++it) {
-               lbXunit->addItem(toqstr(*it));
-               lbYunit->addItem(toqstr(*it));
-               rtXunit->addItem(toqstr(*it));
-               rtYunit->addItem(toqstr(*it));
+       
+       for (int i = 0; i < bb_size; i++) {
+               lbXunit->addItem(qt_(bb_units_gui[i]),
+                       toqstr(bb_units[i]));
+               lbYunit->addItem(qt_(bb_units_gui[i]),
+                       toqstr(bb_units[i]));
+               rtXunit->addItem(qt_(bb_units_gui[i]),
+                       toqstr(bb_units[i]));
+               rtYunit->addItem(qt_(bb_units_gui[i]),
+                       toqstr(bb_units[i]));
        }
-
+       
        // set the right default unit
        Length::UNIT const defaultUnit = Length::defaultUnit();
 
@@ -551,10 +512,10 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
        if (igp.bb.empty()) {
                string const bb = readBoundingBox(igp.filename.absFilename());
                // the values from the file always have the bigpoint-unit bp
-               lbX->setText(toqstr(token(bb, ' ', 0)));
-               lbY->setText(toqstr(token(bb, ' ', 1)));
-               rtX->setText(toqstr(token(bb, ' ', 2)));
-               rtY->setText(toqstr(token(bb, ' ', 3)));
+               doubleToWidget(lbX, token(bb, ' ', 0));
+               doubleToWidget(lbY, token(bb, ' ', 1));
+               doubleToWidget(rtX, token(bb, ' ', 2));
+               doubleToWidget(rtY, token(bb, ' ', 3));
                lbXunit->setCurrentIndex(0);
                lbYunit->setCurrentIndex(0);
                rtXunit->setCurrentIndex(0);
@@ -568,30 +529,30 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
                string const xr = token(igp.bb, ' ', 2);
                string const yr = token(igp.bb, ' ', 3);
                if (isValidLength(xl, &anyLength)) {
-                       lbX->setText(toqstr(convert<string>(anyLength.value())));
+                       doubleToWidget(lbX, anyLength.value());
                        string const unit = unit_name[anyLength.unit()];
-                       lbXunit->setCurrentIndex(itemNumber(units, unit));
+                       lbXunit->setCurrentIndex(lbXunit->findData(toqstr(unit)));
                } else {
                        lbX->setText(toqstr(xl));
                }
                if (isValidLength(yl, &anyLength)) {
-                       lbY->setText(toqstr(convert<string>(anyLength.value())));
+                       doubleToWidget(lbY, anyLength.value());
                        string const unit = unit_name[anyLength.unit()];
-                       lbYunit->setCurrentIndex(itemNumber(units, unit));
+                       lbYunit->setCurrentIndex(lbYunit->findData(toqstr(unit)));
                } else {
                        lbY->setText(toqstr(xl));
                }
                if (isValidLength(xr, &anyLength)) {
-                       rtX->setText(toqstr(convert<string>(anyLength.value())));
+                       doubleToWidget(rtX, anyLength.value());
                        string const unit = unit_name[anyLength.unit()];
-                       rtXunit->setCurrentIndex(itemNumber(units, unit));
+                       rtXunit->setCurrentIndex(rtXunit->findData(toqstr(unit)));
                } else {
                        rtX->setText(toqstr(xl));
                }
                if (isValidLength(yr, &anyLength)) {
-                       rtY->setText(toqstr(convert<string>(anyLength.value())));
+                       doubleToWidget(rtY, anyLength.value());
                        string const unit = unit_name[anyLength.unit()];
-                       rtYunit->setCurrentIndex(itemNumber(units, unit));
+                       rtYunit->setCurrentIndex(rtYunit->findData(toqstr(unit)));
                } else {
                        rtY->setText(toqstr(xl));
                }
@@ -607,7 +568,7 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
 
        // the output section (width/height)
 
-       Scale->setText(toqstr(igp.scale));
+       doubleToWidget(Scale, igp.scale);
        //igp.scale defaults to 100, so we treat it as empty
        bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
        scaleCB->blockSignals(true);
@@ -665,7 +626,7 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
 
        setAutoText();
 
-       angle->setText(toqstr(igp.rotateAngle));
+       doubleToWidget(angle, igp.rotateAngle);
        rotateOrderCB->setChecked(igp.scaleBeforeRotation);
 
        rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
@@ -673,16 +634,13 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
 
        origin->clear();
 
-       vector<RotationOriginPair> origindata = getRotationOriginData();
-       vector<docstring> const origin_lang = getFirst(origindata);
-       origin_ltx = getSecond(origindata);
-
-       for (vector<docstring>::const_iterator it = origin_lang.begin();
-           it != origin_lang.end(); ++it)
-               origin->addItem(toqstr(*it));
+       for (int i = 0; i < rorigin_size; i++) {
+               origin->addItem(qt_(rorigin_gui_strs[i]),
+                       toqstr(rorigin_lyx_strs[i]));
+       }
 
        if (!igp.rotateOrigin.empty())
-               origin->setCurrentIndex(itemNumber(origin_ltx, igp.rotateOrigin));
+               origin->setCurrentIndex(origin->findData(toqstr(igp.rotateOrigin)));
        else
                origin->setCurrentIndex(0);
 
@@ -701,10 +659,10 @@ void GuiGraphics::applyView()
        igp.bb.erase();
        if (bbChanged) {
                string bb;
-               string lbXs = fromqstr(lbX->text());
-               string lbYs = fromqstr(lbY->text());
-               string rtXs = fromqstr(rtX->text());
-               string rtYs = fromqstr(rtY->text());
+               string lbXs = widgetToDoubleStr(lbX);
+               string lbYs = widgetToDoubleStr(lbY);
+               string rtXs = widgetToDoubleStr(rtX);
+               string rtYs = widgetToDoubleStr(rtY);
                int bb_sum =
                        convert<int>(lbXs) + convert<int>(lbYs) +
                        convert<int>(rtXs) + convert<int>(rtXs);
@@ -735,7 +693,7 @@ void GuiGraphics::applyView()
 
        //the graphics section
        if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
-               igp.scale = fromqstr(Scale->text());
+               igp.scale = widgetToDoubleStr(Scale);
                igp.width = Length("0pt");
                igp.height = Length("0pt");
                igp.keepAspectRatio = false;
@@ -756,9 +714,9 @@ void GuiGraphics::applyView()
 
        igp.noUnzip = unzipCB->isChecked();
        igp.lyxscale = displayscale->text().toInt();
-       igp.rotateAngle = fromqstr(angle->text());
+       igp.rotateAngle = widgetToDoubleStr(angle);
 
-       double rotAngle = convert<double>(igp.rotateAngle);
+       double rotAngle = widgetToDouble(angle);
        if (abs(rotAngle) > 360.0) {
                rotAngle -= 360.0 * floor(rotAngle / 360.0);
                igp.rotateAngle = convert<string>(rotAngle);
@@ -766,7 +724,8 @@ void GuiGraphics::applyView()
 
        // save the latex name for the origin. If it is the default
        // then origin_ltx returns ""
-       igp.rotateOrigin = origin_ltx[origin->currentIndex()];
+       igp.rotateOrigin =
+               fromqstr(origin->itemData(origin->currentIndex()).toString());
        igp.scaleBeforeRotation = rotateOrderCB->isChecked();
 
        // more latex options
@@ -787,10 +746,10 @@ void GuiGraphics::getBB()
        bbChanged = false;
        if (bb.empty())
                return;
-       lbX->setText(toqstr(token(bb, ' ', 0)));
-       lbY->setText(toqstr(token(bb, ' ', 1)));
-       rtX->setText(toqstr(token(bb, ' ', 2)));
-       rtY->setText(toqstr(token(bb, ' ', 3)));
+       doubleToWidget(lbX, token(bb, ' ', 0));
+       doubleToWidget(lbY, token(bb, ' ', 1));
+       doubleToWidget(rtX, token(bb, ' ', 2));
+       doubleToWidget(rtY, token(bb, ' ', 3));
        // the default units for the bb values when reading
        // it from the file
        lbXunit->setCurrentIndex(0);
index b9590089540772e4bd42709ab8918c7f1debbefe..6cad13767308076f0881beec28e7ee244d43d5a6 100644 (file)
@@ -218,7 +218,7 @@ void GuiParagraph::applyView()
                break;
        case 4:
                ls = Spacing::Other;
-               other = fromqstr(linespacingValue->text());
+               other = widgetToDoubleStr(linespacingValue);
                break;
        }
 
@@ -281,7 +281,7 @@ void GuiParagraph::updateView()
        }
        linespacing->setCurrentIndex(ls);
        if (space.getSpace() == Spacing::Other) {
-               linespacingValue->setText(toqstr(space.getValueAsString()));
+               doubleToWidget(linespacingValue, space.getValue());
                linespacingValue->setEnabled(true);
        } else {
                linespacingValue->setText(QString());
index 4fefd69fc6a0eef2b1ff4febbcb8259a463630f8..027d1dc4d3c36346705bb642d8d7e31edfc63856 100644 (file)
@@ -868,16 +868,16 @@ void PrefScreenFonts::apply(LyXRC & rc) const
 
        rc.zoom = screenZoomSB->value();
        rc.dpi = screenDpiSB->value();
-       rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text());
-       rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
-       rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
-       rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text());
-       rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text());
-       rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text());
-       rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text());
-       rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text());
-       rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text());
-       rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text());
+       rc.font_sizes[FONT_SIZE_TINY] = widgetToDoubleStr(screenTinyED);
+       rc.font_sizes[FONT_SIZE_SCRIPT] = widgetToDoubleStr(screenSmallestED);
+       rc.font_sizes[FONT_SIZE_FOOTNOTE] = widgetToDoubleStr(screenSmallerED);
+       rc.font_sizes[FONT_SIZE_SMALL] = widgetToDoubleStr(screenSmallED);
+       rc.font_sizes[FONT_SIZE_NORMAL] = widgetToDoubleStr(screenNormalED);
+       rc.font_sizes[FONT_SIZE_LARGE] = widgetToDoubleStr(screenLargeED);
+       rc.font_sizes[FONT_SIZE_LARGER] = widgetToDoubleStr(screenLargerED);
+       rc.font_sizes[FONT_SIZE_LARGEST] = widgetToDoubleStr(screenLargestED);
+       rc.font_sizes[FONT_SIZE_HUGE] = widgetToDoubleStr(screenHugeED);
+       rc.font_sizes[FONT_SIZE_HUGER] = widgetToDoubleStr(screenHugerED);
        rc.use_pixmap_cache = pixmapCacheCB->isChecked();
 
        if (rc.font_sizes != oldrc.font_sizes
@@ -910,16 +910,16 @@ void PrefScreenFonts::update(LyXRC const & rc)
 
        screenZoomSB->setValue(rc.zoom);
        screenDpiSB->setValue(rc.dpi);
-       screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY]));
-       screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT]));
-       screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE]));
-       screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL]));
-       screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL]));
-       screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE]));
-       screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER]));
-       screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST]));
-       screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE]));
-       screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER]));
+       doubleToWidget(screenTinyED, rc.font_sizes[FONT_SIZE_TINY]);
+       doubleToWidget(screenSmallestED, rc.font_sizes[FONT_SIZE_SCRIPT]);
+       doubleToWidget(screenSmallerED, rc.font_sizes[FONT_SIZE_FOOTNOTE]);
+       doubleToWidget(screenSmallED, rc.font_sizes[FONT_SIZE_SMALL]);
+       doubleToWidget(screenNormalED, rc.font_sizes[FONT_SIZE_NORMAL]);
+       doubleToWidget(screenLargeED, rc.font_sizes[FONT_SIZE_LARGE]);
+       doubleToWidget(screenLargerED, rc.font_sizes[FONT_SIZE_LARGER]);
+       doubleToWidget(screenLargestED, rc.font_sizes[FONT_SIZE_LARGEST]);
+       doubleToWidget(screenHugeED, rc.font_sizes[FONT_SIZE_HUGE]);
+       doubleToWidget(screenHugerED, rc.font_sizes[FONT_SIZE_HUGER]);
 
        pixmapCacheCB->setChecked(rc.use_pixmap_cache);
 #if defined(Q_WS_X11)
@@ -1325,7 +1325,7 @@ PrefConverters::PrefConverters(GuiPreferences * form)
 void PrefConverters::apply(LyXRC & rc) const
 {
        rc.use_converter_cache = cacheCB->isChecked();
-       rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
+       rc.converter_cache_maxage = int(widgetToDouble(maxAgeLE) * 86400.0);
 }
 
 
@@ -1333,8 +1333,7 @@ void PrefConverters::update(LyXRC const & rc)
 {
        cacheCB->setChecked(rc.use_converter_cache);
        QString max_age;
-       max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
-       maxAgeLE->setText(max_age);
+       doubleToWidget(maxAgeLE, (double(rc.converter_cache_maxage) / 86400.0), 'g', 6);
        updateGui();
 }
 
index 34141894971f0ca8020f2556b2adacc1909a9be3..d27f6b301f5c4a5459196b71de1ef1a6e02dee31 100644 (file)
@@ -24,6 +24,7 @@
 #include "support/lstrings.h"
 
 #include <QLineEdit>
+#include <QLocale>
 #include <QWidget>
 
 using namespace std;
@@ -39,10 +40,13 @@ LengthValidator::LengthValidator(QWidget * parent)
 
 QValidator::State LengthValidator::validate(QString & qtext, int &) const
 {
-       string const text = fromqstr(qtext);
-       if (text.empty() || support::isStrDbl(text))
+       bool ok;
+       double d = qtext.trimmed().toDouble(&ok);
+       if (qtext.isEmpty() || ok)
                return QValidator::Acceptable;
 
+       string const text = fromqstr(qtext);
+
        if (glue_length_) {
                GlueLength gl;
                return (isValidGlueLength(text, &gl)) ?
index a13eb8c7fd7923aeb0d72cc883e946114a04d8a9..7f99941b8ba1ef2a0e7823ea33e0e9235ef2439e 100644 (file)
@@ -25,6 +25,7 @@
 #include "Length.h"
 #include "TextClass.h"
 
+#include "support/convert.h"
 #include "support/debug.h"
 #include "support/filetools.h"
 #include "support/foreach.h"
@@ -39,6 +40,7 @@
 #include <QCheckBox>
 #include <QComboBox>
 #include <QLineEdit>
+#include <QLocale>
 #include <QPalette>
 #include <QSet>
 
@@ -78,7 +80,7 @@ string widgetsToLength(QLineEdit const * input, LengthCombo const * combo)
 
        Length::UNIT const unit = combo->currentLengthItem();
 
-       return Length(length.toDouble(), unit).asString();
+       return Length(length.trimmed().toDouble(), unit).asString();
 }
 
 
@@ -101,7 +103,7 @@ Length widgetsToLength(QLineEdit const * input, QComboBox const * combo)
                }
        }
 
-       return Length(length.toDouble(), unit);
+       return Length(length.trimmed().toDouble(), unit);
 }
 
 
@@ -109,7 +111,8 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
                      Length const & len, Length::UNIT /*defaultUnit*/)
 {
        combo->setCurrentItem(len.unit());
-       input->setText(QString::number(Length(len).value()));
+       QLocale loc;
+       input->setText(loc.toString(Length(len).value()));
 }
 
 
@@ -137,6 +140,39 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
 }
 
 
+double widgetToDouble(QLineEdit const * input)
+{
+       QString const text = input->text();
+       if (text.isEmpty())
+               return 0.0;
+       
+       return text.trimmed().toDouble();
+}
+
+
+string widgetToDoubleStr(QLineEdit const * input)
+{
+       QString const text = input->text();
+       if (text.isEmpty())
+               return string();
+       
+       return convert<string>(text.trimmed().toDouble());
+}
+
+
+void doubleToWidget(QLineEdit * input, double const & value, char f, int prec)
+{
+       QLocale loc;
+       input->setText(loc.toString(value, f, prec));
+}
+
+
+void doubleToWidget(QLineEdit * input, string const & value, char f, int prec)
+{
+       doubleToWidget(input, convert<double>(value), f, prec);
+}
+
+
 void setValid(QWidget * widget, bool valid)
 {
        if (valid) {
index 7e145f99ef38293d068adfe40e681ceaff5a6c00..dd284a8655099af9de1b77028d41ad0993e43911 100644 (file)
@@ -52,6 +52,17 @@ std::string const & len, Length::UNIT default_unit);
 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
 docstring const & len, Length::UNIT default_unit);
 
+/// method to get a double value from a localized widget (QLineEdit)
+double widgetToDouble(QLineEdit const * input);
+/// method to get a double value from a localized widget (QLineEdit)
+std::string widgetToDoubleStr(QLineEdit const * input);
+/// method to set a (localized) double value in a widget (QLineEdit)
+void doubleToWidget(QLineEdit * input, double const & value,
+       char f = 'g', int prec = 6);
+/// method to set a (localized) double value in a widget (QLineEdit)
+void doubleToWidget(QLineEdit * input, std::string const & value,
+       char f = 'g', int prec = 6);
+
 /// colors a widget red if invalid
 void setValid(QWidget * widget, bool valid);