Edwin Leuven wrote:
updated patch attached:
igonore the previous one, and use the one attached instead and it:
- takes into account booktabs
- fixes a bug where topline in 1st row and bottom line in last row were
not set with booktabs (create a booktabs table without lines to check)
- fixes the ui inconsistency bug (sic ;-)
- fixes the buggy cline support
3 bugs in one go, that is not too bad?!
for this:
> - ignore old (bogus) tabular line settings at the cell level
i will need the help of a lyx2lyx wiz...
good night
Index: src/frontends/controllers/ControlTabular.cpp
===================================================================
--- src/frontends/controllers/ControlTabular.cpp (revision 18533)
+++ src/frontends/controllers/ControlTabular.cpp (working copy)
@@ -83,24 +83,6 @@
}
-void ControlTabular::toggleTopLine()
-{
- if (tabular().isMultiColumn(getActiveCell()))
- set(Tabular::M_TOGGLE_LINE_TOP);
- else
- set(Tabular::TOGGLE_LINE_TOP);
-}
-
-
-void ControlTabular::toggleBottomLine()
-{
- if (tabular().isMultiColumn(getActiveCell()))
- set(Tabular::M_TOGGLE_LINE_BOTTOM);
- else
- set(Tabular::TOGGLE_LINE_BOTTOM);
-}
-
-
void ControlTabular::toggleLeftLine()
{
if (tabular().isMultiColumn(getActiveCell()))
Index: src/frontends/controllers/ControlTabular.h
===================================================================
--- src/frontends/controllers/ControlTabular.h (revision 18533)
+++ src/frontends/controllers/ControlTabular.h (working copy)
@@ -47,8 +47,6 @@
void set(Tabular::Feature, std::string const & arg = std::string());
/// borders
- void toggleTopLine();
- void toggleBottomLine();
void toggleLeftLine();
void toggleRightLine();
Index: src/frontends/qt4/QTabular.cpp
===================================================================
--- src/frontends/qt4/QTabular.cpp (revision 18533)
+++ src/frontends/qt4/QTabular.cpp (working copy)
@@ -257,14 +257,14 @@
void QTabularDialog::topBorder_changed()
{
- form_->controller().toggleTopLine();
+ form_->controller().set(Tabular::TOGGLE_LINE_TOP);
form_->changed();
}
void QTabularDialog::bottomBorder_changed()
{
- form_->controller().toggleBottomLine();
+ form_->controller().set(Tabular::TOGGLE_LINE_BOTTOM);
form_->changed();
}
@@ -598,8 +598,8 @@
if (!isMulticolumnCell) {
dialog_->borders->setLeftEnabled(true);
dialog_->borders->setRightEnabled(true);
- dialog_->borders->setTop(tabular.topLine(cell, true));
- dialog_->borders->setBottom(tabular.bottomLine(cell, true));
+ dialog_->borders->setTop(tabular.topLine(cell));
+ dialog_->borders->setBottom(tabular.bottomLine(cell));
dialog_->borders->setLeft(tabular.leftLine(cell, true));
dialog_->borders->setRight(tabular.rightLine(cell, true));
// repaint the setborder widget
Index: src/insets/InsetTabular.cpp
===================================================================
--- src/insets/InsetTabular.cpp (revision 18533)
+++ src/insets/InsetTabular.cpp (working copy)
@@ -132,8 +132,6 @@
{ Tabular::VALIGN_TOP, "valign-top" },
{ Tabular::VALIGN_BOTTOM, "valign-bottom" },
{ Tabular::VALIGN_MIDDLE, "valign-middle" },
- { Tabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
- { Tabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
{ Tabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
{ Tabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
{ Tabular::M_ALIGN_LEFT, "m-align-left" },
@@ -490,9 +488,9 @@
multicolumn(Tabular::CELL_NORMAL),
alignment(LYX_ALIGN_CENTER),
valignment(LYX_VALIGN_TOP),
- top_line(true),
+ top_line(false),
bottom_line(false),
- left_line(true),
+ left_line(false),
right_line(false),
usebox(BOX_NONE),
rotate(false),
@@ -549,7 +547,7 @@
Tabular::rowstruct::rowstruct()
: ascent_of_row(0),
descent_of_row(0),
- top_line(true),
+ top_line(false),
bottom_line(false),
top_space_default(false),
bottom_space_default(false),
@@ -565,7 +563,7 @@
Tabular::columnstruct::columnstruct()
: alignment(LYX_ALIGN_CENTER),
valignment(LYX_VALIGN_TOP),
- left_line(true),
+ left_line(false),
right_line(false),
width_of_column(0)
{
@@ -599,14 +597,21 @@
column_info.reserve(10);
cell_info.reserve(100);
fixCellNums();
- for (row_type i = 0; i < rows_; ++i)
- cell_info[i].back().right_line = true;
- row_info.back().bottom_line = true;
- row_info.front().bottom_line = true;
- column_info.back().right_line = true;
is_long_tabular = false;
rotate = false;
use_booktabs = false;
+ // set silly default lyx tabular lines
+ row_info.front().bottom_line = true;
+ row_info.back().bottom_line = true;
+ column_info.back().right_line = true;
+ for (row_type i = 0; i < rows_; ++i) {
+ row_info[i].top_line = true;
+ for (col_type j = 0; j < columns_; ++j) {
+ column_info[j].left_line = true;
+ cell_info[i][j].top_line = row_info[i].top_line;
+ cell_info[i][j].bottom_line = row_info[i].bottom_line;
+ }
+ }
}
@@ -620,7 +625,6 @@
cell_info[i][j].inset->setDrawFrame(false);
cell_info[i][j].cellno = cellno++;
}
- cell_info[i].back().right_line = true;
}
set_row_column_number_info();
@@ -813,21 +817,21 @@
}
-bool Tabular::topLine(idx_type const cell, bool const wholerow) const
+bool Tabular::topLine(idx_type const cell) const
{
- if (!wholerow && isMultiColumn(cell) &&
- !(use_booktabs && row_of_cell(cell) == 0))
- return cellinfo_of_cell(cell).top_line;
- return row_info[row_of_cell(cell)].top_line;
+ if (use_booktabs && row_of_cell(cell) == 0)
+ return row_info[row_of_cell(cell)].top_line;
+
+ return cellinfo_of_cell(cell).top_line;
}
-bool Tabular::bottomLine(idx_type const cell, bool wholerow) const
+bool Tabular::bottomLine(idx_type const cell) const
{
- if (!wholerow && isMultiColumn(cell) &&
- !(use_booktabs && isLastRow(cell)))
- return cellinfo_of_cell(cell).bottom_line;
- return row_info[row_of_cell(cell)].bottom_line;
+ if (use_booktabs && isLastRow(cell))
+ return row_info[row_of_cell(cell)].bottom_line;
+
+ return cellinfo_of_cell(cell).bottom_line;
}
@@ -899,27 +903,14 @@
if (!row || row >= rows_)
return 0;
- bool top = true;
bool bottom = true;
+ for (col_type column = 0; bottom && column < columns_; ++column)
+ bottom = cell_info[row - 1][column].bottom_line;
- for (col_type column = 0; column < columns_ && bottom; ++column) {
- switch (cell_info[row - 1][column].multicolumn) {
- case Tabular::CELL_BEGIN_OF_MULTICOLUMN:
- bottom = cell_info[row - 1][column].bottom_line;
- break;
- case Tabular::CELL_NORMAL:
- bottom = row_info[row - 1].bottom_line;
- }
- }
- for (col_type column = 0; column < columns_ && top; ++column) {
- switch (cell_info[row][column].multicolumn) {
- case Tabular::CELL_BEGIN_OF_MULTICOLUMN:
- top = cell_info[row][column].top_line;
- break;
- case Tabular::CELL_NORMAL:
- top = row_info[row].top_line;
- }
- }
+ bool top = true;
+ for (col_type column = 0; top && column < columns_; ++column)
+ top = cell_info[row][column].top_line;
+
int const interline_space = row_info[row - 1].interline_space_default ?
default_line_space :
row_info[row - 1].interline_space.inPixels(width_of_tabular);
@@ -1164,22 +1155,37 @@
}
-void Tabular::setTopLine(idx_type cell, bool line, bool wholerow)
+void Tabular::setTopLine(idx_type cell, bool line)
{
row_type const row = row_of_cell(cell);
- if (wholerow || !isMultiColumn(cell))
- row_info[row].top_line = line;
- else
- cellinfo_of_cell(cell).top_line = line;
+ if (use_booktabs && row == 0)
+ return;
+
+ cellinfo_of_cell(cell).top_line = line;
+ idx_type const i0 = getFirstCellInRow(row);
+ idx_type const i1 = getLastCellInRow(row);
+ bool rowset = true;
+ for (idx_type j = i0; rowset && j <= i1; ++j)
+ rowset = cellinfo_of_cell(j).top_line;
+
+ row_info[row].top_line = rowset;
}
-void Tabular::setBottomLine(idx_type cell, bool line, bool wholerow)
+void Tabular::setBottomLine(idx_type cell, bool line)
{
- if (wholerow || !isMultiColumn(cell))
- row_info[row_of_cell(cell)].bottom_line = line;
- else
- cellinfo_of_cell(cell).bottom_line = line;
+ row_type const row = row_of_cell(cell);
+ if (use_booktabs && row == rows_ - 1)
+ return;
+
+ cellinfo_of_cell(cell).bottom_line = line;
+ idx_type const i0 = getFirstCellInRow(row);
+ idx_type const i1 = getLastCellInRow(row);
+ bool rowset = true;
+ for (idx_type j = i0; rowset && j <= i1; ++j)
+ rowset = cellinfo_of_cell(j).bottom_line;
+
+ row_info[row].bottom_line = rowset;
}
@@ -1554,8 +1560,17 @@
getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
getTokenValue(line, "alignment", cell_info[i][j].alignment);
getTokenValue(line, "valignment", cell_info[i][j].valignment);
- getTokenValue(line, "topline", cell_info[i][j].top_line);
- getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
+
+ if (row_info[i].top_line)
+ cell_info[i][j].top_line = true;
+ else
+ getTokenValue(line, "topline", cell_info[i][j].top_line);
+
+ if (row_info[i].bottom_line)
+ cell_info[i][j].bottom_line = true;
+ else
+ getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
+
getTokenValue(line, "leftline", cell_info[i][j].left_line);
getTokenValue(line, "rightline", cell_info[i][j].right_line);
getTokenValue(line, "rotate", cell_info[i][j].rotate);
@@ -1668,6 +1683,22 @@
void Tabular::setBookTabs(bool what)
{
use_booktabs = what;
+
+ if (!use_booktabs)
+ return;
+
+ // set top line in 1st row
+ row_info[0].top_line = true;
+ idx_type i0 = getFirstCellInRow(0);
+ idx_type i1 = getLastCellInRow(0);
+ for (idx_type j = i0; j <= i1; ++j)
+ cellinfo_of_cell(j).top_line = true;
+ // set bottom line in bottom row
+ row_info[rows_ - 1].bottom_line = true;
+ i0 = getFirstCellInRow(rows_ - 1);
+ i1 = getLastCellInRow(rows_ - 1);
+ for (idx_type j = i0; j <= i1; ++j)
+ cellinfo_of_cell(j).bottom_line = true;
}
@@ -3574,18 +3605,18 @@
status.setOnOff(tabular.isMultiColumn(cur.idx()));
break;
- case Tabular::M_TOGGLE_LINE_TOP:
- flag = false;
- case Tabular::TOGGLE_LINE_TOP:
- status.setOnOff(tabular.topLine(cur.idx(), flag));
+ case Tabular::TOGGLE_LINE_TOP: {
+ row_type const row = tabular.row_of_cell(cur.idx());
+ status.enabled(!(tabular.use_booktabs && row == 0));
+ status.setOnOff(tabular.topLine(cur.idx()));
break;
-
- case Tabular::M_TOGGLE_LINE_BOTTOM:
- flag = false;
- case Tabular::TOGGLE_LINE_BOTTOM:
- status.setOnOff(tabular.bottomLine(cur.idx(), flag));
+ }
+ case Tabular::TOGGLE_LINE_BOTTOM: {
+ row_type const row = tabular.row_of_cell(cur.idx());
+ status.enabled(!(tabular.use_booktabs && row == tabular.rows_ - 1));
+ status.setOnOff(tabular.bottomLine(cur.idx()));
break;
-
+ }
case Tabular::M_TOGGLE_LINE_LEFT:
flag = false;
case Tabular::TOGGLE_LINE_LEFT:
@@ -4223,28 +4254,19 @@
cur.idx() = tabular.getCellNumber(row, column);
break;
- case Tabular::M_TOGGLE_LINE_TOP:
- flag = false;
case Tabular::TOGGLE_LINE_TOP: {
- bool lineSet = !tabular.topLine(cur.idx(), flag);
+ bool lineSet = !tabular.topLine(cur.idx());
for (row_type i = sel_row_start; i <= sel_row_end; ++i)
for (col_type j = sel_col_start; j <= sel_col_end; ++j)
- tabular.setTopLine(
- tabular.getCellNumber(i, j),
- lineSet, flag);
+ tabular.setTopLine(tabular.getCellNumber(i, j), lineSet);
break;
}
- case Tabular::M_TOGGLE_LINE_BOTTOM:
- flag = false;
case Tabular::TOGGLE_LINE_BOTTOM: {
- bool lineSet = !tabular.bottomLine(cur.idx(), flag);
+ bool lineSet = !tabular.bottomLine(cur.idx());
for (row_type i = sel_row_start; i <= sel_row_end; ++i)
for (col_type j = sel_col_start; j <= sel_col_end; ++j)
- tabular.setBottomLine(
- tabular.getCellNumber(i, j),
- lineSet,
- flag);
+ tabular.setBottomLine(tabular.getCellNumber(i, j), lineSet);
break;
}
@@ -4536,9 +4558,9 @@
while (paste_tabular->rows() > rows)
paste_tabular->deleteRow(rows);
- paste_tabular->setTopLine(0, true, true);
+ paste_tabular->setTopLine(0, true);
paste_tabular->setBottomLine(paste_tabular->getFirstCellInRow(rows - 1),
- true, true);
+ true);
for (col_type i = 0; i < cs; ++i)
paste_tabular->deleteColumn(0);
Index: src/insets/InsetTabular.h
===================================================================
--- src/insets/InsetTabular.h (revision 18533)
+++ src/insets/InsetTabular.h (working copy)
@@ -106,10 +106,6 @@
///
VALIGN_MIDDLE,
///
- M_TOGGLE_LINE_TOP,
- ///
- M_TOGGLE_LINE_BOTTOM,
- ///
M_TOGGLE_LINE_LEFT,
///
M_TOGGLE_LINE_RIGHT,
@@ -243,9 +239,9 @@
row_type rows_arg);
/// Returns true if there is a topline, returns false if not
- bool topLine(idx_type cell, bool wholerow = false) const;
+ bool topLine(idx_type cell) const;
/// Returns true if there is a topline, returns false if not
- bool bottomLine(idx_type cell, bool wholerow = false) const;
+ bool bottomLine(idx_type cell) const;
/// Returns true if there is a topline, returns false if not
bool leftLine(idx_type cell, bool wholecolumn = false) const;
/// Returns true if there is a topline, returns false if not
@@ -284,9 +280,9 @@
///
void setAllLines(idx_type cell, bool line);
///
- void setTopLine(idx_type cell, bool line, bool wholerow = false);
+ void setTopLine(idx_type cell, bool line);
///
- void setBottomLine(idx_type cell, bool line, bool wholerow = false);
+ void setBottomLine(idx_type cell, bool line);
///
void setLeftLine(idx_type cell, bool line, bool wholecolumn = false);
///