GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
GmRunProgressReport Class Reference

A class used to create formatted reports based on ProgressStats item attribute values. More...

#include <gmRunProgressReport.h>

Collaboration diagram for GmRunProgressReport:

Classes

struct  ColData
 

Public Types

enum  ColAlignment { GM_RUNPROG_REPORT_LEFT , GM_RUNPROG_REPORT_CENTER , GM_RUNPROG_REPORT_RIGHT , GM_RUNPROG_REPORT_AUTO }
 
using ValueFunctionT = std::function<void(GmRunProgressReport* report, int col, int itemId, void* itemUserData)>
 The column value function type.
 

Public Member Functions

 GmRunProgressReport (GmResultsData *resultsData, QString fileName, const GmLogCategory &logger)
 Report constructor.
 
 ~GmRunProgressReport ()
 Destructor. Closes the report file.
 
QString fileName () const
 Returns the output file name for this report.
 
void setTitle (QString title)
 Adjusts the report title.
 
void addItemDescription (QString description)
 Adds an item description to the report.
 
int addColumn (int itemId, int attrId, QString colTitle="", bool autoTimeUnit=false, int width=-1, ColAlignment align=GM_RUNPROG_REPORT_AUTO, int attrDim=-1)
 Adds to the report a new column whose values can be directly obtained from the given LOCAL attribute belonging to the item provided on the call to saveReportLine(). MUST be called before any call to saveReportLine()
 
int addColumn (QString colTitle, QString colUnit, QString fmt="", bool autoTimeUnit=false, int width=-1, ColAlignment align=GM_RUNPROG_REPORT_RIGHT)
 Adds to the report a new column whose values cshould be provided manually. MUST be called before the call to saveReportLine()
 
void setColumnValueFunction (int col, const ValueFunctionT &f)
 Sets the save function associated with this column.
 
void setColumnIgnoreOnZero (int col)
 Tells the report that a column with a zero value should be printed as an empty column.
 
void setColumnValue (int col, int val)
 Manually set the column value.
 
void setColumnValue (int col, double val)
 Manually set the column value.
 
void setColumnValue (int col, const double *val, int size)
 Manually set the column value. When setting values for a known attribute with a dim filter, v should point to the WHOLE vector.
 
void setColumnValue (int col, QString str)
 Manually set the column value.
 
void saveReportLine (int itemId, void *itemUserData)
 Saves a new line to the report, filled with the current values. Columns tied to an attribute will have their values updated automatically.
 
void saveTrailler (QString traillerStr)
 Adds the report closing trailler data.
 

Private Member Functions

 Q_DISABLE_COPY (GmRunProgressReport)
 
void saveReportHeader ()
 Starts the report saving. Should be called ONCE, AFTER all calls to addColumn().
 
void saveFormattedHeader (bool title)
 Saves the header, possibly including the report title for a formatted report.
 
void saveFormattedLine ()
 Saves a new report line with the data stored on the columns for a formatted report.
 
void saveFormattedTrailler (QString traillerStr)
 Saves the report closing trailler data for a formatted report.
 
void saveCsvHeader (bool title)
 Saves the header, possibly including the report title for a CSV report.
 
void saveCsvLine ()
 Saves a new report line with the data stored on the columns for a Csv report.
 
void saveCsvTrailler (QString traillerStr)
 Saves the report closing trailler data for a Csv report.
 
QStringList prepareTitle (QString title, QString unit) const
 Prepares a title value splitting the given value on new lines and adding the unit if available.
 
QStringList splitMultilineStr (QString title, bool trim) const
 Splits the given value on
characters, returning a string list. Each list entry is trimmed.
 
int findColumnWidth (const ColData &colData, int dataSize) const
 Calculates a best guess for a column width based on the column definition metadata and on the data size (number of dimensions)
 
QString alignStr (QString str, int width, ColAlignment align) const
 Returns the given string suitably aligned into a space of width characters.
 

Private Attributes

GmResultsData_resultsData
 The results data object storing data attributes.
 
GmRunProgressStats_ps
 The ProgressStats object that owns this report.
 
const GmLogCategory_logger
 The logger used to display error messages.
 
QString _fileName
 Output file name.
 
bool _csv
 Save to csv file? If not, a formatted text file will be saved.
 
FILE * _file
 The output file handle.
 
QString _title
 The report title.
 
QStringList _itemDescriptions
 Item descriptions, saved between the title and the column headers.
 
QVector< ColData_columns
 The set of report columns.
 
int _numHeaderRows
 The number of rows needed for the header. Set to -1 if there was an error creating the save file.
 

Detailed Description

A class used to create formatted reports based on ProgressStats item attribute values.

Member Enumeration Documentation

◆ ColAlignment

Enumerator
GM_RUNPROG_REPORT_LEFT 

Column data is aligned to the left (default for strings)

GM_RUNPROG_REPORT_CENTER 

Column data is aligned to the center.

GM_RUNPROG_REPORT_RIGHT 

Column data is aligned to the right (default for numbers)

GM_RUNPROG_REPORT_AUTO 

Column data is aligned according to the data type as defined by the associated result attribute.

Member Function Documentation

◆ addColumn() [1/2]

int GmRunProgressReport::addColumn ( int itemId,
int attrId,
QString colTitle = "",
bool autoTimeUnit = false,
int width = -1,
ColAlignment align = GM_RUNPROG_REPORT_AUTO,
int attrDim = -1 )

Adds to the report a new column whose values can be directly obtained from the given LOCAL attribute belonging to the item provided on the call to saveReportLine(). MUST be called before any call to saveReportLine()

Parameters
itemIdAn item id sharing the given local attribute. The item is used only for sanity checks and to calc automatic column width. It will not be stored. When a line is added to the report, the provided item will be used instead.
attrIdThe LOCAL attribute id.
colTitleIf different from "", replaces the attribute alias as the column title
autoTimeUnitIf enabled, time values will be formatted in a changing unit that better matches the value data.
widthThe column width, in characters. If -1, a suitable width will be calculated based on the column title, data format and size.
alignThe requested column data alignment. If equal to AUTO, the alignment will be inferred from the attribute data type (left for strings, right for numbers)
attrDimIf different from -1 and the attribute is not scalar, defines a dimension filter to apply to that column.
Returns
Returns the new column index (0 for the first call, 1 to the second and so on)

◆ addColumn() [2/2]

int GmRunProgressReport::addColumn ( QString colTitle,
QString colUnit,
QString fmt = "",
bool autoTimeUnit = false,
int width = -1,
ColAlignment align = GM_RUNPROG_REPORT_RIGHT )

Adds to the report a new column whose values cshould be provided manually. MUST be called before the call to saveReportLine()

Parameters
colTitleThe column title
colUnitThe column unit
fmtThe format string used to format numeric values. Follows the result data format.
autoTimeUnitIf enabled, time values will be formatted in a changing unit that better matches the value data. Will only have an effect if colUnit is one of ms, s, min, h or day.
widthThe column width, in characters. If -1, a suitable width will be calculated based on the column title, data format and size.
alignThe requested column data alignment. Should not be equal to AUTO (if it is a RIGHT default will be used)
Returns
Returns the new column index (0 for the first call, 1 to the second and so on)

The documentation for this class was generated from the following files: