OSDN Git Service

Initial commit
[monacoin/monacoin.git] / src / qt / csvmodelwriter.h
1 #ifndef CSVMODELWRITER_H
2 #define CSVMODELWRITER_H
3
4 #include <QObject>
5 #include <QList>
6
7 QT_BEGIN_NAMESPACE
8 class QAbstractItemModel;
9 QT_END_NAMESPACE
10
11 /** Export a Qt table model to a CSV file. This is useful for analyzing or post-processing the data in
12     a spreadsheet.
13  */
14 class CSVModelWriter : public QObject
15 {
16     Q_OBJECT
17
18 public:
19     explicit CSVModelWriter(const QString &filename, QObject *parent = 0);
20
21     void setModel(const QAbstractItemModel *model);
22     void addColumn(const QString &title, int column, int role=Qt::EditRole);
23
24     /** Perform export of the model to CSV.
25         @returns true on success, false otherwise
26     */
27     bool write();
28
29 private:
30     QString filename;
31     const QAbstractItemModel *model;
32
33     struct Column
34     {
35         QString title;
36         int column;
37         int role;
38     };
39     QList<Column> columns;
40 };
41
42 #endif // CSVMODELWRITER_H