The QxtCsvModel class provides a QAbstractTableModel for CSV Files. More...
#include <qxtcsvmodel.h>
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, QxtCsvModelPrivate > | qxt_d |
Friends | |
class | QxtCsvModelPrivate |
The QxtCsvModel class provides a QAbstractTableModel for CSV Files.
Definition at line 53 of file qxtcsvmodel.h.
Enumerator | |
---|---|
NoQuotes | |
SingleQuote | |
DoubleQuote | |
BothQuotes | |
NoEscape | |
TwoQuoteEscape | |
BackslashEscape | |
AlwaysQuoteOutput | |
DefaultQuoteMode |
Definition at line 100 of file qxtcsvmodel.h.
|
explicit |
Creates an empty QxtCsvModel with parent parent.
Definition at line 68 of file qxtcsvmodel.cpp.
References QXT_INIT_PRIVATE.
|
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.
Definition at line 81 of file qxtcsvmodel.cpp.
References QXT_INIT_PRIVATE, and setSource().
|
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.
Definition at line 98 of file qxtcsvmodel.cpp.
References QXT_INIT_PRIVATE, and setSource().
|
virtual |
|
virtual |
\reimp
Definition at line 123 of file qxtcsvmodel.cpp.
References qxt_d.
Referenced by removeColumns(), setData(), and toCSV().
|
virtual |
\reimp
Definition at line 135 of file qxtcsvmodel.cpp.
References qxt_d, and rowCount().
Referenced by setData(), setHeaderData(), text(), and toCSV().
|
virtual |
\reimp
Definition at line 665 of file qxtcsvmodel.cpp.
|
virtual |
\reimp
Definition at line 160 of file qxtcsvmodel.cpp.
References qxt_d.
Referenced by headerText().
QString QxtCsvModel::headerText | ( | int | column | ) | const |
Fetches the content of the cell at row row and column column.
Definition at line 728 of file qxtcsvmodel.cpp.
References headerData().
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().
|
virtual |
\reimp
Definition at line 475 of file qxtcsvmodel.cpp.
References QxtCsvModelPrivate::csvData, QxtCsvModelPrivate::header, QxtCsvModelPrivate::maxColumn, qxt_d, and rowCount().
Referenced by insertColumn().
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().
|
virtual |
\reimp
Definition at line 403 of file qxtcsvmodel.cpp.
References QxtCsvModelPrivate::csvData, qxt_d, and rowCount().
Referenced by insertRow().
QxtCsvModel::QuoteMode QxtCsvModel::quoteMode | ( | ) | const |
Returns the current quoting mode.
Definition at line 674 of file qxtcsvmodel.cpp.
References qxt_d.
bool QxtCsvModel::removeColumn | ( | int | col, |
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().
bool QxtCsvModel::removeRow | ( | int | row, |
const QModelIndex & | parent = QModelIndex() |
||
) |
|
virtual |
\reimp
Definition at line 440 of file qxtcsvmodel.cpp.
References QxtCsvModelPrivate::csvData, qxt_d, and rowCount().
Referenced by removeRow().
|
virtual |
\reimp
Definition at line 111 of file qxtcsvmodel.cpp.
References qxt_d.
Referenced by data(), insertColumns(), insertRows(), removeColumns(), removeRows(), setData(), and toCSV().
|
virtual |
\reimp
Definition at line 367 of file qxtcsvmodel.cpp.
References columnCount(), data(), qxt_d, and rowCount().
Referenced by setText().
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.
|
virtual |
\reimp
Definition at line 338 of file qxtcsvmodel.cpp.
References qxt_d.
Referenced by setHeaderText().
void QxtCsvModel::setHeaderText | ( | int | column, |
const QString & | value | ||
) |
Sets the content of the header for column column to value.
Definition at line 718 of file qxtcsvmodel.cpp.
References setHeaderData().
Referenced by MainWindow::exportToCSVData(), and TMainWindow::exportToCSVData().
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.
Definition at line 686 of file qxtcsvmodel.cpp.
References qxt_d.
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().
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.
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().
void QxtCsvModel::setText | ( | int | row, |
int | column, | ||
const QString & | value | ||
) |
Sets the content of the cell at row row and column column to value.
Definition at line 696 of file qxtcsvmodel.cpp.
References setData().
Referenced by MainWindow::exportToCSVData(), and TMainWindow::exportToCSVData().
QString QxtCsvModel::text | ( | int | row, |
int | column | ||
) | const |
Fetches the content of the cell at row row and column column.
Definition at line 707 of file qxtcsvmodel.cpp.
References data().
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().
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().
|
friend |
Definition at line 118 of file qxtcsvmodel.h.
|
private |
Definition at line 118 of file qxtcsvmodel.h.
Referenced by columnCount(), data(), headerData(), insertColumns(), insertRows(), quoteMode(), removeColumns(), removeRows(), rowCount(), setData(), setHeaderData(), setQuoteMode(), setSource(), and toCSV().