Skip to content
Snippets Groups Projects
Commit 7ce5363e authored by Matthias Puchner's avatar Matthias Puchner
Browse files

rm TestView

this was used as a playground to try out things
parent 8bec14a6
No related branches found
No related tags found
1 merge request!462simplify code; remove test code
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/PropertyEditor/TestComponentView.cpp
//! @brief Defines class TestComponentView
//!
//! @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)
//
// ************************************************************************************************
#include "GUI/View/PropertyEditor/TestComponentView.h"
#include "GUI/Model/Data/IntensityDataItem.h"
#include "GUI/Model/From/GUIObjectBuilder.h"
#include "GUI/Model/Instrument/BeamItems.h"
#include "GUI/Model/Material/MaterialModel.h"
#include "GUI/Model/Sample/GUIDomainSampleVisitor.h"
#include "GUI/Model/Sample/ParticleItem.h"
#include "GUI/Model/Sample/SampleModel.h"
#include "GUI/Model/Types/VectorItem.h"
#include "GUI/View/PropertyEditor/ComponentEditor.h"
#include "GUI/View/PropertyEditor/SessionModelDelegate.h"
#include "GUI/View/Tool/StyleUtils.h"
#include "Sample/Multilayer/MultiLayer.h"
#include "Sample/StandardSamples/ExemplarySamples.h"
#include <QBoxLayout>
#include <QItemSelectionModel>
#include <QPushButton>
#include <QSplitter>
#include <QTreeView>
#include <limits>
TestComponentView::TestComponentView(QWidget* parent)
: QWidget(parent)
, m_sampleModel(new SampleModel(this))
, m_materialModel(new MaterialModel(this))
, m_sourceTree(new QTreeView)
, m_componentTree(new ComponentEditor(ComponentEditor::FullTree))
, m_componentFlat(new ComponentEditor(ComponentEditor::PlainWidget))
, m_updateButton(new QPushButton("Update models"))
, m_addItemButton(new QPushButton("Add item"))
, m_expandButton(new QPushButton("Expand tree"))
, m_splitter(new QSplitter)
, m_delegate(new SessionModelDelegate(this))
, m_isExpaned(false)
{
auto* buttonLayout = new QHBoxLayout;
buttonLayout->addWidget(m_updateButton);
buttonLayout->addWidget(m_addItemButton);
buttonLayout->addWidget(m_expandButton);
m_sourceTree->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
m_sourceTree->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
m_splitter->addWidget(m_sourceTree);
m_splitter->addWidget(componentTreePanel());
m_splitter->addWidget(componentBoxPanel());
auto* layout = new QVBoxLayout();
layout->setMargin(0);
layout->setSpacing(0);
layout->addLayout(buttonLayout);
layout->addWidget(m_splitter);
setLayout(layout);
init_source();
connect(m_updateButton, &QPushButton::clicked, this, &TestComponentView::onUpdateRequest);
connect(m_addItemButton, &QPushButton::clicked, this, &TestComponentView::onAddItemRequest);
connect(m_expandButton, &QPushButton::clicked, this, &TestComponentView::onExpandRequest);
m_sourceTree->setModel(m_sampleModel);
m_sourceTree->setItemDelegate(m_delegate);
GUI::Util::Style::setPropertyStyle(m_sourceTree);
connect(m_sourceTree->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&TestComponentView::onSelectionChanged);
}
void TestComponentView::onUpdateRequest()
{
// m_componentTree->setModel(m_sourceModel);
}
void TestComponentView::onAddItemRequest()
{
m_sampleModel->insertItem<ParticleItem>();
}
void TestComponentView::onExpandRequest()
{
if (!m_isExpaned) {
m_sourceTree->expandAll();
m_sourceTree->resizeColumnToContents(0);
m_sourceTree->resizeColumnToContents(1);
// m_componentTree->treeView()->expandAll();
// m_componentTree->treeView()->resizeColumnToContents(0);
// m_componentTree->treeView()->resizeColumnToContents(1);
} else {
m_sourceTree->collapseAll();
// m_componentTree->treeView()->collapseAll();
}
// const auto imax = std::numeric_limits<int>::max();
const int imax = 1;
QList<int> sizes = {imax, imax, imax};
m_splitter->setSizes(sizes);
m_isExpaned = !m_isExpaned;
}
//! Inserts test items into source model.
void TestComponentView::init_source()
{
const std::unique_ptr<MultiLayer> sample(ExemplarySamples::createHardDisk());
GUIDomainSampleVisitor().populateSampleModel(m_sampleModel, m_materialModel, *sample);
m_sampleModel->insertItem<VectorItem>();
m_sampleModel->insertItem<GISASBeamItem>();
m_sampleModel->insertItem<IntensityDataItem>();
}
void TestComponentView::onSelectionChanged(const QItemSelection& selected, const QItemSelection&)
{
QModelIndexList indices = selected.indexes();
if (!indices.empty()) {
// QModelIndex selectedIndex = indices.front();
// m_componentTree->setRootIndex(selectedIndex);
// m_componentTree->treeView()->expandAll();
auto* item = m_sampleModel->itemForIndex(indices.front());
m_componentTree->setItem(item);
m_componentFlat->setItem(item);
}
}
QWidget* TestComponentView::componentTreePanel()
{
auto* result = new QSplitter(Qt::Vertical);
result->addWidget(m_componentTree);
m_componentTree->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
return result;
}
QWidget* TestComponentView::componentBoxPanel()
{
auto* result = new QSplitter(Qt::Vertical);
result->addWidget(m_componentFlat);
m_componentFlat->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
return result;
}
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/PropertyEditor/TestComponentView.h
//! @brief Defines class TestComponentView
//!
//! @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_PROPERTYEDITOR_TESTCOMPONENTVIEW_H
#define BORNAGAIN_GUI_VIEW_PROPERTYEDITOR_TESTCOMPONENTVIEW_H
#include <QWidget>
class MainWindow;
class QPushButton;
class QTreeView;
class SampleModel;
class SessionModelDelegate;
class QItemSelection;
class ComponentEditor;
class ComponentTreeView;
class QBoxLayout;
class QSplitter;
class ComponentFlatView;
class MaterialModel;
//! View to tests QListView working with ComponentProxyModel.
class TestComponentView : public QWidget {
Q_OBJECT
public:
TestComponentView(QWidget* parent);
private slots:
void onUpdateRequest();
void onAddItemRequest();
void onExpandRequest();
private:
void init_source();
void onSelectionChanged(const QItemSelection& selected, const QItemSelection&);
QWidget* componentTreePanel();
QWidget* componentBoxPanel();
SampleModel* m_sampleModel;
MaterialModel* m_materialModel;
QTreeView* m_sourceTree;
ComponentEditor* m_componentTree;
ComponentEditor* m_componentFlat;
QPushButton* m_updateButton;
QPushButton* m_addItemButton;
QPushButton* m_expandButton;
QSplitter* m_splitter;
SessionModelDelegate* m_delegate;
bool m_isExpaned;
};
#endif // BORNAGAIN_GUI_VIEW_PROPERTYEDITOR_TESTCOMPONENTVIEW_H
...@@ -21,15 +21,10 @@ ...@@ -21,15 +21,10 @@
#include "GUI/View/Common/ModelTreeView.h" #include "GUI/View/Common/ModelTreeView.h"
#include "GUI/View/Main/ProjectManager.h" #include "GUI/View/Main/ProjectManager.h"
#include "GUI/View/PropertyEditor/SessionModelDelegate.h" #include "GUI/View/PropertyEditor/SessionModelDelegate.h"
#include "GUI/View/Toplevel/TestView.h"
#include <QToolBar> #include <QToolBar>
#include <QToolButton> #include <QToolButton>
#include <QVBoxLayout> #include <QVBoxLayout>
namespace {
const bool show_test_view = false;
}
SessionModelView::SessionModelView(QWidget* parent, ProjectDocument* document) SessionModelView::SessionModelView(QWidget* parent, ProjectDocument* document)
: QWidget(parent) : QWidget(parent)
, m_toolBar(new QToolBar) , m_toolBar(new QToolBar)
...@@ -55,9 +50,6 @@ SessionModelView::SessionModelView(QWidget* parent, ProjectDocument* document) ...@@ -55,9 +50,6 @@ SessionModelView::SessionModelView(QWidget* parent, ProjectDocument* document)
setLayout(layout); setLayout(layout);
init_tabs(); init_tabs();
if (show_test_view)
init_test_view();
} }
void SessionModelView::onExpandCollapseTree() void SessionModelView::onExpandCollapseTree()
...@@ -86,10 +78,3 @@ QList<SessionModel*> SessionModelView::modelsForTabs() ...@@ -86,10 +78,3 @@ QList<SessionModel*> SessionModelView::modelsForTabs()
return {m_document->instrumentModel(), m_document->sampleModel(), m_document->realDataModel(), return {m_document->instrumentModel(), m_document->sampleModel(), m_document->realDataModel(),
m_document->materialModel(), m_document->jobModel()}; m_document->materialModel(), m_document->jobModel()};
} }
void SessionModelView::init_test_view()
{
auto* view = new TestView(parentWidget());
int index = m_tabs->addTab(view, "Test View");
m_tabs->setCurrentIndex(index);
}
...@@ -43,7 +43,6 @@ private slots: ...@@ -43,7 +43,6 @@ private slots:
private: private:
void init_tabs(); void init_tabs();
QList<SessionModel*> modelsForTabs(); QList<SessionModel*> modelsForTabs();
void init_test_view();
QToolBar* m_toolBar; QToolBar* m_toolBar;
QTabWidget* m_tabs; QTabWidget* m_tabs;
......
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/Toplevel/TestView.cpp
//! @brief Implements class TestView
//!
//! @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)
//
// ************************************************************************************************
#include "GUI/View/Toplevel/TestView.h"
#include "GUI/Model/Data/Data1DViewItem.h"
#include "GUI/Model/Data/DataPropertyContainer.h"
#include "GUI/Model/Data/RealDataItem.h"
#include "GUI/Model/Data/SpecularDataItem.h"
#include "GUI/Model/Fit/MinimizerItem.h"
#include "GUI/Model/Job/JobItem.h"
#include "GUI/View/Fit/MinimizerSettingsWidget.h"
#include "GUI/View/PropertyEditor/TestComponentView.h"
#include "GUI/View/SpecularData/Plot1DCanvas.h"
#include "GUI/View/Tool/Accordion.h"
#include <QCheckBox>
#include <QLineEdit>
#include <QTreeView>
namespace {
// These functions are required for testing purposes only
// They must be removed after completion of
// SpecularDataWidget
double getTestValue(size_t bin, double factor);
SpecularDataItem* fillTestItem(SessionItem* item, double factor);
} // namespace
TestView::TestView(QWidget* parent) : QWidget(parent)
{
// test_ComponentProxyModel();
// test_MinimizerSettings();
// test_AccordionWidget();
// test_RunFitWidget();
// test_specular_data_widget();
}
void TestView::test_ComponentProxyModel()
{
auto* layout = new QHBoxLayout();
layout->setMargin(0);
layout->setSpacing(0);
layout->addWidget(new TestComponentView(parentWidget()));
setLayout(layout);
}
void TestView::test_MinimizerSettings()
{
auto* widget = new MinimizerSettingsWidget;
auto* layout = new QVBoxLayout;
layout->setMargin(0);
layout->setSpacing(0);
layout->addWidget(widget);
setLayout(layout);
auto* model = new SessionModel("TempModel", this);
auto* minimizerItem = model->insertItem<MinimizerContainerItem>();
widget->setItem(minimizerItem);
}
void TestView::test_AccordionWidget()
{
auto* myAccordion = new QAccordion();
myAccordion->setMultiActive(true);
// add the Accordion to your layout
auto* layout = new QVBoxLayout;
layout->addWidget(myAccordion);
setLayout(layout);
// add a content pane with a header
int firstPaneIndex = myAccordion->addContentPane("My first content pane");
// make sure our content pane was added
if (firstPaneIndex != -1) {
// get a QFrame* from the Content Pane. This is where we place our content
QFrame* contentFrame = myAccordion->getContentPane(firstPaneIndex)->getContentFrame();
// give the QFrame a QLayout
contentFrame->setLayout(new QVBoxLayout());
// add a simpel QLabel to the frame
contentFrame->layout()->addWidget(new QLabel("Hello Cute World!!!"));
}
// add a content pane with a header
int secondPaneIndex = myAccordion->addContentPane("Basic settings");
// make sure our content pane was added
if (secondPaneIndex != -1) {
// get a QFrame* from the Content Pane. This is where we place our content
QFrame* contentFrame = myAccordion->getContentPane(secondPaneIndex)->getContentFrame();
// give the QFrame a QLayout
contentFrame->setLayout(new QVBoxLayout());
// add a simpel QLabel to the frame
auto* led = new QLineEdit();
auto* led2 = new QLineEdit();
contentFrame->layout()->addWidget(new QLabel("Name:"));
contentFrame->layout()->addWidget(led);
contentFrame->layout()->addWidget(new QLabel("Living place:"));
contentFrame->layout()->addWidget(led2);
}
// add a content pane with a header
int third = myAccordion->addContentPane("Advanced");
// make sure our content pane was added
if (third != -1) {
// get a QFrame* from the Content Pane. This is where we place our content
myAccordion->getContentPane(third)->setMaximumHeight(500);
QFrame* contentFrame = myAccordion->getContentPane(third)->getContentFrame();
contentFrame->setMaximumHeight(500);
// give the QFrame a QLayout
contentFrame->setLayout(new QVBoxLayout());
// add a simpel QLabel to the frame
auto* cb = new QCheckBox();
cb->setText("Option 1");
auto* cb2 = new QCheckBox();
cb2->setText("Option 2");
auto* cb3 = new QCheckBox();
cb3->setText("Option 3");
auto* cb4 = new QCheckBox();
cb4->setText("Option 4");
auto* cb5 = new QCheckBox();
cb5->setText("Option 5");
auto* cb6 = new QCheckBox();
cb6->setText("Option 6");
auto* cb7 = new QCheckBox();
cb7->setText("Option 7");
contentFrame->layout()->addWidget(cb);
contentFrame->layout()->addWidget(cb2);
contentFrame->layout()->addWidget(cb3);
contentFrame->layout()->addWidget(cb4);
contentFrame->layout()->addWidget(cb5);
contentFrame->layout()->addWidget(cb6);
contentFrame->layout()->addWidget(cb7);
}
}
void TestView::test_specular_data_widget()
{
auto* tempModel = new SessionModel("Test", this);
// creating job item
auto* job_item = tempModel->insertItem<JobItem>();
// creating "simulation" data
auto* data_item = new SpecularDataItem();
job_item->addDataItem(data_item);
fillTestItem(data_item, 1.0);
// creating "real" data
auto* real_data = new RealDataItem();
job_item->addRealDataItem(real_data);
data_item = new SpecularDataItem();
real_data->insertItem(-1, data_item, RealDataItem::T_INTENSITY_DATA);
fillTestItem(data_item, 2.0);
// creating data view
auto* data_view = new Data1DViewItem();
job_item->addDataViewItem(data_view);
auto* container = data_view->createPropertyContainerItem();
container->addItem(job_item->realDataItem()->dataItem());
container->addItem(job_item->dataItem());
auto* layout = new QVBoxLayout;
layout->setMargin(0);
layout->setSpacing(0);
auto* widget = new Plot1DCanvas(this);
widget->setItem(job_item->dataItemView());
layout->addWidget(widget);
setLayout(layout);
}
namespace {
double getTestValue(size_t bin, double factor)
{
const double angle_factor = M_PI / (180.0 * 100.0);
const double angle = bin * angle_factor;
return (std::cos(angle * 1000.0) + 1.5) * std::exp(-(bin * factor / 100.0));
}
SpecularDataItem* fillTestItem(SessionItem* item, double factor)
{
auto* result = dynamic_cast<SpecularDataItem*>(item);
ASSERT(result);
auto outputData = std::make_unique<OutputData<double>>();
outputData->addAxis(FixedBinAxis("Angle [deg]", 1000, 0.0, 10.0));
for (size_t i = 0; i < 1000; ++i)
outputData->operator[](i) = getTestValue(i, factor);
result->setOutputData(outputData.release());
return result;
}
} // namespace
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/Toplevel/TestView.h
//! @brief Defines class TestView
//!
//! @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_TOPLEVEL_TESTVIEW_H
#define BORNAGAIN_GUI_VIEW_TOPLEVEL_TESTVIEW_H
#include <QWidget>
class TestView : public QWidget {
Q_OBJECT
public:
TestView(QWidget* parent = nullptr);
private:
void test_ComponentProxyModel();
void test_MinimizerSettings();
void test_AccordionWidget();
void test_specular_data_widget();
};
#endif // BORNAGAIN_GUI_VIEW_TOPLEVEL_TESTVIEW_H
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