Seamly2D
Code documentation
QxtCsvModel Class Reference

The QxtCsvModel class provides a QAbstractTableModel for CSV Files. More...

#include <qxtcsvmodel.h>

Inheritance diagram for QxtCsvModel:
Collaboration diagram for QxtCsvModel:

Public Types

enum  QuoteOption {
  NoQuotes = 0 , SingleQuote = 1 , DoubleQuote = 2 , BothQuotes = 3 ,
  NoEscape = 0 , TwoQuoteEscape = 4 , BackslashEscape = 8 , AlwaysQuoteOutput = 16 ,
  DefaultQuoteMode = BothQuotes | BackslashEscape | AlwaysQuoteOutput
}
 

Public Member Functions

 QxtCsvModel (QObject *parent=nullptr)
 Creates an empty QxtCsvModel with parent parent. More...
 
 QxtCsvModel (QIODevice *file, QObject *parent=nullptr, bool withHeader=false, QChar separator=',')
 Creates a QxtCsvModel with the parent parent and content loaded from file. More...
 
 QxtCsvModel (const QString &filename, QObject *parent=nullptr, bool withHeader=false, QChar separator=',')
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates a QxtCsvModel with the parent parent and content loaded from file. More...
 
virtual ~QxtCsvModel () Q_DECL_EQ_DEFAULT
 
virtual int rowCount (const QModelIndex &parent=QModelIndex()) const Q_DECL_OVERRIDE
 \reimp More...
 
virtual int columnCount (const QModelIndex &parent=QModelIndex()) const Q_DECL_OVERRIDE
 \reimp More...
 
virtual QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const Q_DECL_OVERRIDE
 \reimp More...
 
virtual bool setData (const QModelIndex &index, const QVariant &data, int role=Qt::EditRole) Q_DECL_OVERRIDE
 \reimp More...
 
virtual QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const Q_DECL_OVERRIDE
 \reimp More...
 
virtual bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::DisplayRole) Q_DECL_OVERRIDE
 \reimp More...
 
void setHeaderData (const QStringList &data)
 Sets the horizontal headers of the model to the values provided in data. More...
 
QString text (int row, int column) const
 Fetches the content of the cell at row row and column column. More...
 
void setText (int row, int column, const QString &value)
 Sets the content of the cell at row row and column column to value. More...
 
QString headerText (int column) const
 Fetches the content of the cell at row row and column column. More...
 
void setHeaderText (int column, const QString &value)
 Sets the content of the header for column column to value. More...
 
bool insertRow (int row, const QModelIndex &parent=QModelIndex())
 \reimp More...
 
virtual bool insertRows (int row, int count, const QModelIndex &parent=QModelIndex()) Q_DECL_OVERRIDE
 \reimp More...
 
bool removeRow (int row, const QModelIndex &parent=QModelIndex())
 \reimp More...
 
virtual bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex()) Q_DECL_OVERRIDE
 \reimp More...
 
bool insertColumn (int col, const QModelIndex &parent=QModelIndex())
 \reimp More...
 
virtual bool insertColumns (int col, int count, const QModelIndex &parent=QModelIndex()) Q_DECL_OVERRIDE
 \reimp More...
 
bool removeColumn (int col, const QModelIndex &parent=QModelIndex())
 \reimp More...
 
virtual bool removeColumns (int col, int count, const QModelIndex &parent=QModelIndex()) Q_DECL_OVERRIDE
 \reimp More...
 
void setSource (QIODevice *file, bool withHeader=false, QChar separator=',', QTextCodec *codec=nullptr)
 Reads in a CSV file from the provided file using codec. More...
 
void setSource (const QString &filename, bool withHeader=false, QChar separator=',', QTextCodec *codec=nullptr)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads in a CSV file from the provided file using codec. More...
 
void toCSV (QIODevice *file, bool withHeader=false, QChar separator=',', QTextCodec *codec=nullptr) const
 Outputs the content of the model as a CSV file to the device dest using codec. More...
 
void toCSV (const QString &filename, bool withHeader=false, QChar separator=',', QTextCodec *codec=nullptr) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Outputs the content of the model as a CSV file to the file specified by filename using codec. More...
 
QuoteMode quoteMode () const
 Returns the current quoting mode. More...
 
void setQuoteMode (QuoteMode mode)
 Sets the current quoting mode. More...
 
virtual Qt::ItemFlags flags (const QModelIndex &index) const Q_DECL_OVERRIDE
 \reimp More...
 

Private Attributes

QxtPrivateInterface< QxtCsvModel, QxtCsvModelPrivateqxt_d
 

Friends

class QxtCsvModelPrivate
 

Detailed Description

The QxtCsvModel class provides a QAbstractTableModel for CSV Files.

Definition at line 53 of file qxtcsvmodel.h.

Member Enumeration Documentation

◆ QuoteOption

Enumerator
NoQuotes 
SingleQuote 
DoubleQuote 
BothQuotes 
NoEscape 
TwoQuoteEscape 
BackslashEscape 
AlwaysQuoteOutput 
DefaultQuoteMode 

Definition at line 100 of file qxtcsvmodel.h.

Constructor & Destructor Documentation

◆ QxtCsvModel() [1/3]

QT_WARNING_PUSH QxtCsvModel::QxtCsvModel ( QObject *  parent = nullptr)
explicit

Creates an empty QxtCsvModel with parent parent.

Definition at line 68 of file qxtcsvmodel.cpp.

References QXT_INIT_PRIVATE.

◆ QxtCsvModel() [2/3]

QxtCsvModel::QxtCsvModel ( QIODevice *  file,
QObject *  parent = nullptr,
bool  withHeader = false,
QChar  separator = ',' 
)
explicit

Creates a QxtCsvModel with the parent parent and content loaded from file.

See setSource for information on the withHeader and separator properties, or if you need control over the quoting method or codec used to parse the file.

See also
setSource

Definition at line 81 of file qxtcsvmodel.cpp.

References QXT_INIT_PRIVATE, and setSource().

◆ QxtCsvModel() [3/3]

QxtCsvModel::QxtCsvModel ( const QString &  filename,
QObject *  parent = nullptr,
bool  withHeader = false,
QChar  separator = ',' 
)
explicit

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates a QxtCsvModel with the parent parent and content loaded from file.

See setSource for information on the withHeader and separator properties, or if you need control over the quoting method or codec used to parse the file.

See also
setSource

Definition at line 98 of file qxtcsvmodel.cpp.

References QXT_INIT_PRIVATE, and setSource().

◆ ~QxtCsvModel()

virtual QxtCsvModel::~QxtCsvModel ( )
virtual

Member Function Documentation

◆ columnCount()

int QxtCsvModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

\reimp

Definition at line 123 of file qxtcsvmodel.cpp.

References qxt_d.

Referenced by removeColumns(), setData(), and toCSV().

◆ data()

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

\reimp

Definition at line 135 of file qxtcsvmodel.cpp.

References qxt_d, and rowCount().

Referenced by setData(), setHeaderData(), text(), and toCSV().

◆ flags()

Qt::ItemFlags QxtCsvModel::flags ( const QModelIndex &  index) const
virtual

\reimp

Definition at line 665 of file qxtcsvmodel.cpp.

◆ headerData()

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

\reimp

Definition at line 160 of file qxtcsvmodel.cpp.

References qxt_d.

Referenced by headerText().

◆ headerText()

QString QxtCsvModel::headerText ( int  column) const

Fetches the content of the cell at row row and column column.

See also
setText

Definition at line 728 of file qxtcsvmodel.cpp.

References headerData().

◆ insertColumn()

bool QxtCsvModel::insertColumn ( int  col,
const QModelIndex &  parent = QModelIndex() 
)

\reimp

Definition at line 467 of file qxtcsvmodel.cpp.

References insertColumns().

Referenced by MainWindow::exportToCSVData(), and TMainWindow::exportToCSVData().

◆ insertColumns()

bool QxtCsvModel::insertColumns ( int  col,
int  count,
const QModelIndex &  parent = QModelIndex() 
)
virtual

◆ insertRow()

bool QxtCsvModel::insertRow ( int  row,
const QModelIndex &  parent = QModelIndex() 
)

\reimp

Definition at line 395 of file qxtcsvmodel.cpp.

References insertRows().

Referenced by MainWindow::exportToCSVData(), and TMainWindow::exportToCSVData().

◆ insertRows()

bool QxtCsvModel::insertRows ( int  row,
int  count,
const QModelIndex &  parent = QModelIndex() 
)
virtual

\reimp

Definition at line 403 of file qxtcsvmodel.cpp.

References QxtCsvModelPrivate::csvData, qxt_d, and rowCount().

Referenced by insertRow().

◆ quoteMode()

QxtCsvModel::QuoteMode QxtCsvModel::quoteMode ( ) const

Returns the current quoting mode.

See also
setQuoteMode

Definition at line 674 of file qxtcsvmodel.cpp.

References qxt_d.

◆ removeColumn()

bool QxtCsvModel::removeColumn ( int  col,
const QModelIndex &  parent = QModelIndex() 
)

\reimp

Definition at line 507 of file qxtcsvmodel.cpp.

References removeColumns().

◆ removeColumns()

bool QxtCsvModel::removeColumns ( int  col,
int  count,
const QModelIndex &  parent = QModelIndex() 
)
virtual

\reimp

Definition at line 515 of file qxtcsvmodel.cpp.

References columnCount(), QxtCsvModelPrivate::csvData, QxtCsvModelPrivate::header, qxt_d, and rowCount().

Referenced by removeColumn().

◆ removeRow()

bool QxtCsvModel::removeRow ( int  row,
const QModelIndex &  parent = QModelIndex() 
)

\reimp

Definition at line 432 of file qxtcsvmodel.cpp.

References removeRows().

◆ removeRows()

bool QxtCsvModel::removeRows ( int  row,
int  count,
const QModelIndex &  parent = QModelIndex() 
)
virtual

\reimp

Definition at line 440 of file qxtcsvmodel.cpp.

References QxtCsvModelPrivate::csvData, qxt_d, and rowCount().

Referenced by removeRow().

◆ rowCount()

QT_WARNING_POP int QxtCsvModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

\reimp

Definition at line 111 of file qxtcsvmodel.cpp.

References qxt_d.

Referenced by data(), insertColumns(), insertRows(), removeColumns(), removeRows(), setData(), and toCSV().

◆ setData()

bool QxtCsvModel::setData ( const QModelIndex &  index,
const QVariant &  data,
int  role = Qt::EditRole 
)
virtual

\reimp

Definition at line 367 of file qxtcsvmodel.cpp.

References columnCount(), data(), qxt_d, and rowCount().

Referenced by setText().

◆ setHeaderData() [1/2]

void QxtCsvModel::setHeaderData ( const QStringList &  data)

Sets the horizontal headers of the model to the values provided in data.

Definition at line 329 of file qxtcsvmodel.cpp.

References data(), and qxt_d.

◆ setHeaderData() [2/2]

bool QxtCsvModel::setHeaderData ( int  section,
Qt::Orientation  orientation,
const QVariant &  value,
int  role = Qt::DisplayRole 
)
virtual

\reimp

Definition at line 338 of file qxtcsvmodel.cpp.

References qxt_d.

Referenced by setHeaderText().

◆ setHeaderText()

void QxtCsvModel::setHeaderText ( int  column,
const QString &  value 
)

Sets the content of the header for column column to value.

See also
headerText

Definition at line 718 of file qxtcsvmodel.cpp.

References setHeaderData().

Referenced by MainWindow::exportToCSVData(), and TMainWindow::exportToCSVData().

◆ setQuoteMode()

void QxtCsvModel::setQuoteMode ( QuoteMode  mode)

Sets the current quoting mode.

The default quoting mode is BothQuotes | BackslashEscape.

The quoting mode determines what kinds of quoting is used for reading and writing CSV files.

See also
quoteMode
QuoteOption

Definition at line 686 of file qxtcsvmodel.cpp.

References qxt_d.

◆ setSource() [1/2]

void QxtCsvModel::setSource ( const QString &  filename,
bool  withHeader = false,
QChar  separator = ',',
QTextCodec *  codec = nullptr 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads in a CSV file from the provided file using codec.

Definition at line 179 of file qxtcsvmodel.cpp.

References setSource().

◆ setSource() [2/2]

void QxtCsvModel::setSource ( QIODevice *  file,
bool  withHeader = false,
QChar  separator = ',',
QTextCodec *  codec = nullptr 
)

Reads in a CSV file from the provided file using codec.

The value of separator will be used to delimit fields, subject to the specified quoteMode. If withHeader is set to true, the first line of the file will be used to populate the model's horizontal header.

See also
quoteMode

Definition at line 194 of file qxtcsvmodel.cpp.

References BackslashEscape, QxtCsvModelPrivate::csvData, DoubleQuote, QxtCsvModelPrivate::header, QxtCsvModelPrivate::maxColumn, QxtCsvModelPrivate::quoteMode, qxt_d, SingleQuote, and TwoQuoteEscape.

Referenced by QxtCsvModel(), and setSource().

◆ setText()

void QxtCsvModel::setText ( int  row,
int  column,
const QString &  value 
)

Sets the content of the cell at row row and column column to value.

See also
text

Definition at line 696 of file qxtcsvmodel.cpp.

References setData().

Referenced by MainWindow::exportToCSVData(), and TMainWindow::exportToCSVData().

◆ text()

QString QxtCsvModel::text ( int  row,
int  column 
) const

Fetches the content of the cell at row row and column column.

See also
setText

Definition at line 707 of file qxtcsvmodel.cpp.

References data().

◆ toCSV() [1/2]

void QxtCsvModel::toCSV ( const QString &  filename,
bool  withHeader = false,
QChar  separator = ',',
QTextCodec *  codec = nullptr 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Outputs the content of the model as a CSV file to the file specified by filename using codec.

Fields in the output file will be separated by separator. Set withHeader to true to output a row of headers at the top of the file.

Definition at line 656 of file qxtcsvmodel.cpp.

References toCSV().

◆ toCSV() [2/2]

void QxtCsvModel::toCSV ( QIODevice *  dest,
bool  withHeader = false,
QChar  separator = ',',
QTextCodec *  codec = nullptr 
) const

Outputs the content of the model as a CSV file to the device dest using codec.

Fields in the output file will be separated by separator. Set withHeader to true to output a row of headers at the top of the file.

Definition at line 594 of file qxtcsvmodel.cpp.

References columnCount(), QxtCsvModelPrivate::csvData, data(), QxtCsvModelPrivate::header, QxtCsvModelPrivate::quoteMode, qxt_addCsvQuotes(), qxt_d, and rowCount().

Referenced by MainWindow::exportToCSVData(), TMainWindow::exportToCSVData(), and toCSV().

Friends And Related Function Documentation

◆ QxtCsvModelPrivate

friend class QxtCsvModelPrivate
friend

Definition at line 118 of file qxtcsvmodel.h.

Member Data Documentation

◆ qxt_d


The documentation for this class was generated from the following files: