Results.Output.Printers.Table supports separator row line (TODO: separator column line).

This commit is contained in:
Milan Hanajik 2018-04-09 17:43:08 +02:00
parent 673e04a1b6
commit efa5084d8b

View File

@ -72,10 +72,17 @@ namespace Results.Output.Printers
{
for (int rowIx = 0; rowIx < RowsCount; rowIx++)
{
bool isHeader = (colIx < Style.LeftHeadersCount) || (rowIx < Style.TopHeadersCount);
SizeF size = PrintersCommon.Measure(e, Rows[rowIx][colIx], isHeader ? Style.HeaderFont : Style.Font);
if (size.Width > columnWidth[colIx]) columnWidth[colIx] = size.Width;
if (size.Height > rowHeight[rowIx]) rowHeight[rowIx] = size.Height;
if (Rows[rowIx] == null)
{
/// Separator row -> do nothing
}
else
{
bool isHeader = (colIx < Style.LeftHeadersCount) || (rowIx < Style.TopHeadersCount);
SizeF size = PrintersCommon.Measure(e, Rows[rowIx][colIx], isHeader ? Style.HeaderFont : Style.Font);
if (size.Width > columnWidth[colIx]) columnWidth[colIx] = size.Width;
if (size.Height > rowHeight[rowIx]) rowHeight[rowIx] = size.Height;
}
}
bool hasLineToTheLeft = (Style.VertLines == TableLines.All)
@ -86,11 +93,19 @@ namespace Results.Output.Printers
}
for (int rowIx = 0; rowIx < RowsCount; rowIx++)
{
bool hasLineAbove = (Style.HorizLines == TableLines.All)
|| ((Style.HorizLines == TableLines.FirstAndLast) && (rowIx == 0))
|| ((Style.HorizLines == TableLines.FirstSecondAndLast) && (rowIx <= 1));
if (Rows[rowIx] == null)
{
/// Separator row -> do nothing
}
else
{
bool hasLineAbove = (Style.HorizLines == TableLines.All)
|| ((Style.HorizLines == TableLines.FirstAndLast) && (rowIx == 0))
|| ((Style.HorizLines == TableLines.FirstSecondAndLast) && (rowIx <= 1))
|| ((rowIx >= 1) && (Rows[rowIx - 1] == null));
retVal.Height += rowHeight[rowIx] + (hasLineAbove ? (Style.LineWidth + Style.MarginY) : 0) + Style.MarginY;
retVal.Height += rowHeight[rowIx] + (hasLineAbove ? (Style.LineWidth + Style.MarginY) : 0) + Style.MarginY;
}
}
if (Style.VertLines == TableLines.None) retVal.Width -= Style.MarginX;
@ -123,10 +138,19 @@ namespace Results.Output.Printers
{
for (int rowIx = 0; rowIx < RowsCount; rowIx++)
{
bool isHeader = (colIx < Style.LeftHeadersCount) || (rowIx < Style.TopHeadersCount);
SizeF size = PrintersCommon.Measure(e, Rows[rowIx][colIx], isHeader ? Style.HeaderFont : Style.Font);
if (size.Width > columnWidth[colIx]) columnWidth[colIx] = size.Width;
if (size.Height > rowHeight[rowIx]) rowHeight[rowIx] = size.Height;
if (Rows[rowIx] != null)
{
/// In not a separator line
bool isHeader = (colIx < Style.LeftHeadersCount) || (rowIx < Style.TopHeadersCount);
SizeF size = PrintersCommon.Measure(e, Rows[rowIx][colIx], isHeader ? Style.HeaderFont : Style.Font);
if (size.Width > columnWidth[colIx]) columnWidth[colIx] = size.Width;
if (size.Height > rowHeight[rowIx]) rowHeight[rowIx] = size.Height;
}
else
{
/// Separator line -> do nothing
rowHeight[rowIx] = 0;
}
}
bool hasLineToTheLeft = (Style.VertLines == TableLines.All)
@ -138,12 +162,23 @@ namespace Results.Output.Printers
}
for (int rowIx = 0; rowIx < RowsCount; rowIx++)
{
bool hasLineAbove = (Style.HorizLines == TableLines.All)
|| ((Style.HorizLines == TableLines.FirstAndLast) && (rowIx == 0))
|| ((Style.HorizLines == TableLines.FirstSecondAndLast) && (rowIx <= 1));
if (Rows[rowIx] != null)
{
/// In not a separator line
bool hasLineAbove = (Style.HorizLines == TableLines.All)
|| ((Style.HorizLines == TableLines.FirstAndLast) && (rowIx == 0))
|| ((Style.HorizLines == TableLines.FirstSecondAndLast) && (rowIx <= 1))
|| ((rowIx >= 1) && (Rows[rowIx - 1] == null));
rowPos[rowIx] = horizLinePos[rowIx] + (hasLineAbove ? Style.MarginY : 0);
horizLinePos[rowIx + 1] = rowPos[rowIx] + rowHeight[rowIx] + Style.LineWidth + Style.MarginY;
rowPos[rowIx] = horizLinePos[rowIx] + (hasLineAbove ? Style.MarginY : 0);
horizLinePos[rowIx + 1] = rowPos[rowIx] + rowHeight[rowIx] + Style.LineWidth + Style.MarginY;
}
else if (rowIx > 0)
{
/// Separator line
rowPos[rowIx] = rowPos[rowIx - 1];
horizLinePos[rowIx + 1] = horizLinePos[rowIx];
}
}
/// Horizontal lines
@ -153,7 +188,10 @@ namespace Results.Output.Printers
{
for (int rowIx = 0; rowIx <= RowsCount; rowIx++)
{
if (Style.HorizLines == TableLines.All || rowIx == 0 || rowIx == RowsCount || (Style.HorizLines == TableLines.FirstSecondAndLast && rowIx == 1))
if (Style.HorizLines == TableLines.All || rowIx == 0
|| rowIx == RowsCount
|| (Style.HorizLines == TableLines.FirstSecondAndLast && rowIx == 1)
|| ((rowIx >= 1) && (Rows[rowIx - 1] == null)))
{
e.Graphics.DrawLine(new Pen(Color.Black, Style.LineWidth), new PointF(tableLeftX, horizLinePos[rowIx] + Style.LineWidth / 2), new PointF(tableRightX, horizLinePos[rowIx] + Style.LineWidth / 2));
}
@ -180,19 +218,22 @@ namespace Results.Output.Printers
for (int rowIndex = 0; rowIndex < RowsCount; rowIndex++)
{
string[] oneTableRow = Rows[rowIndex];
Alignment[] horizAlignment = HorizAlignments[(RowsCount > rowIndex) ? rowIndex : 0];
VertAlignment[] vertAlignment = VertAlignments[(RowsCount > rowIndex) ? rowIndex : 0];
for (int colIndex = 0; colIndex < tblColumnsCount; colIndex++)
if (oneTableRow != null)
{
bool isHeader = (colIndex < Style.LeftHeadersCount) || (rowIndex < Style.TopHeadersCount);
PrintersCommon.PrintAt(e, oneTableRow[colIndex],
isHeader ? Style.HeaderFont : Style.Font,
columnPos[colIndex],
rowPos[rowIndex],
columnWidth[colIndex],
rowHeight[rowIndex],
horizAlignment[colIndex],
vertAlignment[colIndex]);
Alignment[] horizAlignment = HorizAlignments[(RowsCount > rowIndex) ? rowIndex : 0];
VertAlignment[] vertAlignment = VertAlignments[(RowsCount > rowIndex) ? rowIndex : 0];
for (int colIndex = 0; colIndex < tblColumnsCount; colIndex++)
{
bool isHeader = (colIndex < Style.LeftHeadersCount) || (rowIndex < Style.TopHeadersCount);
PrintersCommon.PrintAt(e, oneTableRow[colIndex],
isHeader ? Style.HeaderFont : Style.Font,
columnPos[colIndex],
rowPos[rowIndex],
columnWidth[colIndex],
rowHeight[rowIndex],
horizAlignment[colIndex],
vertAlignment[colIndex]);
}
}
}
@ -327,36 +368,42 @@ namespace Results.Output.Printers
WMeterRsltItemSpec.TableRowNr = 1;
for (int i = 0; i < items.Count; i++)
{
string[] oneTableRow = new string[columnsCount];
Alignment[] horizAlignment = new Alignment[columnsCount];
VertAlignment[] vertAlignment = new VertAlignment[columnsCount];
oneTableRow[0] = items[i].Caption;
horizAlignment[0] = Alignment.Center;
vertAlignment[0] = VertAlignment.Middle;
oneTableRow[1] = (i == 0) ? "Jednostka" : items[i].Units.ToDescription();
horizAlignment[1] = Alignment.Center;
vertAlignment[1] = VertAlignment.Middle;
WMeterRsltItemSpec.TableColumnNr = 1;
foreach (var mtr in wm.MeterTestRslts)
if (items[i].Uid == (int)ItemID.Separator)
{
if (mtr != null && mtr.IsPilotRslt() && mtr.Publish() == Config.Entities.Publish.Always)
{
int colIx = WMeterRsltItemSpec.TableColumnNr + 1;
/// Strip color information
oneTableRow[colIx] = items[i].Print(wm, mtr.Name()).Split(new char[] { '|' })[0];
horizAlignment[colIx] = items[i].Alignment;
vertAlignment[colIx] = VertAlignment.Middle;
WMeterRsltItemSpec.TableColumnNr++;
}
table.AddRow(null, null, null); /// 'separator' row
}
else
{
string[] oneTableRow = new string[columnsCount];
Alignment[] horizAlignment = new Alignment[columnsCount];
VertAlignment[] vertAlignment = new VertAlignment[columnsCount];
table.AddRow(oneTableRow, horizAlignment, vertAlignment);
oneTableRow[0] = items[i].Caption;
horizAlignment[0] = Alignment.Center;
vertAlignment[0] = VertAlignment.Middle;
oneTableRow[1] = (i == 0) ? "Jednostka" : items[i].Units.ToDescription();
horizAlignment[1] = Alignment.Center;
vertAlignment[1] = VertAlignment.Middle;
WMeterRsltItemSpec.TableColumnNr = 1;
foreach (var mtr in wm.MeterTestRslts)
{
if (mtr != null && mtr.IsPilotRslt() && mtr.Publish() == Config.Entities.Publish.Always)
{
int colIx = WMeterRsltItemSpec.TableColumnNr + 1;
/// Strip color information
oneTableRow[colIx] = items[i].Print(wm, mtr.Name()).Split(new char[] { '|' })[0];
horizAlignment[colIx] = items[i].Alignment;
vertAlignment[colIx] = VertAlignment.Middle;
WMeterRsltItemSpec.TableColumnNr++;
}
}
table.AddRow(oneTableRow, horizAlignment, vertAlignment);
}
WMeterRsltItemSpec.TableRowNr++;
}