1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
crate::ix!();
//-------------------------------------------[.cpp/bitcoin/src/qt/csvmodelwriter.h]
/**
| Export a Qt table model to a CSV file.
| This is useful for analyzing or post-processing
| the data in a spreadsheet.
|
*/
#[Q_OBJECT]
pub struct CSVModelWriter {
base: QObject,
filename: String,
model: *const QAbstractItemModel,
columns: QList<CsvModelWriterColumn>,
}
pub struct CsvModelWriterColumn
{
title: String,
column: i32,
role: i32,
}
lazy_static!{
pub static ref QtEditRole: i32 = ItemDataRole::EditRole.to_int() as i32;
}
//-------------------------------------------[.cpp/bitcoin/src/qt/csvmodelwriter.cpp]
impl CSVModelWriter {
pub fn new(
filename: &String,
parent: *mut QObject) -> Self {
todo!();
/*
: q_object(parent),
: filename(_filename),
: model(nullptr),
*/
}
pub fn set_model(&mut self, model: *const QAbstractItemModel) {
todo!();
/*
this->model = _model;
*/
}
pub fn add_column(&mut self,
title: &String,
column: i32,
role: Option<i32>) {
let role: i32 = role.unwrap_or(*QtEditRole);
todo!();
/*
Column col;
col.title = title;
col.column = column;
col.role = role;
columns.append(col);
*/
}
/**
| Perform export of the model to CSV.
|
|
| -----------
| @return
|
| true on success, false otherwise
|
*/
pub fn write(&mut self) -> bool {
todo!();
/*
QFile file(filename);
if(!file.open(QIODevice::WriteOnly | QIODevice::Text))
return false;
QTextStream out(&file);
int numRows = 0;
if(model)
{
numRows = model->rowCount();
}
// Header row
for(int i=0; i<columns.size(); ++i)
{
if(i!=0)
{
writeSep(out);
}
writeValue(out, columns[i].title);
}
writeNewline(out);
// Data rows
for(int j=0; j<numRows; ++j)
{
for(int i=0; i<columns.size(); ++i)
{
if(i!=0)
{
writeSep(out);
}
QVariant data = model->index(j, columns[i].column).data(columns[i].role);
writeValue(out, data.toString());
}
writeNewline(out);
}
file.close();
return file.error() == QFile::NoError;
*/
}
}
pub fn write_value(
f: &mut QTextStream,
value: &String) {
todo!();
/*
QString escaped = value;
escaped.replace('"', "\"\"");
f << "\"" << escaped << "\"";
*/
}
pub fn write_sep(f: &mut QTextStream) {
todo!();
/*
f << ",";
*/
}
pub fn write_newline(f: &mut QTextStream) {
todo!();
/*
f << "\n";
*/
}