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

clean up model access

parent 81223d90
No related branches found
No related tags found
1 merge request!290Refactor Application Models
Pipeline #44000 passed
......@@ -32,16 +32,18 @@
#include "GUI/Views/SampleDesigner/NodeEditorConnection.h"
#include "GUI/Views/SampleDesigner/SampleViewAligner.h"
#include "GUI/Views/SampleDesigner/SampleViewFactory.h"
#include "GUI/mainwindow/projectdocument.h"
#include "Sample/StandardSamples/SampleBuilderFactory.h"
#include <QGraphicsSceneMouseEvent>
#include <QItemSelection>
#include <QPainter>
#include <boost/polymorphic_cast.hpp>
using boost::polymorphic_cast;
using boost::polymorphic_downcast;
DesignerScene::DesignerScene(QObject* parent)
DesignerScene::DesignerScene(QObject* parent, ProjectDocument* document)
: QGraphicsScene(parent)
, m_sampleModel(nullptr)
, m_materialModel(nullptr)
......@@ -60,48 +62,25 @@ DesignerScene::DesignerScene(QObject* parent)
connect(m_nodeEditor, &NodeEditor::selectionModeChangeRequest, this,
&DesignerScene::selectionModeChangeRequest);
connect(this, &DesignerScene::selectionChanged, this, &DesignerScene::onSceneSelectionChanged);
}
DesignerScene::~DesignerScene()
{
delete m_aligner;
}
void DesignerScene::setSampleModel(SampleModel* sampleModel)
{
ASSERT(sampleModel);
if (sampleModel != m_sampleModel) {
if (m_sampleModel) {
disconnect(m_sampleModel, &SampleModel::modelAboutToBeReset, this,
&DesignerScene::resetScene);
disconnect(m_sampleModel, &SampleModel::rowsInserted, this,
&DesignerScene::onRowsInserted);
disconnect(m_sampleModel, &SampleModel::rowsAboutToBeRemoved, this,
&DesignerScene::onRowsAboutToBeRemoved);
disconnect(m_sampleModel, &SampleModel::rowsRemoved, this,
&DesignerScene::onRowsRemoved);
disconnect(m_sampleModel, &SampleModel::modelReset, this, &DesignerScene::updateScene);
}
m_sampleModel = document->sampleModel();
m_materialModel = document->materialModel();
m_sampleModel = sampleModel;
connect(m_sampleModel, &SampleModel::modelAboutToBeReset, this, &DesignerScene::resetScene);
connect(m_sampleModel, &SampleModel::rowsInserted, this, &DesignerScene::onRowsInserted);
connect(m_sampleModel, &SampleModel::rowsAboutToBeRemoved, this,
&DesignerScene::onRowsAboutToBeRemoved);
connect(m_sampleModel, &SampleModel::rowsRemoved, this, &DesignerScene::onRowsRemoved);
connect(m_sampleModel, &SampleModel::modelReset, this, &DesignerScene::updateScene);
connect(m_sampleModel, &SampleModel::modelAboutToBeReset, this, &DesignerScene::resetScene);
connect(m_sampleModel, &SampleModel::rowsInserted, this, &DesignerScene::onRowsInserted);
connect(m_sampleModel, &SampleModel::rowsAboutToBeRemoved, this,
&DesignerScene::onRowsAboutToBeRemoved);
connect(m_sampleModel, &SampleModel::rowsRemoved, this, &DesignerScene::onRowsRemoved);
connect(m_sampleModel, &SampleModel::modelReset, this, &DesignerScene::updateScene);
resetScene();
updateScene();
}
resetScene();
updateScene();
}
void DesignerScene::setMaterialModel(MaterialModel* materialModel)
DesignerScene::~DesignerScene()
{
m_materialModel = materialModel;
disconnect(); // important! otherwise notifications after deletion + crash
delete m_aligner;
}
void DesignerScene::setSelectionModel(QItemSelectionModel* model, FilterPropertyProxy* proxy)
......
......@@ -31,17 +31,16 @@ class SampleViewAligner;
class NodeEditor;
class FilterPropertyProxy;
class MaterialModel;
class ProjectDocument;
//! Main class which represents SessionModel on graphics scene
class DesignerScene : public QGraphicsScene {
Q_OBJECT
public:
explicit DesignerScene(QObject* parent = 0);
explicit DesignerScene(QObject* parent, ProjectDocument* document);
virtual ~DesignerScene();
void setSampleModel(SampleModel* sampleModel);
void setMaterialModel(MaterialModel* materialModel);
void setSelectionModel(QItemSelectionModel* model, FilterPropertyProxy* proxy);
SampleModel* getSampleModel() { return m_sampleModel; }
......
......@@ -18,21 +18,13 @@
#include "GUI/Views/SampleDesigner/MultiLayerView.h"
#include "Sample/Scattering/ISampleNode.h"
SampleDesigner::SampleDesigner(QWidget* parent)
SampleDesigner::SampleDesigner(QWidget* parent, ProjectDocument* document)
: QObject(parent), m_designerScene(0), m_designerView(0)
{
m_designerScene = new DesignerScene(parent);
m_designerScene = new DesignerScene(parent, document);
m_designerView = new DesignerView(m_designerScene, parent);
}
SampleDesigner::~SampleDesigner() = default;
void SampleDesigner::setModels(ApplicationModels* models)
{
m_designerScene->setSampleModel(models->sampleModel());
m_designerScene->setMaterialModel(models->materialModel());
}
void SampleDesigner::setSelectionModel(QItemSelectionModel* model, FilterPropertyProxy* proxy)
{
if (model)
......
......@@ -24,21 +24,20 @@ class DesignerScene;
class SampleModel;
class FilterPropertyProxy;
class ApplicationModels;
class ProjectDocument;
//! sample designer provide central window with graphic scene to drag and drop
class SampleDesigner : public QObject {
Q_OBJECT
public:
SampleDesigner(QWidget* parent = 0);
virtual ~SampleDesigner();
SampleDesigner(QWidget* parent, ProjectDocument* document);
DesignerScene* getScene() const { return m_designerScene; }
DesignerView* getView() const { return m_designerView; }
QWidget* getCentralWidget() { return m_designerView; }
void setModels(ApplicationModels* models);
void setSelectionModel(QItemSelectionModel* model, FilterPropertyProxy* proxy);
private:
......
......@@ -39,11 +39,6 @@ SampleView::SampleView(QWidget* parent, ProjectDocument* document)
connectSignals();
}
ApplicationModels* SampleView::models()
{
return m_document->applicationModels();
}
void SampleView::toggleRealSpaceView()
{
m_docks->toggleDock(REALSPACEPANEL);
......@@ -68,12 +63,12 @@ ProjectDocument* SampleView::document() const
void SampleView::createSubWindows()
{
m_sampleDesigner = new SampleDesigner(this);
m_sampleDesigner = new SampleDesigner(this, m_document);
m_toolBox = new SampleToolBox(this);
m_treeWidget = new SampleTreeWidget(this, models()->sampleModel());
m_treeWidget = new SampleTreeWidget(this, m_document->sampleModel());
m_propertyWidget = new SamplePropertyWidget(m_treeWidget->treeView()->selectionModel(), this);
m_scriptPanel = new ScriptPanel(models()->sampleModel(), this);
m_realSpacePanel = new RealSpacePanel(models()->sampleModel(),
m_scriptPanel = new ScriptPanel(m_document->sampleModel(), this);
m_realSpacePanel = new RealSpacePanel(m_document->sampleModel(),
m_treeWidget->treeView()->selectionModel(), this);
m_docks->addWidget(TOOLBOX, m_toolBox, Qt::LeftDockWidgetArea);
......@@ -85,7 +80,6 @@ void SampleView::createSubWindows()
connect(m_scriptPanel, &ScriptPanel::widgetHeightRequest, m_docks,
&DocksController::setDockHeightForWidget);
m_sampleDesigner->setModels(models());
m_sampleDesigner->setSelectionModel(
m_treeWidget->treeView()->selectionModel(),
dynamic_cast<FilterPropertyProxy*>(
......
......@@ -17,12 +17,9 @@
#include <QMainWindow>
class MainWindow;
class DocksController;
class SampleDesigner;
class SampleToolBar;
class ApplicationModels;
class QItemSelectionModel;
class SampleToolBox;
class SampleTreeWidget;
class SamplePropertyWidget;
......@@ -37,7 +34,6 @@ public:
SampleView(QWidget* parent, ProjectDocument* document);
ApplicationModels* models();
void toggleRealSpaceView();
void fillViewMenu(QMenu* menu);
......
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