]> git.lyx.org Git - lyx.git/commitdiff
Revert "BufferParams: get rid of the HSpace class for mathindent as requested by...
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 19 Apr 2017 14:19:18 +0000 (16:19 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 19 Apr 2017 14:19:18 +0000 (16:19 +0200)
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
src/BufferParams.cpp
src/BufferParams.h
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiDocument.h

index 36fb8d21d8c59e0d622660f91757e556ce738dcd..479589217cbf446ca7d3d992009edd8bffa3d0d7 100644 (file)
@@ -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();
index 9f05fe8156a1a1f9c26f6cf1cb3dfc30d3f166de..863e80252fc6a918a45e0d1024d79c9f161777c4 100644 (file)
@@ -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";
                }
        }
index 437d00b700d23cdfc2954b6a7062bc6cc6d36bd9..14935a9370ceda7c0acb2fb1311ab68d4a59ee52 100644 (file)
@@ -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;
 
index 691bb2c9249da2c967eef959adb60ef7f4a19a3a..64975fe93002a9aa136099352f57f49c4603d916 100644 (file)
@@ -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);
index 7527a59edc9cdf857c82ad856993ae2816e70c53..b33fca95f82ba511acc4334199108366960fc444 100644 (file)
@@ -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();