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

reduce global access to document

parent d2623177
No related branches found
No related tags found
1 merge request!494Remove SessionModel/SessionItem from MaterialModel/MaterialItem
...@@ -110,9 +110,8 @@ void LayerOrientedSampleEditor::setCurrentSample(MultiLayerItem* multiLayerItem) ...@@ -110,9 +110,8 @@ void LayerOrientedSampleEditor::setCurrentSample(MultiLayerItem* multiLayerItem)
} }
if (!m_editControllers.contains(m_currentMultiLayerItem)) if (!m_editControllers.contains(m_currentMultiLayerItem))
m_editControllers.insert( m_editControllers.insert(m_currentMultiLayerItem,
m_currentMultiLayerItem, new SampleEditorController(m_document, m_currentMultiLayerItem));
new SampleEditorController(m_document->materialModel(), m_currentMultiLayerItem));
auto* ec = m_editControllers[m_currentMultiLayerItem]; auto* ec = m_editControllers[m_currentMultiLayerItem];
connect(ec, &SampleEditorController::requestViewInRealSpace, this, connect(ec, &SampleEditorController::requestViewInRealSpace, this,
&LayerOrientedSampleEditor::requestViewInRealSpace); &LayerOrientedSampleEditor::requestViewInRealSpace);
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "GUI/Model/Material/MaterialModel.h" #include "GUI/Model/Material/MaterialModel.h"
#include "GUI/Model/Sample/ItemWithMaterial.h" #include "GUI/Model/Sample/ItemWithMaterial.h"
#include "GUI/Model/Session/ModelPath.h" #include "GUI/Model/Session/ModelPath.h"
#include "GUI/Model/State/SessionData.h"
#include "GUI/Model/Types/DoubleDescriptor.h" #include "GUI/Model/Types/DoubleDescriptor.h"
#include "GUI/Model/Types/VectorDescriptor.h" #include "GUI/Model/Types/VectorDescriptor.h"
#include "GUI/View/Edit/DoubleLineEdit.h" #include "GUI/View/Edit/DoubleLineEdit.h"
...@@ -40,7 +39,7 @@ MaterialInplaceForm::MaterialInplaceForm(QWidget* parent, ItemWithMaterial* item ...@@ -40,7 +39,7 @@ MaterialInplaceForm::MaterialInplaceForm(QWidget* parent, ItemWithMaterial* item
m_layout->setContentsMargins(0, 0, 0, 0); m_layout->setContentsMargins(0, 0, 0, 0);
createWidgets(); createWidgets();
connect(gSessionData->projectDocument->materialModel(), &MaterialModel::materialChanged, this, connect(ec->materialModel(), &MaterialModel::materialChanged, this,
&MaterialInplaceForm::onMaterialChanged); &MaterialInplaceForm::onMaterialChanged);
} }
...@@ -64,7 +63,7 @@ void MaterialInplaceForm::updateValues() ...@@ -64,7 +63,7 @@ void MaterialInplaceForm::updateValues()
void MaterialInplaceForm::selectMaterial() void MaterialInplaceForm::selectMaterial()
{ {
const QString newMaterialIdentifier = MaterialEditorDialog::chooseMaterial( const QString newMaterialIdentifier = MaterialEditorDialog::chooseMaterial(
baWin, gSessionData->projectDocument, m_item->materialIdentifier()); baWin, m_ec->projectDocument(), m_item->materialIdentifier());
if (!newMaterialIdentifier.isEmpty() && newMaterialIdentifier != m_item->materialIdentifier()) { if (!newMaterialIdentifier.isEmpty() && newMaterialIdentifier != m_item->materialIdentifier()) {
GUI::Util::Layout::clearLayout(m_layout, true); GUI::Util::Layout::clearLayout(m_layout, true);
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "GUI/View/SampleDesigner/SampleEditorController.h" #include "GUI/View/SampleDesigner/SampleEditorController.h"
#include "GUI/Model/Material/MaterialModel.h" #include "GUI/Model/Material/MaterialModel.h"
#include "GUI/Model/Project/ProjectDocument.h"
#include "GUI/Model/Sample/InterferenceItems.h" #include "GUI/Model/Sample/InterferenceItems.h"
#include "GUI/Model/Sample/LayerItem.h" #include "GUI/Model/Sample/LayerItem.h"
#include "GUI/Model/Sample/MesoCrystalItem.h" #include "GUI/Model/Sample/MesoCrystalItem.h"
...@@ -35,8 +36,8 @@ ...@@ -35,8 +36,8 @@
#include "GUI/View/SampleDesigner/ParticleLayoutForm.h" #include "GUI/View/SampleDesigner/ParticleLayoutForm.h"
#include "GUI/View/SampleDesigner/SampleEditorCommands.h" #include "GUI/View/SampleDesigner/SampleEditorCommands.h"
SampleEditorController::SampleEditorController(MaterialModel* materialModel, MultiLayerItem* multi) SampleEditorController::SampleEditorController(ProjectDocument* document, MultiLayerItem* multi)
: m_multiLayerItem(multi), m_multiLayerForm(nullptr), m_materialModel(materialModel) : m_multiLayerItem(multi), m_multiLayerForm(nullptr), m_document(document)
{ {
} }
...@@ -96,8 +97,8 @@ void SampleEditorController::addLayer(LayerItem* before) ...@@ -96,8 +97,8 @@ void SampleEditorController::addLayer(LayerItem* before)
// - create new layer // - create new layer
LayerItem* layer = m_multiLayerItem->addLayer(rowInMultiLayer); LayerItem* layer = m_multiLayerItem->addLayer(rowInMultiLayer);
layer->setMaterialModel(m_materialModel); layer->setMaterialModel(materialModel());
layer->setMaterial(m_materialModel->defaultMaterial()); layer->setMaterial(materialModel()->defaultMaterial());
layer->setColor(color); layer->setColor(color);
ASSERT(m_multiLayerForm); ASSERT(m_multiLayerForm);
...@@ -129,9 +130,9 @@ void SampleEditorController::addParticle(ParticleLayoutItem* layoutItem, const Q ...@@ -129,9 +130,9 @@ void SampleEditorController::addParticle(ParticleLayoutItem* layoutItem, const Q
SessionItem* newItem = nullptr; SessionItem* newItem = nullptr;
if (ItemCatalog::isFormFactorModelType(classname)) { if (ItemCatalog::isFormFactorModelType(classname)) {
auto* new_particle = layoutItem->model()->insertItem<ParticleItem>(layoutItem); auto* new_particle = layoutItem->model()->insertItem<ParticleItem>(layoutItem);
new_particle->setMaterialModel(m_materialModel); new_particle->setMaterialModel(materialModel());
new_particle->setFormFactor(classname); new_particle->setFormFactor(classname);
new_particle->setMaterial(m_materialModel->defaultMaterial()); new_particle->setMaterial(materialModel()->defaultMaterial());
newItem = new_particle; newItem = new_particle;
} else } else
newItem = layoutItem->model()->insertNewItem(classname, layoutItem); newItem = layoutItem->model()->insertNewItem(classname, layoutItem);
...@@ -155,9 +156,9 @@ void SampleEditorController::addParticle(ParticleCompositionItem* compositionIte ...@@ -155,9 +156,9 @@ void SampleEditorController::addParticle(ParticleCompositionItem* compositionIte
SessionItem* newItem = nullptr; SessionItem* newItem = nullptr;
if (ItemCatalog::isFormFactorModelType(classname)) { if (ItemCatalog::isFormFactorModelType(classname)) {
auto* new_particle = compositionItem->model()->insertItem<ParticleItem>(compositionItem); auto* new_particle = compositionItem->model()->insertItem<ParticleItem>(compositionItem);
new_particle->setMaterialModel(m_materialModel); new_particle->setMaterialModel(materialModel());
new_particle->setFormFactor(classname); new_particle->setFormFactor(classname);
new_particle->setMaterial(m_materialModel->defaultMaterial()); new_particle->setMaterial(materialModel()->defaultMaterial());
newItem = new_particle; newItem = new_particle;
} else } else
newItem = compositionItem->model()->insertNewItem(classname, compositionItem); newItem = compositionItem->model()->insertNewItem(classname, compositionItem);
...@@ -293,7 +294,12 @@ QUndoStack* SampleEditorController::undoStack() ...@@ -293,7 +294,12 @@ QUndoStack* SampleEditorController::undoStack()
MaterialModel* SampleEditorController::materialModel() const MaterialModel* SampleEditorController::materialModel() const
{ {
return m_materialModel; return m_document->materialModel();
}
ProjectDocument* SampleEditorController::projectDocument() const
{
return m_document;
} }
void SampleEditorController::selectMaterial(ItemWithMaterial* item, void SampleEditorController::selectMaterial(ItemWithMaterial* item,
......
...@@ -37,6 +37,7 @@ class InterferenceItem; ...@@ -37,6 +37,7 @@ class InterferenceItem;
class AbstractSelectionContainerForm; class AbstractSelectionContainerForm;
class LatticeTypeSelectionForm; class LatticeTypeSelectionForm;
class MaterialModel; class MaterialModel;
class ProjectDocument;
//! Class to modify a sample from the layer oriented sample editor. //! Class to modify a sample from the layer oriented sample editor.
//! //!
...@@ -46,7 +47,7 @@ class MaterialModel; ...@@ -46,7 +47,7 @@ class MaterialModel;
class SampleEditorController : public QObject { class SampleEditorController : public QObject {
Q_OBJECT Q_OBJECT
public: public:
SampleEditorController(MaterialModel* materialModel, MultiLayerItem* multi); SampleEditorController(ProjectDocument* document, MultiLayerItem* multi);
//! Set the current form. //! Set the current form.
//! //!
...@@ -66,6 +67,9 @@ public: ...@@ -66,6 +67,9 @@ public:
//! The materials of the current document //! The materials of the current document
MaterialModel* materialModel() const; MaterialModel* materialModel() const;
//! The current document
ProjectDocument* projectDocument() const;
void addLayer(LayerItem* before); void addLayer(LayerItem* before);
void removeLayer(LayerItem* layerItem); void removeLayer(LayerItem* layerItem);
void addLayout(LayerForm* layerItem); void addLayout(LayerForm* layerItem);
...@@ -109,7 +113,7 @@ private: ...@@ -109,7 +113,7 @@ private:
QUndoStack m_undoStack; QUndoStack m_undoStack;
MultiLayerItem* m_multiLayerItem; MultiLayerItem* m_multiLayerItem;
MultiLayerForm* m_multiLayerForm; MultiLayerForm* m_multiLayerForm;
MaterialModel* m_materialModel; ProjectDocument* m_document;
}; };
......
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
#include "GUI/View/SampleDesigner/SampleListView.h" #include "GUI/View/SampleDesigner/SampleListView.h"
#include "GUI/Application/ApplicationSettings.h" #include "GUI/Application/ApplicationSettings.h"
#include "GUI/Model/From/GUIExamplesFactory.h" #include "GUI/Model/From/GUIExamplesFactory.h"
#include "GUI/Model/Sample/MultiLayerItem.h"
#include "GUI/Model/From/SampleListModel.h" #include "GUI/Model/From/SampleListModel.h"
#include "GUI/Model/State/SessionData.h" #include "GUI/Model/Project/ProjectDocument.h"
#include "GUI/Model/Sample/MultiLayerItem.h"
#include "GUI/View/Common/ItemViewOverlayButtons.h" #include "GUI/View/Common/ItemViewOverlayButtons.h"
#include "GUI/View/Tool/ItemDelegateForHTML.h" #include "GUI/View/Tool/ItemDelegateForHTML.h"
#include <QAction> #include <QAction>
...@@ -63,9 +63,10 @@ protected: ...@@ -63,9 +63,10 @@ protected:
} // namespace } // namespace
SampleListView::SampleListView(QWidget* parent, SampleModel* sampleModel) : QListView(parent) SampleListView::SampleListView(QWidget* parent, ProjectDocument* document)
: QListView(parent), m_document(document)
{ {
m_model = new SampleListModel(this, sampleModel); m_model = new SampleListModel(this, document->sampleModel());
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
setModel(m_model); setModel(m_model);
...@@ -143,8 +144,8 @@ void SampleListView::createNewSample() ...@@ -143,8 +144,8 @@ void SampleListView::createNewSample()
void SampleListView::createSampleFromLibrary(const QString& classname, const QString& title, void SampleListView::createSampleFromLibrary(const QString& classname, const QString& title,
const QString& description) const QString& description)
{ {
const QModelIndex newIndex = m_model->createSampleFromExamples( const QModelIndex newIndex = m_model->createSampleFromExamples(classname, title, description,
classname, title, description, gSessionData->projectDocument->materialModel()); m_document->materialModel());
setCurrentIndex(newIndex); setCurrentIndex(newIndex);
} }
......
...@@ -17,15 +17,15 @@ ...@@ -17,15 +17,15 @@
#include <QListView> #include <QListView>
class SampleModel;
class SampleListModel; class SampleListModel;
class MultiLayerItem; class MultiLayerItem;
class ProjectDocument;
//! List view to select one sample (left side of layer-oriented sample editor) //! List view to select one sample (left side of layer-oriented sample editor)
class SampleListView : public QListView { class SampleListView : public QListView {
Q_OBJECT Q_OBJECT
public: public:
SampleListView(QWidget* parent, SampleModel* sampleModel); SampleListView(QWidget* parent, ProjectDocument* document);
void setCurrentSample(MultiLayerItem* multiLayer); void setCurrentSample(MultiLayerItem* multiLayer);
MultiLayerItem* currentSample(); MultiLayerItem* currentSample();
...@@ -53,6 +53,7 @@ private: ...@@ -53,6 +53,7 @@ private:
private: private:
SampleListModel* m_model; SampleListModel* m_model;
ProjectDocument* m_document;
QAction* m_newSampleAction; QAction* m_newSampleAction;
QAction* m_chooseFromLibraryAction; QAction* m_chooseFromLibraryAction;
}; };
......
...@@ -47,7 +47,7 @@ SampleView::SampleView(QWidget* parent, ProjectDocument* document) ...@@ -47,7 +47,7 @@ SampleView::SampleView(QWidget* parent, ProjectDocument* document)
sampleSelectionLayout->setSpacing(0); sampleSelectionLayout->setSpacing(0);
auto* sampleSelectionToolbar = new StyledToolBar(sampleSelectionPane); auto* sampleSelectionToolbar = new StyledToolBar(sampleSelectionPane);
auto* sampleSelectionView = new SampleListView(this, m_document->sampleModel()); auto* sampleSelectionView = new SampleListView(this, m_document);
sampleSelectionToolbar->addAction(sampleSelectionView->newSampleAction()); sampleSelectionToolbar->addAction(sampleSelectionView->newSampleAction());
sampleSelectionToolbar->addAction(sampleSelectionView->chooseFromLibraryAction()); sampleSelectionToolbar->addAction(sampleSelectionView->chooseFromLibraryAction());
if (auto* btn = dynamic_cast<QToolButton*>(sampleSelectionToolbar->widgetForAction( if (auto* btn = dynamic_cast<QToolButton*>(sampleSelectionToolbar->widgetForAction(
......
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