Qt Model Utilities  2.0.3
A set of utilities for the model/view framework of Qt
jsonmodelserialiser.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 JSONMODELSERIALISER_H
15 #define JSONMODELSERIALISER_H
16 
17 #include "abstractstringserialiser.h"
18 #include <QJsonObject>
19 #include <QJsonDocument>
20 class JsonModelSerialiserPrivate;
21 class MODELUTILITIES_EXPORT JsonModelSerialiser : public AbstractStringSerialiser
22 {
23  Q_OBJECT
24  Q_DECLARE_PRIVATE(JsonModelSerialiser)
25  Q_DISABLE_COPY(JsonModelSerialiser)
26 public:
27  explicit JsonModelSerialiser(QObject *parent = Q_NULLPTR);
28  JsonModelSerialiser(QAbstractItemModel *model, QObject *parent);
29  JsonModelSerialiser(const QAbstractItemModel *model, QObject *parent);
30  bool saveModel(QIODevice *destination) const Q_DECL_OVERRIDE;
31  bool saveModel(QByteArray *destination) const Q_DECL_OVERRIDE;
32  bool saveModel(QString *destination) const Q_DECL_OVERRIDE;
33  Q_INVOKABLE virtual QJsonObject toJsonObject() const;
34  bool loadModel(QIODevice *source) Q_DECL_OVERRIDE;
35  bool loadModel(const QByteArray &source) Q_DECL_OVERRIDE;
36  bool loadModel(QString *source) Q_DECL_OVERRIDE;
37  Q_INVOKABLE virtual bool fromJsonObject(const QJsonObject &source);
38  Q_INVOKABLE QJsonDocument::JsonFormat format() const;
39 public Q_SLOTS:
40  void setFormat(QJsonDocument::JsonFormat val);
41 
42 protected:
43  JsonModelSerialiser(JsonModelSerialiserPrivate &d, QObject *parent);
44 };
45 #endif // JSONMODELSERIALISER_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 JSON format.
Definition: jsonmodelserialiser.h:22