-
Notifications
You must be signed in to change notification settings - Fork 4
/
documentio.h
57 lines (42 loc) · 1.29 KB
/
documentio.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef _DOCUMENTIO_H_
#define _DOCUMENTIO_H_
#include <QVariant>
class Document;
typedef QMap<QString, QVariant> VariantMap;
typedef QList<QVariant> VariantList;
class DocumentIo
{
public:
DocumentIo(Document *doc);
virtual ~DocumentIo();
QVariant save(QString &error);
bool load(const QVariant &data, QString &error);
virtual int version() const = 0;
virtual QVariant serialize(QString &error) const = 0;
virtual bool deserialize(const VariantMap &data, QString &error) = 0;
protected:
Document *document_;
};
class DocumentIoV1 : public DocumentIo
{
public:
DocumentIoV1(Document *doc);
~DocumentIoV1();
int version() const { return 1; }
QVariant serialize(QString &error) const;
bool deserialize(const VariantMap &data, QString &error);
private:
VariantList serializeColors(QString &error) const;
VariantList serializeStitches(QString &error) const;
bool deserializeStitches(const VariantList &list, QString &error);
};
class DocumentFactory
{
public:
static DocumentIo* defaultSerializer(Document *d);
static Document* load(const QString &path, QString &error);
static Document* load(const QImage &image, ColorManager *manager,
int width, const QColor *transparentColor);
static bool save(Document *doc, const QString &path, QString &error);
};
#endif