Qt Model Utilities  2.0.3
A set of utilities for the model/view framework of Qt
csvmodelserialiser.h
1 /****************************************************************************\
2  Copyright 2018 Luca Beldi
3  Licensed under the Apache License, Version 2.0 (the "License");
4  you may not use this file except in compliance with the License.
5  You may obtain a copy of the License at
6  http://www.apache.org/licenses/LICENSE-2.0
7  Unless required by applicable law or agreed to in writing, software
8  distributed under the License is distributed on an "AS IS" BASIS,
9  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10  See the License for the specific language governing permissions and
11  limitations under the License.
12 \****************************************************************************/
13 
14 #ifndef CSVMODELSERIALISER_H
15 #define CSVMODELSERIALISER_H
16 
17 #include "abstractsingleroleserialiser.h"
18 class CsvModelSerialiserPrivate;
19 class QTextStream;
20 class MODELUTILITIES_EXPORT CsvModelSerialiser : public AbstractSingleRoleSerialiser
21 {
22  Q_OBJECT
23  Q_PROPERTY(QString csvSeparator READ csvSeparator WRITE setCsvSeparator)
24  Q_PROPERTY(bool firstRowIsHeader READ firstRowIsHeader WRITE setFirstRowIsHeader)
25  Q_PROPERTY(bool firstColumnIsHeader READ firstColumnIsHeader WRITE setFirstColumnIsHeader)
26  Q_DECLARE_PRIVATE(CsvModelSerialiser)
27  Q_DISABLE_COPY(CsvModelSerialiser)
28 public:
29  explicit CsvModelSerialiser(QObject *parent = Q_NULLPTR);
30  CsvModelSerialiser(QAbstractItemModel *model, QObject *parent);
31  CsvModelSerialiser(const QAbstractItemModel *model, QObject *parent);
32  const QString &csvSeparator() const;
33  void setCsvSeparator(const QString &val);
34  bool firstRowIsHeader();
35  bool firstColumnIsHeader();
36  void setFirstRowIsHeader(bool val);
37  void setFirstColumnIsHeader(bool val);
38  virtual bool saveModel(QTextStream &stream) const;
39  bool saveModel(QIODevice *destination) const Q_DECL_OVERRIDE;
40  bool saveModel(QByteArray *destination) const Q_DECL_OVERRIDE;
41  bool saveModel(QString *destination) const Q_DECL_OVERRIDE;
42  bool loadModel(QString *source) Q_DECL_OVERRIDE;
43  bool loadModel(QIODevice *source) Q_DECL_OVERRIDE;
44  bool loadModel(const QByteArray &source) Q_DECL_OVERRIDE;
45  virtual bool loadModel(QTextStream &stream);
46 
47 protected:
48  CsvModelSerialiser(CsvModelSerialiserPrivate &d, QObject *parent);
49 
50 #ifdef MS_DECLARE_STREAM_OPERATORS
51  friend QTextStream &operator<<(QTextStream &stream, const QAbstractItemModel &model);
52  friend QTextStream &operator>>(QTextStream &stream, QAbstractItemModel &model);
53 #endif
54 };
55 #ifdef MS_DECLARE_STREAM_OPERATORS
56 QTextStream &operator<<(QTextStream &stream, const QAbstractItemModel &model);
57 QTextStream &operator>>(QTextStream &stream, QAbstractItemModel &model);
58 #endif
59 #endif // CSVMODELSERIALISER_H
The interface for model serialisers saving only one role.
Definition: abstractsingleroleserialiser.h:20
virtual Q_INVOKABLE bool saveModel(QString *destination) const =0
virtual Q_INVOKABLE bool loadModel(QString *source)=0
Serialiser to save and load models in csv (comma separated values) format.
Definition: csvmodelserialiser.h:21