commit 58e6c6c87649cc12b0a3d077f4500ab68ad10e99
Author: Uwe Stöhr <uwesto...@lyx.org>
Date:   Sat Apr 15 06:57:52 2017 +0200

    InsetFloat: allow float placement for rotated floats
    
    - fixes bug #10270
    - fileformat change
    - fixes also a bug that unwanted placement was output to LaTeX on certain 
cases
---
 development/FORMAT                   |    4 +++
 lib/lyx2lyx/lyx_2_3.py               |   49 +++++++++++++++++++++++++++++++++-
 src/frontends/qt4/FloatPlacement.cpp |   23 +++++++++++++---
 src/insets/InsetFloat.cpp            |    6 +++-
 src/tex2lyx/text.cpp                 |    5 +++
 src/version.h                        |    4 +-
 6 files changed, 82 insertions(+), 9 deletions(-)

diff --git a/development/FORMAT b/development/FORMAT
index 10cc86e..7c55968 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -7,6 +7,10 @@ changes happened in particular if possible. A good example 
would be
 
 -----------------------
 
+2017-04-15 Uwe Stöhr <uwesto...@web.de>
+       * Format incremented to 540: support for rotated float placements
+         - no new LFUN or buffer parameters
+
 2017-04-08 Uwe Stöhr <uwesto...@web.de>
        * Format incremented to 539: support for \baselineskip.
          - new length unit BLS
diff --git a/lib/lyx2lyx/lyx_2_3.py b/lib/lyx2lyx/lyx_2_3.py
index cdb9c29..76130c8 100644
--- a/lib/lyx2lyx/lyx_2_3.py
+++ b/lib/lyx2lyx/lyx_2_3.py
@@ -2077,6 +2077,51 @@ def revert_baselineskip(document):
     i = i + 1
 
 
+def revert_rotfloat(document):
+  " Revert placement options for rotated floats "
+  i = 0
+  j = 0
+  k = 0
+  while True:
+    i = find_token(document.body, "sideways true", i)
+    if i != -1:
+      regexp = re.compile(r'^.*placement.*$')
+      j = find_re(document.body, regexp, i-2)
+      if j == -1:
+          return
+      if j != i-2:
+          i = i + 1
+          continue
+    else:
+      return
+    # we found a sideways float with placement options
+    # at first store the placement
+    beg = document.body[i-2].rfind(" ");
+    placement = document.body[i-2][beg+1:]
+    # check if the option'H' is used
+    if placement.find("H") != -1:
+      add_to_preamble(document, ["\\usepackage{float}"])  
+    # now check if it is a starred type
+    if document.body[i-1].find("wide true") != -1:
+      star = '*'
+    else:
+      star = ''
+    # store the float type
+    beg = document.body[i-3].rfind(" ");
+    fType = document.body[i-3][beg+1:]
+    # now output TeX code
+    endInset = find_end_of_inset(document.body, i-3)
+    if endInset == -1:
+      document.warning("Malformed LyX document: Missing '\\end_inset' of Float 
inset.")
+      return
+    else:
+      document.body[endInset-2: endInset+1] = put_cmd_in_ert("\\end{sideways" 
+ fType + star + '}')
+      document.body[i-3: i+2] = put_cmd_in_ert("\\begin{sideways" + fType + 
star + "}[" + placement + ']')
+      add_to_preamble(document, ["\\usepackage{rotfloat}"])  
+    
+    i = i + 1
+
+
 ##
 # Conversion hub
 #
@@ -2113,10 +2158,12 @@ convert = [
            [536, []],
            [537, []],
            [538, [convert_mathindent]],
-           [539, []]
+           [539, []],
+           [540, []]
           ]
 
 revert =  [
+           [539, [revert_rotfloat]],
            [538, [revert_baselineskip]],
            [537, [revert_mathindent]],
            [536, [revert_xout]],
diff --git a/src/frontends/qt4/FloatPlacement.cpp 
b/src/frontends/qt4/FloatPlacement.cpp
index b446c7c..59bdf62 100644
--- a/src/frontends/qt4/FloatPlacement.cpp
+++ b/src/frontends/qt4/FloatPlacement.cpp
@@ -244,21 +244,36 @@ void FloatPlacement::checkAllowed() const
        if (spanCB->isVisible()) {
                bool const span = spanCB->isChecked();
                bool const sideways = sidewaysCB->isChecked();
-               defaultsCB->setEnabled(!sideways);
                topCB->setEnabled(!sideways && !defaults && !heredefinitely
                                  && contains(allowed_placement_, 't'));
                bottomCB->setEnabled(!sideways && !defaults && !span && 
!heredefinitely
                                     && contains(allowed_placement_, 'b'));
                pageCB->setEnabled(!sideways && !defaults && !heredefinitely
                                   && contains(allowed_placement_, 'p'));
-               herepossiblyCB->setEnabled(!sideways && !defaults && !span && 
!heredefinitely
+               if (!pageCB->isChecked())
+                       pageCB->setChecked(sideways && 
contains(allowed_placement_, 'p'));
+               herepossiblyCB->setEnabled(!defaults && !span && !heredefinitely
                                           && contains(allowed_placement_, 
'h'));
-               heredefinitelyCB->setEnabled(!sideways && !defaults && !span
+               heredefinitelyCB->setEnabled(!defaults && !span
                                             && contains(allowed_placement_, 
'H'));
-               ignoreCB->setEnabled(!sideways && !defaults && ignore && 
!heredefinitely
+               ignoreCB->setEnabled(!defaults && ignore && !heredefinitely
                                     && contains(allowed_placement_, '!'));
+               // handle special case with sideways
+               if ((!herepossiblyCB->isChecked() && sideways) || (span && 
sideways))
+                       ignoreCB->setEnabled(false);
+               // when disabled the options must be unchecked to avoid strange 
LaTeX export
+               // don't do it for pageCB because this case is handled with 
sideways
+               if (ignoreCB->isChecked() && !ignoreCB->isEnabled())
+                       ignoreCB->setChecked(false);
+               if (herepossiblyCB->isChecked() && !herepossiblyCB->isEnabled())
+                       herepossiblyCB->setChecked(false);
+               if (topCB->isChecked() && !topCB->isEnabled())
+                       topCB->setChecked(false);
+               if (bottomCB->isChecked() && !bottomCB->isEnabled())
+                       bottomCB->setChecked(false);
                spanCB->setEnabled(allows_wide_ && (!sideways || 
standardfloat_));
                sidewaysCB->setEnabled(allows_sideways_);
+               defaultsCB->setEnabled(!(sideways && span));
        } else {
                topCB->setEnabled(!defaults && !heredefinitely);
                bottomCB->setEnabled(!defaults && !heredefinitely);
diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp
index 287cfa4..e0586cc 100644
--- a/src/insets/InsetFloat.cpp
+++ b/src/insets/InsetFloat.cpp
@@ -389,8 +389,10 @@ void InsetFloat::latex(otexstream & os, OutputParams const 
& runparams_in) const
        if (runparams.lastid != -1)
                os.texrow().start(runparams.lastid, runparams.lastpos);
        // We only output placement if different from the def_placement.
-       // sidewaysfloats always use their own page
-       if (!placement.empty() && !params_.sideways)
+       // sidewaysfloats always use their own page,
+       // therefore don't output the p option that is always set
+       if (!placement.empty()
+           && (!params_.sideways || (params_.sideways && from_ascii(placement) 
!= "p")))
                os << '[' << from_ascii(placement) << ']';
        os << '\n';
 
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index d28ed5a..811883e 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -1468,6 +1468,7 @@ void parse_environment(Parser & p, ostream & os, bool 
outer,
        else if (unstarred_name == "sidewaysfigure"
                || unstarred_name == "sidewaystable"
                || unstarred_name == "sidewaysalgorithm") {
+               string const opt = p.hasOpt() ? p.getArg('[', ']') : string();
                eat_whitespace(p, os, parent_context, false);
                parent_context.check_layout(os);
                if (unstarred_name == "sidewaysfigure")
@@ -1476,6 +1477,10 @@ void parse_environment(Parser & p, ostream & os, bool 
outer,
                        begin_inset(os, "Float table\n");
                else if (unstarred_name == "sidewaysalgorithm")
                        begin_inset(os, "Float algorithm\n");
+               if (!opt.empty())
+                       os << "placement " << opt << '\n';
+               if (contains(opt, "H"))
+                       preamble.registerAutomaticallyLoadedPackage("float");
                os << "wide " << convert<string>(is_starred)
                   << "\nsideways true"
                   << "\nstatus open\n\n";
diff --git a/src/version.h b/src/version.h
index f119480..ff15d4d 100644
--- a/src/version.h
+++ b/src/version.h
@@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 539 // uwestoehr: support for \baselineskip
-#define LYX_FORMAT_TEX2LYX 539
+#define LYX_FORMAT_LYX 540 // uwestoehr: enable placement for rotated floats
+#define LYX_FORMAT_TEX2LYX 540
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER

Reply via email to