[rkward-cvs] [rkward] /: Better behavior for <matrix> with (now somewhat mis-named option) fixed_width="true"; add min_rows, and min_columns attributes.

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Thu Jan 8 21:14:31 UTC 2015


Git commit 9fab0e9422077f8a743119f008bc5f5e70ee90af by Thomas Friedrichsmeier.
Committed on 08/01/2015 at 18:58.
Pushed by tfry into branch 'master'.

Better behavior for <matrix> with (now somewhat mis-named option) fixed_width="true"; add min_rows, and min_columns attributes.

M  +1    -0    ChangeLog
M  +10   -2    doc/rkwardplugins/index.docbook
M  +17   -12   rkward/plugin/rkmatrixinput.cpp
M  +1    -0    rkward/plugin/rkmatrixinput.h

http://commits.kde.org/rkward/9fab0e9422077f8a743119f008bc5f5e70ee90af

diff --git a/ChangeLog b/ChangeLog
index 6491636..5e5ecfb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+- <matrix> element gains options min_rows and min_columns, and the details of fixed_width="true" have been improved
 - Fixed: <valueslot>s were quirky with respect to showing as invalid
 - Fix a hang-on-exit issue
 - Add R function rk.set.plugin.status() to allow further customization of loaded plugins (hiding of individual menu entries)
diff --git a/doc/rkwardplugins/index.docbook b/doc/rkwardplugins/index.docbook
index 134146b..5d686c7 100644
--- a/doc/rkwardplugins/index.docbook
+++ b/doc/rkwardplugins/index.docbook
@@ -3068,14 +3068,22 @@ made checkable, thus acting like a simple checkbox at the same time.
 	<listitem><para>Number of columns in the matrix. Has no effect for allow_user_resize_columns="true". <note><para>This can also be controlled by setting the "columns" property".</para></note> (optional, defaults to 2).</para></listitem>
 	</varlistentry>
 	<varlistentry>
-	<term><parameter>fixed_width</parameter></term>
-	<listitem><para>Force the GUI element to stay at its initial width. Do not use in combination with matrices, where the number of columns may change in any way. Useful, esp. when creating a vector input element (rows="1"). With this option set to true, no vertical scroll bar will be shown, even in the matrix exceeds the available height (as this would affect the width). (optional, defaults to false).</para></listitem>
+	<term><parameter>min_rows</parameter></term>
+	<listitem><para>Minimum number of rows in the matrix. The matrix will refuse shrink below this size. (optional, defaults to 0; see also: <parameter>allow_missings</parameter>.).</para></listitem>
+	</varlistentry>
+	<varlistentry>
+	<term><parameter>min_columns</parameter></term>
+	<listitem><para>Minimum number of columns in the matrix. The matrix will refuse shrink below this size. (optional, defaults to 0; see also: <parameter>allow_missings</parameter>.).</para></listitem>
 	</varlistentry>
 	<varlistentry>
 	<term><parameter>fixed_height</parameter></term>
 	<listitem><para>Force the GUI element to stay at its initial height. Do not use in combination with matrices, where the number of rows may change in any way. Useful, esp. when creating a vector input element (columns="1"). With this option set to true, no horizontal scroll bar will be shown, even in the matrix exceeds the available width (as this would affect the height). (optional, defaults to false).</para></listitem>
 	</varlistentry>
 	<varlistentry>
+	<term><parameter>fixed_width</parameter></term>
+	<listitem><para>Slightly misnamed: Assume the column count will not change. The last (or typically only) column will be stretched to take up the available width. Do not use in combination with matrices, where the number of columns may change in any way. Useful, esp. when creating a vector input element (rows="1"). (optional, defaults to false).</para></listitem>
+	</varlistentry>
+	<varlistentry>
 	<term><parameter>horiz_headers</parameter></term>
 	<listitem><para>Strings to ues for the horiztonal header, separated by ";". The header will be hidden, if set to "". (optional, defaults to column number).</para></listitem>
 	</varlistentry>
diff --git a/rkward/plugin/rkmatrixinput.cpp b/rkward/plugin/rkmatrixinput.cpp
index 1d768dd..001b459 100644
--- a/rkward/plugin/rkmatrixinput.cpp
+++ b/rkward/plugin/rkmatrixinput.cpp
@@ -34,6 +34,8 @@
 RKMatrixInput::RKMatrixInput (const QDomElement& element, RKComponent* parent_component, QWidget* parent_widget) : RKComponent (parent_component, parent_widget) {
 	RK_TRACE (PLUGIN);
 
+	is_valid = true;
+
 	// get xml-helper
 	XMLHelper *xml = parent_component->xmlHelper ();
 
@@ -59,6 +61,9 @@ RKMatrixInput::RKMatrixInput (const QDomElement& element, RKComponent* parent_co
 		max = FLT_MAX;
 	}
 
+	min_rows = xml->getIntAttribute (element, "min_rows", 0, DL_INFO);
+	min_columns = xml->getIntAttribute (element, "min_columns", 0, DL_INFO);
+
 	// Note: string type matrix allows missings, implicitly (treating them as empty strings)
 	allow_missings = xml->getBoolAttribute (element, "allow_missings", false, DL_INFO);
 	if (mode == String) allow_missings = true;
@@ -67,8 +72,8 @@ RKMatrixInput::RKMatrixInput (const QDomElement& element, RKComponent* parent_co
 	trailing_rows = allow_user_resize_rows ? 1 : 0;
 	trailing_columns = allow_user_resize_columns ? 1 : 0;
 
-	row_count = new RKComponentPropertyInt (this, false, xml->getIntAttribute (element, "rows", 2, DL_INFO));
-	column_count = new RKComponentPropertyInt (this, false, xml->getIntAttribute (element, "columns", 2, DL_INFO));
+	row_count = new RKComponentPropertyInt (this, false, xml->getIntAttribute (element, "rows", qMax (2, min_rows), DL_INFO));
+	column_count = new RKComponentPropertyInt (this, false, xml->getIntAttribute (element, "columns", qMax (2, min_columns), DL_INFO));
 	tsv_data = new RKComponentPropertyBase (this, false);
 	row_count->setInternal (true);
 	addChild ("rows", row_count);
@@ -91,9 +96,7 @@ RKMatrixInput::RKMatrixInput (const QDomElement& element, RKComponent* parent_co
 	display->setModel (model);
 	display->setAlternatingRowColors (true);
 	if (xml->getBoolAttribute (element, "fixed_width", false, DL_INFO)) {
-		int max_col = column_count->intValue () - 1;
-		display->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
-		display->setFixedWidth (display->verticalHeader ()->width () + display->columnViewportPosition (max_col) + display->columnWidth (max_col) + display->verticalHeader ()->fontMetrics ().width ("0"));
+		display->horizontalHeader ()->setStretchLastSection (true);
 	}
 	if (xml->getBoolAttribute (element, "fixed_height", false, DL_INFO)) {
 		int max_row = row_count->intValue () - 1;
@@ -199,7 +202,7 @@ void RKMatrixInput::updateColumn (int column) {
 
 	// check for trailing empty rows:
 	int last_row = col.storage.size ();
-	while ((--last_row >= 0) && col.storage[last_row].isEmpty ()) {	// strip empty trailing strings
+	while ((--last_row >= min_rows) && col.storage[last_row].isEmpty ()) {	// strip empty trailing strings
 		col.storage.pop_back ();
 	}
 
@@ -244,9 +247,10 @@ void RKMatrixInput::updateAll () {
 		for (int i = columns.size () - 1; i >= 0; --i) {
 			max_row = qMax (max_row, columns[i].storage.size () - 1);
 		}
-		if (max_row != row_count->intValue () - 1) {
-			row_count->setIntValue (max_row + 1);
-		}
+	}
+	max_row = qMax (min_rows - 1, max_row);
+	if (max_row != row_count->intValue () - 1) {
+		row_count->setIntValue (max_row + 1);
 	}
 
 	int max_col = column_count->intValue () - 1;
@@ -256,9 +260,10 @@ void RKMatrixInput::updateAll () {
 				break;
 			}
 		}
-		if (max_col != column_count->intValue () - 1) {
-			column_count->setIntValue (max_col + 1);
-		}
+	}
+	max_col = qMax (min_columns - 1, max_col);
+	if (max_col != column_count->intValue () - 1) {
+		column_count->setIntValue (max_col + 1);
 	}
 
 	QStringList tsv;
diff --git a/rkward/plugin/rkmatrixinput.h b/rkward/plugin/rkmatrixinput.h
index 30b7d91..6606f2f 100644
--- a/rkward/plugin/rkmatrixinput.h
+++ b/rkward/plugin/rkmatrixinput.h
@@ -67,6 +67,7 @@ private:
 	bool allow_user_resize_columns;
 	int trailing_rows;
 	int trailing_columns;
+	int min_rows, min_columns;
 
 	bool isValueValid (const QString &value) const;
 	void updateAll ();





More information about the rkward-tracker mailing list