]> git.lyx.org Git - features.git/commitdiff
Factor out some code for later use (and to remove duplication).
authorRichard Heck <rgheck@comcast.net>
Fri, 19 Jun 2009 12:18:38 +0000 (12:18 +0000)
committerRichard Heck <rgheck@comcast.net>
Fri, 19 Jun 2009 12:18:38 +0000 (12:18 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30177 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/InsetFloat.cpp
src/insets/InsetFloat.h

index 63f2b97a411f0f614bd7ca1c73ece449994e3637..ef99d07ebfd8b2db6d3dbab26870630ed0ff20ce 100644 (file)
@@ -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<InsetCaption *>(it->inset);
-                               ins->getOptArg(ods, runparams);
-                               ods << '[';
-                               ins->getArgument(ods, runparams);
-                               ods << ']';
-                               return ods.str();
+                               InsetCaption const * ins =
+                                       static_cast<InsetCaption const *>(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<InsetCaption *>(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();
 }
 
 
index ff4b144ed2153f858adcaf7d08fd8389812e06d2..4f1328da02de44f6752b284bb00d8dabffdff3ca 100644 (file)
@@ -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_;