2014-01-05 21:03:23 +01:00
|
|
|
// Copyright (c) 2011-2014 The Bitcoin Core developers
|
2014-12-13 05:09:33 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-04 16:20:43 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2014-11-03 16:16:40 +01:00
|
|
|
#ifndef BITCOIN_QT_CSVMODELWRITER_H
|
|
|
|
#define BITCOIN_QT_CSVMODELWRITER_H
|
2011-07-07 14:27:16 +02:00
|
|
|
|
|
|
|
#include <QList>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <QObject>
|
2011-07-07 14:27:16 +02:00
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
class QAbstractItemModel;
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2011-11-13 13:19:52 +01: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 14:27:16 +02:00
|
|
|
class CSVModelWriter : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2013-01-23 21:51:02 +01:00
|
|
|
|
2011-07-07 14:27:16 +02: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 13:19:52 +01:00
|
|
|
/** Perform export of the model to CSV.
|
|
|
|
@returns true on success, false otherwise
|
|
|
|
*/
|
2011-07-07 14:27:16 +02:00
|
|
|
bool write();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString filename;
|
|
|
|
const QAbstractItemModel *model;
|
|
|
|
|
|
|
|
struct Column
|
|
|
|
{
|
|
|
|
QString title;
|
|
|
|
int column;
|
|
|
|
int role;
|
|
|
|
};
|
|
|
|
QList<Column> columns;
|
|
|
|
};
|
|
|
|
|
2014-11-03 16:16:40 +01:00
|
|
|
#endif // BITCOIN_QT_CSVMODELWRITER_H
|