All pastes #419078 Raw Edit

ahigerd

public cpp v1 · immutable
·published 2007-04-01 01:10 UTC
rendered paste body
/*************************************************************************** *   Copyright (C) 2005 by Adam Higerd                                     * *   ahigerd@stratitec.com                                                 * *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * *   This program is distributed in the hope that it will be useful,       * *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * *   GNU General Public License for more details.                          * *                                                                         * *   You should have received a copy of the GNU General Public License     * *   along with this program; if not, write to the                         * *   Free Software Foundation, Inc.,                                       * *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * ***************************************************************************/#ifndef CSVMODEL_H#define CSVMODEL_H#include <QAbstractTableModel>#include <QVariant>#include <QIODevice>#include <QChar>#include <QString>#include <QStringList>#include <QModelIndex>/**@author Adam Higerd*/class CSVModel : public QAbstractTableModel{Q_OBJECTpublic:    CSVModel(QObject *parent = 0);    CSVModel(QIODevice *file, QObject *parent = 0, bool withHeader = false, QChar separator = ',');    CSVModel(const QString filename, QObject *parent = 0, bool withHeader = false, QChar separator = ',');    ~CSVModel();    int rowCount(const QModelIndex& parent = QModelIndex()) const;    int columnCount(const QModelIndex& parent = QModelIndex()) const;    QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;    bool setData(const QModelIndex& index, const QVariant& data, int role = Qt::EditRole);    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;    void setHeaderData(const QStringList data);    bool insertRow(int row, const QModelIndex& parent = QModelIndex());    bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex());    bool removeRow(int row, const QModelIndex& parent = QModelIndex());    bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());    bool insertColumn(int col, const QModelIndex& parent = QModelIndex());    bool insertColumns(int col, int count, const QModelIndex& parent = QModelIndex());    bool removeColumn(int col, const QModelIndex& parent = QModelIndex());    bool removeColumns(int col, int count, const QModelIndex& parent = QModelIndex());    void setSource(QIODevice *file, bool withHeader = false, QChar separator = ',');    void setSource(const QString filename, bool withHeader = false, QChar separator = ',');    void toCSV(QIODevice *file, bool withHeader = false, QChar separator = ',');    void toCSV(const QString filename, bool withHeader = false, QChar separator = ',');    Qt::ItemFlags flags(const QModelIndex& index) const;protected:    QIODevice* csvFile;    QStringList csvData;    QStringList header;    int maxColumn;};#endif