Commit e7e876df authored by Thomas Friedrichsmeier's avatar Thomas Friedrichsmeier
Browse files

Better behavior for <matrix> with (now somewhat mis-named option)...

Better behavior for <matrix> with (now somewhat mis-named option) fixed_width="true"; add min_rows, and min_columns attributes.
parent d8ed35d5
- <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)
......
......@@ -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>
......
......@@ -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;
......
......@@ -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 ();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment