Seamly2D
Code documentation
qxtcsvmodel.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (c) 2006 - 2011, the LibQxt project.
3 ** See the Qxt AUTHORS file for a list of authors and copyright holders.
4 ** All rights reserved.
5 **
6 ** Redistribution and use in source and binary forms, with or without
7 ** modification, are permitted provided that the following conditions are met:
8 ** * Redistributions of source code must retain the above copyright
9 ** notice, this list of conditions and the following disclaimer.
10 ** * Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
13 ** * Neither the name of the LibQxt project nor the
14 ** names of its contributors may be used to endorse or promote products
15 ** derived from this software without specific prior written permission.
16 **
17 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 ** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
21 ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 **
28 ** <http://libqxt.org> <foundation@libqxt.org>
29 *****************************************************************************/
30 
31 #ifndef QXTCSVMODEL_H
32 #define QXTCSVMODEL_H
33 
34 #include <qcompilerdetection.h>
35 #include <QAbstractTableModel>
36 #include <QChar>
37 #include <QFlags>
38 #include <QIODevice>
39 #include <QIncompatibleFlag>
40 #include <QMetaObject>
41 #include <QModelIndex>
42 #include <QObject>
43 #include <QString>
44 #include <QStringList>
45 #include <QVariant>
46 #include <Qt>
47 #include <QtGlobal>
48 
49 #include "def.h"
50 
51 class QxtCsvModelPrivate;
52 
53 class QxtCsvModel : public QAbstractTableModel
54 {
55  Q_OBJECT
56 public:
57  explicit QxtCsvModel(QObject *parent = nullptr);
58  explicit QxtCsvModel(QIODevice *file, QObject *parent = nullptr, bool withHeader = false, QChar separator = ',');
59  explicit QxtCsvModel(const QString &filename, QObject *parent = nullptr, bool withHeader = false,
60  QChar separator = ',');
61  virtual ~QxtCsvModel() Q_DECL_EQ_DEFAULT;
62 
63  virtual int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
64  virtual int columnCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
65  virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
66  virtual bool setData(const QModelIndex& index, const QVariant& data, int role = Qt::EditRole) Q_DECL_OVERRIDE;
67  virtual QVariant headerData(int section, Qt::Orientation orientation,
68  int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
69  virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant& value,
70  int role = Qt::DisplayRole) Q_DECL_OVERRIDE;
71  void setHeaderData(const QStringList& data);
72 
73  QString text(int row, int column) const;
74  void setText(int row, int column, const QString& value);
75 
76  QString headerText(int column) const;
77  void setHeaderText(int column, const QString& value);
78 
79 
80  bool insertRow(int row, const QModelIndex& parent = QModelIndex());
81  virtual bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) Q_DECL_OVERRIDE;
82 
83  bool removeRow(int row, const QModelIndex& parent = QModelIndex());
84  virtual bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) Q_DECL_OVERRIDE;
85 
86  bool insertColumn(int col, const QModelIndex& parent = QModelIndex());
87  virtual bool insertColumns(int col, int count, const QModelIndex& parent = QModelIndex()) Q_DECL_OVERRIDE;
88 
89  bool removeColumn(int col, const QModelIndex& parent = QModelIndex());
90  virtual bool removeColumns(int col, int count, const QModelIndex& parent = QModelIndex()) Q_DECL_OVERRIDE;
91 
92  void setSource(QIODevice *file, bool withHeader = false, QChar separator = ',', QTextCodec* codec = nullptr);
93  void setSource(const QString &filename, bool withHeader = false, QChar separator = ',',
94  QTextCodec* codec = nullptr);
95 
96  void toCSV(QIODevice *file, bool withHeader = false, QChar separator = ',', QTextCodec* codec = nullptr) const;
97  void toCSV(const QString &filename, bool withHeader = false, QChar separator = ',',
98  QTextCodec* codec = nullptr) const;
99 
100  enum QuoteOption { NoQuotes = 0,
104  NoEscape = 0,
109  Q_DECLARE_FLAGS(QuoteMode, QuoteOption)
110 
111  QuoteMode quoteMode() const;
112  void setQuoteMode(QuoteMode mode);
113 
114  virtual Qt::ItemFlags flags(const QModelIndex& index) const Q_DECL_OVERRIDE;
115 
116 private:
117  Q_DISABLE_COPY(QxtCsvModel)
119 };
120 Q_DECLARE_OPERATORS_FOR_FLAGS(QxtCsvModel::QuoteMode)
121 
122 #endif // QXTCSVMODEL_H
The QxtCsvModel class provides a QAbstractTableModel for CSV Files.
Definition: qxtcsvmodel.h:54
virtual bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex()) Q_DECL_OVERRIDE
\reimp
void setText(int row, int column, const QString &value)
Sets the content of the cell at row row and column column to value.
bool insertColumn(int col, const QModelIndex &parent=QModelIndex())
\reimp
void setHeaderText(int column, const QString &value)
Sets the content of the header for column column to value.
QString headerText(int column) const
Fetches the content of the cell at row row and column column.
bool removeColumn(int col, const QModelIndex &parent=QModelIndex())
\reimp
virtual bool insertColumns(int col, int count, const QModelIndex &parent=QModelIndex()) Q_DECL_OVERRIDE
\reimp
virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::DisplayRole) Q_DECL_OVERRIDE
\reimp
void setSource(QIODevice *file, bool withHeader=false, QChar separator=',', QTextCodec *codec=nullptr)
Reads in a CSV file from the provided file using codec.
bool removeRow(int row, const QModelIndex &parent=QModelIndex())
\reimp
QuoteMode quoteMode() const
Returns the current quoting mode.
virtual Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE
\reimp
virtual ~QxtCsvModel() Q_DECL_EQ_DEFAULT
bool insertRow(int row, const QModelIndex &parent=QModelIndex())
\reimp
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const Q_DECL_OVERRIDE
\reimp
void setQuoteMode(QuoteMode mode)
Sets the current quoting mode.
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const Q_DECL_OVERRIDE
\reimp
virtual bool removeColumns(int col, int count, const QModelIndex &parent=QModelIndex()) Q_DECL_OVERRIDE
\reimp
virtual bool setData(const QModelIndex &index, const QVariant &data, int role=Qt::EditRole) Q_DECL_OVERRIDE
\reimp
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const Q_DECL_OVERRIDE
\reimp
QString text(int row, int column) const
Fetches the content of the cell at row row and column column.
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const Q_DECL_OVERRIDE
\reimp
void toCSV(QIODevice *file, bool withHeader=false, QChar separator=',', QTextCodec *codec=nullptr) const
Outputs the content of the model as a CSV file to the device dest using codec.
QxtCsvModel(QObject *parent=nullptr)
Creates an empty QxtCsvModel with parent parent.
Definition: qxtcsvmodel.cpp:68
virtual bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) Q_DECL_OVERRIDE
\reimp
#define QXT_DECLARE_PRIVATE(PUB)
Definition: def.h:541