Qt Model Utilities  2.0.3
A set of utilities for the model/view framework of Qt
xmlmodelserialiser.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 XMLMODELSERIALISER_H
15 #define XMLMODELSERIALISER_H
16 
17 #include "abstractstringserialiser.h"
18 class XmlModelSerialiserPrivate;
19 class QXmlStreamWriter;
20 class QXmlStreamReader;
21 class MODELUTILITIES_EXPORT XmlModelSerialiser : public AbstractStringSerialiser
22 {
23  Q_OBJECT
24  Q_PROPERTY(bool printStartDocument READ printStartDocument WRITE setPrintStartDocument)
25  Q_DECLARE_PRIVATE(XmlModelSerialiser)
26  Q_DISABLE_COPY(XmlModelSerialiser)
27 public:
28  explicit XmlModelSerialiser(QObject *parent = Q_NULLPTR);
29  XmlModelSerialiser(QAbstractItemModel *model, QObject *parent);
30  XmlModelSerialiser(const QAbstractItemModel *model, QObject *parent);
32  bool printStartDocument() const;
33  void setPrintStartDocument(bool val);
34  virtual bool saveModel(QXmlStreamWriter &stream) const;
35  bool saveModel(QIODevice *destination) const Q_DECL_OVERRIDE;
36  bool saveModel(QByteArray *destination) const Q_DECL_OVERRIDE;
37  bool saveModel(QString *destination) const Q_DECL_OVERRIDE;
38  bool loadModel(QString *source) Q_DECL_OVERRIDE;
39  bool loadModel(QIODevice *source) Q_DECL_OVERRIDE;
40  bool loadModel(const QByteArray &source) Q_DECL_OVERRIDE;
41  virtual bool loadModel(QXmlStreamReader &stream);
42 
43 protected:
44  XmlModelSerialiser(XmlModelSerialiserPrivate &d, QObject *parent);
45 
46 #ifdef MS_DECLARE_STREAM_OPERATORS
47  friend QXmlStreamWriter &operator<<(QXmlStreamWriter &stream, const QAbstractItemModel &model);
48  friend QXmlStreamReader &operator>>(QXmlStreamReader &stream, QAbstractItemModel &model);
49 #endif
50 };
51 #ifdef MS_DECLARE_STREAM_OPERATORS
52 QXmlStreamWriter &operator<<(QXmlStreamWriter &stream, const QAbstractItemModel &model);
53 QXmlStreamReader &operator>>(QXmlStreamReader &stream, QAbstractItemModel &model);
54 #endif
55 #endif // XMLMODELSERIALISER_H
The interface for model serialisers saving to strings.
Definition: abstractstringserialiser.h:23
virtual Q_INVOKABLE bool saveModel(QString *destination) const =0
virtual Q_INVOKABLE bool loadModel(QString *source)=0
Serialiser to save and load models in XML format.
Definition: xmlmodelserialiser.h:22