]> git.lyx.org Git - features.git/commitdiff
Fix problems with immediate apply and length validators
authorJuergen Spitzmueller <spitz@lyx.org>
Wed, 20 May 2015 17:12:23 +0000 (19:12 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Wed, 20 May 2015 17:13:12 +0000 (19:13 +0200)
Fixes bugs #7022 and #7599.

src/frontends/qt4/GuiParagraph.cpp
src/frontends/qt4/GuiTabular.cpp
src/frontends/qt4/InsetParamsDialog.cpp
src/frontends/qt4/Validator.cpp
src/frontends/qt4/Validator.h

index 6a0248ad2c2cb3ca56b5f496e4fb50d65599bc7c..1bc22488a9a112c8f1192b3c9096f06f283bcbce 100644 (file)
@@ -72,7 +72,9 @@ GuiParagraph::GuiParagraph(GuiView & lv)
 #endif
 
        on_synchronizedViewCB_toggled();
-       linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
+       QDoubleValidator * val = new QDoubleValidator(linespacingValue);
+       val->setNotation(QDoubleValidator::StandardNotation);
+       linespacingValue->setValidator(val);
 
        labelWidth->setWhatsThis(qt_(
                "As described in the User Guide, the width of"
@@ -164,7 +166,10 @@ void GuiParagraph::on_synchronizedViewCB_toggled()
 
 void GuiParagraph::changed()
 {
-       if (synchronizedViewCB->isChecked())
+       QLocale loc;
+       if (synchronizedViewCB->isChecked()
+           && !linespacingValue->text().endsWith(loc.decimalPoint())
+           && linespacingValue->hasAcceptableInput())
                on_applyPB_clicked();
 }
 
index 8f1118bc23f4ad3a0d93a75fc4040bbe6c7264b6..58dcd597a1bcd6e857d3d43290f3c1d8459cbfd7 100644 (file)
@@ -751,7 +751,8 @@ void GuiTabular::paramsToDialog(Inset const * inset)
        // Set width and alignment
 
        Length const tabwidth = tabular.tabularWidth();
-       if (tabwidth.zero())
+       if (tabwidth.zero()
+           && !(tabularWidthED->hasFocus() && tabularWidthED->text() == "0"))
                tabularWidthED->clear();
        else
                lengthToWidgets(tabularWidthED, tabularWidthUnitLC,
@@ -769,7 +770,8 @@ void GuiTabular::paramsToDialog(Inset const * inset)
                pwidth = getColumnPWidth(tabular, cell);
        }
        string colwidth;
-       if (pwidth.zero())
+       if (pwidth.zero()
+           && !(columnWidthED->hasFocus() && columnWidthED->text() == "0"))
                columnWidthED->clear();
        else {
                colwidth = pwidth.asString();
@@ -780,7 +782,8 @@ void GuiTabular::paramsToDialog(Inset const * inset)
        if (multirow)
                mroffset = getMROffset(tabular, cell);
        string offset;
-       if (mroffset.zero())
+       if (mroffset.zero()
+           && !(multirowOffsetED->hasFocus() && multirowOffsetED->text() == "0"))
                multirowOffsetED->clear();
        else {
                offset = mroffset.asString();
index 9777d5951f6c92c2dd5f3251064a07a77fb1a2f8..41b4bfa09c0e6c789e0db5ef3211ef2cf4bf643b 100644 (file)
@@ -192,7 +192,8 @@ void InsetParamsDialog::onWidget_changed()
 {
        d->changed_ = true;
        docstring const argument = checkWidgets(immediateApplyCB->isChecked());
-       if (immediateApplyCB->isChecked())
+       if (immediateApplyCB->isChecked()
+           && d->widget_->checkWidgets(buffer().isReadonly()))
                dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
 }
 
index 4e363ac8c2a917740ce2a008c751bfd42cb9172f..6d0ffc0175242391a297dbda0fdb84944774448c 100644 (file)
@@ -34,7 +34,7 @@ namespace frontend {
 
 LengthValidator::LengthValidator(QWidget * parent)
        : QValidator(parent),
-         no_bottom_(true), glue_length_(false)
+         no_bottom_(true), glue_length_(false), unsigned_(false)
 {}
 
 
@@ -42,20 +42,29 @@ QValidator::State LengthValidator::validate(QString & qtext, int &) const
 {
        QLocale loc;
        bool ok;
-       loc.toDouble(qtext.trimmed(), &ok);
+       double d = loc.toDouble(qtext.trimmed(), &ok);
+       // QLocale::toDouble accepts something like "1."
+       // We don't.
+       bool dp = qtext.endsWith(loc.decimalPoint());
        if (!ok) {
                // Fall back to C
                QLocale c(QLocale::C);
-               c.toDouble(qtext.trimmed(), &ok);
+               d = c.toDouble(qtext.trimmed(), &ok);
+               dp = qtext.endsWith(c.decimalPoint());
        }
 
-       if (qtext.isEmpty() || ok)
+       if (ok && unsigned_ && d < 0)
+               return QValidator::Invalid;
+
+       if (qtext.isEmpty() || (ok && !dp))
                return QValidator::Acceptable;
 
        string const text = fromqstr(qtext);
 
        if (glue_length_) {
                GlueLength gl;
+               if (unsigned_ && gl.len().value() < 0)
+                       return QValidator::Invalid;
                return (isValidGlueLength(text, &gl)) ?
                        QValidator::Acceptable : QValidator::Intermediate;
        }
@@ -68,6 +77,9 @@ QValidator::State LengthValidator::validate(QString & qtext, int &) const
        if (no_bottom_)
                return QValidator::Acceptable;
 
+       if (unsigned_ && l.value() < 0)
+               return QValidator::Invalid;
+
        return b_.inPixels(100) <= l.inPixels(100) ?
                QValidator::Acceptable : QValidator::Intermediate;
 }
@@ -92,6 +104,7 @@ LengthValidator * unsignedLengthValidator(QLineEdit * ed)
 {
        LengthValidator * v = new LengthValidator(ed);
        v->setBottom(Length());
+       v->setUnsigned(true);
        return v;
 }
 
@@ -100,6 +113,7 @@ LengthValidator * unsignedGlueLengthValidator(QLineEdit * ed)
 {
        LengthValidator * v = new LengthValidator(ed);
        v->setBottom(GlueLength());
+       v->setUnsigned(true);
        return v;
 }
 
@@ -122,6 +136,7 @@ LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit * ed, QString const
 {
        LengthAutoValidator * v = new LengthAutoValidator(ed, autotext);
        v->setBottom(Length());
+       v->setUnsigned(true);
        return v;
 }
 
index 0c4dbde632f0265fb9a1189248d10fd6d3e07d88..22e8d484d3d4b7ab02c3c50a817886eca23bd536 100644 (file)
@@ -62,6 +62,7 @@ public:
        void setBottom(Length const &);
        void setBottom(GlueLength const &);
        Length bottom() const { return b_; }
+       void setUnsigned(bool const u) { unsigned_ = u; }
        //@}
 
 private:
@@ -69,6 +70,7 @@ private:
        GlueLength g_;
        bool no_bottom_;
        bool glue_length_;
+       bool unsigned_;
 };