Skip to content
Snippets Groups Projects
Commit c7401a01 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

rm DatafileEditor

parent 34ebfb6f
No related branches found
No related tags found
1 merge request!2408rm instrument linking; repair simulation (break endless loop); rename and move things
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/Data/DatafileEditor.cpp
//! @brief Implements class DatafileEditor.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2021
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#include "GUI/View/Data/DatafileEditor.h"
#include "GUI/Model/Device/DatafileItem.h"
#include "GUI/Model/Device/InstrumentsSet.h"
#include "GUI/Model/Project/LinkInstrumentManager.h"
#include "GUI/Model/Project/ProjectDocument.h"
#include "GUI/View/Tool/Globals.h"
#include <QLabel>
#include <QVBoxLayout>
DatafileEditor::DatafileEditor()
: m_instrument_combo(new QComboBox)
, m_current_datafile_item(nullptr)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
setWindowTitle("DatafileEditor");
auto* layout = new QVBoxLayout;
layout->setContentsMargins(5, 5, 5, 5);
layout->setSpacing(2);
m_instrument_combo->setToolTip("Select instrument to link with real data");
layout->addWidget(new QLabel("Linked instrument"));
layout->addWidget(m_instrument_combo);
layout->addStretch();
setLayout(layout);
updateInstrumentComboEntries();
setEnabled(false);
connect(m_instrument_combo, &QComboBox::currentIndexChanged, this,
&DatafileEditor::onInstrumentComboIndexChanged);
connect(gDoc->instruments(), &InstrumentsSet::setChanged, this,
&DatafileEditor::updateInstrumentComboEntries);
connect(gDoc->linkInstrumentManager(), &LinkInstrumentManager::linkToInstrumentChanged, this,
&DatafileEditor::updateInstrumentComboIndex);
}
void DatafileEditor::setDatafileItem(DatafileItem* dfile_item)
{
m_current_datafile_item = dfile_item;
updateInstrumentComboIndex();
setEnabled(m_current_datafile_item != nullptr);
}
void DatafileEditor::onInstrumentComboIndexChanged(int /*index*/)
{
if (!m_current_datafile_item)
return;
const QString newSelectedInstrumentId = m_instrument_combo->currentData().toString();
if (newSelectedInstrumentId == m_current_datafile_item->instrumentId())
return;
if (gDoc->linkInstrumentManager()->canLinkDataToInstrument(
m_current_datafile_item, newSelectedInstrumentId, GUI::Global::mainWindow)) {
const auto* newSelectedInstrument =
gDoc->instruments()->findInstrumentItemById(newSelectedInstrumentId);
m_current_datafile_item->linkToInstrument(newSelectedInstrument);
gDoc->setModified();
}
// If linking was impossible or denied --> set combo to previous state.
// Otherwise keep combobox updated to the current data after unlinking other data
updateInstrumentComboIndex();
emit instrumentUpdated(m_current_datafile_item);
}
//! Updates instrument selector for new instruments and their names.
//! Current selection will be preserved.
void DatafileEditor::updateInstrumentComboEntries()
{
QSignalBlocker b(m_instrument_combo);
m_instrument_combo->clear();
// fill the combo. Userdata contains instrument's uid
m_instrument_combo->addItem("Undefined", ""); // undefined instrument
for (auto* t : *gDoc->instruments())
m_instrument_combo->addItem(t->name(), t->id());
updateInstrumentComboIndex();
emit instrumentUpdated(m_current_datafile_item);
}
//! Sets instrument combo selector to the state corresponding to given instrument identifier.
void DatafileEditor::updateInstrumentComboIndex()
{
const QString instrumentId =
m_current_datafile_item != nullptr ? m_current_datafile_item->instrumentId() : "";
QSignalBlocker b(m_instrument_combo);
m_instrument_combo->setCurrentIndex(m_instrument_combo->findData(instrumentId));
}
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/Data/DatafileEditor.h
//! @brief Defines class DatafileEditor.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#ifndef BORNAGAIN_GUI_VIEW_DATA_DATAFILEEDITOR_H
#define BORNAGAIN_GUI_VIEW_DATA_DATAFILEEDITOR_H
#include <QComboBox>
#include <QWidget>
class DatafileItem;
//! For viewing and changing properties of a loaded datafile.
//!
//! Shown at the bottom of DatafilesSelector.
//!
//! Currently provides one single button, for linking the file to an instrument model.
class DatafileEditor : public QWidget {
Q_OBJECT
public:
DatafileEditor();
QSize sizeHint() const override { return {64, 135}; }
QSize minimumSizeHint() const override { return {64, 128}; }
//! Set current DatafileItem to display in instrument selector.
void setDatafileItem(DatafileItem* dfile_item);
signals:
void instrumentUpdated(DatafileItem* dfile_item);
private:
//! Processes user interaction with instrument selector combo. If there is dfile_item,
//! it will be linked with selected instrument.
void onInstrumentComboIndexChanged(int index);
void updateInstrumentComboEntries();
void updateInstrumentComboIndex();
QComboBox* m_instrument_combo;
DatafileItem* m_current_datafile_item;
};
#endif // BORNAGAIN_GUI_VIEW_DATA_DATAFILEEDITOR_H
......@@ -17,7 +17,6 @@
#include "GUI/Model/Data/DataItem.h"
#include "GUI/Model/Device/DatafileItem.h"
#include "GUI/Model/Files/DatafilesSet.h"
#include "GUI/View/Data/DatafileEditor.h"
#include "GUI/View/Frame/StackedFrames.h"
#include "GUI/View/Loader/DataLoader.h"
#include "GUI/View/Manager/ProjectManager.h"
......@@ -32,7 +31,6 @@
DatafilesSelector::DatafilesSelector()
: m_set(gDoc->datafilesModifier())
, m_qlistview(new SetView(m_set))
, m_editor(new DatafileEditor)
{
setMinimumWidth(200);
setMaximumWidth(300);
......@@ -49,12 +47,7 @@ DatafilesSelector::DatafilesSelector()
toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
setToolbarActions(toolbar);
auto* splitter = new QSplitter;
layout->addWidget(splitter);
splitter->setOrientation(Qt::Vertical);
splitter->addWidget(m_qlistview);
splitter->addWidget(m_editor);
splitter->setChildrenCollapsible(true);
layout->addWidget(m_qlistview);
connect(m_set, &AbstractSetModel::setChanged, this, &DatafilesSelector::updateActions);
updateActions();
......
......@@ -17,17 +17,11 @@
#include <QWidget>
class DatafileEditor;
class DatafilesSet;
class QToolBar;
class SetView;
//! For viewing and selecting loaded datafiles.
//!
//! Shown as left panel in DataView.
//!
//! Contains a listing of loaded datafiles (m_qlistview & m_qlistmodel)
//! and an editor for acting on the currently selected datafile (DatafileEditor).
//! A list of loaded datafiles, shown as left panel in DataView.
class DatafilesSelector : public QWidget {
Q_OBJECT
......@@ -40,7 +34,6 @@ private:
DatafilesSet* m_set;
SetView* m_qlistview;
DatafileEditor* m_editor;
QAction* m_rm_action;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment