2014-01-05 12:03:23 -08:00
|
|
|
// Copyright (c) 2011-2014 The Bitcoin Core developers
|
2014-12-12 20:09:33 -08:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-04 07:20:43 -08:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2014-11-03 07:16:40 -08:00
|
|
|
#ifndef BITCOIN_QT_CSVMODELWRITER_H
|
|
|
|
#define BITCOIN_QT_CSVMODELWRITER_H
|
2011-07-07 05:27:16 -07:00
|
|
|
|
|
|
|
#include <QList>
|
2013-04-12 22:13:08 -07:00
|
|
|
#include <QObject>
|
2011-07-07 05:27:16 -07:00
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
class QAbstractItemModel;
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2011-11-13 04:19:52 -08:00
|
|
|
/** Export a Qt table model to a CSV file. This is useful for analyzing or post-processing the data in
|
|
|
|
a spreadsheet.
|
|
|
|
*/
|
2011-07-07 05:27:16 -07:00
|
|
|
class CSVModelWriter : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2013-01-23 12:51:02 -08:00
|
|
|
|
2011-07-07 05:27:16 -07:00
|
|
|
public:
|
|
|
|
explicit CSVModelWriter(const QString &filename, QObject *parent = 0);
|
|
|
|
|
|
|
|
void setModel(const QAbstractItemModel *model);
|
|
|
|
void addColumn(const QString &title, int column, int role=Qt::EditRole);
|
|
|
|
|
2011-11-13 04:19:52 -08:00
|
|
|
/** Perform export of the model to CSV.
|
|
|
|
@returns true on success, false otherwise
|
|
|
|
*/
|
2011-07-07 05:27:16 -07:00
|
|
|
bool write();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString filename;
|
|
|
|
const QAbstractItemModel *model;
|
|
|
|
|
|
|
|
struct Column
|
|
|
|
{
|
|
|
|
QString title;
|
|
|
|
int column;
|
|
|
|
int role;
|
|
|
|
};
|
|
|
|
QList<Column> columns;
|
|
|
|
};
|
|
|
|
|
2014-11-03 07:16:40 -08:00
|
|
|
#endif // BITCOIN_QT_CSVMODELWRITER_H
|