Newer
Older
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/Sample/SampleForm.cpp
//!
//! @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/Sample/SampleForm.h"
#include "GUI/Model/Project/ProjectDocument.h"
#include "GUI/Model/Sample/LayerItem.h"
#include "GUI/Model/Sample/LayerStackItem.h"
#include "GUI/Model/Sample/SamplesSet.h"
#include "GUI/View/Base/ActionFactory.h"
#include "GUI/View/Base/LayoutUtil.h"
#include "GUI/View/Sample/CompoundForm.h"
#include "GUI/View/Sample/CoreAndShellForm.h"
#include "GUI/View/Sample/HeinzFormLayout.h"
#include "GUI/View/Sample/LayerForm.h"
#include "GUI/View/Sample/LayerStackForm.h"
#include "GUI/View/Sample/MesocrystalForm.h"
#include "GUI/View/Sample/ParticleForm.h"
#include "GUI/View/Sample/ParticleLayoutForm.h"
#include "GUI/View/Sample/SampleEditorController.h"
#include "GUI/View/Widget/AppConfig.h"
#include <QLabel>
#include <QLineEdit>
#include <QTextEdit>
SampleForm::SampleForm(SampleItem* sampleItem, SampleEditorController* ec)
: m_layout(new QVBoxLayout(this))
{
setAttribute(Qt::WA_StyledBackground, true);
auto* summary = new CollapsibleGroupBox("Summary and layer-independent parameters", this,
sampleItem->expandInfo);
m_layout->addWidget(summary, 0, Qt::AlignTop);
auto* gLayout = new HeinzFormLayout(ec);
summary->body()->setLayout(gLayout);
nameEdit->setText(sampleItem->name());
connect(nameEdit, &QLineEdit::textEdited,
[](const QString& s) { gDoc->samplesRW()->setCurrentName(s); });
gLayout->addBoldRow("Description:", descriptionEdit);
descriptionEdit->setFixedHeight(60);
descriptionEdit->setAcceptRichText(false);
descriptionEdit->setTabChangesFocus(true);
descriptionEdit->setPlainText(sampleItem->description());
connect(descriptionEdit, &QTextEdit::textChanged, [descriptionEdit] {
gDoc->samplesRW()->setCurrentDescription(descriptionEdit->toPlainText());

Wuttke, Joachim
committed
});
// Processing external field is not implemented yet, so temporary disable it (see issue #654)
// m_layout->addVector(sampleItem->externalField(), false);
auto* showInRealspaceAction = ActionFactory::createShowInRealspaceAction(
this, "sample", [this] { m_ec->requestViewInRealspace(m_sample_item); });
summary->addTitleAction(showInRealspaceAction);
m_layout->addWidget(new LayerStackForm(this, &m_sample_item->outerStackItem(), m_ec), 0,
Qt::AlignTop);
void SampleForm::onLayerMoved(ItemWithLayers* item)
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// LayerContainerForm* wl = nullptr;
// AddLayerContainerWidget* al = nullptr;
// for (int index = 0; index < m_layout->count(); index++) {
// if (auto* w =
// dynamic_cast<AddLayerContainerWidget*>(m_layout->itemAt(index)->widget()))
// if (w->m_item == item) {
// al = w;
// m_layout->takeAt(index);
// break;
// }
// }
// for (int index = 0; index < m_layout->count(); index++) {
// if (auto* w = dynamic_cast<LayerContainerForm*>(m_layout->itemAt(index)->widget()))
// if (w->item() == item) {
// wl = w;
// m_layout->takeAt(index);
// break;
// }
// }
// const int rowInMultiLayer = Vec::indexOfPtr(item, m_sample_item->uniqueLayerItems());
// const int rowInLayout = rowInMultiLayer * 2 + 1;
// m_layout->insertWidget(rowInLayout, wl, 0, Qt::AlignTop);
// // same row => button is above!
// m_layout->insertWidget(rowInLayout, al, 0, Qt::AlignTop);
// updateRowVisibilities();
void SampleForm::updateRowVisibilities()
{
for (auto* c : findChildren<LayerContainerForm*>())
c->updatePositionDependentElements();
LayerStackForm* SampleForm::formOfStackItem(const LayerStackItem* searchedStackItem)
{
for (auto* c : findChildren<LayerStackForm*>())
if (&c->stackItem() == searchedStackItem)
return c;
return nullptr;
}
LayerForm* SampleForm::findNextLayerForm(QWidget* w)
{
while (w != nullptr && dynamic_cast<LayerForm*>(w) == nullptr) {
if (index + 1 < m_layout->count())
w = m_layout->itemAt(index + 1)->widget();
}
return dynamic_cast<LayerForm*>(w);
}