Michael Gerz wrote:
Edwin Leuven wrote:
is there a reason to have both M_TOGGLE_LINE_TOP and TOGGLE_LINE_TOP ?
couldn't we just have one TOGGLE_LINE_TOP and set the proper flags
depending whether we are in a multicolumn cell or not?
This is exactly what I proposed for 1.4 :-)
the attach patch does just that...
Georg Baum wrote:
what happened?
Nobody dared to open the can of worms that the tabular inset is. IMO the
tabular code that is spread over tabular.C and insets/insettabular.C needs
to be put into one file and almost completely rewritten. Of course now is
not the time to do so...
agreed. the patch is an improvement to the current code though because
it basically gets rid of the M_TOGGLE_LINE stuff...
moreover, atm the dialog and toolbar give inconsistent results. the
patch solves that (and gets rid of a bog).
...
the only thing left is the enabling/disabling of the toolbuttons (which
btw is not done atm either)
it is not really clear to me in what situations we should allow what. i
found the following comment:
// pay attention to left/right lines: they are only allowed
// to set if we are in first/last cell of row or if the left/right
// cell is also a multicolumn.
why is that, and what would be the preferred policy here?
not a good idea (do we loose functionality?) or nobody
has found the time or appetite to do it?
what would be a good way of setting lines anyway? (am not a latex expert)
on a per cell basis using \cline and switching to \hline when all
columns are spanned?
This is done AFAIK.
not in the user interface....
Index: frontends/controllers/ControlTabular.C
===================================================================
--- frontends/controllers/ControlTabular.C (revision 15927)
+++ frontends/controllers/ControlTabular.C (working copy)
@@ -83,42 +83,6 @@
}
-void ControlTabular::toggleTopLine()
-{
- if (tabular().isMultiColumn(getActiveCell()))
- set(LyXTabular::M_TOGGLE_LINE_TOP);
- else
- set(LyXTabular::TOGGLE_LINE_TOP);
-}
-
-
-void ControlTabular::toggleBottomLine()
-{
- if (tabular().isMultiColumn(getActiveCell()))
- set(LyXTabular::M_TOGGLE_LINE_BOTTOM);
- else
- set(LyXTabular::TOGGLE_LINE_BOTTOM);
-}
-
-
-void ControlTabular::toggleLeftLine()
-{
- if (tabular().isMultiColumn(getActiveCell()))
- set(LyXTabular::M_TOGGLE_LINE_LEFT);
- else
- set(LyXTabular::TOGGLE_LINE_LEFT);
-}
-
-
-void ControlTabular::toggleRightLine()
-{
- if (tabular().isMultiColumn(getActiveCell()))
- set(LyXTabular::M_TOGGLE_LINE_RIGHT);
- else
- set(LyXTabular::TOGGLE_LINE_RIGHT);
-}
-
-
void ControlTabular::setSpecial(string const & special)
{
if (tabular().isMultiColumn(getActiveCell()))
Index: frontends/controllers/ControlTabular.h
===================================================================
--- frontends/controllers/ControlTabular.h (revision 15927)
+++ frontends/controllers/ControlTabular.h (working copy)
@@ -46,12 +46,6 @@
/// set a parameter
void set(LyXTabular::Feature, std::string const & arg = std::string());
- /// borders
- void toggleTopLine();
- void toggleBottomLine();
- void toggleLeftLine();
- void toggleRightLine();
-
void setSpecial(std::string const & special);
void setWidth(std::string const & width);
Index: frontends/qt4/QTabular.C
===================================================================
--- frontends/qt4/QTabular.C (revision 15927)
+++ frontends/qt4/QTabular.C (working copy)
@@ -114,20 +114,19 @@
LyXTabular::idx_type const cell = controller().getActiveCell();
bool const isMulticolumnCell = tabular.isMultiColumn(cell);
+ dialog_->borders->setTop(tabular.topLine(cell));
+ dialog_->borders->setBottom(tabular.bottomLine(cell));
+ dialog_->borders->setLeft(tabular.leftLine(cell));
+ dialog_->borders->setRight(tabular.rightLine(cell));
+
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->setLeft(tabular.leftLine(cell, true));
- dialog_->borders->setRight(tabular.rightLine(cell, true));
// repaint the setborder widget
dialog_->borders->update();
return;
}
- dialog_->borders->setTop(tabular.topLine(cell));
- dialog_->borders->setBottom(tabular.bottomLine(cell));
// pay attention to left/right lines: they are only allowed
// to set if we are in first/last cell of row or if the left/right
// cell is also a multicolumn.
Index: frontends/qt4/QTabularDialog.C
===================================================================
--- frontends/qt4/QTabularDialog.C (revision 15927)
+++ frontends/qt4/QTabularDialog.C (working copy)
@@ -230,28 +230,28 @@
void QTabularDialog::leftBorder_changed()
{
- form_->controller().toggleLeftLine();
+ form_->controller().set(LyXTabular::TOGGLE_LINE_LEFT);
form_->changed();
}
void QTabularDialog::rightBorder_changed()
{
- form_->controller().toggleRightLine();
+ form_->controller().set(LyXTabular::TOGGLE_LINE_RIGHT);
form_->changed();
}
void QTabularDialog::topBorder_changed()
{
- form_->controller().toggleTopLine();
+ form_->controller().set(LyXTabular::TOGGLE_LINE_TOP);
form_->changed();
}
void QTabularDialog::bottomBorder_changed()
{
- form_->controller().toggleBottomLine();
+ form_->controller().set(LyXTabular::TOGGLE_LINE_BOTTOM);
form_->changed();
}
Index: insets/insettabular.C
===================================================================
--- insets/insettabular.C (revision 15927)
+++ insets/insettabular.C (working copy)
@@ -108,10 +108,6 @@
{ LyXTabular::VALIGN_TOP, "valign-top" },
{ LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
{ LyXTabular::VALIGN_MIDDLE, "valign-middle" },
- { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
- { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
- { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
- { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
{ LyXTabular::M_ALIGN_LEFT, "m-align-left" },
{ LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
{ LyXTabular::M_ALIGN_CENTER, "m-align-center" },
@@ -843,28 +839,20 @@
status.setOnOff(tabular.isMultiColumn(cur.idx()));
break;
- case LyXTabular::M_TOGGLE_LINE_TOP:
- flag = false;
case LyXTabular::TOGGLE_LINE_TOP:
- status.setOnOff(tabular.topLine(cur.idx(), flag));
+ status.setOnOff(tabular.topLine(cur.idx()));
break;
- case LyXTabular::M_TOGGLE_LINE_BOTTOM:
- flag = false;
case LyXTabular::TOGGLE_LINE_BOTTOM:
- status.setOnOff(tabular.bottomLine(cur.idx(), flag));
+ status.setOnOff(tabular.bottomLine(cur.idx()));
break;
- case LyXTabular::M_TOGGLE_LINE_LEFT:
- flag = false;
case LyXTabular::TOGGLE_LINE_LEFT:
- status.setOnOff(tabular.leftLine(cur.idx(), flag));
+ status.setOnOff(tabular.leftLine(cur.idx()));
break;
- case LyXTabular::M_TOGGLE_LINE_RIGHT:
- flag = false;
case LyXTabular::TOGGLE_LINE_RIGHT:
- status.setOnOff(tabular.rightLine(cur.idx(), flag));
+ status.setOnOff(tabular.rightLine(cur.idx()));
break;
case LyXTabular::M_ALIGN_LEFT:
@@ -1477,54 +1465,35 @@
cur.idx() = tabular.getCellNumber(row, column);
break;
- case LyXTabular::M_TOGGLE_LINE_TOP:
- flag = false;
case LyXTabular::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 LyXTabular::M_TOGGLE_LINE_BOTTOM:
- flag = false;
case LyXTabular::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;
}
- case LyXTabular::M_TOGGLE_LINE_LEFT:
- flag = false;
case LyXTabular::TOGGLE_LINE_LEFT: {
- bool lineSet = !tabular.leftLine(cur.idx(), flag);
+ bool lineSet = !tabular.leftLine(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.setLeftLine(
- tabular.getCellNumber(i,j),
- lineSet,
- flag);
+ tabular.setLeftLine(tabular.getCellNumber(i,j),
lineSet);
break;
}
- case LyXTabular::M_TOGGLE_LINE_RIGHT:
- flag = false;
case LyXTabular::TOGGLE_LINE_RIGHT: {
- bool lineSet = !tabular.rightLine(cur.idx(), flag);
+ bool lineSet = !tabular.rightLine(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.setRightLine(
- tabular.getCellNumber(i,j),
- lineSet,
- flag);
+
tabular.setRightLine(tabular.getCellNumber(i,j), lineSet);
break;
}
@@ -1776,9 +1745,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);
@@ -1787,9 +1756,8 @@
while (paste_tabular->columns() > columns)
paste_tabular->deleteColumn(columns);
- paste_tabular->setLeftLine(0, true, true);
- paste_tabular->setRightLine(paste_tabular->getLastCellInRow(0),
- true, true);
+ paste_tabular->setLeftLine(0, true);
+ paste_tabular->setRightLine(paste_tabular->getLastCellInRow(0), true);
odocstringstream os;
OutputParams const runparams;
Index: tabular.C
===================================================================
--- tabular.C (revision 15927)
+++ tabular.C (working copy)
@@ -662,31 +662,30 @@
}
-bool LyXTabular::topLine(idx_type const cell, bool const onlycolumn) const
+bool LyXTabular::topLine(idx_type const cell) const
{
- if (!onlycolumn && isMultiColumn(cell) &&
- !(use_booktabs && row_of_cell(cell) == 0))
+ if (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;
}
-bool LyXTabular::bottomLine(idx_type const cell, bool onlycolumn) const
+bool LyXTabular::bottomLine(idx_type const cell) const
{
- if (!onlycolumn && isMultiColumn(cell) &&
+ if (isMultiColumn(cell) &&
!(use_booktabs && isLastRow(cell)))
return cellinfo_of_cell(cell).bottom_line;
return row_info[row_of_cell(cell)].bottom_line;
}
-bool LyXTabular::leftLine(idx_type cell, bool onlycolumn) const
+bool LyXTabular::leftLine(idx_type cell) const
{
if (use_booktabs)
return false;
- if (!onlycolumn && isMultiColumn(cell) &&
- (isFirstCellInRow(cell) || isMultiColumn(cell-1)))
- {
+ if (isMultiColumn(cell) &&
+ (isFirstCellInRow(cell) || isMultiColumn(cell-1))) {
if (cellinfo_of_cell(cell).align_special.empty())
return cellinfo_of_cell(cell).left_line;
return prefixIs(ltrim(cellinfo_of_cell(cell).align_special),
"|");
@@ -697,13 +696,12 @@
}
-bool LyXTabular::rightLine(idx_type cell, bool onlycolumn) const
+bool LyXTabular::rightLine(idx_type cell) const
{
if (use_booktabs)
return false;
- if (!onlycolumn && isMultiColumn(cell) &&
- (isLastCellInRow(cell) || isMultiColumn(cell + 1)))
- {
+ if (isMultiColumn(cell) &&
+ (isLastCellInRow(cell) || isMultiColumn(cell + 1))) {
if (cellinfo_of_cell(cell).align_special.empty())
return cellinfo_of_cell(cell).right_line;
return suffixIs(rtrim(cellinfo_of_cell(cell).align_special),
"|");
@@ -891,9 +889,9 @@
int width = 0;
int add_width = 0;
- if (rightLine(cell_info[row][column1].cellno, true) &&
+ if (rightLine(cell_info[row][column1].cellno) &&
column1 < columns_ - 1 &&
- leftLine(cell_info[row][column1+1].cellno, true))
+ leftLine(cell_info[row][column1+1].cellno))
{
add_width = WIDTH_OF_LINE;
}
@@ -1025,37 +1023,37 @@
}
-void LyXTabular::setTopLine(idx_type cell, bool line, bool onlycolumn)
+void LyXTabular::setTopLine(idx_type cell, bool line)
{
row_type const row = row_of_cell(cell);
- if (onlycolumn || !isMultiColumn(cell))
+ if (!isMultiColumn(cell) || (use_booktabs && row == 0))
row_info[row].top_line = line;
else
cellinfo_of_cell(cell).top_line = line;
}
-void LyXTabular::setBottomLine(idx_type cell, bool line, bool onlycolumn)
+void LyXTabular::setBottomLine(idx_type cell, bool line)
{
- if (onlycolumn || !isMultiColumn(cell))
+ if (!isMultiColumn(cell) || (use_booktabs && isLastRow(cell)))
row_info[row_of_cell(cell)].bottom_line = line;
else
cellinfo_of_cell(cell).bottom_line = line;
}
-void LyXTabular::setLeftLine(idx_type cell, bool line, bool onlycolumn)
+void LyXTabular::setLeftLine(idx_type cell, bool line)
{
- if (onlycolumn || !isMultiColumn(cell))
+ if (!isMultiColumn(cell) && !use_booktabs)
column_info[column_of_cell(cell)].left_line = line;
else
cellinfo_of_cell(cell).left_line = line;
}
-void LyXTabular::setRightLine(idx_type cell, bool line, bool onlycolumn)
+void LyXTabular::setRightLine(idx_type cell, bool line)
{
- if (onlycolumn || !isMultiColumn(cell))
+ if (!isMultiColumn(cell) && !use_booktabs)
column_info[right_column_of_cell(cell)].right_line = line;
else
cellinfo_of_cell(cell).right_line = line;
@@ -1912,8 +1910,8 @@
} else {
if (leftLine(cell) &&
(isFirstCellInRow(cell) ||
- (!isMultiColumn(cell - 1) && !leftLine(cell,
true) &&
- !rightLine(cell - 1, true))))
+ (!isMultiColumn(cell - 1) && !leftLine(cell) &&
+ !rightLine(cell - 1))))
{
os << '|';
}
Index: tabular.h
===================================================================
--- tabular.h (revision 15927)
+++ tabular.h (working copy)
@@ -72,10 +72,6 @@
///
VALIGN_MIDDLE,
///
- M_TOGGLE_LINE_TOP,
- ///
- M_TOGGLE_LINE_BOTTOM,
- ///
M_TOGGLE_LINE_LEFT,
///
M_TOGGLE_LINE_RIGHT,
@@ -205,13 +201,13 @@
row_type rows_arg);
/// Returns true if there is a topline, returns false if not
- bool topLine(idx_type cell, bool onlycolumn = 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 onlycolumn = 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 onlycolumn = false) const;
+ bool leftLine(idx_type cell) const;
/// Returns true if there is a topline, returns false if not
- bool rightLine(idx_type cell, bool onlycolumn = false) const;
+ bool rightLine(idx_type cell) const;
///
bool topAlreadyDrawn(idx_type cell) const;
@@ -246,13 +242,13 @@
///
void setAllLines(idx_type cell, bool line);
///
- void setTopLine(idx_type cell, bool line, bool onlycolumn = false);
+ void setTopLine(idx_type cell, bool line);
///
- void setBottomLine(idx_type cell, bool line, bool onlycolumn = false);
+ void setBottomLine(idx_type cell, bool line);
///
- void setLeftLine(idx_type cell, bool line, bool onlycolumn = false);
+ void setLeftLine(idx_type cell, bool line);
///
- void setRightLine(idx_type cell, bool line, bool onlycolumn = false);
+ void setRightLine(idx_type cell, bool line);
///
void setAlignment(idx_type cell, LyXAlignment align,
bool onlycolumn = false);