From d86954eb815b8018eb216bfbc1ab344c45e18ebe Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Wed, 19 Apr 2017 16:19:18 +0200 Subject: [PATCH] Revert "BufferParams: get rid of the HSpace class for mathindent as requested by JMarc" This reverts commit d9a2a4026800865b15da186620ffab4c6b409765. This is not the right way of getting rid of HSpace. We need a proper Length, not a string. --- src/Buffer.cpp | 2 +- src/BufferParams.cpp | 25 +++++++++++--- src/BufferParams.h | 5 +++ src/frontends/qt4/GuiDocument.cpp | 56 ++++++++++++++----------------- src/frontends/qt4/GuiDocument.h | 1 - 5 files changed, 51 insertions(+), 38 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 36fb8d21d8..479589217c 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -916,7 +916,7 @@ int Buffer::readHeader(Lexer & lex) params().headheight.erase(); params().headsep.erase(); params().footskip.erase(); - params().math_indentation = "default"; + params().math_indentation.erase(); params().columnsep.erase(); params().fonts_cjk.erase(); params().listings_params.clear(); diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 9f05fe8156..863e80252f 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -342,6 +342,7 @@ public: * and for detached paragraphs in "indented" documents. */ VSpace defskip; + HSpace math_indentation; PDFOptions pdfoptions; LayoutFileIndex baseClass_; FormatList exportableFormatList; @@ -628,6 +629,18 @@ PDFOptions const & BufferParams::pdfoptions() const } +HSpace const & BufferParams::getMathIndentation() const +{ + return pimpl_->math_indentation; +} + + +void BufferParams::setMathIndentation(HSpace const & indent) +{ + pimpl_->math_indentation = indent; +} + + Length const & BufferParams::getParIndent() const { return pimpl_->parindent; @@ -838,7 +851,9 @@ string BufferParams::readToken(Lexer & lex, string const & token, } else if (token == "\\is_math_indent") { lex >> is_math_indent; } else if (token == "\\math_indentation") { - lex >> math_indentation; + lex.next(); + string math_indentation = lex.getString(); + pimpl_->math_indentation = HSpace(math_indentation); } else if (token == "\\quotes_style") { string qstyle; lex >> qstyle; @@ -1337,8 +1352,8 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const else os << "\n\\defskip " << getDefSkip().asLyXCommand(); os << "\n\\is_math_indent " << is_math_indent; - if (is_math_indent && math_indentation != "default") - os << "\n\\math_indentation " << math_indentation; + if (is_math_indent && getMathIndentation().asLyXCommand() != "default") + os << "\n\\math_indentation " << getMathIndentation().asLyXCommand(); os << "\n\\quotes_style " << string_quotes_style[quotes_style] << "\n\\dynamic_quotes " << dynamic_quotes @@ -1950,9 +1965,9 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, if (is_math_indent) { // when formula indentation // only output something when it is not the default - if (math_indentation != "default") { + if (getMathIndentation().asLyXCommand() != "default") { os << "\\setlength{\\mathindent}{" - << from_utf8(math_indentation) + << from_utf8(getMathIndentation().asLatexCommand()) << "}\n"; } } diff --git a/src/BufferParams.h b/src/BufferParams.h index 437d00b700..14935a9370 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -102,6 +102,11 @@ public: /// void setDefSkip(VSpace const & vs); + /// + HSpace const & getMathIndentation() const; + /// + void setMathIndentation(HSpace const & indent); + /// Whether formulas are indented bool is_math_indent; diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 691bb2c924..64975fe930 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -727,8 +727,6 @@ GuiDocument::GuiDocument(GuiView & lv) connect(textLayoutModule->MathIndentCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor())); - connect(textLayoutModule->MathIndentCB, SIGNAL(toggled(bool)), - this, SLOT(allowMathIndent())); connect(textLayoutModule->MathIndentCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); connect(textLayoutModule->MathIndentCO, SIGNAL(activated(int)), @@ -1612,22 +1610,6 @@ void GuiDocument::enableSkip(bool skip) setSkip(textLayoutModule->skipCO->currentIndex()); } -void GuiDocument::allowMathIndent() -{ - // only disable when not checked, checked does not always allow enabling - if (!textLayoutModule->MathIndentCB->isChecked()) { - textLayoutModule->MathIndentLE->setEnabled(false); - textLayoutModule->MathIndentLengthCO->setEnabled(false); - } - if (textLayoutModule->MathIndentCB->isChecked() - && textLayoutModule->MathIndentCO->currentIndex() == 1) { - textLayoutModule->MathIndentLE->setEnabled(true); - textLayoutModule->MathIndentLengthCO->setEnabled(true); - - } - isValid(); -} - void GuiDocument::setMathIndent(int item) { bool const enable = (item == 1); @@ -2918,7 +2900,16 @@ void GuiDocument::applyView() if (rb->isChecked()) bp_.use_package(it->first, BufferParams::package_off); } - + bp_.is_math_indent = textLayoutModule->MathIndentCB->isChecked(); + // if math is indented + if (bp_.is_math_indent) { + HSpace MathIndentation = HSpace( + widgetsToLength(textLayoutModule->MathIndentLE, + textLayoutModule->MathIndentLengthCO) + ); + bp_.setMathIndentation(MathIndentation); + } + // Page Layout if (pageLayoutModule->pagestyleCO->currentIndex() == 0) bp_.pagestyle = "default"; @@ -3006,24 +2997,26 @@ void GuiDocument::applyView() } } - bp_.is_math_indent = textLayoutModule->MathIndentCB->isChecked(); - if (bp_.is_math_indent) { - // if math is indented + if (textLayoutModule->MathIndentCB->isChecked()) { + // if formulas are indented switch (textLayoutModule->MathIndentCO->currentIndex()) { case 0: - bp_.math_indentation = "default"; + bp_.setMathIndentation(HSpace(HSpace::DEFAULT)); break; - case 1: - bp_.math_indentation = widgetsToLength(textLayoutModule->MathIndentLE, - textLayoutModule->MathIndentLengthCO); + case 1: { + HSpace MathIndent = HSpace( + widgetsToLength(textLayoutModule->MathIndentLE, + textLayoutModule->MathIndentLengthCO) + ); + bp_.setMathIndentation(MathIndent); break; + } default: // this should never happen - bp_.math_indentation = "default"; + bp_.setMathIndentation(HSpace(HSpace::DEFAULT)); break; } - } else - bp_.math_indentation = "default"; + } bp_.options = fromqstr(latexModule->optionsLE->text()); @@ -3391,11 +3384,12 @@ void GuiDocument::paramsToDialog() // math if (bp_.is_math_indent) { textLayoutModule->MathIndentCB->setChecked(bp_.is_math_indent); + string MathIndentation = bp_.getMathIndentation().asLyXCommand(); int MathIndent = 0; - if (bp_.math_indentation != "default") { + if (MathIndentation != "default") { lengthToWidgets(textLayoutModule->MathIndentLE, textLayoutModule->MathIndentLengthCO, - bp_.math_indentation, default_unit); + MathIndentation, default_unit); MathIndent = 1; } textLayoutModule->MathIndentCO->setCurrentIndex(MathIndent); diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index 7527a59edc..b33fca95f8 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -109,7 +109,6 @@ private Q_SLOTS: void enableIndent(bool); void setSkip(int); void enableSkip(bool); - void allowMathIndent(); void setMathIndent(int); void browseLayout(); void browseMaster(); -- 2.39.2