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