21 #include <QXmlStreamWriter>
25 const QString XML_ROOT_TAG =
"BornAgainInstrumentLibrary";
26 const QString XML_VERSION_TAG =
"Version";
28 QString instrumentLibraryFilePath()
37 : m_ec(&m_instrumentItems)
76 QFile file(instrumentLibraryFilePath());
77 if (!file.open(QFile::ReadWrite | QIODevice::Truncate | QFile::Text))
80 QXmlStreamWriter writer(&file);
81 writer.setAutoFormatting(
true);
82 writer.writeStartDocument();
83 writer.writeStartElement(XML_ROOT_TAG);
84 writer.writeAttribute(XML_VERSION_TAG,
"2");
89 writer.writeEndElement();
90 writer.writeEndDocument();
102 QFile file(instrumentLibraryFilePath());
103 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
107 QXmlStreamReader reader(&file);
109 while (!reader.atEnd()) {
111 if (reader.isStartElement()) {
112 if (reader.name() == XML_ROOT_TAG) {
113 const int foundVersion =
114 reader.attributes().value(XML_VERSION_TAG).toString().toInt();
115 if (foundVersion != 2)
124 if (reader.hasError()) {
131 }
catch (
const std::exception&) {
Defines class DeserializationException.
Defines class InstrumentItem and all its children.
Defines class InstrumentLibrary.
Defines class Helpers functions.
void serialize(Streamer &s)
QVector< InstrumentItem * > collectedItems() const
QString suggestInstrumentName(const QString &baseName) const
Abstract base class for instrument-specific item classes.
InstrumentsEditController * editController()
InstrumentItem * add(const QString &name, const InstrumentItem &itemToCopy)
Returns the new element.
QString suggestName(const QString &name) const
InstrumentCollection m_instrumentItems
InstrumentsEditController m_ec
QList< InstrumentItem * > collectedItems() const
Class to modify the instruments list or a single instrument and provide the necessary signaling withi...
InstrumentItem * addCopy(const InstrumentItem *instrument, const QString &name)
Copy an instrument, set its name and emit the respective signal.
void instrumentAddedOrRemoved()
Signals a change in the list of instruments.
void instrumentChanged(const InstrumentItem *instrument)
Signals any change in the settings of the given instrument.
Supports serialization to or deserialization from QXmlStream.
QString const & name(EShape k)
QString appDataFolder()
The folder where persistent application data shall be stored. Under Windows this is the AppData/Roami...