Code Documentation 3.5
Social Network Visualizer
Loading...
Searching...
No Matches
TableExport Namespace Reference

Free functions that serialise any QAbstractItemModel to CSV or JSON. More...

Functions

static QString csvQuote (const QString &value)
 
bool toCSV (QAbstractItemModel *model, const QString &filePath)
 Writes model to an RFC 4180 CSV file at filePath.
 
bool toJSON (QAbstractItemModel *model, const QString &filePath)
 Writes model to a JSON file at filePath.
 

Detailed Description

Free functions that serialise any QAbstractItemModel to CSV or JSON.

Both functions operate on whatever rows and columns the model exposes — pass a QSortFilterProxyModel to export only the currently visible rows, or the raw source model to export everything.

Constraint: QtCore only — no widgets, no UI signals.

Function Documentation

◆ csvQuote()

static QString TableExport::csvQuote ( const QString &  value)
static

◆ toCSV()

bool TableExport::toCSV ( QAbstractItemModel *  model,
const QString &  filePath 
)

Writes model to an RFC 4180 CSV file at filePath.

The first row is the column headers from headerData(). Each subsequent row is one model row. Fields containing commas, double-quotes, or newlines are enclosed in double-quotes; embedded double-quotes are escaped as "".

Returns
true on success, false if the file could not be opened/written.

◆ toJSON()

bool TableExport::toJSON ( QAbstractItemModel *  model,
const QString &  filePath 
)

Writes model to a JSON file at filePath.

Produces a top-level JSON array of objects. Each object has one key per column, taken from headerData(), with the display-role cell value as the string value.

Returns
true on success, false if the file could not be opened/written.