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

simplify RealSpace (3D) view - refactor/remove unnecessary class hierarchy (rm RealSpaceWidget)

parent 87b78753
No related branches found
No related tags found
1 merge request!430Simplify real space view
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/Realspace/RealSpaceWidget.cpp
//! @brief Implements class RealSpaceWidget
//!
//! @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/Realspace/RealSpaceWidget.h"
#include "GUI/View/Common/StyledToolBar.h"
#include "GUI/View/Realspace/RealSpaceCanvas.h"
#include <QLabel>
#include <QVBoxLayout>
RealSpaceWidget::RealSpaceWidget(SampleModel* sampleModel, QItemSelectionModel* selectionModel,
QWidget* parent)
: QWidget(parent)
, m_canvas(new RealSpaceCanvas)
, m_sampleModel(sampleModel)
, m_selectionModel(selectionModel)
{
createActions();
auto hlayout = new QHBoxLayout;
hlayout->setMargin(0);
hlayout->setSpacing(0);
hlayout->setContentsMargins(0, 0, 0, 0);
hlayout->addWidget(m_canvas);
auto* toolbar = new StyledToolBar(this);
toolbar->addAction(m_savePictureAction);
toolbar->addSeparator();
toolbar->addAction(m_defaultViewAction);
toolbar->addSeparator();
toolbar->addAction(m_sideViewAction);
toolbar->addSeparator();
toolbar->addAction(m_topViewAction);
toolbar->addSeparator();
toolbar->addAction(m_increaseLayerSizeAction);
toolbar->addSeparator();
toolbar->addAction(m_decreaseLayerSizeAction);
toolbar->addSeparator();
toolbar->addAction(m_lockViewAction);
auto* mainLayout = new QVBoxLayout;
mainLayout->setMargin(0);
mainLayout->setSpacing(0);
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->addWidget(toolbar);
mainLayout->addLayout(hlayout);
setLayout(mainLayout);
connect(m_defaultViewAction, &QAction::triggered, m_canvas,
&RealSpaceCanvas::onDefaultViewAction);
connect(m_sideViewAction, &QAction::triggered, m_canvas, &RealSpaceCanvas::onSideViewAction);
connect(m_topViewAction, &QAction::triggered, m_canvas, &RealSpaceCanvas::onTopViewAction);
connect(m_lockViewAction, &QAction::triggered, m_canvas, &RealSpaceCanvas::onLockViewAction);
connect(m_increaseLayerSizeAction, &QAction::triggered,
[this]() { m_canvas->onChangeLayerSizeAction(1.25); });
connect(m_decreaseLayerSizeAction, &QAction::triggered,
[this]() { m_canvas->onChangeLayerSizeAction(0.8); });
connect(m_savePictureAction, &QAction::triggered, m_canvas,
&RealSpaceCanvas::onSavePictureAction);
}
void RealSpaceWidget::showEvent(QShowEvent*)
{
m_canvas->setModel(m_sampleModel, m_selectionModel);
}
void RealSpaceWidget::hideEvent(QHideEvent*)
{
m_canvas->setModel(nullptr, nullptr);
}
void RealSpaceWidget::createActions()
{
m_savePictureAction = new QAction(this);
m_savePictureAction->setText("Save Picture");
m_savePictureAction->setToolTip("Save 3D real space view as .png file");
m_defaultViewAction = new QAction(this);
m_defaultViewAction->setText("Default View");
m_defaultViewAction->setToolTip("Reset view and zoom level to default");
m_sideViewAction = new QAction(this);
m_sideViewAction->setText("Side View");
m_sideViewAction->setToolTip("View sample from the side at current zoom level");
m_topViewAction = new QAction(this);
m_topViewAction->setText("Top View");
m_topViewAction->setToolTip("View sample from the top at current zoom level");
m_lockViewAction = new QAction(this);
m_lockViewAction->setText("Lock View");
m_lockViewAction->setToolTip("Lock/unlock current sample selection");
m_lockViewAction->setCheckable(true);
m_increaseLayerSizeAction = new QAction(this);
m_increaseLayerSizeAction->setText("Enlarge");
m_increaseLayerSizeAction->setToolTip("Increase layer size");
m_decreaseLayerSizeAction = new QAction(this);
m_decreaseLayerSizeAction->setText("Reduce");
m_decreaseLayerSizeAction->setToolTip("Decrease layer size");
}
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/Realspace/RealSpaceWidget.h
//! @brief Defines class RealSpaceWidget
//!
//! @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_REALSPACE_REALSPACEWIDGET_H
#define BORNAGAIN_GUI_VIEW_REALSPACE_REALSPACEWIDGET_H
#include <QWidget>
#include <QTreeView>
class RealSpaceCanvas;
class SampleModel;
//! Prototype of real space widget to present sample structure in 3D view.
class RealSpaceWidget : public QWidget {
Q_OBJECT
public:
RealSpaceWidget(SampleModel* sampleModel = nullptr,
QItemSelectionModel* selectionModel = nullptr, QWidget* parent = nullptr);
protected:
void showEvent(QShowEvent*) override;
void hideEvent(QHideEvent*) override;
private:
void createActions();
private:
RealSpaceCanvas* m_canvas;
SampleModel* m_sampleModel;
QItemSelectionModel* m_selectionModel;
QAction* m_savePictureAction;
QAction* m_defaultViewAction;
QAction* m_sideViewAction;
QAction* m_topViewAction;
QAction* m_lockViewAction;
QAction* m_increaseLayerSizeAction;
QAction* m_decreaseLayerSizeAction;
};
#endif // BORNAGAIN_GUI_VIEW_REALSPACE_REALSPACEWIDGET_H
......@@ -7,33 +7,77 @@
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @copyright Forschungszentrum Jülich GmbH 2021
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#include "GUI/View/SampleDesigner/RealSpacePanel.h"
#include "GUI/View/Realspace/RealSpaceWidget.h"
#include "GUI/View/Common/StyledToolBar.h"
#include "GUI/View/Realspace/RealSpaceCanvas.h"
#include <QVBoxLayout>
RealSpacePanel::RealSpacePanel(SampleModel* sampleModel, QItemSelectionModel* selectionModel,
QWidget* parent)
: QWidget(parent), m_realSpaceWidget(nullptr)
: QWidget(parent)
, m_canvas(new RealSpaceCanvas)
, m_sampleModel(sampleModel)
, m_selectionModel(selectionModel)
{
setWindowTitle("Real Space");
setObjectName("Sample3DPanel");
auto layout = new QVBoxLayout;
layout->setMargin(0);
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
auto* toolbar = new StyledToolBar(this);
m_realSpaceWidget = new RealSpaceWidget(sampleModel, selectionModel, this);
layout->addWidget(m_realSpaceWidget);
setLayout(layout);
const auto createAction = [&](const QString& text, const QString& tooltip) -> QAction* {
auto* action = new QAction(text, this);
action->setToolTip("Save 3D real space view as .png file");
toolbar->addAction(action);
toolbar->addSeparator();
return action;
};
auto* action = createAction("Save Picture", "Save 3D real space view as .png file");
connect(action, &QAction::triggered, m_canvas, &RealSpaceCanvas::onSavePictureAction);
action = createAction("Default View", "Reset view and zoom level to default");
connect(action, &QAction::triggered, m_canvas, &RealSpaceCanvas::onDefaultViewAction);
action = createAction("Side View", "View sample from the side at current zoom level");
connect(action, &QAction::triggered, m_canvas, &RealSpaceCanvas::onSideViewAction);
action = createAction("Top View", "View sample from the top at current zoom level");
connect(action, &QAction::triggered, m_canvas, &RealSpaceCanvas::onTopViewAction);
action = createAction("Enlarge", "Increase layer size");
connect(action, &QAction::triggered, [this]() { m_canvas->onChangeLayerSizeAction(1.25); });
action = createAction("Reduce", "Decrease layer size");
connect(action, &QAction::triggered, [this]() { m_canvas->onChangeLayerSizeAction(0.8); });
action = createAction("Lock View", "Lock/unlock current sample selection");
action->setCheckable(true);
connect(action, &QAction::triggered, m_canvas, &RealSpaceCanvas::onLockViewAction);
auto* mainLayout = new QVBoxLayout(this);
mainLayout->setMargin(0);
mainLayout->setSpacing(0);
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->addWidget(toolbar);
mainLayout->addWidget(m_canvas);
}
QSize RealSpacePanel::sizeHint() const
{
return QSize(300, 300);
}
void RealSpacePanel::showEvent(QShowEvent*)
{
m_canvas->setModel(m_sampleModel, m_selectionModel);
}
void RealSpacePanel::hideEvent(QHideEvent*)
{
m_canvas->setModel(nullptr, nullptr);
}
......@@ -7,7 +7,7 @@
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @copyright Forschungszentrum Jülich GmbH 2021
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
......@@ -19,9 +19,10 @@
class SampleModel;
class QItemSelectionModel;
class RealSpaceWidget;
class RealSpaceCanvas;
class QAction;
//! Panel with item selector, property editor on the right side of RealSpaceWidget.
//! Panel to show 3D view of sample. Contains toolbar and RealSpaceCanvas
class RealSpacePanel : public QWidget {
Q_OBJECT
......@@ -31,8 +32,14 @@ public:
QSize sizeHint() const override;
protected:
void showEvent(QShowEvent*) override;
void hideEvent(QHideEvent*) override;
private:
RealSpaceWidget* m_realSpaceWidget;
RealSpaceCanvas* m_canvas;
SampleModel* m_sampleModel;
QItemSelectionModel* m_selectionModel;
};
#endif // BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_REALSPACEPANEL_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