7#include <QAbstractItemModel>
32static void writeValue(QTextStream &f,
const QString &value)
34 QString escaped = value;
35 escaped.replace(
'"',
"\"\"");
36 f <<
"\"" << escaped <<
"\"";
52 if(!file.open(QIODevice::WriteOnly | QIODevice::Text))
54 QTextStream
out(&file);
59 numRows =
model->rowCount();
63 for(
int i=0; i<
columns.size(); ++i)
74 for(
int j=0; j<numRows; ++j)
76 for(
int i=0; i<
columns.size(); ++i)
90 return file.error() == QFile::NoError;
CSVModelWriter(const QString &filename, QObject *parent=nullptr)
bool write()
Perform export of the model to CSV.
void setModel(const QAbstractItemModel *model)
void addColumn(const QString &title, int column, int role=Qt::EditRole)
const QAbstractItemModel * model
static void writeValue(QTextStream &f, const QString &value)
static void writeSep(QTextStream &f)
static void writeNewline(QTextStream &f)