andre@1: #ifndef QXTCSVMODEL_H andre@1: /**************************************************************************** andre@1: ** Copyright (c) 2006 - 2011, the LibQxt project. andre@1: ** See the Qxt AUTHORS file for a list of authors and copyright holders. andre@1: ** All rights reserved. andre@1: ** andre@1: ** Redistribution and use in source and binary forms, with or without andre@1: ** modification, are permitted provided that the following conditions are met: andre@1: ** * Redistributions of source code must retain the above copyright andre@1: ** notice, this list of conditions and the following disclaimer. andre@1: ** * Redistributions in binary form must reproduce the above copyright andre@1: ** notice, this list of conditions and the following disclaimer in the andre@1: ** documentation and/or other materials provided with the distribution. andre@1: ** * Neither the name of the LibQxt project nor the andre@1: ** names of its contributors may be used to endorse or promote products andre@1: ** derived from this software without specific prior written permission. andre@1: ** andre@1: ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND andre@1: ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED andre@1: ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE andre@1: ** DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY andre@1: ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES andre@1: ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; andre@1: ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND andre@1: ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT andre@1: ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS andre@1: ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. andre@1: ** andre@1: ** andre@1: *****************************************************************************/ andre@1: andre@1: #define QXTCSVMODEL_H andre@1: andre@1: #include andre@1: #include andre@1: #include andre@1: #include andre@1: #include andre@1: #include andre@1: #include andre@1: #include andre@1: class QTextCodec; andre@1: andre@1: class QxtCsvModelPrivate; andre@13: class QxtCsvModel : public QAbstractTableModel andre@1: { andre@1: Q_OBJECT andre@1: public: andre@1: QxtCsvModel(QObject *parent = 0); andre@1: explicit QxtCsvModel(QIODevice *file, QObject *parent = 0, bool withHeader = false, QChar separator = ','); andre@1: explicit QxtCsvModel(const QString filename, QObject *parent = 0, bool withHeader = false, QChar separator = ','); andre@1: ~QxtCsvModel(); andre@1: andre@1: int rowCount(const QModelIndex& parent = QModelIndex()) const; andre@1: int columnCount(const QModelIndex& parent = QModelIndex()) const; andre@1: QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; andre@1: bool setData(const QModelIndex& index, const QVariant& data, int role = Qt::EditRole); andre@1: QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; andre@1: bool setHeaderData(int section, Qt::Orientation orientation, const QVariant& value, int role = Qt::DisplayRole); andre@1: void setHeaderData(const QStringList& data); andre@1: QString text(int row, int column) const; andre@1: void setText(int row, int column, const QString& value); andre@1: QString headerText(int column) const; andre@1: void setHeaderText(int column, const QString& value); andre@1: andre@1: andre@1: bool insertRow(int row, const QModelIndex& parent = QModelIndex()); andre@1: bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()); andre@1: bool removeRow(int row, const QModelIndex& parent = QModelIndex()); andre@1: bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()); andre@1: bool insertColumn(int col, const QModelIndex& parent = QModelIndex()); andre@1: bool insertColumns(int col, int count, const QModelIndex& parent = QModelIndex()); andre@1: bool removeColumn(int col, const QModelIndex& parent = QModelIndex()); andre@1: bool removeColumns(int col, int count, const QModelIndex& parent = QModelIndex()); andre@1: andre@1: void setSource(QIODevice *file, bool withHeader = false, QChar separator = ',', QTextCodec* codec = 0); andre@1: void setSource(const QString filename, bool withHeader = false, QChar separator = ',', QTextCodec* codec = 0); andre@1: andre@1: void toCSV(QIODevice *file, bool withHeader = false, QChar separator = ',', QTextCodec* codec = 0) const; andre@1: void toCSV(const QString filename, bool withHeader = false, QChar separator = ',', QTextCodec* codec = 0) const; andre@1: andre@1: enum QuoteOption { NoQuotes = 0, SingleQuote = 1, DoubleQuote = 2, BothQuotes = 3, andre@1: NoEscape = 0, TwoQuoteEscape = 4, BackslashEscape = 8, andre@1: AlwaysQuoteOutput = 16, DefaultQuoteMode = BothQuotes | BackslashEscape | AlwaysQuoteOutput }; andre@1: Q_DECLARE_FLAGS(QuoteMode, QuoteOption) andre@1: QuoteMode quoteMode() const; andre@1: void setQuoteMode(QuoteMode mode); andre@1: andre@1: Qt::ItemFlags flags(const QModelIndex& index) const; andre@1: andre@1: private: andre@1: QXT_DECLARE_PRIVATE(QxtCsvModel) andre@1: }; andre@1: Q_DECLARE_OPERATORS_FOR_FLAGS(QxtCsvModel::QuoteMode) andre@1: andre@1: #endif