Fix problems with immediate apply and length validators

Fixes bugs #7022 and #7599.
This commit is contained in:
Juergen Spitzmueller 2015-05-20 19:12:23 +02:00
parent 7b0ecf1f38
commit 9e16608867
5 changed files with 36 additions and 10 deletions

View File

@ -72,7 +72,9 @@ GuiParagraph::GuiParagraph(GuiView & lv)
#endif #endif
on_synchronizedViewCB_toggled(); on_synchronizedViewCB_toggled();
linespacingValue->setValidator(new QDoubleValidator(linespacingValue)); QDoubleValidator * val = new QDoubleValidator(linespacingValue);
val->setNotation(QDoubleValidator::StandardNotation);
linespacingValue->setValidator(val);
labelWidth->setWhatsThis(qt_( labelWidth->setWhatsThis(qt_(
"As described in the User Guide, the width of" "As described in the User Guide, the width of"
@ -164,7 +166,10 @@ void GuiParagraph::on_synchronizedViewCB_toggled()
void GuiParagraph::changed() void GuiParagraph::changed()
{ {
if (synchronizedViewCB->isChecked()) QLocale loc;
if (synchronizedViewCB->isChecked()
&& !linespacingValue->text().endsWith(loc.decimalPoint())
&& linespacingValue->hasAcceptableInput())
on_applyPB_clicked(); on_applyPB_clicked();
} }

View File

@ -751,7 +751,8 @@ void GuiTabular::paramsToDialog(Inset const * inset)
// Set width and alignment // Set width and alignment
Length const tabwidth = tabular.tabularWidth(); Length const tabwidth = tabular.tabularWidth();
if (tabwidth.zero()) if (tabwidth.zero()
&& !(tabularWidthED->hasFocus() && tabularWidthED->text() == "0"))
tabularWidthED->clear(); tabularWidthED->clear();
else else
lengthToWidgets(tabularWidthED, tabularWidthUnitLC, lengthToWidgets(tabularWidthED, tabularWidthUnitLC,
@ -769,7 +770,8 @@ void GuiTabular::paramsToDialog(Inset const * inset)
pwidth = getColumnPWidth(tabular, cell); pwidth = getColumnPWidth(tabular, cell);
} }
string colwidth; string colwidth;
if (pwidth.zero()) if (pwidth.zero()
&& !(columnWidthED->hasFocus() && columnWidthED->text() == "0"))
columnWidthED->clear(); columnWidthED->clear();
else { else {
colwidth = pwidth.asString(); colwidth = pwidth.asString();
@ -780,7 +782,8 @@ void GuiTabular::paramsToDialog(Inset const * inset)
if (multirow) if (multirow)
mroffset = getMROffset(tabular, cell); mroffset = getMROffset(tabular, cell);
string offset; string offset;
if (mroffset.zero()) if (mroffset.zero()
&& !(multirowOffsetED->hasFocus() && multirowOffsetED->text() == "0"))
multirowOffsetED->clear(); multirowOffsetED->clear();
else { else {
offset = mroffset.asString(); offset = mroffset.asString();

View File

@ -192,7 +192,8 @@ void InsetParamsDialog::onWidget_changed()
{ {
d->changed_ = true; d->changed_ = true;
docstring const argument = checkWidgets(immediateApplyCB->isChecked()); docstring const argument = checkWidgets(immediateApplyCB->isChecked());
if (immediateApplyCB->isChecked()) if (immediateApplyCB->isChecked()
&& d->widget_->checkWidgets(buffer().isReadonly()))
dispatch(FuncRequest(LFUN_INSET_MODIFY, argument)); dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
} }

View File

@ -34,7 +34,7 @@ namespace frontend {
LengthValidator::LengthValidator(QWidget * parent) LengthValidator::LengthValidator(QWidget * parent)
: QValidator(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; QLocale loc;
bool ok; 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) { if (!ok) {
// Fall back to C // Fall back to C
QLocale c(QLocale::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; return QValidator::Acceptable;
string const text = fromqstr(qtext); string const text = fromqstr(qtext);
if (glue_length_) { if (glue_length_) {
GlueLength gl; GlueLength gl;
if (unsigned_ && gl.len().value() < 0)
return QValidator::Invalid;
return (isValidGlueLength(text, &gl)) ? return (isValidGlueLength(text, &gl)) ?
QValidator::Acceptable : QValidator::Intermediate; QValidator::Acceptable : QValidator::Intermediate;
} }
@ -68,6 +77,9 @@ QValidator::State LengthValidator::validate(QString & qtext, int &) const
if (no_bottom_) if (no_bottom_)
return QValidator::Acceptable; return QValidator::Acceptable;
if (unsigned_ && l.value() < 0)
return QValidator::Invalid;
return b_.inPixels(100) <= l.inPixels(100) ? return b_.inPixels(100) <= l.inPixels(100) ?
QValidator::Acceptable : QValidator::Intermediate; QValidator::Acceptable : QValidator::Intermediate;
} }
@ -92,6 +104,7 @@ LengthValidator * unsignedLengthValidator(QLineEdit * ed)
{ {
LengthValidator * v = new LengthValidator(ed); LengthValidator * v = new LengthValidator(ed);
v->setBottom(Length()); v->setBottom(Length());
v->setUnsigned(true);
return v; return v;
} }
@ -100,6 +113,7 @@ LengthValidator * unsignedGlueLengthValidator(QLineEdit * ed)
{ {
LengthValidator * v = new LengthValidator(ed); LengthValidator * v = new LengthValidator(ed);
v->setBottom(GlueLength()); v->setBottom(GlueLength());
v->setUnsigned(true);
return v; return v;
} }
@ -122,6 +136,7 @@ LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit * ed, QString const
{ {
LengthAutoValidator * v = new LengthAutoValidator(ed, autotext); LengthAutoValidator * v = new LengthAutoValidator(ed, autotext);
v->setBottom(Length()); v->setBottom(Length());
v->setUnsigned(true);
return v; return v;
} }

View File

@ -62,6 +62,7 @@ public:
void setBottom(Length const &); void setBottom(Length const &);
void setBottom(GlueLength const &); void setBottom(GlueLength const &);
Length bottom() const { return b_; } Length bottom() const { return b_; }
void setUnsigned(bool const u) { unsigned_ = u; }
//@} //@}
private: private:
@ -69,6 +70,7 @@ private:
GlueLength g_; GlueLength g_;
bool no_bottom_; bool no_bottom_;
bool glue_length_; bool glue_length_;
bool unsigned_;
}; };