From dd11fc928fcc50434b1f555950ed973098c08a85 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Fri, 19 Jun 2009 12:18:38 +0000 Subject: [PATCH] Factor out some code for later use (and to remove duplication). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30177 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/InsetFloat.cpp | 58 ++++++++++++++++++++------------------- src/insets/InsetFloat.h | 4 +++ 2 files changed, 34 insertions(+), 28 deletions(-) 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_;