NeTrainSim 0.1.1 beta
The Open-Source Network Trains Simulator
 
Loading...
Searching...
No Matches
CSVManager Class Reference

#include <csvmanager.h>

Inheritance diagram for CSVManager:

Signals

void dataReady (const QVector< QVector< QString > > &data)
 Signal emitted when the data is ready.
 

Public Member Functions

 CSVManager (QObject *parent=nullptr)
 
QVector< QVector< QString > > readCSV (const QString &filename, const QString &delimiter, bool firstRowHeader=true)
 Reads a CSV file and returns the data as a 2D QVector of QString values.
 
QVector< QVector< QString > > filterByColumn (int column, const QString &value) const
 Filters the data based on a specific column and value.
 
QVector< QVector< QString > > filterByColumn (const QVector< QVector< QString > > &data, int column, const QString &value) const
 Filters the provided data based on a specific column and value.
 
QStringList getDistinctColumnValues (int column) const
 Retrieves the distinct values in a specific column.
 
QVector< QString > getColumnValues (const QVector< QVector< QString > > &data, int column) const
 Retrieves the values in a specific column from the provided data.
 

Constructor & Destructor Documentation

◆ CSVManager()

CSVManager::CSVManager ( QObject *  parent = nullptr)
explicit

Member Function Documentation

◆ dataReady

void CSVManager::dataReady ( const QVector< QVector< QString > > &  data)
signal

Signal emitted when the data is ready.

Parameters
dataThe data as a QVector of QVector<QString>.

◆ filterByColumn() [1/2]

QVector< QVector< QString > > CSVManager::filterByColumn ( const QVector< QVector< QString > > &  data,
int  column,
const QString &  value 
) const

Filters the provided data based on a specific column and value.

Parameters
dataThe data to filter.
columnThe index of the column to filter by.
valueThe value to filter for in the specified column.
Returns
A filtered 2D QVector containing the rows that match the filter.

◆ filterByColumn() [2/2]

QVector< QVector< QString > > CSVManager::filterByColumn ( int  column,
const QString &  value 
) const

Filters the data based on a specific column and value.

Parameters
columnThe index of the column to filter by.
valueThe value to filter for in the specified column.
Returns
A filtered 2D QVector containing the rows that match the filter.

◆ getColumnValues()

QVector< QString > CSVManager::getColumnValues ( const QVector< QVector< QString > > &  data,
int  column 
) const

Retrieves the values in a specific column from the provided data.

Parameters
dataThe data to extract column values from.
columnThe index of the column to extract values from.
Returns
A QVector containing the values in the specified column.

◆ getDistinctColumnValues()

QStringList CSVManager::getDistinctColumnValues ( int  column) const

Retrieves the distinct values in a specific column.

Parameters
columnThe index of the column to retrieve distinct values from.
Returns
A QStringList containing the distinct values in the specified column.

◆ readCSV()

QVector< QVector< QString > > CSVManager::readCSV ( const QString &  filename,
const QString &  delimiter,
bool  firstRowHeader = true 
)

Reads a CSV file and returns the data as a 2D QVector of QString values.

Parameters
filenameThe filename of the CSV file to read.
delimiterThe delimiter used in the CSV file.
firstRowHeaderFlag indicating whether the first row is a header row.
Returns
A 2D QVector containing the data from the CSV file.