BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
InstrumentsEditController.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Device/InstrumentsEditController.h
6 //! @brief Defines class InstrumentsEditController
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTSEDITCONTROLLER_H
16 #define BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTSEDITCONTROLLER_H
17 
19 #include <QObject>
20 
22 class InstrumentItem;
23 class RealDataItem;
24 
25 //! Class to modify the instruments list or a single instrument and provide the necessary signaling
26 //! within BornAgain.
27 //!
28 //! An instance of this class is held in the project document (ProjectDocument). Whenever you want
29 //! to modify instruments of the current project, use this instance to ensure proper signaling of
30 //! changes. If you change an instrument without using any method in this class, you have to notify
31 //! this class about the modification by calling notifyInstrumentChanged.
32 //!
33 //! If you want to be notified about any changes of instruments in the current project, listen to
34 //! the signals of this instance.
35 //!
36 //! For uses other than the instruments in the current project (like e.g. for the instruments
37 //! library), you can create a dedicated instance and handle the instrument collection in question
38 //! with this separate instance.
39 
40 class InstrumentsEditController : public QObject {
41  Q_OBJECT
42 
43 public:
45 
46  //! The list of existing instruments.
48 
49  //! Add an instrument and emit the respective signal.
50  template <typename T>
51  T* addInstrument();
52 
53  //! Add an instrument and emit the respective signal.
54  void removeInstrument(InstrumentItem* instrument);
55 
56  //! Copy an instrument, set its name and emit the respective signal.
57  InstrumentItem* addCopy(const InstrumentItem* instrument, const QString& name);
58 
59  //! Set an instrument's name and emit the respective signal.
60  void setInstrumentName(InstrumentItem* instrument, const QString& name);
61 
62  //! Calls the instrument's updateToRealData and emits the respective signal.
64  const RealDataItem* realDataItem);
65 
66  //! Simply emits the instrumentChanged signal. Call this whenever you change an instrument's
67  //! data without using this edit controller. By calling this method, the listeners will be
68  //! notified about the changes.
69  void notifyInstrumentChanged(InstrumentItem* instrument);
70 
71 signals:
72  //! Signals a change in the list of instruments.
74 
75  //! Signals any change in the settings of the given instrument.
76  //!
77  //! Signals also a name change, which has its own additional signal
78  void instrumentChanged(const InstrumentItem* instrument);
79 
80  //! Signals name change of the given instrument.
81  //!
82  //! In addition to this, instrumentChanged() will be emitted as well.
83  void instrumentNameChanged(const InstrumentItem* instrument);
84 
85 private:
86  InstrumentCollection* m_instruments; //!< The edited/controlled instruments. This pointer is
87  //!< borrowed, not owned.
88 };
89 
90 template <typename T>
92 {
93  auto* t = m_instruments->addInstrument<T>();
95  return t;
96 }
97 
98 #endif // BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTSEDITCONTROLLER_H
Defines class InstrumentCollection.
Abstract base class for instrument-specific item classes.
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 instrumentNameChanged(const InstrumentItem *instrument)
Signals name change of the given instrument.
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.
void notifyInstrumentChanged(InstrumentItem *instrument)
Simply emits the instrumentChanged signal. Call this whenever you change an instrument's data without...
void setInstrumentName(InstrumentItem *instrument, const QString &name)
Set an instrument's name and emit the respective signal.
void removeInstrument(InstrumentItem *instrument)
Add an instrument and emit the respective signal.
InstrumentsEditController(InstrumentCollection *instruments)
InstrumentCollection * collectedItems()
The list of existing instruments.
void updateInstrumentToRealDataItem(InstrumentItem *instrument, const RealDataItem *realDataItem)
Calls the instrument's updateToRealData and emits the respective signal.
T * addInstrument()
Add an instrument and emit the respective signal.
InstrumentCollection * m_instruments
The edited/controlled instruments. This pointer is borrowed, not owned.
Provides access to experimental data, for display and fitting. Owns an AbstractDataLoader.
Definition: RealDataItem.h:33
QString const & name(EShape k)
Definition: particles.cpp:20