7 #include <QAbstractItemModel> 13 filename(_filename), model(0)
32 static void writeValue(QTextStream &
f,
const QString &value)
35 escaped.replace(
'"',
"\"\"");
36 f <<
"\"" << escaped <<
"\"";
39 static void writeSep(QTextStream &
f)
44 static void writeNewline(QTextStream &
f)
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)
69 writeValue(out,
columns[i].title);
74 for(
int j=0; j<numRows; ++j)
76 for(
int i=0; i<
columns.size(); ++i)
83 writeValue(out, data.toString());
90 return file.error() == QFile::NoError;
void addColumn(const QString &title, int column, int role=Qt::EditRole)
std::string escaped(std::string const &_s, bool _all=true)
Escapes a string into the C-string representation.
const QAbstractItemModel * model
CSVModelWriter(const QString &filename, QObject *parent=0)
void setModel(const QAbstractItemModel *model)
bool write()
Perform export of the model to CSV.