Skip to content

Commit beae48d

Browse files
author
Rik
committed
Redo uitable RowName and ColumnName properties for Matlab Compatibility.
* Table.cc (updateColumnname, updateRowname): Check for empty value in cell array of names and make corresponding label the empty string "". When there are too few names for the number of rows/columns, make the remaining rows/cols unlabeled ("").
1 parent 3a5b731 commit beae48d

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

libgui/graphics/Table.cc

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,43 +1013,53 @@ Table::updateColumnname ()
10131013
{
10141014
octave_idx_type n = columnname.numel ();
10151015
Cell cell_value = columnname.cell_value ();
1016+
octave_idx_type i = 0;
10161017

1017-
for (octave_idx_type i = 0; i < n; i++)
1018+
for (; i < n; i++)
10181019
{
1019-
octave_value v = cell_value (i);
1020+
octave_value v = cell_value(i);
10201021
if (v.is_string ())
10211022
l << Utils::fromStdString (v.string_value (true));
10221023
else if (v.is_matrix_type ())
10231024
{
10241025
Matrix data = v.matrix_value ();
10251026

1027+
if (data.isempty ())
1028+
l << "";
10261029
/* Now Matlab does something very strange here:
10271030
* If data is a row or column matrix,
10281031
* then each datapoint is added.
1029-
* Otherwise, nothing is set.
1030-
*/
1031-
if (data.rows () > 1 && data.cols () > 1)
1032+
* Otherwise, nothing is set. */
1033+
else if (data.rows () > 1 && data.cols () > 1)
10321034
l << "";
10331035
else
10341036
for (octave_idx_type j = 0; j < data.numel (); j++)
10351037
l << QString::number (data(j));
10361038
}
10371039
else if (v.isnumeric ())
10381040
l << QString::number (v.double_value ());
1041+
// FIXME: Should this just be an error? struct or cell at this point.
10391042
else
10401043
l << QString::number (v.double_value ());
10411044
}
1045+
// Any remaining columns are unlabeled
1046+
for (; i < m_tableWidget->columnCount (); i++)
1047+
l << "";
10421048
}
1043-
else if (columnname.is_matrix_type ())
1049+
else if (columnname.is_matrix_type () || columnname.is_scalar_type ())
10441050
{
10451051
octave_idx_type n = columnname.numel ();
10461052
Matrix matrix_value = columnname.matrix_value ();
1053+
octave_idx_type i = 0;
10471054

1048-
for (octave_idx_type i = 0; i < n; i++)
1055+
for (; i < n; i++)
10491056
l << QString::number (matrix_value(i));
1057+
for (; i < m_tableWidget->columnCount (); i++)
1058+
l << "";
10501059
}
10511060
else
10521061
{
1062+
// FIXME: Would it be better to error here when unknown value found?
10531063
for (int i = 0; i < m_tableWidget->columnCount (); i++)
10541064
l << "";
10551065
visible = false;
@@ -1421,43 +1431,53 @@ Table::updateRowname ()
14211431
{
14221432
octave_idx_type n = rowname.numel ();
14231433
Cell cell_value = rowname.cell_value ();
1434+
octave_idx_type i = 0;
14241435

1425-
for (octave_idx_type i = 0; i < n; i++)
1436+
for (; i < n; i++)
14261437
{
1427-
octave_value v = cell_value (i);
1438+
octave_value v = cell_value(i);
14281439
if (v.is_string ())
14291440
l << Utils::fromStdString (v.string_value (true));
14301441
else if (v.is_matrix_type ())
14311442
{
14321443
Matrix data = v.matrix_value ();
14331444

1445+
if (data.isempty ())
1446+
l << "";
14341447
/* Now Matlab does something very strange here:
14351448
* If data is a row or column matrix,
14361449
* then each datapoint is added.
1437-
* Otherwise, nothing is set.
1438-
*/
1439-
if (data.rows () > 1 && data.cols () > 1)
1450+
* Otherwise, nothing is set. */
1451+
else if (data.rows () > 1 && data.cols () > 1)
14401452
l << "";
14411453
else
14421454
for (octave_idx_type j = 0; j < data.numel (); j++)
14431455
l << QString::number (data(j));
14441456
}
14451457
else if (v.isnumeric ())
14461458
l << QString::number (v.double_value (true));
1459+
// FIXME: Should this just be an error? struct or cell at this point.
14471460
else
14481461
l << QString::number (v.double_value (true));
14491462
}
1463+
// Any remaining rows are unlabeled
1464+
for (; i < m_tableWidget->rowCount (); i++)
1465+
l << "";
14501466
}
1451-
else if (rowname.is_matrix_type ())
1467+
else if (rowname.is_matrix_type () || rowname.is_scalar_type ())
14521468
{
14531469
octave_idx_type n = rowname.numel ();
14541470
Matrix matrix_value = rowname.matrix_value ();
1471+
octave_idx_type i = 0;
14551472

1456-
for (octave_idx_type i = 0; i < n; i++)
1473+
for (; i < n; i++)
14571474
l << QString::number (matrix_value(i));
1475+
for (; i < m_tableWidget->rowCount (); i++)
1476+
l << "";
14581477
}
14591478
else
14601479
{
1480+
// FIXME: Would it be better to error here when unknown value found?
14611481
for (int i = 0; i < m_tableWidget->columnCount (); i++)
14621482
l << "";
14631483
visible = false;

0 commit comments

Comments
 (0)