support for table cell rotations; fileformat change

This commit is contained in:
Uwe Stöhr 2012-03-16 02:29:37 +01:00
parent a4503bc1b4
commit 7a46910f04
9 changed files with 320 additions and 182 deletions

View File

@ -11,6 +11,11 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
-----------------------
2012-03-16 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 428
support for table cell rotation
(table cell option "rotate" specifies now a number with the rotation angle)
2012-03-06 Jürgen Spitzmüller <spitz@lyx.org>
* Format incremented to 427 (r40867)
Add native TIPA inset.

View File

@ -573,6 +573,66 @@ def revert_tipa(document):
i = j
def revert_cell_rotation(document):
"Revert cell rotations to TeX-code"
load_rotating = False
i = 0
try:
while True:
# first, let's find out if we need to do anything
# cell type 3 is multirow begin cell
i = find_token(document.body, '<cell ', i)
if i == -1:
return
j = document.body[i].find('rotate="')
if j != -1:
k = document.body[i].find('"', j + 8)
value = document.body[i][j + 8 : k]
if value == "0":
rgx = re.compile(r'rotate="[^"]+?"')
# remove rotate option
document.body[i] = rgx.sub('', document.body[i])
elif value == "90":
rgx = re.compile(r'rotate="[^"]+?"')
document.body[i] = rgx.sub('rotate="true"', document.body[i])
else:
rgx = re.compile(r'rotate="[^"]+?"')
load_rotating = True
# remove rotate option
document.body[i] = rgx.sub('', document.body[i])
# write ERT
document.body[i + 5 : i + 5] = \
put_cmd_in_ert("\\end{turn}")
document.body[i + 4 : i + 4] = \
put_cmd_in_ert("\\begin{turn}{" + value + "}")
i += 1
finally:
if load_rotating:
add_to_preamble(document, ["\\@ifundefined{turnbox}{\usepackage{rotating}}{}"])
def convert_cell_rotation(document):
'Convert cell rotation statements from "true" to "90"'
i = 0
while True:
# first, let's find out if we need to do anything
# cell type 3 is multirow begin cell
i = find_token(document.body, '<cell ', i)
if i == -1:
return
j = document.body[i].find('rotate="true"')
if j != -1:
rgx = re.compile(r'rotate="[^"]+?"')
# convert "true" to "90"
document.body[i] = rgx.sub('rotate="90"', document.body[i])
i += 1
##
# Conversion hub
#
@ -592,10 +652,12 @@ convert = [
[424, [convert_cite_engine_type]],
[425, []],
[426, []],
[427, []]
[427, []],
[428, [convert_cell_rotation]]
]
revert = [
[427, [revert_cell_rotation]],
[426, [revert_tipa]],
[425, [revert_verbatim]],
[424, [revert_cancel]],

View File

@ -162,7 +162,7 @@ ToolbarSet
Item "Align middle" "command-alternatives inset-modify tabular m-valign-middle;inset-modify tabular valign-middle"
Item "Align bottom" "command-alternatives inset-modify tabular m-valign-bottom;inset-modify tabular valign-bottom"
Separator
Item "Rotate cell" "inset-modify tabular toggle-rotate-cell"
Item "Rotate cell by 90° or unset rotation" "inset-modify tabular toggle-rotate-cell"
Item "Rotate table" "inset-modify tabular toggle-rotate-tabular"
Item "Set multi-column" "inset-modify tabular multicolumn"
Item "Set multi-row" "inset-modify tabular multirow"

View File

@ -31,6 +31,7 @@
#include "insets/InsetTabular.h"
#include "support/convert.h"
#include "support/debug.h"
#include <QCheckBox>
@ -144,6 +145,8 @@ GuiTabular::GuiTabular(QWidget * parent)
this, SLOT(checkEnabled()));
connect(rotateCellCB, SIGNAL(clicked()),
this, SLOT(checkEnabled()));
connect(rotateCellAngleSB, SIGNAL(valueChanged(int)),
this, SLOT(checkEnabled()));
connect(TableAlignCO, SIGNAL(activated(int)),
this, SLOT(checkEnabled()));
connect(longTabularCB, SIGNAL(clicked()),
@ -218,6 +221,8 @@ void GuiTabular::checkEnabled()
bool const is_tabular_star = !tabularWidthED->text().isEmpty();
rotateTabularCB->setDisabled(is_tabular_star);
rotateCellAngleSB->setEnabled(rotateCellCB->isChecked());
bool const enable_valign =
!multirowCB->isChecked()
&& !widgetsToLength(columnWidthED, columnWidthUnitLC).empty()
@ -559,11 +564,12 @@ docstring GuiTabular::dialogToParams() const
setParam(param_str, Tabular::SET_ROTATE_TABULAR);
else
setParam(param_str, Tabular::UNSET_ROTATE_TABULAR);
//
// store the cell rotation angle
string angle = convert<string>(rotateCellAngleSB->value());
if (rotateCellCB->isChecked())
setParam(param_str, Tabular::SET_ROTATE_CELL);
setParam(param_str, Tabular::SET_ROTATE_CELL, angle);
else
setParam(param_str, Tabular::UNSET_ROTATE_CELL);
setParam(param_str, Tabular::UNSET_ROTATE_CELL, angle);
//
if (longTabularCB->isChecked())
setParam(param_str, Tabular::SET_LONGTABULAR);
@ -699,7 +705,11 @@ void GuiTabular::paramsToDialog(Inset const * inset)
bool const multirow = tabular.isMultiRow(cell);
multirowCB->setChecked(multirow);
rotateCellCB->setChecked(tabular.getRotateCell(cell));
rotateCellCB->setChecked(tabular.getRotateCell(cell) != 0);
if (tabular.getRotateCell(cell) != 0)
rotateCellAngleSB->setValue(tabular.getRotateCell(cell));
else
rotateCellAngleSB->setValue(90);
rotateTabularCB->setChecked(tabular.rotate);
longTabularCB->setChecked(tabular.is_long_tabular);

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TabularUi</class>
<widget class="QWidget" name="TabularUi">
@ -5,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>433</width>
<width>497</width>
<height>400</height>
</rect>
</property>
@ -19,6 +20,77 @@
<property name="margin">
<number>0</number>
</property>
<item row="1" column="0">
<layout class="QHBoxLayout" name="_3">
<item>
<widget class="QLabel" name="TextLabel1">
<property name="text">
<string>Current cell:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="tabularRowED">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>32767</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>Current row position</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="tabularColumnED">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>32767</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>Current column position</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QTabWidget" name="TabWidget">
<property name="toolTip">
@ -235,77 +307,6 @@
</layout>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Row setting</string>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
<widget class="QCheckBox" name="multirowCB">
<property name="toolTip">
<string>Merge cells of different rows</string>
</property>
<property name="text">
<string>M&amp;ultirow</string>
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="multirowOffsetLA">
<property name="toolTip">
<string/>
</property>
<property name="text">
<string>&amp;Vertical Offset:</string>
</property>
<property name="buddy">
<cstring>multirowOffsetED</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="multirowOffsetED">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Optional vertical offset</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="LengthCombo" name="multirowOffsetUnitLC"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="1" column="2">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Cell setting</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<widget class="QCheckBox" name="rotateCellCB">
<property name="toolTip">
<string>Rotate this cell by 90 degrees</string>
</property>
<property name="text">
<string>Rotate &amp;cell 90 degrees</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="specialAlignmentLA">
<property name="text">
@ -415,6 +416,129 @@
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Row setting</string>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
<widget class="QCheckBox" name="multirowCB">
<property name="toolTip">
<string>Merge cells of different rows</string>
</property>
<property name="text">
<string>M&amp;ultirow</string>
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="multirowOffsetLA">
<property name="toolTip">
<string/>
</property>
<property name="text">
<string>&amp;Vertical Offset:</string>
</property>
<property name="buddy">
<cstring>multirowOffsetED</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="multirowOffsetED">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Optional vertical offset</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="LengthCombo" name="multirowOffsetUnitLC"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Cell setting</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QCheckBox" name="rotateCellCB">
<property name="toolTip">
<string>Rotate this cell by 90 degrees</string>
</property>
<property name="text">
<string>Rotate</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="rotateCellAngleSB">
<property name="maximumSize">
<size>
<width>51</width>
<height>20</height>
</size>
</property>
<property name="toolTip">
<string>rotation angle</string>
</property>
<property name="minimum">
<number>-180</number>
</property>
<property name="maximum">
<number>180</number>
</property>
<property name="singleStep">
<number>5</number>
</property>
<property name="value">
<number>90</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="rotateCellLA">
<property name="text">
<string>degrees</string>
</property>
<property name="buddy">
<cstring>tabularWidthED</cstring>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>13</width>
<height>41</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="Borders">
@ -1425,77 +1549,6 @@
</widget>
</widget>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="_3">
<item>
<widget class="QLabel" name="TextLabel1">
<property name="text">
<string>Current cell:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="tabularRowED">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>32767</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>Current row position</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="tabularColumnED">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>32767</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>Current column position</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
@ -1522,6 +1575,7 @@
<tabstop>multirowOffsetED</tabstop>
<tabstop>multirowOffsetUnitLC</tabstop>
<tabstop>rotateCellCB</tabstop>
<tabstop>rotateCellAngleSB</tabstop>
<tabstop>tabularWidthED</tabstop>
<tabstop>tabularWidthUnitLC</tabstop>
<tabstop>TableAlignCO</tabstop>

View File

@ -152,9 +152,9 @@ TabularFeature tabularFeature[] =
{ Tabular::SET_ROTATE_TABULAR, "set-rotate-tabular", false },
{ Tabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular", false },
{ Tabular::TOGGLE_ROTATE_TABULAR, "toggle-rotate-tabular", false },
{ Tabular::SET_ROTATE_CELL, "set-rotate-cell", false },
{ Tabular::UNSET_ROTATE_CELL, "unset-rotate-cell", false },
{ Tabular::TOGGLE_ROTATE_CELL, "toggle-rotate-cell", false },
{ Tabular::SET_ROTATE_CELL, "set-rotate-cell", true },
{ Tabular::UNSET_ROTATE_CELL, "unset-rotate-cell", true },
{ Tabular::TOGGLE_ROTATE_CELL, "toggle-rotate-cell", true },
{ Tabular::SET_USEBOX, "set-usebox", true },
{ Tabular::SET_LTHEAD, "set-lthead", true },
{ Tabular::UNSET_LTHEAD, "unset-lthead", true },
@ -565,7 +565,7 @@ Tabular::CellData::CellData(Buffer * buf)
left_line(false),
right_line(false),
usebox(BOX_NONE),
rotate(false),
rotate(0),
inset(new InsetTableCell(buf))
{
inset->setBuffer(*buf);
@ -1741,13 +1741,13 @@ void Tabular::unsetMultiRow(idx_type cell)
}
void Tabular::setRotateCell(idx_type cell, bool flag)
void Tabular::setRotateCell(idx_type cell, int value)
{
cellInfo(cell).rotate = flag;
cellInfo(cell).rotate = value;
}
bool Tabular::getRotateCell(idx_type cell) const
int Tabular::getRotateCell(idx_type cell) const
{
return cellInfo(cell).rotate;
}
@ -1759,7 +1759,7 @@ bool Tabular::needRotating() const
return true;
for (row_type r = 0; r < nrows(); ++r)
for (col_type c = 0; c < ncols(); ++c)
if (cell_info[r][c].rotate)
if (cell_info[r][c].rotate != 0)
return true;
return false;
}
@ -2315,9 +2315,9 @@ void Tabular::TeXCellPreamble(otexstream & os, idx_type cell,
os << "{";
} // end if ismultirow
if (getRotateCell(cell)) {
os << "\\begin{sideways}\n";
}
if (getRotateCell(cell) != 0)
os << "\\begin{turn}{" << convert<string>(getRotateCell(cell)) << "}\n";
if (getUsebox(cell) == BOX_PARBOX) {
os << "\\parbox[";
switch (valign) {
@ -2364,8 +2364,8 @@ void Tabular::TeXCellPostamble(otexstream & os, idx_type cell,
os << '}';
else if (getUsebox(cell) == BOX_MINIPAGE)
os << breakln << "\\end{minipage}";
if (getRotateCell(cell))
os << breakln << "\\end{sideways}";
if (getRotateCell(cell) != 0)
os << breakln << "\\end{turn}";
if (ismultirow)
os << '}';
if (ismulticol)
@ -5144,7 +5144,6 @@ bool InsetTabular::tabularFeatures(Cursor & cur, string const & argument)
for (; tabularFeature[i].action != Tabular::LAST_ACTION; ++i) {
if (s != tabularFeature[i].feature)
continue;
action = tabularFeature[i].action;
break;
}
@ -5187,9 +5186,13 @@ bool InsetTabular::oneCellHasRotationState(bool rotated,
{
for (row_type r = row_start; r <= row_end; ++r)
for (col_type c = col_start; c <= col_end; ++c)
if (tabular.getRotateCell(tabular.cellIndex(r, c)) == rotated)
return true;
if (rotated) {
if (tabular.getRotateCell(tabular.cellIndex(r, c)) != 0)
return true;
} else {
if (tabular.getRotateCell(tabular.cellIndex(r, c)) == 0)
return true;
}
return false;
}
@ -5586,13 +5589,13 @@ void InsetTabular::tabularFeatures(Cursor & cur,
case Tabular::SET_ROTATE_CELL:
for (row_type r = sel_row_start; r <= sel_row_end; ++r)
for (col_type c = sel_col_start; c <= sel_col_end; ++c)
tabular.setRotateCell(tabular.cellIndex(r, c), true);
tabular.setRotateCell(tabular.cellIndex(r, c), convert<int>(value));
break;
case Tabular::UNSET_ROTATE_CELL:
for (row_type r = sel_row_start; r <= sel_row_end; ++r)
for (col_type c = sel_col_start; c <= sel_col_end; ++c)
tabular.setRotateCell(tabular.cellIndex(r, c), false);
tabular.setRotateCell(tabular.cellIndex(r, c), convert<int>("0"));
break;
case Tabular::TOGGLE_ROTATE_CELL:
@ -5601,9 +5604,13 @@ void InsetTabular::tabularFeatures(Cursor & cur,
sel_row_start, sel_row_end, sel_col_start, sel_col_end);
for (row_type r = sel_row_start; r <= sel_row_end; ++r)
for (col_type c = sel_col_start; c <= sel_col_end; ++c)
tabular.setRotateCell(tabular.cellIndex(r, c),
oneNotRotated);
for (col_type c = sel_col_start; c <= sel_col_end; ++c) {
// when pressing the rotate cell button we default to 90° rotation
if (oneNotRotated)
tabular.setRotateCell(tabular.cellIndex(r, c), convert<int>("90"));
else
tabular.setRotateCell(tabular.cellIndex(r, c), convert<int>("0"));
}
}
break;

View File

@ -502,9 +502,9 @@ public:
///
col_type cellColumn(idx_type cell) const;
///
void setRotateCell(idx_type cell, bool);
void setRotateCell(idx_type cell, int);
///
bool getRotateCell(idx_type cell) const;
int getRotateCell(idx_type cell) const;
///
bool needRotating() const;
///
@ -612,7 +612,7 @@ public:
///
BoxType usebox;
///
bool rotate;
int rotate;
///
docstring align_special;
///

View File

@ -118,7 +118,7 @@ class CellInfo {
public:
CellInfo() : multi(CELL_NORMAL), align('n'), valign('n'),
leftlines(0), rightlines(0), topline(false),
bottomline(false), rotate(false) {}
bottomline(false), rotate(0) {}
/// cell content
string content;
/// multicolumn flag
@ -135,8 +135,8 @@ public:
bool topline;
/// do we have a line below?
bool bottomline;
/// is the cell rotated?
bool rotate;
/// how is the cell rotated?
int rotate;
/// width for multicolumn cells
string width;
/// special formatting for multicolumn cells

View File

@ -30,13 +30,13 @@ 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 427 // spitz: tipa inset
#define LYX_FORMAT_TEX2LYX 427 // spitz: tipa inset
#define LYX_FORMAT_LYX 428 // uwestoehr: rotated table cells
#define LYX_FORMAT_TEX2LYX 428 // uwestoehr: rotated table cells
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
#warning "tex2lyx produces an out of date file format."
#warning "Please update tex2lyx as soon as possible, since it depends implicitly"
#warning "on the current file format in some places (this causes bugs like #7780)."
//#warning "tex2lyx produces an out of date file format."
//#warning "Please update tex2lyx as soon as possible, since it depends implicitly"
//#warning "on the current file format in some places (this causes bugs like #7780)."
#endif
//} // namespace lyx