-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCircuitFileParser.h
84 lines (65 loc) · 3.11 KB
/
CircuitFileParser.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
#ifndef CIRCUITFILEPARSER_H
#define CIRCUITFILEPARSER_H
#include "RuntimeConfigParser.h"
#include <QFile>
#include <QFileInfo>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QCborMap>
///
/// \brief The CircuitFileParser handles all circuit file loading and saving operations
///
class CircuitFileParser : public QObject
{
Q_OBJECT
public:
/// \brief Constructor for the CircuitFileParser
/// \param pRuntimeConfigParser: Reference to the runtime config parser
CircuitFileParser(RuntimeConfigParser& pRuntimeConfigParser);
/// \brief Load the circuit in the given file
/// \param pFileInfo: The file to load
/// \param pIsFromRecents: Whether the file to open is from the recent files list
void LoadJson(const QFileInfo& pFileInfo, bool pIsFromRecents = false);
/// \brief Saves the circuit to current file
/// \param pJson: The JSON to save into the file
void SaveJson(const QJsonObject& pJson);
/// \brief Saves the circuit to the given file
/// \param pFileInfo: The file to save into
/// \param pJson: The JSON to save into the file
void SaveJsonAs(const QFileInfo& pFileInfo, const QJsonObject& pJson);
void ResetCurrentFileInfo(void);
/// \brief Returns true, if there is a known file path to save the current circuit into
/// \return True, if there is a known file path to save the current circuit into
bool IsFileOpen(void) const;
/// \brief Getter for the current file info, if it exists
/// \return The current file info, if it exists
std::optional<QFileInfo> GetFileInfo(void) const;
/// \brief Returns true, if the circuit has been modified after the last save or load
/// \return True, if the circuit has been modified after the last save or load
bool IsCircuitModified(void) const;
/// \brief Emits a signal if the circuit is newly modified
void MarkAsModified(void);
signals:
/// \brief Emitted when a circuit file has been opened successfully
/// \param pFileInfo: Info about the opened file
/// \param pJson: The file content as a QJsonObject reference
void LoadCircuitFileSuccessSignal(const QFileInfo& pFileInfo, const QJsonObject& pJson);
/// \brief Emitted when a circuit file could not be opened
/// \param pFileInfo: Info about the file
/// \param pIsFromRecents: Whether the file is from the recent files list
void LoadCircuitFileFailedSignal(const QFileInfo& pFileInfo, bool pIsFromRecents);
/// \brief Emitted when a circuit file has been saved successfully
/// \param pFileInfo: Info about the saved file
void SaveCircuitFileSuccessSignal(const QFileInfo& pFileInfo);
/// \brief Emitted when a circuit file could not be saved
/// \param pFileInfo: Info about the file
void SaveCircuitFileFailedSignal(const QFileInfo& pFileInfo);
/// \brief Emitted when the circuit goes from an unmodified (saved or empty) to a modified (unsaved) state
void CircuitModifiedSignal(void);
protected:
std::optional<QFileInfo> mCurrentFile;
bool mIsCircuitModified;
RuntimeConfigParser& mRuntimeConfigParser;
};
#endif // CIRCUITFILEPARSER_H