]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Check path of Qt tools if qtchooser is detected
[lyx.git] / src / Buffer.cpp
index f4d238fb293299c15f813ba440a052defdfa5b02..888fb93d9b16a7dbc19f0186b02ed28e3c730f01 100644 (file)
@@ -57,6 +57,7 @@
 #include "PDFOptions.h"
 #include "SpellChecker.h"
 #include "sgml.h"
+#include "texstream.h"
 #include "TexRow.h"
 #include "Text.h"
 #include "TextClass.h"
@@ -1684,7 +1685,7 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
        ErrorList & errorList = d->errorLists["Export"];
        errorList.clear();
        bool failed_export = false;
-       otexstream os(ofs, d->texrow);
+       otexstream os(ofs);
 
        // make sure we are ready to export
        // this needs to be done before we validate
@@ -1694,7 +1695,6 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
        updateMacroInstances(OutputUpdate);
 
        try {
-               os.texrow().reset();
                writeLaTeXSource(os, original_path, runparams, output);
        }
        catch (EncodingException const & e) {
@@ -1725,6 +1725,8 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
                lyx_exit(1);
        }
 
+       d->texrow = move(os.texrow());
+
        ofs.close();
        if (ofs.fail()) {
                failed_export = true;
@@ -2218,8 +2220,8 @@ void Buffer::validate(LaTeXFeatures & features) const
        if (!features.runparams().is_child)
                params().validate(features);
 
-       for_each(paragraphs().begin(), paragraphs().end(),
-                bind(&Paragraph::validate, _1, ref(features)));
+       for (Paragraph const & p : paragraphs())
+               p.validate(features);
 
        if (lyxerr.debugging(Debug::LATEX)) {
                features.showStruct();
@@ -3715,14 +3717,13 @@ unique_ptr<TexRow> Buffer::getSourceCode(odocstream & os, string const & format,
                        LaTeXFeatures features(*this, params(), runparams);
                        params().validate(features);
                        runparams.use_polyglossia = features.usePolyglossia();
-                       texrow = make_unique<TexRow>();
-                       texrow->newline();
-                       texrow->newline();
                        // latex or literate
-                       otexstream ots(os, *texrow);
-
+                       otexstream ots(os);
+                       // output above
+                       ots.texrow().newlines(2);
                        // the real stuff
                        latexParagraphs(*this, text(), ots, runparams);
+                       texrow = ots.releaseTexRow();
                        texrow->finalize();
 
                        // Restore the parenthood
@@ -3758,13 +3759,13 @@ unique_ptr<TexRow> Buffer::getSourceCode(odocstream & os, string const & format,
                                writeDocBookSource(os, absFileName(), runparams, output);
                } else {
                        // latex or literate
-                       texrow = make_unique<TexRow>();
-                       texrow->newline();
-                       texrow->newline();
-                       otexstream ots(os, *texrow);
+                       otexstream ots(os);
+                       // output above
+                       ots.texrow().newlines(2);
                        if (master)
                                runparams.is_child = true;
                        writeLaTeXSource(ots, string(), runparams, output);
+                       texrow = ots.releaseTexRow();
                        texrow->finalize();
                }
        }
@@ -4314,26 +4315,22 @@ Buffer::ExportStatus Buffer::preview(string const & format, bool includeall) con
        ExportStatus const status = doExport(format, true, false, result_file);
        FileName const previewFile(result_file);
 
-       LATTEST (isClone());
-       d->cloned_buffer_->d->preview_file_ = previewFile;
-       d->cloned_buffer_->d->preview_format_ = format;
-       d->cloned_buffer_->d->preview_error_ = (status != ExportSuccess);
+       Impl * theimpl = isClone() ? d->cloned_buffer_->d : d;
+       theimpl->preview_file_ = previewFile;
+       theimpl->preview_format_ = format;
+       theimpl->preview_error_ = (status != ExportSuccess);
 
        if (status != ExportSuccess)
                return status;
-       if (previewFile.exists()) {
-               if (!formats.view(*this, previewFile, format))
-                       return PreviewError;
-               else
-                       return PreviewSuccess;
-       }
-       else {
-               // Successful export but no output file?
-               // Probably a bug in error detection.
-               LATTEST (status != ExportSuccess);
 
-               return status;
-       }
+       if (previewFile.exists())
+               return formats.view(*this, previewFile, format) ?
+                       PreviewSuccess : PreviewError;
+
+       // Successful export but no output file?
+       // Probably a bug in error detection.
+       LATTEST(status != ExportSuccess);
+       return status;
 }
 
 
@@ -4622,6 +4619,11 @@ static depth_type getDepth(DocIterator const & it)
                if (!it[i].inset().inMathed())
                        depth += it[i].paragraph().getDepth() + 1;
        // remove 1 since the outer inset does not count
+       // we should have at least one non-math inset, so
+       // depth should nevery be 0. but maybe it is worth
+       // marking this, just in case.
+       LATTEST(depth > 0);
+       // coverity[INTEGER_OVERFLOW]
        return depth - 1;
 }