diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index 63f2b97a41..ef99d07ebf 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -435,29 +435,39 @@ void InsetFloat::setNewLabel(BufferParams const & bp) } -docstring InsetFloat::getCaption(OutputParams const & runparams) const +InsetCaption const * InsetFloat::getCaptionInset() const { - if (paragraphs().empty()) - return docstring(); - ParagraphList::const_iterator pit = paragraphs().begin(); for (; pit != paragraphs().end(); ++pit) { InsetList::const_iterator it = pit->insetList().begin(); for (; it != pit->insetList().end(); ++it) { Inset & inset = *it->inset; if (inset.lyxCode() == CAPTION_CODE) { - odocstringstream ods; - InsetCaption * ins = - static_cast(it->inset); - ins->getOptArg(ods, runparams); - ods << '['; - ins->getArgument(ods, runparams); - ods << ']'; - return ods.str(); + InsetCaption const * ins = + static_cast(it->inset); + return ins; } } } - return docstring(); + return 0; +} + + +docstring InsetFloat::getCaption(OutputParams const & runparams) const +{ + if (paragraphs().empty()) + return docstring(); + + InsetCaption const * ins = getCaptionInset(); + if (ins == 0) + return docstring(); + + odocstringstream ods; + ins->getOptArg(ods, runparams); + ods << '['; + ins->getArgument(ods, runparams); + ods << ']'; + return ods.str(); } @@ -466,21 +476,13 @@ docstring InsetFloat::getCaptionText(OutputParams const & runparams) const if (paragraphs().empty()) return docstring(); - ParagraphList::const_iterator pit = paragraphs().begin(); - for (; pit != paragraphs().end(); ++pit) { - InsetList::const_iterator it = pit->insetList().begin(); - for (; it != pit->insetList().end(); ++it) { - Inset & inset = *it->inset; - if (inset.lyxCode() == CAPTION_CODE) { - odocstringstream ods; - InsetCaption * ins = - static_cast(it->inset); - ins->getCaptionText(ods, runparams); - return ods.str(); - } - } - } - return docstring(); + InsetCaption const * ins = getCaptionInset(); + if (ins == 0) + return docstring(); + + odocstringstream ods; + ins->getCaptionText(ods, runparams); + return ods.str(); } diff --git a/src/insets/InsetFloat.h b/src/insets/InsetFloat.h index ff4b144ed2..4f1328da02 100644 --- a/src/insets/InsetFloat.h +++ b/src/insets/InsetFloat.h @@ -18,6 +18,8 @@ namespace lyx { +class InsetCaption; + class InsetFloatParams { public: /// @@ -111,6 +113,8 @@ private: /// docstring getCaptionText(OutputParams const &) const; /// + InsetCaption const * getCaptionInset() const; + /// InsetFloatParams params_; /// docstring name_;