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

Description

Definition at line 27 of file InstrumentCollection.h.

Public Member Functions

 ~InstrumentCollection ()
 
template<typename T >
T * addInstrument ()
 
void clear ()
 
QVector< InstrumentItem * > collectedItems () const
 
void emplace_back (InstrumentItem *item)
 
InstrumentItemfindInstrumentById (const QString &instrumentId) const
 
InstrumentIteminsertCopy (const InstrumentItem &source)
 Inserts a deep copy (also of any non xml data in a pointwise axis) The id will not be copied, but a new unique one will be created Returns the newly created instrument. More...
 
QVector< Instrument2DItem * > instrument2DItems () const
 
bool instrumentExists (const QString &instrumentId) const
 
QVector< InstrumentItem * > instrumentItems (const std::function< bool(const InstrumentItem *)> &accept) const
 
QStringList instrumentNames () const
 
void removeInstrument (InstrumentItem *instrument)
 
void serialize (Streamer &s)
 
QString suggestInstrumentName (const QString &baseName) const
 

Private Attributes

QVector< InstrumentItem * > m_instruments
 

Constructor & Destructor Documentation

◆ ~InstrumentCollection()

InstrumentCollection::~InstrumentCollection ( )

Definition at line 22 of file InstrumentCollection.cpp.

23 {
24  qDeleteAll(m_instruments);
25 }
QVector< InstrumentItem * > m_instruments

References m_instruments.

Member Function Documentation

◆ addInstrument()

template<typename T >
T* InstrumentCollection::addInstrument ( )
inline

Definition at line 32 of file InstrumentCollection.h.

33  {
34  auto* t = new T();
35  m_instruments << t;
36  return t;
37  }

References m_instruments.

Referenced by InstrumentsEditController::addInstrument().

◆ clear()

void InstrumentCollection::clear ( )

Definition at line 27 of file InstrumentCollection.cpp.

28 {
29  qDeleteAll(m_instruments);
30  m_instruments.clear();
31 }

References m_instruments.

Referenced by InstrumentLibrary::load().

◆ collectedItems()

◆ emplace_back()

void InstrumentCollection::emplace_back ( InstrumentItem item)
inline

Definition at line 44 of file InstrumentCollection.h.

44 { m_instruments.push_back(item); } // TODO Qt6 emplace

References m_instruments.

Referenced by GUI::Transform::FromCore::itemizeInstruments().

◆ findInstrumentById()

InstrumentItem * InstrumentCollection::findInstrumentById ( const QString &  instrumentId) const

Definition at line 86 of file InstrumentCollection.cpp.

87 {
88  for (auto* instrument : collectedItems())
89  if (instrument->id() == instrumentId)
90  return instrument;
91 
92  return nullptr;
93 }
QVector< InstrumentItem * > collectedItems() const

References collectedItems().

Referenced by LinkInstrumentManager::canLinkDataToInstrument(), instrumentExists(), and RealDataPropertiesWidget::onInstrumentComboIndexChanged().

Here is the call graph for this function:

◆ insertCopy()

InstrumentItem * InstrumentCollection::insertCopy ( const InstrumentItem source)

Inserts a deep copy (also of any non xml data in a pointwise axis) The id will not be copied, but a new unique one will be created Returns the newly created instrument.

Definition at line 39 of file InstrumentCollection.cpp.

40 {
41  auto* copy = source.createCopy();
42  copy->setId(QUuid::createUuid().toString());
43  m_instruments << copy;
44  return copy;
45 }
InstrumentItem * createCopy() const
Creates an exact copy; also ID is the same!
void setId(const QString &id)
QString toString(const QModelIndex &index)
Provides string representation of index data.

References InstrumentItem::createCopy(), m_instruments, InstrumentItem::setId(), and GUI::View::PropertyEditorFactory::toString().

Referenced by InstrumentsEditController::addCopy().

Here is the call graph for this function:

◆ instrument2DItems()

QVector< Instrument2DItem * > InstrumentCollection::instrument2DItems ( ) const

Definition at line 76 of file InstrumentCollection.cpp.

77 {
78  QVector<Instrument2DItem*> result;
79  for (auto* p : collectedItems())
80  if (auto* p2D = dynamic_cast<Instrument2DItem*>(p))
81  result << p2D;
82 
83  return result;
84 }

References collectedItems().

Here is the call graph for this function:

◆ instrumentExists()

bool InstrumentCollection::instrumentExists ( const QString &  instrumentId) const

Definition at line 95 of file InstrumentCollection.cpp.

96 {
97  return findInstrumentById(instrumentId) != nullptr;
98 }
InstrumentItem * findInstrumentById(const QString &instrumentId) const

References findInstrumentById().

Referenced by LinkInstrumentManager::onInstrumentAddedOrRemoved().

Here is the call graph for this function:

◆ instrumentItems()

QVector< InstrumentItem * > InstrumentCollection::instrumentItems ( const std::function< bool(const InstrumentItem *)> &  accept) const

Definition at line 65 of file InstrumentCollection.cpp.

67 {
68  QVector<InstrumentItem*> result;
69  for (auto* p : collectedItems())
70  if (accept(p))
71  result << p;
72 
73  return result;
74 }

References collectedItems().

Referenced by InstrumentsTreeModel::instruments().

Here is the call graph for this function:

◆ instrumentNames()

QStringList InstrumentCollection::instrumentNames ( ) const

Definition at line 52 of file InstrumentCollection.cpp.

53 {
54  QStringList existingNames;
55  for (const auto* item : collectedItems())
56  existingNames << item->instrumentName();
57  return existingNames;
58 }

References collectedItems().

Referenced by suggestInstrumentName(), and SimulationView::writeOptionsToUI().

Here is the call graph for this function:

◆ removeInstrument()

void InstrumentCollection::removeInstrument ( InstrumentItem instrument)

Definition at line 100 of file InstrumentCollection.cpp.

101 {
102  m_instruments.removeAll(instrument);
103  delete instrument;
104 }

References m_instruments.

Referenced by InstrumentsEditController::removeInstrument(), and InstrumentsTreeModel::removeItem().

◆ serialize()

void InstrumentCollection::serialize ( Streamer s)

Definition at line 33 of file InstrumentCollection.cpp.

34 {
35  s.assertVersion(0);
36  Serialize::rwCatalogized<InstrumentItemCatalog>(s, "InstrumentCollection", m_instruments);
37 }
void assertVersion(unsigned expectedVersion) const
As reader, throws DeserializationException unless the expected version is read. As writer,...
Definition: Streamer.cpp:26

References Streamer::assertVersion(), and m_instruments.

Referenced by InstrumentLibrary::load(), ProjectDocument::readProject(), InstrumentLibrary::saveIfModified(), and ProjectDocument::writeTo().

Here is the call graph for this function:

◆ suggestInstrumentName()

QString InstrumentCollection::suggestInstrumentName ( const QString &  baseName) const

Definition at line 60 of file InstrumentCollection.cpp.

61 {
63 }
QStringList instrumentNames() const
QString baseName(const QString &fileName)
Returns base name of file.
Definition: Path.cpp:133
QString suggestName(const QStringList &existingNames, const QString &name)
Returns a name suggestion based on the given name.
Definition: String.cpp:26

References GUI::Util::Path::baseName(), instrumentNames(), and GUI::Util::String::suggestName().

Referenced by InstrumentListModel::addNewInstrument(), InstrumentListModel::copyInstrument(), and InstrumentLibrary::suggestName().

Here is the call graph for this function:

Member Data Documentation

◆ m_instruments

QVector<InstrumentItem*> InstrumentCollection::m_instruments
private

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