-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathqcpl_io_json.h
121 lines (102 loc) · 3.89 KB
/
qcpl_io_json.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#ifndef QCPL_IO_JSON_H
#define QCPL_IO_JSON_H
#include <QString>
#include <QPen>
class QCPAxis;
class QCPColorScale;
class QCPGraph;
class QCPLegend;
class QCPTextElement;
QT_BEGIN_NAMESPACE
class QJsonObject;
QT_END_NAMESPACE
namespace QCPL {
class Plot;
struct JsonError
{
enum { OK, NoData, BadVersion } code = OK;
QString message;
bool ok() const { return code == OK; }
};
using JsonReport = QVector<JsonError>;
struct WritePlotOptions
{
bool onlyPrimaryAxes = true;
};
QJsonObject writePlot(Plot *plot, const WritePlotOptions& opts = WritePlotOptions());
QJsonObject writeLegend(QCPLegend* legend);
QJsonObject writeTitle(QCPTextElement* title);
QJsonObject writeAxis(QCPAxis *axis);
QJsonObject writeColorScale(QCPColorScale *scale);
QJsonObject writeGraph(QCPGraph * graph);
QJsonObject writePen(const QPen& pen);
struct ReadPlotOptions
{
bool autoCreateAxes = false;
};
void readPlot(const QJsonObject& root, Plot *plot, JsonReport* report, const ReadPlotOptions& opts = ReadPlotOptions());
JsonError readLegend(const QJsonObject &obj, QCPLegend* legend);
JsonError readTitle(const QJsonObject &obj, QCPTextElement* title);
JsonError readAxis(const QJsonObject &obj, QCPAxis* axis);
JsonError readColorScale(const QJsonObject &obj, QCPColorScale *scale);
JsonError readGraph(const QJsonObject &obj, QCPGraph * graph);
QPen readPen(const QJsonObject& obj, const QPen& def);
/**
Allows a plot to store default view format of its elements.
The view format is fonts and colors of axes, of legend, etc.
Make an object of derived class and assign to the Plot::formatSaver field.
*/
class FormatSaver
{
public:
virtual ~FormatSaver() {}
virtual void saveLegend(QCPLegend* legend) = 0;
virtual void saveTitle(QCPTextElement* title) = 0;
virtual void saveAxis(QCPAxis* axis) = 0;
virtual void saveColorScale(QCPColorScale* scale) = 0;
};
/**
Default implementation of FormatSaver that stores plot format
in local INI settings as JSON strings.
*/
class FormatStorageIni: public FormatSaver
{
public:
void save(Plot* plot);
void load(Plot* plot, JsonReport *report);
void saveLegend(QCPLegend* legend) override;
void saveTitle(QCPTextElement* title) override;
void saveAxis(QCPAxis* axis) override;
void saveColorScale(QCPColorScale* scale) override;
};
/**
Loads plot format settings from file and returns empty string when succeeded.
If error message is returned this means settings have not beed read and plot unchanged.
Non critical warnings can be optional put in the report object and later shown in app log.
Suggesting there errors are rare,
we don't support localization here and return user readable message in common language.
*/
QString loadFormatFromFile(const QString& fileName, Plot *plot, JsonReport* report, const ReadPlotOptions& opts = ReadPlotOptions());
/**
Saves plot format settings to file and returns empty string when succeeded.
Suggesting there errors are rare,
we don't support localization here and return user readable message in common language.
*/
QString saveFormatToFile(const QString& fileName, Plot *plot, const WritePlotOptions& opts = WritePlotOptions());
void copyPlotFormat(Plot* plot);
void copyLegendFormat(QCPLegend* legend);
void copyTitleFormat(QCPTextElement* title);
void copyAxisFormat(QCPAxis* axis);
void copyColorScaleFormat(QCPColorScale* scale);
void copyGraphFormat(QCPGraph* graph);
// These commands are for context menus and hence should be invoked on visible elements.
// It's not expected that element gets hidden when its format pasted
// so the functions don't change visibility
QString pastePlotFormat(Plot* plot);
QString pasteLegendFormat(QCPLegend* legend);
QString pasteTitleFormat(QCPTextElement* title);
QString pasteAxisFormat(QCPAxis* axis);
QString pasteColorScaleFormat(QCPColorScale* scale);
QString pasteGraphFormat(QCPGraph* graph);
} // namespace QCPL
#endif // QCPL_IO_JSON_H