diff --git a/GUI/coregui/Models/GUIObjectBuilder.cpp b/GUI/coregui/Models/GUIObjectBuilder.cpp index d041a6e155c54989bf2624f1c46e44517ded3a06..164c3a02d6501bc4a7efe14a64b837b33eff8310 100644 --- a/GUI/coregui/Models/GUIObjectBuilder.cpp +++ b/GUI/coregui/Models/GUIObjectBuilder.cpp @@ -22,7 +22,7 @@ #include "DetectorItems.h" #include "MultiLayerItem.h" #include "MaterialUtils.h" -#include "MaterialEditor.h" +#include "MaterialSvc.h" #include "MaterialModel.h" #include "ParticleItem.h" #include "TransformationItem.h" @@ -664,10 +664,10 @@ MaterialProperty GUIObjectBuilder::createMaterialFromDomain( + QString(material->getName().c_str()); MaterialProperty materialProperty = - MaterialEditor::getMaterialProperty(materialName); + MaterialSvc::getMaterialProperty(materialName); if(materialProperty.isDefined()) return materialProperty; - MaterialModel *model = MaterialEditor::getMaterialModel(); + MaterialModel *model = MaterialSvc::getMaterialModel(); if(material->isScalarMaterial()) { complex_t rindex = material->getRefractiveIndex(); diff --git a/GUI/coregui/Models/SessionModel.cpp b/GUI/coregui/Models/SessionModel.cpp index f10d642deab99ccbcb75726beb59eef96da616e8..d500d66eb62612459360913d904ce815d7d8c23c 100644 --- a/GUI/coregui/Models/SessionModel.cpp +++ b/GUI/coregui/Models/SessionModel.cpp @@ -16,7 +16,6 @@ #include "SessionModel.h" #include "ItemFactory.h" #include "GUIHelpers.h" -#include "MaterialEditor.h" #include "ComboProperty.h" #include "ScientificDoubleProperty.h" #include "IconProvider.h" diff --git a/GUI/coregui/Views/MaterialEditor/MaterialEditor.cpp b/GUI/coregui/Views/MaterialEditor/MaterialEditor.cpp index ba3c9ae54f535592fd11466fcc285c2553d8aa58..743678dbcded6d008233d52e883d034f27849971 100644 --- a/GUI/coregui/Views/MaterialEditor/MaterialEditor.cpp +++ b/GUI/coregui/Views/MaterialEditor/MaterialEditor.cpp @@ -14,123 +14,104 @@ // ************************************************************************** // #include "MaterialEditor.h" -#include "MaterialEditorDialog.h" +#include "MaterialEditorToolBar.h" +#include "ComponentEditor.h" #include "MaterialModel.h" -#include "MaterialItem.h" -#include "MaterialUtils.h" -#include "SessionModel.h" -#include <QDebug> - -MaterialEditor *MaterialEditor::m_instance = 0; - -MaterialEditor::MaterialEditor(MaterialModel *materialModel) - : m_materialModel(materialModel) -{ - Q_ASSERT(!m_instance); - m_instance = this; -} - - -MaterialEditor::~MaterialEditor() -{ - m_instance = 0; -} - -MaterialEditor *MaterialEditor::instance() +#include <QListView> +#include <QSplitter> +#include <QVBoxLayout> + +MaterialEditor::MaterialEditor(MaterialModel *materialModel, QWidget *parent) + : QWidget(parent) + , m_materialModel(materialModel) + , m_toolBar(new MaterialEditorToolBar(materialModel, this)) + , m_splitter(new QSplitter) + , m_listView(new QListView) + , m_componentEditor(new ComponentEditor) { - return m_instance; -} + setWindowTitle("MaterialEditorWidget"); + setMinimumSize(128, 128); + resize(512, 400); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + QVBoxLayout *layout = new QVBoxLayout; + layout->setContentsMargins(0,0,0,0); -MaterialProperty MaterialEditor::selectMaterialProperty() -{ - Q_ASSERT(m_instance); - return m_instance->this_selectMaterialProperty(); -} + m_splitter->addWidget(m_listView); + m_splitter->addWidget(m_componentEditor); + m_splitter->setCollapsible(0, false); + m_splitter->setCollapsible(1, false); + layout->addWidget(m_toolBar); + layout->addWidget(m_splitter); -MaterialProperty MaterialEditor::this_selectMaterialProperty() -{ - qDebug() << "MaterialEditor::this_getMaterialProperty()"; - MaterialEditorDialog widget(m_materialModel); - if(widget.exec() == QDialog::Accepted) { - return widget.getSelectedMaterialProperty(); - } + setLayout(layout); - return MaterialProperty(); + init_views(); } - -MaterialProperty MaterialEditor::getMaterialProperty(const QString &name) +QItemSelectionModel *MaterialEditor::getSelectionModel() { - Q_ASSERT(m_instance); - return m_instance->this_getMaterialProperty(name); + Q_ASSERT(m_listView); + return m_listView->selectionModel(); } - -MaterialProperty MaterialEditor::this_getMaterialProperty(const QString &name) +MaterialItem *MaterialEditor::getSelectedMaterial() { - MaterialItem *material = m_materialModel->getMaterial(name); - if(material) - return MaterialProperty(material->getIdentifier()); - - return MaterialProperty(); + QModelIndexList selected = getSelectionModel()->selectedIndexes(); + if(selected.size()) { + return m_materialModel->getMaterial(selected.front()); + } + return nullptr; } - -MaterialProperty MaterialEditor::getDefaultMaterialProperty() +void MaterialEditor::onSelectionChanged(const QItemSelection &selected, + const QItemSelection &) { - Q_ASSERT(m_instance); - return m_instance->this_getDefaultMaterialProperty(); -} + QModelIndexList indices = selected.indexes(); -//! Returns default MaterialProperty which is the signature of the first -//! MaterialItem in the model. -MaterialProperty MaterialEditor::this_getDefaultMaterialProperty() -{ - Q_ASSERT(m_materialModel); - if((m_materialModel->rowCount( QModelIndex() ) ) ) { - QModelIndex firstIndex = m_materialModel->index(0, 0, QModelIndex()); - MaterialItem *material = dynamic_cast<MaterialItem *>(m_materialModel->itemForIndex(firstIndex)); - Q_ASSERT(material); - return MaterialProperty(material->getIdentifier()); + if(indices.isEmpty()) { + m_componentEditor->setItem(0); } else { - return MaterialProperty(); + if(SessionItem *item = m_materialModel->itemForIndex(indices.at(0))) { + m_componentEditor->setItem(item); + } } } - -MaterialModel *MaterialEditor::getMaterialModel() -{ - Q_ASSERT(m_instance); - return m_instance->this_getMaterialModel(); -} - -MaterialItem *MaterialEditor::getMaterial(const MaterialProperty &property) +//! Context menu reimplemented to supress default menu +void MaterialEditor::contextMenuEvent(QContextMenuEvent *event) { - Q_ASSERT(m_instance); - return m_instance->this_getMaterial(property); + Q_UNUSED(event); } -//MaterialItem *MaterialEditor::getMaterial(const QString &material_name) -//{ -// Q_ASSERT(m_instance); -// return m_instance->this_getMaterial(material_name); -//} - - -MaterialModel *MaterialEditor::this_getMaterialModel() -{ - return m_materialModel; -} -MaterialItem *MaterialEditor::this_getMaterial(const MaterialProperty &property) +void MaterialEditor::init_views() { - return this_getMaterialModel()->getMaterial(property); -} + m_listView->setContextMenuPolicy(Qt::CustomContextMenu); + m_listView->setModel(m_materialModel); + m_listView->setMovement(QListView::Static); + m_listView->setMinimumWidth(50); + m_listView->setMaximumWidth(220); + m_listView->setSpacing(5); + + m_toolBar->setSelectionModel(getSelectionModel()); + + connect(getSelectionModel(), + SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), + this, + SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)), + Qt::UniqueConnection + ); + + + // making first material selected + if (!getSelectionModel()->hasSelection()) { + QModelIndex itemIndex = m_materialModel->index(0, 0, QModelIndex()); + getSelectionModel()->select(itemIndex, QItemSelectionModel::Select); + } -//MaterialItem *MaterialEditor::this_getMaterial(const QString &material_name) -//{ -// return this_getMaterialModel()->getMaterial(material_name); -//} + connect(m_listView, SIGNAL(customContextMenuRequested(const QPoint &)), + m_toolBar, SLOT(onCustomContextMenuRequested(const QPoint &))); +} diff --git a/GUI/coregui/Views/MaterialEditor/MaterialEditor.h b/GUI/coregui/Views/MaterialEditor/MaterialEditor.h index 4c4307f1071cd6b30dab55eb648aa3c42bdfed2b..2daef9ff3f4c5b44c67bd73e5650b1f2ea59baf8 100644 --- a/GUI/coregui/Views/MaterialEditor/MaterialEditor.h +++ b/GUI/coregui/Views/MaterialEditor/MaterialEditor.h @@ -17,46 +17,45 @@ #define MATERIALEDITOR_H #include "WinDllMacros.h" -#include "MaterialProperty.h" -#include <QObject> +#include <QWidget> class MaterialModel; -class SessionModel; +class MaterialEditorToolBar; +class QSplitter; +class QListView; +class ComponentEditor; +class QItemSelection; +class QItemSelectionModel; class MaterialItem; -//! The MaterialEditor is the main class to access materials. -class BA_CORE_API_ MaterialEditor : public QObject +//! Main widget of MaterialEditor +class BA_CORE_API_ MaterialEditor : public QWidget { Q_OBJECT + public: - MaterialEditor(MaterialModel *materialModel); - virtual ~MaterialEditor(); + MaterialEditor(MaterialModel *materialModel, QWidget *parent = 0); - static MaterialEditor *instance(); + QItemSelectionModel *getSelectionModel(); - static MaterialProperty getMaterialProperty(const QString &name); - static MaterialProperty selectMaterialProperty(); - static MaterialProperty getDefaultMaterialProperty(); + MaterialItem *getSelectedMaterial(); - static MaterialModel *getMaterialModel(); +private slots: + void onSelectionChanged(const QItemSelection &selected, const QItemSelection&); - static MaterialItem *getMaterial(const MaterialProperty &property); -// MaterialItem *getMaterial(const QString &material_name); +protected: + void contextMenuEvent(QContextMenuEvent *event); private: - MaterialProperty this_selectMaterialProperty(); - MaterialProperty this_getMaterialProperty(const QString &name); - MaterialProperty this_getDefaultMaterialProperty(); - MaterialModel *this_getMaterialModel(); - MaterialItem *this_getMaterial(const MaterialProperty &property); -// MaterialItem *this_getMaterial(const QString &material_name); - - static MaterialEditor *m_instance; + void init_views(); + MaterialModel *m_materialModel; + MaterialEditorToolBar *m_toolBar; + QSplitter *m_splitter; + QListView *m_listView; + ComponentEditor *m_componentEditor; }; - #endif - diff --git a/GUI/coregui/Views/MaterialEditor/MaterialEditorDialog.cpp b/GUI/coregui/Views/MaterialEditor/MaterialEditorDialog.cpp index fdaf3ae36a4ab1a8e26793bed6fc03fc2c5dbbb5..86f64a955ba5d162d2e9bfc9e7335eec49a7127d 100644 --- a/GUI/coregui/Views/MaterialEditor/MaterialEditorDialog.cpp +++ b/GUI/coregui/Views/MaterialEditor/MaterialEditorDialog.cpp @@ -15,23 +15,17 @@ #include "MaterialEditorDialog.h" #include "MaterialModel.h" -#include "MaterialEditorWidget.h" +#include "MaterialEditor.h" #include "MaterialUtils.h" -//#include <QStyle> -//#include <QStatusBar> -//#include <QToolBar> #include <QVBoxLayout> #include <QPushButton> #include <QAction> #include <QDebug> -//#include <QtTreePropertyBrowser> -//int MaterialEditorDialog::m_IndexOfUnnamed = 0; - MaterialEditorDialog::MaterialEditorDialog(MaterialModel *materialModel, QWidget *parent) : QDialog(parent) - , m_materialEditor(new MaterialEditorWidget(materialModel, this)) + , m_materialEditor(new MaterialEditor(materialModel, this)) { setWindowTitle("Material Editor"); setMinimumSize(128, 128); diff --git a/GUI/coregui/Views/MaterialEditor/MaterialEditorDialog.h b/GUI/coregui/Views/MaterialEditor/MaterialEditorDialog.h index 7a83d12015fc0abceb1c957705fe1b0e1b3d3042..1b636414defb4e3d86e5d739224af07f559d0ba2 100644 --- a/GUI/coregui/Views/MaterialEditor/MaterialEditorDialog.h +++ b/GUI/coregui/Views/MaterialEditor/MaterialEditorDialog.h @@ -22,7 +22,7 @@ #include "WinDllMacros.h" class MaterialModel; -class MaterialEditorWidget; +class MaterialEditor; //! Main widget of MaterialEditor class BA_CORE_API_ MaterialEditorDialog : public QDialog @@ -39,7 +39,7 @@ public slots: void onCancelButton(); private: - MaterialEditorWidget *m_materialEditor; + MaterialEditor *m_materialEditor; }; #endif diff --git a/GUI/coregui/Views/MaterialEditor/MaterialEditorWidget.cpp b/GUI/coregui/Views/MaterialEditor/MaterialEditorWidget.cpp deleted file mode 100644 index 069e26261450cd9f49e44c294171ac2bc64c4a06..0000000000000000000000000000000000000000 --- a/GUI/coregui/Views/MaterialEditor/MaterialEditorWidget.cpp +++ /dev/null @@ -1,117 +0,0 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file coregui/Views/MaterialEditor/MaterialEditorWidget.cpp -//! @brief Implements class MaterialEditorWidget -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2015 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke -// -// ************************************************************************** // - -#include "MaterialEditorWidget.h" -#include "MaterialEditorToolBar.h" -#include "ComponentEditor.h" -#include "MaterialModel.h" -#include <QListView> -#include <QSplitter> -#include <QVBoxLayout> - -MaterialEditorWidget::MaterialEditorWidget(MaterialModel *materialModel, QWidget *parent) - : QWidget(parent) - , m_materialModel(materialModel) - , m_toolBar(new MaterialEditorToolBar(materialModel, this)) - , m_splitter(new QSplitter) - , m_listView(new QListView) - , m_componentEditor(new ComponentEditor) -{ - setWindowTitle("MaterialEditorWidget"); - setMinimumSize(128, 128); - resize(512, 400); - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - - QVBoxLayout *layout = new QVBoxLayout; - layout->setContentsMargins(0,0,0,0); - - m_splitter->addWidget(m_listView); - m_splitter->addWidget(m_componentEditor); - m_splitter->setCollapsible(0, false); - m_splitter->setCollapsible(1, false); - - layout->addWidget(m_toolBar); - layout->addWidget(m_splitter); - - setLayout(layout); - - init_views(); -} - -QItemSelectionModel *MaterialEditorWidget::getSelectionModel() -{ - Q_ASSERT(m_listView); - return m_listView->selectionModel(); -} - -MaterialItem *MaterialEditorWidget::getSelectedMaterial() -{ - QModelIndexList selected = getSelectionModel()->selectedIndexes(); - if(selected.size()) { - return m_materialModel->getMaterial(selected.front()); - } - return nullptr; -} - -void MaterialEditorWidget::onSelectionChanged(const QItemSelection &selected, - const QItemSelection &) -{ - QModelIndexList indices = selected.indexes(); - - if(indices.isEmpty()) { - m_componentEditor->setItem(0); - } else { - if(SessionItem *item = m_materialModel->itemForIndex(indices.at(0))) { - m_componentEditor->setItem(item); - } - } -} - -//! Context menu reimplemented to supress default menu -void MaterialEditorWidget::contextMenuEvent(QContextMenuEvent *event) -{ - Q_UNUSED(event); -} - - -void MaterialEditorWidget::init_views() -{ - m_listView->setContextMenuPolicy(Qt::CustomContextMenu); - m_listView->setModel(m_materialModel); - m_listView->setMovement(QListView::Static); - m_listView->setMinimumWidth(50); - m_listView->setMaximumWidth(220); - m_listView->setSpacing(5); - - m_toolBar->setSelectionModel(getSelectionModel()); - - connect(getSelectionModel(), - SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), - this, - SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)), - Qt::UniqueConnection - ); - - - // making first material selected - if (!getSelectionModel()->hasSelection()) { - QModelIndex itemIndex = m_materialModel->index(0, 0, QModelIndex()); - getSelectionModel()->select(itemIndex, QItemSelectionModel::Select); - } - - connect(m_listView, SIGNAL(customContextMenuRequested(const QPoint &)), - m_toolBar, SLOT(onCustomContextMenuRequested(const QPoint &))); - -} diff --git a/GUI/coregui/Views/MaterialEditor/MaterialEditorWidget.h b/GUI/coregui/Views/MaterialEditor/MaterialEditorWidget.h deleted file mode 100644 index 2ef7e1975afe1468d26e937b908d0c2ba0e56c7d..0000000000000000000000000000000000000000 --- a/GUI/coregui/Views/MaterialEditor/MaterialEditorWidget.h +++ /dev/null @@ -1,61 +0,0 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file coregui/Views/MaterialEditor/MaterialEditorWidget.h -//! @brief Defines class MaterialEditorWidget -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2015 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke -// -// ************************************************************************** // - -#ifndef MATERIALEDITORWIDGET_H -#define MATERIALEDITORWIDGET_H - -#include "WinDllMacros.h" -#include <QWidget> - -class MaterialModel; -class MaterialEditorToolBar; -class QSplitter; -class QListView; -class ComponentEditor; -class QItemSelection; -class QItemSelectionModel; -class MaterialItem; - -//! Main widget of MaterialEditor -class BA_CORE_API_ MaterialEditorWidget : public QWidget -{ - Q_OBJECT - -public: - MaterialEditorWidget(MaterialModel *materialModel, QWidget *parent = 0); - - QItemSelectionModel *getSelectionModel(); - - MaterialItem *getSelectedMaterial(); - -private slots: - void onSelectionChanged(const QItemSelection &selected, const QItemSelection&); - -protected: - void contextMenuEvent(QContextMenuEvent *event); - -private: - void init_views(); - - MaterialModel *m_materialModel; - MaterialEditorToolBar *m_toolBar; - QSplitter *m_splitter; - QListView *m_listView; - ComponentEditor *m_componentEditor; -}; - - -#endif - diff --git a/GUI/coregui/Views/MaterialEditor/MaterialProperty.cpp b/GUI/coregui/Views/MaterialEditor/MaterialProperty.cpp index 01d2e5fdd28ac6101561ef0626b4a224ac534f8f..c532264675e688636f2963fd62132f3ee6a4882b 100644 --- a/GUI/coregui/Views/MaterialEditor/MaterialProperty.cpp +++ b/GUI/coregui/Views/MaterialEditor/MaterialProperty.cpp @@ -15,13 +15,13 @@ #include "MaterialProperty.h" #include "MaterialItem.h" -#include "MaterialEditor.h" +#include "MaterialSvc.h" #include "MaterialModel.h" QString MaterialProperty::getName() const { MaterialProperty property(getIdentifier()); - MaterialItem *materialItem = MaterialEditor::getMaterial(property); + MaterialItem *materialItem = MaterialSvc::getMaterial(property); if(materialItem) { return materialItem->itemName(); } else { @@ -33,7 +33,7 @@ QString MaterialProperty::getName() const QColor MaterialProperty::getColor() const { MaterialProperty property(getIdentifier()); - MaterialItem *materialItem = MaterialEditor::getMaterial(property); + MaterialItem *materialItem = MaterialSvc::getMaterial(property); if(materialItem) { return materialItem->getColor(); } else { diff --git a/GUI/coregui/Views/MaterialEditor/MaterialSvc.cpp b/GUI/coregui/Views/MaterialEditor/MaterialSvc.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4fbef9b851b06d3983543c93fd9e5324818b75ce --- /dev/null +++ b/GUI/coregui/Views/MaterialEditor/MaterialSvc.cpp @@ -0,0 +1,125 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/Views/MaterialEditor/MaterialEditor.cpp +//! @brief Implements class MaterialEditor +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#include "MaterialSvc.h" +#include "MaterialEditorDialog.h" +#include "MaterialModel.h" +#include "MaterialItem.h" +#include "MaterialUtils.h" +#include "SessionModel.h" +#include <QDebug> + +MaterialSvc *MaterialSvc::m_instance = 0; + +MaterialSvc::MaterialSvc(MaterialModel *materialModel) + : m_materialModel(materialModel) +{ + Q_ASSERT(!m_instance); + m_instance = this; +} + + +MaterialSvc::~MaterialSvc() +{ + m_instance = 0; +} + +MaterialSvc *MaterialSvc::instance() +{ + return m_instance; +} + + +MaterialProperty MaterialSvc::selectMaterialProperty() +{ + Q_ASSERT(m_instance); + return m_instance->this_selectMaterialProperty(); +} + + +MaterialProperty MaterialSvc::this_selectMaterialProperty() +{ + qDebug() << "MaterialEditor::this_getMaterialProperty()"; + MaterialEditorDialog widget(m_materialModel); + if(widget.exec() == QDialog::Accepted) { + return widget.getSelectedMaterialProperty(); + } + + return MaterialProperty(); +} + + +MaterialProperty MaterialSvc::getMaterialProperty(const QString &name) +{ + Q_ASSERT(m_instance); + return m_instance->this_getMaterialProperty(name); +} + + +MaterialProperty MaterialSvc::this_getMaterialProperty(const QString &name) +{ + MaterialItem *material = m_materialModel->getMaterial(name); + if(material) + return MaterialProperty(material->getIdentifier()); + + return MaterialProperty(); +} + + +MaterialProperty MaterialSvc::getDefaultMaterialProperty() +{ + Q_ASSERT(m_instance); + return m_instance->this_getDefaultMaterialProperty(); +} + +//! Returns default MaterialProperty which is the signature of the first +//! MaterialItem in the model. +MaterialProperty MaterialSvc::this_getDefaultMaterialProperty() +{ + Q_ASSERT(m_materialModel); + if((m_materialModel->rowCount( QModelIndex() ) ) ) { + QModelIndex firstIndex = m_materialModel->index(0, 0, QModelIndex()); + MaterialItem *material = dynamic_cast<MaterialItem *>(m_materialModel->itemForIndex(firstIndex)); + Q_ASSERT(material); + return MaterialProperty(material->getIdentifier()); + } else { + return MaterialProperty(); + } +} + + +MaterialModel *MaterialSvc::getMaterialModel() +{ + Q_ASSERT(m_instance); + return m_instance->this_getMaterialModel(); +} + +MaterialItem *MaterialSvc::getMaterial(const MaterialProperty &property) +{ + Q_ASSERT(m_instance); + return m_instance->this_getMaterial(property); +} + + +MaterialModel *MaterialSvc::this_getMaterialModel() +{ + return m_materialModel; +} + +MaterialItem *MaterialSvc::this_getMaterial(const MaterialProperty &property) +{ + return this_getMaterialModel()->getMaterial(property); +} + diff --git a/GUI/coregui/Views/MaterialEditor/MaterialSvc.h b/GUI/coregui/Views/MaterialEditor/MaterialSvc.h new file mode 100644 index 0000000000000000000000000000000000000000..36ea10401d22ebecd4d2b093c4f1b8961f63fd07 --- /dev/null +++ b/GUI/coregui/Views/MaterialEditor/MaterialSvc.h @@ -0,0 +1,60 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/Views/MaterialEditor/MaterialSvc.h +//! @brief Defines class MaterialSvc +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#ifndef MATERIALSVC_H +#define MATERIALSVC_H + +#include "WinDllMacros.h" +#include "MaterialProperty.h" +#include <QObject> + +class MaterialModel; +class SessionModel; +class MaterialItem; + +//! The MaterialEditor is the main class to access materials. +class BA_CORE_API_ MaterialSvc : public QObject +{ + Q_OBJECT +public: + MaterialSvc(MaterialModel *materialModel); + virtual ~MaterialSvc(); + + static MaterialSvc *instance(); + + static MaterialProperty getMaterialProperty(const QString &name); + static MaterialProperty selectMaterialProperty(); + static MaterialProperty getDefaultMaterialProperty(); + + static MaterialModel *getMaterialModel(); + + static MaterialItem *getMaterial(const MaterialProperty &property); + +private: + MaterialProperty this_selectMaterialProperty(); + MaterialProperty this_getMaterialProperty(const QString &name); + MaterialProperty this_getDefaultMaterialProperty(); + MaterialModel *this_getMaterialModel(); + MaterialItem *this_getMaterial(const MaterialProperty &property); + + static MaterialSvc *m_instance; + MaterialModel *m_materialModel; +}; + + + +#endif + + diff --git a/GUI/coregui/Views/MaterialEditor/MaterialUtils.cpp b/GUI/coregui/Views/MaterialEditor/MaterialUtils.cpp index b722216b6d54a196b1e366a14de667fd747e2faa..e09fabd3e9c5c5ef0466e493104413e1965b3d20 100644 --- a/GUI/coregui/Views/MaterialEditor/MaterialUtils.cpp +++ b/GUI/coregui/Views/MaterialEditor/MaterialUtils.cpp @@ -18,7 +18,7 @@ #include "GUIHelpers.h" #include "HomogeneousMaterial.h" #include "HomogeneousMagneticMaterial.h" -#include "MaterialEditor.h" +#include "MaterialSvc.h" #include "MaterialModel.h" #include "RefractiveIndexItem.h" #include "MagneticFieldItem.h" @@ -48,8 +48,8 @@ QColor MaterialUtils::suggestMaterialColor(const QString &name) MaterialProperty MaterialUtils::getDefaultMaterialProperty() { - if(MaterialEditor::instance()) { - return MaterialEditor::getDefaultMaterialProperty(); + if(MaterialSvc::instance()) { + return MaterialSvc::getDefaultMaterialProperty(); } return MaterialProperty(); } @@ -64,7 +64,7 @@ std::unique_ptr<IMaterial> MaterialUtils::createDomainMaterial(const MaterialProperty &material_property) { MaterialItem *materialItem - = MaterialEditor::getMaterial(material_property); + = MaterialSvc::getMaterial(material_property); Q_ASSERT(materialItem); return materialItem->createMaterial(); } diff --git a/GUI/coregui/Views/PropertyEditor/PropertyBrowserUtils.cpp b/GUI/coregui/Views/PropertyEditor/PropertyBrowserUtils.cpp index dcba1a205656971966b12fc4b2eee1b13c6cb027..dd9303696f37ac64a234737ca1becdcd4f05cb40 100644 --- a/GUI/coregui/Views/PropertyEditor/PropertyBrowserUtils.cpp +++ b/GUI/coregui/Views/PropertyEditor/PropertyBrowserUtils.cpp @@ -14,7 +14,7 @@ // ************************************************************************** // #include "PropertyBrowserUtils.h" -#include "MaterialEditor.h" +#include "MaterialSvc.h" #include "GUIHelpers.h" #include <QHBoxLayout> #include <QToolButton> @@ -63,7 +63,7 @@ MaterialPropertyEdit::MaterialPropertyEdit(QWidget *parent) void MaterialPropertyEdit::buttonClicked() { - MaterialProperty mat = MaterialEditor::selectMaterialProperty(); + MaterialProperty mat = MaterialSvc::selectMaterialProperty(); if(mat.isDefined() ) { setMaterialProperty(mat); emit materialPropertyChanged(m_materialProperty); diff --git a/GUI/coregui/Views/SampleDesigner/SampleToolBar.cpp b/GUI/coregui/Views/SampleDesigner/SampleToolBar.cpp index 30e9b1dffd67e8e6cadd8b6fd52223b3eb8a23fc..4af7cb59e8956ea460cadbb77d83194b43069561 100644 --- a/GUI/coregui/Views/SampleDesigner/SampleToolBar.cpp +++ b/GUI/coregui/Views/SampleDesigner/SampleToolBar.cpp @@ -14,7 +14,7 @@ // ************************************************************************** // #include "SampleToolBar.h" -#include "MaterialEditor.h" +#include "MaterialSvc.h" #include "MaterialProperty.h" #include "DesignerView.h" #include <QIcon> @@ -157,7 +157,7 @@ void SampleToolBar::onScaleComboChanged(const QString &scale_string) void SampleToolBar::onMaterialEditorCall() { - MaterialProperty mp = MaterialEditor::selectMaterialProperty(); + MaterialProperty mp = MaterialSvc::selectMaterialProperty(); qDebug() << "SampleToolBar::materialBrowserCall()" << mp.getName() << mp.getColor(); } diff --git a/GUI/coregui/Views/TestView.cpp b/GUI/coregui/Views/TestView.cpp index fc5f1b507f111f10dbf732c3a300b20c19a71067..f7d0147cd8e69ddeff514e24e79fd8a42b12e2a4 100644 --- a/GUI/coregui/Views/TestView.cpp +++ b/GUI/coregui/Views/TestView.cpp @@ -19,7 +19,7 @@ #include "mainwindow.h" #include "FitParameterWidget.h" #include "JobModel.h" -#include "MaterialEditorWidget.h" +#include "MaterialEditor.h" #include <QMimeData> #include <QVBoxLayout> #include <AccordionWidget.h> @@ -93,7 +93,7 @@ void TestView::test_sessionModel() void TestView::test_MaterialEditor() { - MaterialEditorWidget *materialEditor = new MaterialEditorWidget(m_mainWindow->getMaterialModel()); + MaterialEditor *materialEditor = new MaterialEditor(m_mainWindow->getMaterialModel()); QVBoxLayout *layout = new QVBoxLayout; layout->setMargin(0); layout->setSpacing(0); diff --git a/GUI/coregui/mainwindow/mainwindow.cpp b/GUI/coregui/mainwindow/mainwindow.cpp index 7d76112fac8b3ef8919add79df0f77fde5a5f6ce..7d621e0e44874dfffba1ca8a596b2b43e58b7f46 100644 --- a/GUI/coregui/mainwindow/mainwindow.cpp +++ b/GUI/coregui/mainwindow/mainwindow.cpp @@ -27,7 +27,7 @@ #include "JobModel.h" #include "MaterialModel.h" #include "InstrumentModel.h" -#include "MaterialEditor.h" +#include "MaterialSvc.h" #include "Instrument.h" #include "Units.h" #include "Samples.h" @@ -272,7 +272,7 @@ void MainWindow::createMaterialModel() // m_materialModel->addMaterial("Air", 0.0, 0.0); // m_materialModel->addMaterial("Particle", 6e-4, 2e-8); // m_materialModel->addMaterial("Substrate", 6e-6, 2e-8); - m_materialEditor = new MaterialEditor(m_materialModel); + m_materialEditor = new MaterialSvc(m_materialModel); } void MainWindow::createSampleModel() diff --git a/GUI/coregui/mainwindow/mainwindow.h b/GUI/coregui/mainwindow/mainwindow.h index d07e56f5317804d5a62e173ef7376081617a9d6f..c539ed856f736e262454c224f0dd9b82c82cbd71 100644 --- a/GUI/coregui/mainwindow/mainwindow.h +++ b/GUI/coregui/mainwindow/mainwindow.h @@ -39,7 +39,7 @@ class ProjectManager; class QCloseEvent; class QSettings; class InstrumentModel; -class MaterialEditor; +class MaterialSvc; class ToolTipDataBase; class MaterialModel; class SampleModel; @@ -101,7 +101,7 @@ private: InstrumentModel *m_instrumentModel; //!< model for all instruments MaterialModel *m_materialModel; //!< model for all materials FitModel *m_fitModel; //!< model for fitting - MaterialEditor *m_materialEditor; + MaterialSvc *m_materialEditor; ToolTipDataBase *m_toolTipDataBase; UpdateNotifier *m_updateNotifier; diff --git a/GUI/coregui/utils/GUIFunctionalTest.cpp b/GUI/coregui/utils/GUIFunctionalTest.cpp index f2a95fba4d7874be2bd2ff7fb53039c63bf4257e..ef3668319dd44aefa27e80f78e215429e8785396 100644 --- a/GUI/coregui/utils/GUIFunctionalTest.cpp +++ b/GUI/coregui/utils/GUIFunctionalTest.cpp @@ -18,7 +18,7 @@ #include "GUIObjectBuilder.h" #include "InstrumentModel.h" #include "SampleModel.h" -#include "MaterialEditor.h" +#include "MaterialSvc.h" #include "MaterialModel.h" #include "Instrument.h" #include "DomainObjectBuilder.h" diff --git a/Tests/UnitTests/TestGUI/TestParticleItems.h b/Tests/UnitTests/TestGUI/TestParticleItems.h index 9f5017162a5438bca5587fc6211be2be8b4998d1..3f65d5bcbdb9ff7660683e37369ce64657d0bae9 100644 --- a/Tests/UnitTests/TestGUI/TestParticleItems.h +++ b/Tests/UnitTests/TestGUI/TestParticleItems.h @@ -10,7 +10,7 @@ #include "GUIObjectBuilder.h" #include "ParticleItem.h" #include "TransformToDomain.h" -#include "MaterialEditor.h" +#include "MaterialSvc.h" #include "MaterialModel.h" #include "GroupProperty.h" #include "FormFactorItems.h" diff --git a/Tests/UnitTests/TestGUI/TestSessionModel.h b/Tests/UnitTests/TestGUI/TestSessionModel.h index dd1fc26f8230f8775c7e1b21809614af5ec46d30..f09c2367c8c03d14eef1cb523f8c5e22117839ed 100644 --- a/Tests/UnitTests/TestGUI/TestSessionModel.h +++ b/Tests/UnitTests/TestGUI/TestSessionModel.h @@ -6,7 +6,7 @@ #include "SampleModel.h" #include "MaterialModel.h" #include "InstrumentModel.h" -#include "MaterialEditor.h" +#include "MaterialSvc.h" #include "JobModel.h" #include <QXmlStreamWriter> #include <memory>