> Since you are now using this method multiple times, I think you should factor
> out the method

This is done in the attached patch for branch. I also added your requested FIXME and a FIXME for bug 5754.

I wrote in my initial post:

> The only thing this is now missing:
> - when the first header empty checkbox is checked, then haveLTFirstHead() 
needs
> to be set true

This is now also fixed.

regards Uwe
Index: src/frontends/qt4/GuiTabular.cpp
===================================================================
--- src/frontends/qt4/GuiTabular.cpp	(revision 28428)
+++ src/frontends/qt4/GuiTabular.cpp	(working copy)
@@ -23,6 +23,8 @@
 #include "BufferView.h"
 #include "Cursor.h"
 #include "FuncRequest.h"
+#include "FuncStatus.h"
+#include "LyXFunc.h"
 #include "LyXRC.h"
 
 #include "insets/InsetTabular.h"
@@ -786,6 +788,37 @@
 	captionStatusCB->setChecked(tabular_.ltCaption(row));
 	captionStatusCB->blockSignals(false);
 
+	// FIXME: shouldn't this be handled by GuiDialog?
+	// FIXME: Some of them should be handled directly in TabularUI.ui
+	firstheaderBorderAboveCB->setEnabled(funcEnabled(Tabular::SET_LTFIRSTHEAD));
+	firstheaderBorderBelowCB->setEnabled(funcEnabled(Tabular::SET_LTFIRSTHEAD));
+	// first header can only be suppressed when there is a header
+	firstheaderNoContentsCB->setEnabled(tabular_.haveLTHead()
+		&& !tabular_.haveLTFirstHead());
+	// check if setting a first header is allowed
+	// additionally check firstheaderStatusCB because when this is the case
+	// a first header makes no sense
+	firstheaderStatusCB->setEnabled(funcEnabled(Tabular::SET_LTFIRSTHEAD)
+		&& !firstheaderNoContentsCB->isChecked());
+	//firstheaderStatusCB->setEnabled(!firstheaderNoContentsCB->isChecked());
+	headerBorderAboveCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD));
+	headerBorderBelowCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD));
+	headerStatusCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD));
+	footerBorderAboveCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT));
+	footerBorderBelowCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT));
+	footerStatusCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT));
+	lastfooterBorderAboveCB->setEnabled(funcEnabled(Tabular::SET_LTLASTFOOT));
+	lastfooterBorderBelowCB->setEnabled(funcEnabled(Tabular::SET_LTLASTFOOT));
+	// last footer can only be suppressed when there is a footer
+	lastfooterNoContentsCB->setEnabled(tabular_.haveLTFoot()
+		&& !tabular_.haveLTLastFoot());
+	// check if setting a last footer is allowed
+	// additionally check lastfooterNoContentsCB because when this is the case
+	// a last footer makes no sense
+	lastfooterStatusCB->setEnabled(funcEnabled(Tabular::SET_LTLASTFOOT)
+		&& !lastfooterNoContentsCB->isChecked());
+	captionStatusCB->setEnabled(funcEnabled(Tabular::TOGGLE_LTCAPTION));
+
 	Tabular::ltType ltt;
 	bool use_empty;
 	bool row_set = tabular_.getRowOfLTHead(row, ltt);
@@ -815,7 +848,6 @@
 		firstheaderBorderAboveCB->setChecked(false);
 		firstheaderBorderBelowCB->setChecked(false);
 		if (use_empty) {
-			firstheaderNoContentsCB->setChecked(ltt.empty);
 			if (ltt.empty)
 				firstheaderStatusCB->setEnabled(false);
 		}
@@ -838,7 +870,7 @@
 	}
 
 	row_set = tabular_.getRowOfLTLastFoot(row, ltt);
-		lastfooterStatusCB->setChecked(row_set);
+	lastfooterStatusCB->setChecked(row_set);
 	if (ltt.set && (!ltt.empty || !use_empty)) {
 		lastfooterBorderAboveCB->setChecked(ltt.topDL);
 		lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
@@ -848,7 +880,6 @@
 		lastfooterBorderAboveCB->setChecked(false);
 		lastfooterBorderBelowCB->setChecked(false);
 		if (use_empty) {
-			lastfooterNoContentsCB->setChecked(ltt.empty);
 			if (ltt.empty)
 				lastfooterStatusCB->setEnabled(false);
 		}
@@ -1127,6 +1158,13 @@
 }
 
 
+// to get the status of the longtable row settings
+bool GuiTabular::funcEnabled(Tabular::Feature f) const
+{
+	return getStatus(FuncRequest(getLfun(), featureAsString(f))).enabled();
+}
+
+
 Dialog * createGuiTabular(GuiView & lv) { return new GuiTabular(lv); }
 
 
Index: src/frontends/qt4/GuiTabular.h
===================================================================
--- src/frontends/qt4/GuiTabular.h	(revision 28428)
+++ src/frontends/qt4/GuiTabular.h	(working copy)
@@ -117,6 +117,8 @@
 
 	void longTabular(bool yes);
 
+	bool funcEnabled(Tabular::Feature f) const;
+
 	///
 	Tabular::idx_type active_cell_;
 	///
Index: src/insets/InsetTabular.cpp
===================================================================
--- src/insets/InsetTabular.cpp	(revision 28428)
+++ src/insets/InsetTabular.cpp	(working copy)
@@ -1744,8 +1744,14 @@
 		setBottomLine(i, false);
 		setLeftLine(i, false);
 		setRightLine(i, false);
-	} else
+		// FIXME: when a row is set as caption, then also insert a caption
+		// dispatch(FuncRequest(LFUN_CAPTION_INSERT));
+	} else {
 		unsetMultiColumn(i);
+		// FIXME: when unsetting a caption row, also all existing captions
+		// in this row must be dissolved, see (bug 5754)
+		// dispatch(FuncRequest(LFUN_INSET_DISSOLVE, "caption-insert"));
+	}
 	row_info[row].caption = what;
 	return i;
 }
@@ -1757,6 +1763,15 @@
 }
 
 
+bool Tabular::haveLTCaption() const
+{
+	for (row_type i = 0; i < row_info.size(); ++i)
+		if (row_info[i].caption)
+			return true;
+	return false;
+}
+
+
 // end longtable support functions
 
 void Tabular::setRowAscent(row_type row, int height)
@@ -3831,7 +3846,17 @@
 			status.setOnOff(convert<int>(argument) == tabular.getUsebox(cur.idx()));
 			break;
 
-		case Tabular::SET_LTFIRSTHEAD:
+		// when a header/footer/caption is set, no other row can be the same
+		// furthermore, every row can only be one thing:
+		//		either a footer or header or caption
+		case Tabular::SET_LTFIRSTHEAD:			
+			status.setEnabled(sel_row_start == sel_row_end
+				&& !tabular.getRowOfLTHead(sel_row_start, dummyltt)
+				&& !tabular.getRowOfLTFoot(sel_row_start, dummyltt)
+				&& !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
+				&& !tabular.ltCaption(sel_row_start)
+				&& (!tabular.haveLTFirstHead()
+				|| tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)));
 			status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
 			break;
 
@@ -3840,6 +3865,13 @@
 			break;
 
 		case Tabular::SET_LTHEAD:
+			status.setEnabled(sel_row_start == sel_row_end
+				&& !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
+				&& !tabular.getRowOfLTFoot(sel_row_start, dummyltt)
+				&& !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
+				&& !tabular.ltCaption(sel_row_start)
+				&& (!tabular.haveLTHead()
+				|| tabular.getRowOfLTHead(sel_row_start, dummyltt)));
 			status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
 			break;
 
@@ -3848,6 +3880,13 @@
 			break;
 
 		case Tabular::SET_LTFOOT:
+			status.setEnabled(sel_row_start == sel_row_end
+				&& !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
+				&& !tabular.getRowOfLTHead(sel_row_start, dummyltt)
+				&& !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
+				&& !tabular.ltCaption(sel_row_start)
+				&& (!tabular.haveLTFoot()
+				|| tabular.getRowOfLTFoot(sel_row_start, dummyltt)));
 			status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
 			break;
 
@@ -3856,6 +3895,13 @@
 			break;
 
 		case Tabular::SET_LTLASTFOOT:
+			status.setEnabled(sel_row_start == sel_row_end
+				&& !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
+				&& !tabular.getRowOfLTHead(sel_row_start, dummyltt)
+				&& !tabular.getRowOfLTFoot(sel_row_start, dummyltt)
+				&& !tabular.ltCaption(sel_row_start)
+				&& (!tabular.haveLTLastFoot()
+				|| tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)));
 			status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
 			break;
 
@@ -3868,7 +3914,15 @@
 			break;
 
 		case Tabular::TOGGLE_LTCAPTION:
-			status.setEnabled(sel_row_start == sel_row_end);
+			status.setEnabled(sel_row_start == sel_row_end
+				&& !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
+				&& !tabular.getRowOfLTHead(sel_row_start, dummyltt)
+				&& !tabular.getRowOfLTFoot(sel_row_start, dummyltt)
+				&& !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
+				// Only the first row can be the caption.
+				&& sel_row_start == 0
+				&& (!tabular.haveLTCaption()
+				|| tabular.ltCaption(sel_row_start)));
 			status.setOnOff(tabular.ltCaption(sel_row_start));
 			break;
 
Index: src/insets/InsetTabular.h
===================================================================
--- src/insets/InsetTabular.h	(revision 28428)
+++ src/insets/InsetTabular.h	(working copy)
@@ -420,6 +420,8 @@
 	///
 	bool haveLTLastFoot() const;
 	///
+	bool haveLTCaption() const;
+	///
 	// end longtable support
 	///
 	boost::shared_ptr<InsetTableCell> cellInset(idx_type cell) const;

Reply via email to