support for tabular*

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37471 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Edwin Leuven 2011-02-03 23:11:26 +00:00
parent c0a727a9d4
commit 119ea9cd24
7 changed files with 674 additions and 559 deletions

View File

@ -11,6 +11,11 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
-----------------------
2011-02-03 Edwin Leuven <e.leuven@gmail.com>
* Format incremented to 411 (r37471)
Support tabular* : add tabularwidth parameter to
tabular features
2011-02-03 Jürgen Spitzmüller <spitz@lyx.org>
* Format incremented to 411
New buffer param \language_package to allow per-document

View File

@ -2436,6 +2436,28 @@ def convert_langpack(document):
document.header.insert(i + 1, "\\language_package default")
def revert_tabularwidth(document):
i = 0
while True:
i = find_token(document.body, "\\begin_inset Tabular", i)
if i == -1:
return
j = find_end_of_inset(document.body, i)
if j == -1:
document.warning("Unable to find end of Tabular inset at line " + str(i))
i += 1
continue
i += 1
features = find_token(document.body, "<features", i, j)
if features == -1:
document.warning("Can't find any features in Tabular inset at line " + str(i))
i = j
continue
if document.body[features].find('alignment="tabularwidth"') != -1:
remove_option(document.body, features, 'tabularwidth')
##
# Conversion hub
#
@ -2506,10 +2528,12 @@ convert = [[346, []],
[408, []],
[409, [convert_use_xetex]],
[410, []],
[411, [convert_langpack]]
[411, [convert_langpack]],
[410, []]
]
revert = [[410, [revert_langpack]],
revert = [[411, [revert_tabularwidth]],
[410, [revert_langpack]],
[409, [revert_labeling]],
[408, [revert_use_xetex]],
[407, [revert_script]],

View File

@ -127,7 +127,7 @@ namespace {
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
int const LYX_FORMAT = 411; // spitz: lang_package buffer param
int const LYX_FORMAT = 412; // edwin: set tabular width
typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;

View File

@ -48,12 +48,14 @@ GuiTabular::GuiTabular(QWidget * parent)
{
setupUi(this);
tabularWidthED->setValidator(unsignedLengthValidator(tabularWidthED));
widthED->setValidator(unsignedLengthValidator(widthED));
multirowOffsetED->setValidator(new LengthValidator(multirowOffsetED));
topspaceED->setValidator(new LengthValidator(topspaceED));
bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
tabularWidthUnitCB->setCurrentItem(Length::defaultUnit());
widthUnitCB->setCurrentItem(Length::defaultUnit());
multirowOffsetUnitCB->setCurrentItem(Length::defaultUnit());
topspaceUnitCB->setCurrentItem(Length::defaultUnit());
@ -152,6 +154,8 @@ GuiTabular::GuiTabular(QWidget * parent)
this, SLOT(checkEnabled()));
connect(rightRB, SIGNAL(clicked()),
this, SLOT(checkEnabled()));
connect(tabularWidthED, SIGNAL(textEdited(const QString &)),
this, SLOT(checkEnabled()));
decimalPointLE->setInputMask("X; ");
decimalPointLE->setMaxLength(1);
@ -199,15 +203,25 @@ void GuiTabular::checkEnabled()
hAlignCB->setEnabled(!(multirowCB->isChecked()
&& !widgetsToLength(widthED, widthUnitCB).empty())
&& specialAlignmentED->text().isEmpty());
bool dalign =
bool const dalign =
hAlignCB->itemData(hAlignCB->currentIndex()).toString() == QString("decimal");
decimalPointLE->setEnabled(dalign);
decimalL->setEnabled(dalign);
bool const setwidth = TableAlignCB->currentText() == qt_("Middle")
&& !longTabularCB->isChecked() && !rotateTabularCB->isChecked();
tabularWidthL->setEnabled(setwidth);
tabularWidthED->setEnabled(setwidth);
tabularWidthUnitCB->setEnabled(setwidth);
bool const is_tabular_star = !tabularWidthED->text().isEmpty();
rotateTabularCB->setDisabled(is_tabular_star);
vAlignCB->setEnabled(!multirowCB->isChecked()
&& !widgetsToLength(widthED, widthUnitCB).empty()
&& specialAlignmentED->text().isEmpty());
topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
topspaceUnitCB->setEnabled(topspaceCO->currentIndex() == 2);
bottomspaceED->setEnabled(bottomspaceCO->currentIndex() == 2);
@ -216,13 +230,15 @@ void GuiTabular::checkEnabled()
interlinespaceUnitCB->setEnabled(interlinespaceCO->currentIndex() == 2);
// setting as longtable is not allowed when table is inside a float
longTabularCB->setEnabled(funcEnabled(Tabular::SET_LONGTABULAR));
longTabularCB->setEnabled(!is_tabular_star && funcEnabled(Tabular::SET_LONGTABULAR));
bool const longtabular = longTabularCB->isChecked();
longtableGB->setEnabled(true);
newpageCB->setEnabled(longtabular);
alignmentGB->setEnabled(longtabular);
// longtables cannot have a vertical alignment
TableAlignCB->setDisabled(longtabular);
// longtables and tabular* cannot have a vertical alignment
TableAlignCB->setDisabled(is_tabular_star || longtabular);
TableAlignCO->setDisabled(is_tabular_star || longtabular);
TableAlignCB->setDisabled(is_tabular_star || longtabular);
// FIXME: This Dialog is really horrible, disabling/enabling a checkbox
// depending on the cursor position is very very unintuitive...
@ -394,6 +410,12 @@ docstring GuiTabular::dialogToParams() const
// FIXME: We should use Tabular directly.
string param_str = "tabular";
// table width
string tabwidth = widgetsToLength(tabularWidthED, tabularWidthUnitCB);
if (tabwidth.empty())
tabwidth = "0pt";
setParam(param_str, Tabular::SET_TABULAR_WIDTH, tabwidth);
// apply the fixed width values
// this must be done before applying the column alignment
// because its value influences the alignment of multirow cells
@ -674,6 +696,14 @@ void GuiTabular::paramsToDialog(Inset const * inset)
///////////////////////////////////
// Set width and alignment
Length const tabwidth = tabular.tabularWidth();
if (tabwidth.zero())
tabularWidthED->clear();
else
lengthToWidgets(widthED, widthUnitCB,
tabwidth.asString(), default_unit);
Length pwidth;
docstring special;
if (multicol) {

View File

@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>427</width>
<height>429</height>
<width>433</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
@ -120,7 +120,7 @@
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -306,6 +306,23 @@
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="specialAlignmentLA">
<property name="text">
<string>LaTe&amp;X argument:</string>
</property>
<property name="buddy">
<cstring>specialAlignmentED</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="specialAlignmentED">
<property name="toolTip">
<string>Custom column format (LaTeX)</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="QGroupBox" name="tabAlignmentGB">
<property name="enabled">
@ -315,7 +332,23 @@
<string>Table-wide settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0" >
<item row="1" column="0">
<widget class="QLabel" name="tabularWidthL">
<property name="text">
<string>Table w&amp;idth:</string>
</property>
<property name="buddy">
<cstring>tabularWidthED</cstring>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="LengthCombo" name="tabularWidthUnitCB"/>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="tabularWidthED"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="TableAlignCO">
<property name="text">
<string>Verti&amp;cal alignment:</string>
@ -325,7 +358,7 @@
</property>
</widget>
</item>
<item row="0" column="1" >
<item row="2" column="1">
<widget class="QComboBox" name="TableAlignCB">
<property name="toolTip">
<string>Vertical alignment of the table</string>
@ -350,7 +383,7 @@
</item>
</widget>
</item>
<item row="0" column="2" >
<item row="2" column="2">
<spacer name="spacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -366,7 +399,7 @@
</property>
</spacer>
</item>
<item row="1" column="0" colspan="2" >
<item row="2" column="3">
<widget class="QCheckBox" name="rotateTabularCB">
<property name="enabled">
<bool>true</bool>
@ -382,23 +415,6 @@
</layout>
</widget>
</item>
<item row="3" column="0" >
<widget class="QLabel" name="specialAlignmentLA" >
<property name="text" >
<string>LaTe&amp;X argument:</string>
</property>
<property name="buddy" >
<cstring>specialAlignmentED</cstring>
</property>
</widget>
</item>
<item row="3" column="1" >
<widget class="QLineEdit" name="specialAlignmentED" >
<property name="toolTip" >
<string>Custom column format (LaTeX)</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="Borders">
@ -415,7 +431,7 @@
<item row="0" column="0">
<widget class="QFrame" name="bordersF">
<property name="sizePolicy">
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -897,9 +913,9 @@
</property>
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="GuiSetBorder" native="1" name="borders" >
<widget class="GuiSetBorder" name="borders" native="true">
<property name="sizePolicy">
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -1421,7 +1437,7 @@
<item>
<widget class="QLineEdit" name="tabularRowED">
<property name="sizePolicy">
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -1443,7 +1459,7 @@
<item>
<widget class="QLineEdit" name="tabularColumnED">
<property name="sizePolicy">
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -1503,43 +1519,47 @@
<tabstop>vAlignCB</tabstop>
<tabstop>multicolumnCB</tabstop>
<tabstop>multirowCB</tabstop>
<tabstop>multirowOffsetED</tabstop>
<tabstop>multirowOffsetUnitCB</tabstop>
<tabstop>rotateCellCB</tabstop>
<tabstop>tabularWidthED</tabstop>
<tabstop>tabularWidthUnitCB</tabstop>
<tabstop>TableAlignCB</tabstop>
<tabstop>rotateTabularCB</tabstop>
<tabstop>specialAlignmentED</tabstop>
<tabstop>borderSetPB</tabstop>
<tabstop>borderDefaultRB</tabstop>
<tabstop>borderUnsetPB</tabstop>
<tabstop>booktabsRB</tabstop>
<tabstop>topspaceCO</tabstop>
<tabstop>bottomspaceUnitCB</tabstop>
<tabstop>topspaceED</tabstop>
<tabstop>topspaceUnitCB</tabstop>
<tabstop>bottomspaceCO</tabstop>
<tabstop>bottomspaceED</tabstop>
<tabstop>interlinespaceED</tabstop>
<tabstop>bottomspaceUnitCB</tabstop>
<tabstop>interlinespaceCO</tabstop>
<tabstop>longTabularCB</tabstop>
<tabstop>interlinespaceED</tabstop>
<tabstop>interlinespaceUnitCB</tabstop>
<tabstop>longTabularCB</tabstop>
<tabstop>headerStatusCB</tabstop>
<tabstop>firstheaderNoContentsCB</tabstop>
<tabstop>headerBorderAboveCB</tabstop>
<tabstop>headerBorderBelowCB</tabstop>
<tabstop>firstheaderStatusCB</tabstop>
<tabstop>firstheaderBorderAboveCB</tabstop>
<tabstop>firstheaderBorderBelowCB</tabstop>
<tabstop>footerBorderAboveCB</tabstop>
<tabstop>firstheaderNoContentsCB</tabstop>
<tabstop>footerStatusCB</tabstop>
<tabstop>newpageCB</tabstop>
<tabstop>footerBorderAboveCB</tabstop>
<tabstop>footerBorderBelowCB</tabstop>
<tabstop>lastfooterStatusCB</tabstop>
<tabstop>lastfooterBorderAboveCB</tabstop>
<tabstop>lastfooterBorderBelowCB</tabstop>
<tabstop>lastfooterNoContentsCB</tabstop>
<tabstop>captionStatusCB</tabstop>
<tabstop>newpageCB</tabstop>
<tabstop>leftRB</tabstop>
<tabstop>borderSetPB</tabstop>
<tabstop>centerRB</tabstop>
<tabstop>rightRB</tabstop>
<tabstop>borderUnsetPB</tabstop>
</tabstops>
<includes>
<include location="local">qt_i18n.h</include>

View File

@ -183,6 +183,7 @@ TabularFeature tabularFeature[] =
{ Tabular::LONGTABULAR_ALIGN_CENTER, "longtabular-align-center", false },
{ Tabular::LONGTABULAR_ALIGN_RIGHT, "longtabular-align-right", false },
{ Tabular::SET_DECIMAL_POINT, "set-decimal-point", true },
{ Tabular::SET_TABULAR_WIDTH, "set-tabular-width", true },
{ Tabular::LAST_ACTION, "", false }
};
@ -678,6 +679,7 @@ void Tabular::init(Buffer * buf, row_type rows_arg,
updateIndexes();
is_long_tabular = false;
tabular_valignment = LYX_VALIGN_MIDDLE;
tabular_width = Length();
longtabular_alignment = LYX_LONGTABULAR_ALIGN_CENTER;
rotate = false;
use_booktabs = false;
@ -1391,8 +1393,10 @@ void Tabular::write(ostream & os) const
<< write_attribute("lastFootBottomDL", endlastfoot.bottomDL)
<< write_attribute("lastFootEmpty", endlastfoot.empty);
// longtables cannot be aligned vertically
if (!is_long_tabular)
if (!is_long_tabular) {
os << write_attribute("tabularvalignment", tabular_valignment);
os << write_attribute("tabularwidth", tabular_width);
}
if (is_long_tabular)
os << write_attribute("longtabularalignment",
longtabular_alignment);
@ -1489,6 +1493,7 @@ void Tabular::read(Lexer & lex)
getTokenValue(line, "booktabs", use_booktabs);
getTokenValue(line, "islongtable", is_long_tabular);
getTokenValue(line, "tabularvalignment", tabular_valignment);
getTokenValue(line, "tabularwidth", tabular_width);
getTokenValue(line, "longtabularalignment", longtabular_alignment);
getTokenValue(line, "firstHeadTopDL", endfirsthead.topDL);
getTokenValue(line, "firstHeadBottomDL", endfirsthead.bottomDL);
@ -2594,6 +2599,7 @@ int Tabular::TeXRow(otexstream & os, row_type row,
int Tabular::latex(otexstream & os, OutputParams const & runparams) const
{
int ret = 0;
bool const is_tabular_star = !tabular_width.zero();
//+---------------------------------------------------------------------
//+ first the opening preamble +
@ -2616,6 +2622,9 @@ int Tabular::latex(otexstream & os, OutputParams const & runparams) const
break;
}
} else {
if (is_tabular_star)
os << "\\begin{tabular*}{" << from_ascii(tabular_width.asLatexString()) << "}";
else
os << "\\begin{tabular}";
switch (tabular_valignment) {
case LYX_VALIGN_TOP:
@ -2631,6 +2640,9 @@ int Tabular::latex(otexstream & os, OutputParams const & runparams) const
os << "{";
if (is_tabular_star)
os << "@{\\extracolsep{\\fill}}";
for (col_type c = 0; c < ncols(); ++c) {
if (columnLeftLine(c))
os << '|';
@ -2715,6 +2727,9 @@ int Tabular::latex(otexstream & os, OutputParams const & runparams) const
if (is_long_tabular)
os << "\\end{longtable}";
else
if (is_tabular_star)
os << "\\end{tabular*}";
else
os << "\\end{tabular}";
if (rotate) {
@ -4360,6 +4375,11 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
status.clear();
return true;
case Tabular::SET_TABULAR_WIDTH:
status.setEnabled(!tabular.rotate && !tabular.is_long_tabular
&& tabular.tabular_valignment == Tabular::LYX_VALIGN_MIDDLE);
break;
case Tabular::SET_DECIMAL_POINT:
status.setEnabled(
tabular.getAlignment(cur.idx()) == LYX_ALIGN_DECIMAL);
@ -4498,18 +4518,22 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
case Tabular::TOGGLE_ROTATE_TABULAR:
case Tabular::SET_ROTATE_TABULAR:
status.setEnabled(tabular.tabular_width.zero());
status.setOnOff(tabular.rotate);
break;
case Tabular::TABULAR_VALIGN_TOP:
status.setEnabled(tabular.tabular_width.zero());
status.setOnOff(tabular.tabular_valignment
== Tabular::LYX_VALIGN_TOP);
break;
case Tabular::TABULAR_VALIGN_MIDDLE:
status.setEnabled(tabular.tabular_width.zero());
status.setOnOff(tabular.tabular_valignment
== Tabular::LYX_VALIGN_MIDDLE);
break;
case Tabular::TABULAR_VALIGN_BOTTOM:
status.setEnabled(tabular.tabular_width.zero());
status.setOnOff(tabular.tabular_valignment
== Tabular::LYX_VALIGN_BOTTOM);
break;
@ -5187,6 +5211,10 @@ void InsetTabular::tabularFeatures(Cursor & cur,
switch (feature) {
case Tabular::SET_TABULAR_WIDTH:
tabular.setTabularWidth(Length(value));
break;
case Tabular::SET_PWIDTH: {
Length const len(value);
tabular.setColumnPWidth(cur, cur.idx(), len);

View File

@ -270,6 +270,8 @@ public:
///
SET_DECIMAL_POINT,
///
SET_TABULAR_WIDTH,
///
LAST_ACTION
};
///
@ -402,6 +404,10 @@ public:
void setVAlignment(idx_type cell, VAlignment align,
bool onlycolumn = false);
///
void setTabularWidth(Length const & l) { tabular_width = l; }
///
Length tabularWidth() const { return tabular_width; }
///
void setColumnPWidth(Cursor &, idx_type, Length const &);
///
bool setMColumnPWidth(Cursor &, idx_type, Length const &);
@ -675,6 +681,8 @@ public:
///
mutable cell_vvector cell_info;
///
Length tabular_width;
///
bool use_booktabs;
///
bool rotate;