Mercurial > retraceit
comparison src/libqxt/qxtcsvmodel.h @ 1:7a2637c3eb83
Add csv parser from libqxt
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 23 Mar 2015 16:33:26 +0100 |
parents | |
children | 06c9b37d1e1b |
comparison
equal
deleted
inserted
replaced
0:147b08bc7d64 | 1:7a2637c3eb83 |
---|---|
1 #ifndef QXTCSVMODEL_H | |
2 /**************************************************************************** | |
3 ** Copyright (c) 2006 - 2011, the LibQxt project. | |
4 ** See the Qxt AUTHORS file for a list of authors and copyright holders. | |
5 ** All rights reserved. | |
6 ** | |
7 ** Redistribution and use in source and binary forms, with or without | |
8 ** modification, are permitted provided that the following conditions are met: | |
9 ** * Redistributions of source code must retain the above copyright | |
10 ** notice, this list of conditions and the following disclaimer. | |
11 ** * Redistributions in binary form must reproduce the above copyright | |
12 ** notice, this list of conditions and the following disclaimer in the | |
13 ** documentation and/or other materials provided with the distribution. | |
14 ** * Neither the name of the LibQxt project nor the | |
15 ** names of its contributors may be used to endorse or promote products | |
16 ** derived from this software without specific prior written permission. | |
17 ** | |
18 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
19 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
20 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 ** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY | |
22 ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
23 ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
24 ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
25 ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
27 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 ** | |
29 ** <http://libqxt.org> <foundation@libqxt.org> | |
30 *****************************************************************************/ | |
31 | |
32 #define QXTCSVMODEL_H | |
33 | |
34 #include <QAbstractTableModel> | |
35 #include <QVariant> | |
36 #include <QIODevice> | |
37 #include <QChar> | |
38 #include <QString> | |
39 #include <QStringList> | |
40 #include <QModelIndex> | |
41 #include <qxtglobal.h> | |
42 class QTextCodec; | |
43 | |
44 class QxtCsvModelPrivate; | |
45 class QXT_CORE_EXPORT QxtCsvModel : public QAbstractTableModel | |
46 { | |
47 Q_OBJECT | |
48 public: | |
49 QxtCsvModel(QObject *parent = 0); | |
50 explicit QxtCsvModel(QIODevice *file, QObject *parent = 0, bool withHeader = false, QChar separator = ','); | |
51 explicit QxtCsvModel(const QString filename, QObject *parent = 0, bool withHeader = false, QChar separator = ','); | |
52 ~QxtCsvModel(); | |
53 | |
54 int rowCount(const QModelIndex& parent = QModelIndex()) const; | |
55 int columnCount(const QModelIndex& parent = QModelIndex()) const; | |
56 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; | |
57 bool setData(const QModelIndex& index, const QVariant& data, int role = Qt::EditRole); | |
58 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; | |
59 bool setHeaderData(int section, Qt::Orientation orientation, const QVariant& value, int role = Qt::DisplayRole); | |
60 void setHeaderData(const QStringList& data); | |
61 QString text(int row, int column) const; | |
62 void setText(int row, int column, const QString& value); | |
63 QString headerText(int column) const; | |
64 void setHeaderText(int column, const QString& value); | |
65 | |
66 | |
67 bool insertRow(int row, const QModelIndex& parent = QModelIndex()); | |
68 bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()); | |
69 bool removeRow(int row, const QModelIndex& parent = QModelIndex()); | |
70 bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()); | |
71 bool insertColumn(int col, const QModelIndex& parent = QModelIndex()); | |
72 bool insertColumns(int col, int count, const QModelIndex& parent = QModelIndex()); | |
73 bool removeColumn(int col, const QModelIndex& parent = QModelIndex()); | |
74 bool removeColumns(int col, int count, const QModelIndex& parent = QModelIndex()); | |
75 | |
76 void setSource(QIODevice *file, bool withHeader = false, QChar separator = ',', QTextCodec* codec = 0); | |
77 void setSource(const QString filename, bool withHeader = false, QChar separator = ',', QTextCodec* codec = 0); | |
78 | |
79 void toCSV(QIODevice *file, bool withHeader = false, QChar separator = ',', QTextCodec* codec = 0) const; | |
80 void toCSV(const QString filename, bool withHeader = false, QChar separator = ',', QTextCodec* codec = 0) const; | |
81 | |
82 enum QuoteOption { NoQuotes = 0, SingleQuote = 1, DoubleQuote = 2, BothQuotes = 3, | |
83 NoEscape = 0, TwoQuoteEscape = 4, BackslashEscape = 8, | |
84 AlwaysQuoteOutput = 16, DefaultQuoteMode = BothQuotes | BackslashEscape | AlwaysQuoteOutput }; | |
85 Q_DECLARE_FLAGS(QuoteMode, QuoteOption) | |
86 QuoteMode quoteMode() const; | |
87 void setQuoteMode(QuoteMode mode); | |
88 | |
89 Qt::ItemFlags flags(const QModelIndex& index) const; | |
90 | |
91 private: | |
92 QXT_DECLARE_PRIVATE(QxtCsvModel) | |
93 }; | |
94 Q_DECLARE_OPERATORS_FOR_FLAGS(QxtCsvModel::QuoteMode) | |
95 | |
96 #endif |