4#include "include/spreadsheet/private/spreadsheet_file.h"
8namespace ehm_dal::settings {
16class QAbstractTableModel;
22namespace ehm_dal::spreadsheet {
34 inline void add() { add(QVariant()); }
35 inline void add(
const QString &text) { add(QVariant(text)); }
36 void add(
const QVariant &data);
37 void add(
const QVariant &data,
const qint32
row);
38 void add(
const QVariant &data,
const qint32 start_row,
const qint32 row_count);
56 const std::vector<qint32> &column_index_list,
57 const Qt::ItemDataRole role = Qt::DisplayRole);
67 const Qt::ItemDataRole role = Qt::DisplayRole);
78 const std::vector<qint32> &column_index_list,
79 const Qt::ItemDataRole role = Qt::DisplayRole);
88 void add(QAbstractTableModel *model,
const Qt::ItemDataRole role = Qt::DisplayRole);
96 void add(QAbstractTableModel *model,
97 const std::vector<qint32> &column_index_list,
98 const Qt::ItemDataRole role = Qt::DisplayRole);
106 void add(QAbstractTableModel *model,
108 const Qt::ItemDataRole role = Qt::DisplayRole);
117 void add(QAbstractTableModel *model,
119 const std::vector<qint32> &column_index_list,
120 const Qt::ItemDataRole role = Qt::DisplayRole);
136 const std::vector<qint32> &column_index_list,
137 const Qt::ItemDataRole role = Qt::DisplayRole);
143 void add(
const std::vector<ehm_dal::data_types::Pointer> &pointer_list,
144 const Qt::ItemDataRole role = Qt::DisplayRole);
151 void add(
const std::vector<ehm_dal::data_types::Pointer> &pointer_list,
152 const std::vector<qint32> &column_index_list,
153 const Qt::ItemDataRole role = Qt::DisplayRole);
164 inline void addPrefix(
const QVariant &data) { prefix_cell_data_.push_back(data); }
200 void addHeader(QAbstractTableModel *model,
const std::vector<qint32> &column_index_list);
211 inline void addHeaderPrefix(
const QVariant &data) { prefix_header_data_.push_back(data); }
264 inline QString
identifier() {
return headerCell(0,0).toString().replace(
" ",
"_").toLower(); }
305 bool open(
const QString &file_path);
312 bool open(
const QString &folder,
const QString &file_name);
324 bool save(
const QString &folder,
const QString &file_name);
352 bool showSaveDialog(
const QString &file_name =
"output.csv", QString file_path = QString());
366 QVariant
cell(
const qint32
row,
const qint32 col,
const bool return_as_date =
false)
const;
375 const qint32 col_count)
const;
392 std::span<const QVariant>
row(
const qint32
row)
const;
397 inline qint32
rowCount()
const {
return static_cast<qint32
>(cell_data_.size()); }
400 QVariant prefix(
const qint32
row)
const;
401 inline bool hasPrefixData()
const {
return prefixCount() > 0; }
402 inline qint32 prefixCount()
const {
return static_cast<qint32
>(prefix_cell_data_.size()); }
405 std::span<const QVariant> header(
const qint32
row)
const;
406 QVariant headerCell(
const qint32
row,
const quint16 col)
const;
407 inline qint32 headerCount()
const
409 return std::max(
static_cast<qint32
>(header_data_.size()), header_count_);
413 QVariant prefixHeader(
const qint32
row)
const;
414 inline bool hasPrefixHeaderData()
const {
return prefixHeaderCount() > 0; }
415 inline qint32 prefixHeaderCount()
const
417 return static_cast<qint32
>(prefix_header_data_.size());
457 std::vector<std::vector<QVariant>> cell_data_;
458 std::vector<std::vector<QVariant>> header_data_;
459 std::vector<QVariant> prefix_cell_data_;
460 std::vector<QVariant> prefix_header_data_;
463 void addFromTableModel(QAbstractTableModel *model,
464 const std::vector<qint32> &column_index_list,
465 const Qt::ItemDataRole role = Qt::DisplayRole);
466 void addFromTableModel(QAbstractTableModel *model,
468 const std::vector<qint32> &column_index_list,
469 const Qt::ItemDataRole role = Qt::DisplayRole);
470 void addFromTreeModel(QAbstractTableModel *model,
471 const std::vector<qint32> &column_index_list,
472 const Qt::ItemDataRole role = Qt::DisplayRole);
473 void addFromTreeModel(QAbstractTableModel *model,
474 const qint32 parent_row,
475 const std::vector<qint32> &column_index_list,
476 const Qt::ItemDataRole role = Qt::DisplayRole);
479 std::vector<qint32> columnList(
const qint32 column_count)
const;
482 QDate toDate(
const QVariant &value)
const;
485 static QString date_format_;
488 quint8 file_extension_;
493 static QHash<QString, quint8> fileExtensions();
494 static QString filterText(
const qint32 type);
497 enum ENUM_FILE_EXTENSIONS { CSV, XLSX, FILE_EXTENSION_COUNT };
500 qint32 header_count_{2};
503 bool hide_progress_{
false};
506 std::vector<QVariant> *currentHeaderRow();
507 std::vector<QVariant> *currentRow();
The Pointer class represents a pointer to a table item.
Definition: pointer.h:21
Definition: folder_path.h:11
Definition: spreadsheet.h:26
qint32 rowCount() const
Returns the data row count.
Definition: spreadsheet.h:397
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.
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 addNewHeaderRow()
Adds a new header row.
void addHeader(const QStringList &text_list)
Adds the text_list to the current header row.
QString identifier()
Returns the identifier text string located at the top left cell (i.e. Cell A1).
Definition: spreadsheet.h:264
QString file()
Returns the file path, file base name and file extension.
QString fileName()
Returns the file path and name of the output spreadsheet.
Definition: spreadsheet.h:251
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 e...
bool showSaveDialog(const QString &file_name="output.csv", QString file_path=QString())
Displays a dialog window allowing the user to save the spreadsheet.
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 QAbstract...
static void setDefaultFileExtension(const qint32 i)
Set the default file extension to i.
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 re...
void addHeaderPrefix(const QVariant &data)
Adds data to the current prefix header row.
Definition: spreadsheet.h:211
qint32 columnCount(const qint32 row) const
Returns the column count for the selected row.
static QString dateFormatString()
Returns the current date format used when returning cell data.
Definition: spreadsheet.h:230
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.
static QStringList fileExtensionListAsStringList()
Returns a list of supported file extensions.
void addPrefix(const QVariant &data)
Adds data to the current prefix row.
Definition: spreadsheet.h:164
bool showSaveDialog(settings::FolderPath &path)
Displays a dialog window allowing the user to save the spreadsheet.
void addPrefix()
Adds a blank cell to the current prefix row.
Definition: spreadsheet.h:159
bool save(const QString &folder, const QString &file_name)
Saves the spreadsheet to the selected folder path and file name.
bool read()
Reads the current file.
bool columnContainsData(const qint32 column) const
Returns whether a column contains any data.
static QString fileExtensionListAsString(const bool merged_list=true)
Returns a list of supported file extensions.
bool showOpenDialog(QString file_path=QString(), const bool read_data=true)
Displays a dialog window allowing the user to select a spreadsheet to open.
static QString importPath()
Returns the default file path used for importing data.
void addHeader()
Adds a blank cell to the current header row.
Definition: spreadsheet.h:170
DateFormat
The DateFormat enum represents the date format used when returning cell data.
Definition: spreadsheet.h:217
bool setFile(const QString &path)
Set the file path, name and extension from path.
QString folderPath() const
Returns the file path.
Definition: spreadsheet.h:260
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 e...
bool write()
Writes/saves the spreadsheet to the output file.
void setHeaderCount(const qint32 header_row_count)
Sets the number of header rows to header_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::...
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 expor...
QVariant cell(const qint32 row, const qint32 col, const bool return_as_date=false) const
Returns the data located at row and col.
void addHeader(const QString &text)
Adds text to the current header row.
Definition: spreadsheet.h:175
static qint32 defaultFileExtension()
Returns the default file extension.
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.
std::span< const QVariant > row(const qint32 row) const
Returns the data of the entirety of the selected row.
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...
void addHeader(QAbstractTableModel *model)
Adds a header row of column names of all columns from the 'model'. This is typically used to add the ...
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...
std::unique_ptr< SpreadsheetFile > newSpreadsheet(QFile &f)
Creates a new spreadsheet from f and returns a pointer to the created ehm_dal::spreadsheet::Spreadshe...
void addNewRow()
Adds a new data row.
void addHeaderPrefix()
Adds a blank cell to the current prefix header row.
Definition: spreadsheet.h:206
void printDiagnosticData() const
Prints various diagnostic data to the console.
bool open(const QString &folder, const QString &file_name)
Opens a file without showing a dialog window.
static DateFormat dateFormat()
Returns the current date format used when returning cell data.
static QString exportPath()
Returns the default file path used for exporting data.
void addFileNameSuffix(const QString &suffix)
Adds suffix to the end of the file name.
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...
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(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 expor...
bool showOpenDialog(settings::FolderPath &path, const bool read_data=true)
Displays a dialog window allowing the user to select a spreadsheet to open.
QString fileType() const
Returns the file type of the output spreadsheet.
bool open(const QString &file_path)
Opens a file without showing a dialog window.
void addHeader(const QVariant &data)
Adds data to the current header row.
The Table class represents a database table and provides access to rows of data.
Definition: abstract_table.h:29
namespace ehm_dal::data_types
Definition: attribute.h:6
namespace ehm_dal::tables
Definition: column.h:4