EHM DAL 0.2.3
Data abstraction layer for Eastside Hockey Manager
Loading...
Searching...
No Matches
ehm_dal::spreadsheet::Spreadsheet Class Reference

Public Types

enum class  DateFormat { DateMonthYear , MonthDateYear , YearMonthDate }
 The DateFormat enum represents the date format used when returning cell data. More...
 

Public Member Functions

 Spreadsheet (const QString &file_path=QString())
 
 Spreadsheet (const settings::FolderPath &path)
 
void add ()
 
void add (const QString &text)
 
void add (const QVariant &data)
 
void add (const QVariant &data, const qint32 row)
 
void add (const QVariant &data, const qint32 start_row, const qint32 row_count)
 
void add (ehm_dal::tables::AbstractTable *model, const Qt::ItemDataRole role=Qt::DisplayRole)
 Adds all rows and columns from model to the spreadsheet. This is generally used to export a ehm_dal::tables::AbstractTable using Qt::DisplayRole or Qt::EditRole.
 
void add (ehm_dal::tables::AbstractTable *model, const std::vector< qint32 > &column_index_list, const Qt::ItemDataRole role=Qt::DisplayRole)
 Adds all rows and the selected columns from model to the spreadsheet. This is generally used to export a ehm_dal::tables::AbstractTable using Qt::DisplayRole or Qt::EditRole.
 
void add (ehm_dal::tables::AbstractTable *model, const qint32 row, const Qt::ItemDataRole role=Qt::DisplayRole)
 Adds the selected row and all columns from model to the spreadsheet. This is generally used to export a ehm_dal::tables::AbstractTable using Qt::DisplayRole or Qt::EditRole.
 
void add (ehm_dal::tables::AbstractTable *model, const qint32 row, const std::vector< qint32 > &column_index_list, const Qt::ItemDataRole role=Qt::DisplayRole)
 Adds the selected row and selected columns from model to the spreadsheet. This is generally used to export a ehm_dal::tables::AbstractTable using Qt::DisplayRole or Qt::EditRole.
 
void add (QAbstractTableModel *model, const Qt::ItemDataRole role=Qt::DisplayRole)
 Adds all rows and columns from model to the spreadsheet. This is generally used to export a QAbstractTableModel using Qt::DisplayRole or Qt::EditRole.
 
void add (QAbstractTableModel *model, const std::vector< qint32 > &column_index_list, const Qt::ItemDataRole role=Qt::DisplayRole)
 Adds all rows and the selected columns from model to the spreadsheet. This is generally used to export a QAbstractTableModel using Qt::DisplayRole or Qt::EditRole.
 
void add (QAbstractTableModel *model, const qint32 row, const Qt::ItemDataRole role=Qt::DisplayRole)
 Adds the selected row and all columns from model to the spreadsheet. This is generally used to export a QAbstractTableModel using Qt::DisplayRole or Qt::EditRole.
 
void add (QAbstractTableModel *model, const qint32 row, const std::vector< qint32 > &column_index_list, const Qt::ItemDataRole role=Qt::DisplayRole)
 Adds the selected row and selected columns from model to the spreadsheet. This is generally used to export a QAbstractTableModel using Qt::DisplayRole or Qt::EditRole.
 
void add (const ehm_dal::data_types::Pointer &pointer, const Qt::ItemDataRole role=Qt::DisplayRole)
 Adds all columns of the selected Pointer to the spreadsheet.
 
void add (const ehm_dal::data_types::Pointer &pointer, const std::vector< qint32 > &column_index_list, const Qt::ItemDataRole role=Qt::DisplayRole)
 Adds the selected columns of the selected Pointer to the spreadsheet.
 
void add (const std::vector< ehm_dal::data_types::Pointer > &pointer_list, const Qt::ItemDataRole role=Qt::DisplayRole)
 Adds all columns of the selected Pointers to the spreadsheet.
 
void add (const std::vector< ehm_dal::data_types::Pointer > &pointer_list, const std::vector< qint32 > &column_index_list, const Qt::ItemDataRole role=Qt::DisplayRole)
 Adds the selected columns of the selected Pointers to the spreadsheet.
 
void addPrefix ()
 Adds a blank cell to the current prefix row.
 
void addPrefix (const QVariant &data)
 Adds data to the current prefix row.
 
void addHeader ()
 Adds a blank cell to the current header row.
 
void addHeader (const QString &text)
 Adds text to the current header row.
 
void addHeader (const QStringList &text_list)
 Adds the text_list to the current header row.
 
void addHeader (const QVariant &data)
 Adds data to the current header row.
 
void addHeader (QAbstractTableModel *model)
 Adds a header row of column names of all columns from the 'model'. This is typically used to add the names of all columns from a Table as a header row to the spreadsheet.
 
void addHeader (QAbstractTableModel *model, const std::vector< qint32 > &column_index_list)
 Adds a header row of column names of the selected columnd from the 'model'. This is typically used to add the names of the selected columns from a Table as a header row to the spreadsheet.
 
void addHeaderPrefix ()
 Adds a blank cell to the current prefix header row.
 
void addHeaderPrefix (const QVariant &data)
 Adds data to the current prefix header row.
 
void printDiagnosticData () const
 Prints various diagnostic data to the console.
 
QString file ()
 Returns the file path, file base name and file extension.
 
QString fileName ()
 Returns the file path and name of the output spreadsheet.
 
QString fileType () const
 Returns the file type of the output spreadsheet.
 
QString folderPath () const
 Returns the file path.
 
QString identifier ()
 Returns the identifier text string located at the top left cell (i.e. Cell A1).
 
void addFileNameSuffix (const QString &suffix)
 Adds suffix to the end of the file name.
 
bool setFile (const QString &path)
 Set the file path, name and extension from path.
 
bool open (const QString &file_path)
 Opens a file without showing a dialog window.
 
bool open (const QString &folder, const QString &file_name)
 Opens a file without showing a dialog window.
 
bool read ()
 Reads the current file.
 
bool save (const QString &folder, const QString &file_name)
 Saves the spreadsheet to the selected folder path and file name.
 
bool write ()
 Writes/saves the spreadsheet to the output file.
 
bool showOpenDialog (QString file_path=QString(), const bool read_data=true)
 Displays a dialog window allowing the user to select a spreadsheet to open.
 
bool showOpenDialog (settings::FolderPath &path, const bool read_data=true)
 Displays a dialog window allowing the user to select a spreadsheet to open.
 
bool showSaveDialog (const QString &file_name="output.csv", QString file_path=QString())
 Displays a dialog window allowing the user to save the spreadsheet.
 
bool showSaveDialog (settings::FolderPath &path)
 Displays a dialog window allowing the user to save the spreadsheet.
 
QVariant cell (const qint32 row, const qint32 col, const bool return_as_date=false) const
 Returns the data located at row and col.
 
std::span< const QVariant > cells (const qint32 row, const qint32 col, const qint32 col_count) const
 Returns the cell data as a QDate located at row and col.
 
bool columnContainsData (const qint32 column) const
 Returns whether a column contains any data.
 
qint32 columnCount (const qint32 row) const
 Returns the column count for the selected row.
 
std::span< const QVariant > row (const qint32 row) const
 Returns the data of the entirety of the selected row.
 
qint32 rowCount () const
 Returns the data row count.
 
QVariant prefix (const qint32 row) const
 
bool hasPrefixData () const
 
qint32 prefixCount () const
 
std::span< const QVariant > header (const qint32 row) const
 
QVariant headerCell (const qint32 row, const quint16 col) const
 
qint32 headerCount () const
 
QVariant prefixHeader (const qint32 row) const
 
bool hasPrefixHeaderData () const
 
qint32 prefixHeaderCount () const
 
void addNewHeaderRow ()
 Adds a new header row.
 
void addNewRow ()
 Adds a new data row.
 
void setHeaderCount (const qint32 header_row_count)
 Sets the number of header rows to header_row_count.
 
std::unique_ptr< SpreadsheetFilenewSpreadsheet (QFile &f)
 Creates a new spreadsheet from f and returns a pointer to the created ehm_dal::spreadsheet::SpreadsheetFile.
 

Static Public Member Functions

static DateFormat dateFormat ()
 Returns the current date format used when returning cell data.
 
static QString dateFormatString ()
 Returns the current date format used when returning cell data.
 
static void setDateFormat (const DateFormat date_format)
 Sets the data format to date_format when returning cell data. This can be modified before or after reading spreadsheet data.
 
static qint32 defaultFileExtension ()
 Returns the default file extension.
 
static QString fileExtensionListAsString (const bool merged_list=true)
 Returns a list of supported file extensions.
 
static QStringList fileExtensionListAsStringList ()
 Returns a list of supported file extensions.
 
static void setDefaultFileExtension (const qint32 i)
 Set the default file extension to i.
 
static QString exportPath ()
 Returns the default file path used for exporting data.
 
static QString importPath ()
 Returns the default file path used for importing data.
 

Member Enumeration Documentation

◆ DateFormat

The DateFormat enum represents the date format used when returning cell data.

Enumerator
DateMonthYear 

DD-MM-YYYY

MonthDateYear 

MM-DD-YYYY

YearMonthDate 

YYYY-MM-DD

Member Function Documentation

◆ add() [1/12]

void ehm_dal::spreadsheet::Spreadsheet::add ( const ehm_dal::data_types::Pointer pointer,
const Qt::ItemDataRole  role = Qt::DisplayRole 
)

Adds all columns of the selected Pointer to the spreadsheet.

Parameters
pointerSource pointer
roleSource data role

◆ add() [2/12]

void ehm_dal::spreadsheet::Spreadsheet::add ( const ehm_dal::data_types::Pointer pointer,
const std::vector< qint32 > &  column_index_list,
const Qt::ItemDataRole  role = Qt::DisplayRole 
)

Adds the selected columns of the selected Pointer to the spreadsheet.

Parameters
pointerSource pointer
column_index_listColumn indexes to be added
roleSource data role

◆ add() [3/12]

void ehm_dal::spreadsheet::Spreadsheet::add ( const std::vector< ehm_dal::data_types::Pointer > &  pointer_list,
const Qt::ItemDataRole  role = Qt::DisplayRole 
)

Adds all columns of the selected Pointers to the spreadsheet.

Parameters
pointer_listSource pointers
roleSource data role

◆ add() [4/12]

void ehm_dal::spreadsheet::Spreadsheet::add ( const std::vector< ehm_dal::data_types::Pointer > &  pointer_list,
const std::vector< qint32 > &  column_index_list,
const Qt::ItemDataRole  role = Qt::DisplayRole 
)

Adds the selected columns of the selected Pointers to the spreadsheet.

Parameters
pointer_listSource pointers
column_index_listColumn indexes to be added
roleSource data role

◆ add() [5/12]

void ehm_dal::spreadsheet::Spreadsheet::add ( ehm_dal::tables::AbstractTable model,
const qint32  row,
const Qt::ItemDataRole  role = Qt::DisplayRole 
)

Adds the selected row and all columns from model to the spreadsheet. This is generally used to export a ehm_dal::tables::AbstractTable using Qt::DisplayRole or Qt::EditRole.

Parameters
modelSource ehm_dal::tables::AbstractTable
rowSource row
roleSource data role

◆ add() [6/12]

void ehm_dal::spreadsheet::Spreadsheet::add ( ehm_dal::tables::AbstractTable model,
const qint32  row,
const std::vector< qint32 > &  column_index_list,
const Qt::ItemDataRole  role = Qt::DisplayRole 
)

Adds the selected row and selected columns from model to the spreadsheet. This is generally used to export a ehm_dal::tables::AbstractTable using Qt::DisplayRole or Qt::EditRole.

Parameters
modelSource ehm_dal::tables::AbstractTable
rowSource row
column_index_listColumn indexes to be added
roleSource data role

◆ add() [7/12]

void ehm_dal::spreadsheet::Spreadsheet::add ( ehm_dal::tables::AbstractTable model,
const Qt::ItemDataRole  role = Qt::DisplayRole 
)

Adds all rows and columns from model to the spreadsheet. This is generally used to export a ehm_dal::tables::AbstractTable using Qt::DisplayRole or Qt::EditRole.

Parameters
modelSource ehm_dal::tables::AbstractTable
roleSource data role

◆ add() [8/12]

void ehm_dal::spreadsheet::Spreadsheet::add ( ehm_dal::tables::AbstractTable model,
const std::vector< qint32 > &  column_index_list,
const Qt::ItemDataRole  role = Qt::DisplayRole 
)

Adds all rows and the selected columns from model to the spreadsheet. This is generally used to export a ehm_dal::tables::AbstractTable using Qt::DisplayRole or Qt::EditRole.

Parameters
modelSource ehm_dal::tables::AbstractTable
column_index_listColumn indexes to be added
roleSource data role

◆ add() [9/12]

void ehm_dal::spreadsheet::Spreadsheet::add ( QAbstractTableModel *  model,
const qint32  row,
const Qt::ItemDataRole  role = Qt::DisplayRole 
)

Adds the selected row and all columns from model to the spreadsheet. This is generally used to export a QAbstractTableModel using Qt::DisplayRole or Qt::EditRole.

Parameters
modelSource QAbstractTableModel
rowSource row
roleSource data role

◆ add() [10/12]

void ehm_dal::spreadsheet::Spreadsheet::add ( QAbstractTableModel *  model,
const qint32  row,
const std::vector< qint32 > &  column_index_list,
const Qt::ItemDataRole  role = Qt::DisplayRole 
)

Adds the selected row and selected columns from model to the spreadsheet. This is generally used to export a QAbstractTableModel using Qt::DisplayRole or Qt::EditRole.

Parameters
modelSource QAbstractTableModel
rowSource row
column_index_listColumn indexes to be added
roleSource data role

◆ add() [11/12]

void ehm_dal::spreadsheet::Spreadsheet::add ( QAbstractTableModel *  model,
const Qt::ItemDataRole  role = Qt::DisplayRole 
)

Adds all rows and columns from model to the spreadsheet. This is generally used to export a QAbstractTableModel using Qt::DisplayRole or Qt::EditRole.

Parameters
modelSource QAbstractTableModel
roleSource data role

◆ add() [12/12]

void ehm_dal::spreadsheet::Spreadsheet::add ( QAbstractTableModel *  model,
const std::vector< qint32 > &  column_index_list,
const Qt::ItemDataRole  role = Qt::DisplayRole 
)

Adds all rows and the selected columns from model to the spreadsheet. This is generally used to export a QAbstractTableModel using Qt::DisplayRole or Qt::EditRole.

Parameters
modelSource QAbstractTableModel
column_index_listColumn indexes to be added
roleSource data role

◆ addFileNameSuffix()

void ehm_dal::spreadsheet::Spreadsheet::addFileNameSuffix ( const QString &  suffix)

Adds suffix to the end of the file name.

Parameters
suffix

◆ addHeader() [1/5]

void ehm_dal::spreadsheet::Spreadsheet::addHeader ( const QString &  text)
inline

Adds text to the current header row.

Parameters
textText to be added

◆ addHeader() [2/5]

void ehm_dal::spreadsheet::Spreadsheet::addHeader ( const QStringList &  text_list)

Adds the text_list to the current header row.

Parameters
text_listQStringList to be added

◆ addHeader() [3/5]

void ehm_dal::spreadsheet::Spreadsheet::addHeader ( const QVariant &  data)

Adds data to the current header row.

Parameters
dataData to be added

◆ addHeader() [4/5]

void ehm_dal::spreadsheet::Spreadsheet::addHeader ( QAbstractTableModel *  model)

Adds a header row of column names of all columns from the 'model'. This is typically used to add the names of all columns from a Table as a header row to the spreadsheet.

Parameters
modelSource QAbstractTableModel or Table

◆ addHeader() [5/5]

void ehm_dal::spreadsheet::Spreadsheet::addHeader ( QAbstractTableModel *  model,
const std::vector< qint32 > &  column_index_list 
)

Adds a header row of column names of the selected columnd from the 'model'. This is typically used to add the names of the selected columns from a Table as a header row to the spreadsheet.

Parameters
modelSource QAbstractTableModel or Table
column_index_listColumn indexes to be added

◆ addHeaderPrefix()

void ehm_dal::spreadsheet::Spreadsheet::addHeaderPrefix ( const QVariant &  data)
inline

Adds data to the current prefix header row.

Parameters
dataData to be added

◆ addPrefix()

void ehm_dal::spreadsheet::Spreadsheet::addPrefix ( const QVariant &  data)
inline

Adds data to the current prefix row.

Parameters
dataData to be added

◆ cell()

QVariant ehm_dal::spreadsheet::Spreadsheet::cell ( const qint32  row,
const qint32  col,
const bool  return_as_date = false 
) const

Returns the data located at row and col.

Parameters
rowRow index
colColumn index

◆ cells()

std::span< const QVariant > ehm_dal::spreadsheet::Spreadsheet::cells ( const qint32  row,
const qint32  col,
const qint32  col_count 
) const

Returns the cell data as a QDate located at row and col.

Parameters
rowRow index
colColumn index
return_as_dateTrue = return the value as a date

◆ columnContainsData()

bool ehm_dal::spreadsheet::Spreadsheet::columnContainsData ( const qint32  column) const

Returns whether a column contains any data.

Parameters
columnColumn index

◆ columnCount()

qint32 ehm_dal::spreadsheet::Spreadsheet::columnCount ( const qint32  row) const

Returns the column count for the selected row.

Parameters
rowRow index
Returns
column count

◆ fileExtensionListAsString()

static QString ehm_dal::spreadsheet::Spreadsheet::fileExtensionListAsString ( const bool  merged_list = true)
static

Returns a list of supported file extensions.

Parameters
merged_listIf true, the list will include ";;" separators for use as individual file filters.

◆ fileType()

QString ehm_dal::spreadsheet::Spreadsheet::fileType ( ) const

Returns the file type of the output spreadsheet.

Returns
the file type

◆ newSpreadsheet()

std::unique_ptr< SpreadsheetFile > ehm_dal::spreadsheet::Spreadsheet::newSpreadsheet ( QFile &  f)

Creates a new spreadsheet from f and returns a pointer to the created ehm_dal::spreadsheet::SpreadsheetFile.

Parameters
fSource QFile
Returns
pointer to the created ehm_dal::spreadsheet::SpreadsheetFile

◆ open() [1/2]

bool ehm_dal::spreadsheet::Spreadsheet::open ( const QString &  file_path)

Opens a file without showing a dialog window.

Parameters
file_pathFolder path and file name to be opened
Returns
whether or not the file was successfully read

◆ open() [2/2]

bool ehm_dal::spreadsheet::Spreadsheet::open ( const QString &  folder,
const QString &  file_name 
)

Opens a file without showing a dialog window.

Parameters
folderFolder path
file_nameFile name
Returns
whether or not the file was successfully read

◆ read()

bool ehm_dal::spreadsheet::Spreadsheet::read ( )

Reads the current file.

Returns
whether or not the file was successfully read

◆ row()

std::span< const QVariant > ehm_dal::spreadsheet::Spreadsheet::row ( const qint32  row) const

Returns the data of the entirety of the selected row.

Parameters
rowRow index
Returns
Column data

◆ rowCount()

qint32 ehm_dal::spreadsheet::Spreadsheet::rowCount ( ) const
inline

Returns the data row count.

Returns
row count

◆ save()

bool ehm_dal::spreadsheet::Spreadsheet::save ( const QString &  folder,
const QString &  file_name 
)

Saves the spreadsheet to the selected folder path and file name.

Parameters
folderFolder path
file_nameFile name
Returns
whether or not the file was successfully saved

◆ setDateFormat()

static void ehm_dal::spreadsheet::Spreadsheet::setDateFormat ( const DateFormat  date_format)
static

Sets the data format to date_format when returning cell data. This can be modified before or after reading spreadsheet data.

Parameters
date_formatSelected DateFormat

◆ setDefaultFileExtension()

static void ehm_dal::spreadsheet::Spreadsheet::setDefaultFileExtension ( const qint32  i)
static

Set the default file extension to i.

Parameters
iSpreadsheet::ENUM_FILE_EXTENSIONS

◆ setFile()

bool ehm_dal::spreadsheet::Spreadsheet::setFile ( const QString &  path)

Set the file path, name and extension from path.

Parameters
path
Returns
Returns whether path contains any text.

◆ setHeaderCount()

void ehm_dal::spreadsheet::Spreadsheet::setHeaderCount ( const qint32  header_row_count)

Sets the number of header rows to header_row_count.

Parameters
header_row_count

◆ showOpenDialog() [1/2]

bool ehm_dal::spreadsheet::Spreadsheet::showOpenDialog ( QString  file_path = QString(),
const bool  read_data = true 
)

Displays a dialog window allowing the user to select a spreadsheet to open.

Parameters
file_pathInitial file path to show in the dialog
read_dataTrue = read the file. False = do not read the file.
Returns
whether the file was successfully read and/or selected. Returns false if the user has clicked cancel.

◆ showOpenDialog() [2/2]

bool ehm_dal::spreadsheet::Spreadsheet::showOpenDialog ( settings::FolderPath path,
const bool  read_data = true 
)

Displays a dialog window allowing the user to select a spreadsheet to open.

Parameters
pathInitial file path to show in the dialog
read_dataTrue = read the file. False = do not read the file.
Returns
whether the file was successfully read and/or selected. Returns false if the user has clicked cancel.

◆ showSaveDialog() [1/2]

bool ehm_dal::spreadsheet::Spreadsheet::showSaveDialog ( const QString &  file_name = "output.csv",
QString  file_path = QString() 
)

Displays a dialog window allowing the user to save the spreadsheet.

Parameters
file_nameInitial file name to show in the dialog
file_pathInitial file path to show in the dialog
Returns
whether the file was successfully saved. Returns false if the user has clicked cancel.

◆ showSaveDialog() [2/2]

bool ehm_dal::spreadsheet::Spreadsheet::showSaveDialog ( settings::FolderPath path)

Displays a dialog window allowing the user to save the spreadsheet.

Parameters
Initialfile path to show in the dialog
Returns
whether the file was successfully saved. Returns false if the user has clicked cancel.

◆ write()

bool ehm_dal::spreadsheet::Spreadsheet::write ( )

Writes/saves the spreadsheet to the output file.

Returns
whether the spreadsheet file was successfully saved