BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
InstrumentLibrary Class Reference

Description

Definition at line 21 of file InstrumentLibrary.h.

Collaboration diagram for InstrumentLibrary:
[legend]

Public Member Functions

 InstrumentLibrary ()
 
InstrumentItemadd (const QString &name, const InstrumentItem &itemToCopy)
 Returns the new element. More...
 
InstrumentCollectioncollectedItems ()
 
QList< InstrumentItem * > collectedItems () const
 
InstrumentsEditControllereditController ()
 
bool isEmpty () const
 
bool load ()
 
bool saveIfModified ()
 
QString suggestName (const QString &name) const
 

Private Attributes

InstrumentsEditController m_ec
 
InstrumentCollection m_instrumentItems
 
bool m_modified
 

Constructor & Destructor Documentation

◆ InstrumentLibrary()

InstrumentLibrary::InstrumentLibrary ( )

Definition at line 36 of file InstrumentLibrary.cpp.

38  , m_modified(false)
39 {
41  [&]() { m_modified = true; });
43  [&]() { m_modified = true; });
44 }
InstrumentCollection m_instrumentItems
InstrumentsEditController m_ec
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.

References InstrumentsEditController::instrumentAddedOrRemoved(), InstrumentsEditController::instrumentChanged(), m_ec, and m_modified.

Member Function Documentation

◆ add()

InstrumentItem * InstrumentLibrary::add ( const QString &  name,
const InstrumentItem itemToCopy 
)

Returns the new element.

Definition at line 51 of file InstrumentLibrary.cpp.

52 {
53  return m_ec.addCopy(&itemToCopy, name);
54 }
InstrumentItem * addCopy(const InstrumentItem *instrument, const QString &name)
Copy an instrument, set its name and emit the respective signal.
QString const & name(EShape k)
Definition: particles.cpp:20

References InstrumentsEditController::addCopy(), m_ec, and GUI::RealSpace::Particles::name().

Referenced by InstrumentLibraryEditor::execAdd().

Here is the call graph for this function:

◆ collectedItems() [1/2]

InstrumentCollection * InstrumentLibrary::collectedItems ( )

Definition at line 140 of file InstrumentLibrary.cpp.

141 {
142  return &m_instrumentItems;
143 }

References m_instrumentItems.

◆ collectedItems() [2/2]

QList< InstrumentItem * > InstrumentLibrary::collectedItems ( ) const

Definition at line 61 of file InstrumentLibrary.cpp.

62 {
63  return m_instrumentItems.collectedItems().toList();
64 }
QVector< InstrumentItem * > collectedItems() const

References InstrumentCollection::collectedItems(), and m_instrumentItems.

Here is the call graph for this function:

◆ editController()

InstrumentsEditController * InstrumentLibrary::editController ( )

◆ isEmpty()

bool InstrumentLibrary::isEmpty ( ) const

Definition at line 56 of file InstrumentLibrary.cpp.

57 {
58  return m_instrumentItems.collectedItems().isEmpty();
59 }

References InstrumentCollection::collectedItems(), and m_instrumentItems.

Referenced by InstrumentListView::onLoadFromLibrary().

Here is the call graph for this function:

◆ load()

bool InstrumentLibrary::load ( )

Definition at line 97 of file InstrumentLibrary.cpp.

98 {
99  m_modified = false;
101 
102  QFile file(instrumentLibraryFilePath());
103  if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
104  return false;
105 
106  try {
107  QXmlStreamReader reader(&file);
108 
109  while (!reader.atEnd()) {
110  reader.readNext();
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)
116  return false;
117 
118  Streamer sInstruments(&reader);
119  m_instrumentItems.serialize(sInstruments);
120  }
121  }
122  }
123 
124  if (reader.hasError()) {
126  return false;
127  }
128 
129  file.close();
130  return true;
131  } catch (const std::exception&) {
133  return false;
134  } catch (const DeserializationException&) {
136  return false;
137  }
138 }
void serialize(Streamer &s)
Supports serialization to or deserialization from QXmlStream.
Definition: Streamer.h:36

References InstrumentCollection::clear(), m_instrumentItems, m_modified, and InstrumentCollection::serialize().

Referenced by main().

Here is the call graph for this function:

◆ saveIfModified()

bool InstrumentLibrary::saveIfModified ( )

Definition at line 71 of file InstrumentLibrary.cpp.

72 {
73  if (!m_modified)
74  return true;
75 
76  QFile file(instrumentLibraryFilePath());
77  if (!file.open(QFile::ReadWrite | QIODevice::Truncate | QFile::Text))
78  return false;
79 
80  QXmlStreamWriter writer(&file);
81  writer.setAutoFormatting(true);
82  writer.writeStartDocument();
83  writer.writeStartElement(XML_ROOT_TAG);
84  writer.writeAttribute(XML_VERSION_TAG, "2");
85 
86  Streamer sInstruments(&writer);
87  m_instrumentItems.serialize(sInstruments);
88 
89  writer.writeEndElement();
90  writer.writeEndDocument();
91 
92  file.close();
93  m_modified = false;
94  return true;
95 }

References m_instrumentItems, m_modified, and InstrumentCollection::serialize().

Referenced by main().

Here is the call graph for this function:

◆ suggestName()

QString InstrumentLibrary::suggestName ( const QString &  name) const

Definition at line 46 of file InstrumentLibrary.cpp.

47 {
49 }
QString suggestInstrumentName(const QString &baseName) const

References m_instrumentItems, GUI::RealSpace::Particles::name(), and InstrumentCollection::suggestInstrumentName().

Referenced by InstrumentLibraryEditor::execAdd().

Here is the call graph for this function:

Member Data Documentation

◆ m_ec

InstrumentsEditController InstrumentLibrary::m_ec
private

Definition at line 41 of file InstrumentLibrary.h.

Referenced by InstrumentLibrary(), add(), and editController().

◆ m_instrumentItems

InstrumentCollection InstrumentLibrary::m_instrumentItems
private

Definition at line 40 of file InstrumentLibrary.h.

Referenced by collectedItems(), isEmpty(), load(), saveIfModified(), and suggestName().

◆ m_modified

bool InstrumentLibrary::m_modified
private

Definition at line 42 of file InstrumentLibrary.h.

Referenced by InstrumentLibrary(), load(), and saveIfModified().


The documentation for this class was generated from the following files: