Skip to main content

CsvDatasetPreviewModel

CsvDatasetPreviewModel

Lazy-loading table model for CSV file preview. More…

#include <CsvDatasetPreviewModel.hpp>

Inherits from QAbstractTableModel

Public Signals

Name
void loadError(QString const & message)
Emitted when file loading fails.
void fileLoaded(qint64 num_rows, int num_cols)
Emitted when file is successfully loaded.

Public Functions

Name
CsvDatasetPreviewModel(QObject * parent =[nullptr])
~CsvDatasetPreviewModel() override
bool loadFile(QString const & file_path, CsvParseConfig const & config)
Load a CSV file for preview with the given parse configuration.
bool reloadWithConfig(CsvParseConfig const & config)
Reload the current file with a new parse configuration.
void clear()
Clear the current file.
bool hasData() const
Check if a file is currently loaded.
CsvFileInfo const & fileInfo() const
Get the computed file information.
CsvParseConfig const & parseConfig() const
Get the current parse configuration.
int chunkSize() const
Get the chunk size used for lazy loading.
void setChunkSize(int size)
Set the chunk size for lazy loading.
int rowCount(QModelIndex const & parent =QModelIndex()) const override
int columnCount(QModelIndex const & parent =QModelIndex()) const override
QVariant data(QModelIndex const & index, int role =Qt::DisplayRole) const override
QVariant headerData(int section, Qt::Orientation orientation, int role =Qt::DisplayRole) const override

Detailed Description

class CsvDatasetPreviewModel;

Lazy-loading table model for CSV file preview.

This model presents CSV data in a table format:

  • Rows correspond to data lines (after skipping header lines)
  • Columns are determined by splitting the first data line on the delimiter
  • Column headers come from the first header line (if configured) or are auto-generated

Data is loaded in chunks (default 100 rows) and cached using QCache to provide smooth scrolling while minimizing memory usage.

The model supports line-based random access by pre-scanning the file to build a line offset index on load.

Public Signals Documentation

signal loadError

void loadError(
    QString const & message
)

Emitted when file loading fails.

Parameters:

  • message Error message

signal fileLoaded

void fileLoaded(
    qint64 num_rows,
    int num_cols
)

Emitted when file is successfully loaded.

Parameters:

  • num_rows Number of rows in the view
  • num_cols Number of columns in the view

Public Functions Documentation

function CsvDatasetPreviewModel

explicit CsvDatasetPreviewModel(
    QObject * parent =nullptr
)

function ~CsvDatasetPreviewModel

~CsvDatasetPreviewModel() override

function loadFile

bool loadFile(
    QString const & file_path,
    CsvParseConfig const & config
)

Load a CSV file for preview with the given parse configuration.

Parameters:

  • file_path Path to the CSV file
  • config Parse configuration

Return: true if file was loaded successfully

function reloadWithConfig

bool reloadWithConfig(
    CsvParseConfig const & config
)

Reload the current file with a new parse configuration.

Parameters:

  • config New parse configuration

Return: true if reload was successful

function clear

void clear()

Clear the current file.

function hasData

inline bool hasData() const

Check if a file is currently loaded.

function fileInfo

inline CsvFileInfo const & fileInfo() const

Get the computed file information.

function parseConfig

inline CsvParseConfig const & parseConfig() const

Get the current parse configuration.

function chunkSize

inline int chunkSize() const

Get the chunk size used for lazy loading.

function setChunkSize

void setChunkSize(
    int size
)

Set the chunk size for lazy loading.

Parameters:

  • size Number of rows to load at once (minimum 10)

function rowCount

int rowCount(
    QModelIndex const & parent =QModelIndex()
) const override

function columnCount

int columnCount(
    QModelIndex const & parent =QModelIndex()
) const override

function data

QVariant data(
    QModelIndex const & index,
    int role =Qt::DisplayRole
) const override

function headerData

QVariant headerData(
    int section,
    Qt::Orientation orientation,
    int role =Qt::DisplayRole
) const override

Updated on 2026-11-13 at 20:25:41 +0000