Skip to content
Snippets Groups Projects
Commit 7185ccaf authored by Van Herck, Walter's avatar Van Herck, Walter
Browse files

added first derived ParameterizedItem for MultiLayer

parent 713f252a
No related branches found
No related tags found
No related merge requests found
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Models/ItemFactory.cpp
//! @brief Implements class ItemFactory.
//!
//! @homepage http://apps.jcns.fz-juelich.de/BornAgain
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2013
//! @authors Scientific Computing Group at MLZ Garching
//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke
//
// ************************************************************************** //
#include "ItemFactory.h"
#include "MultiLayerItem.h"
ParameterizedItem *ItemFactory::createItem(const QString &model_name)
{
if (model_name==QString("MultiLayer")) {
return new MultiLayerItem();
}
}
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Models/ItemFactory.h
//! @brief Defines class ItemFactory.
//!
//! @homepage http://apps.jcns.fz-juelich.de/BornAgain
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2013
//! @authors Scientific Computing Group at MLZ Garching
//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke
//
// ************************************************************************** //
#ifndef ITEMFACTORY_H
#define ITEMFACTORY_H
#include "ParameterizedItem.h"
class ItemFactory
{
public:
static ParameterizedItem *createItem(const QString &model_name);
private:
ItemFactory() {}
~ItemFactory() {}
};
#endif // ITEMFACTORY_H
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Models/MultiLayerItem.cpp
//! @brief Implements class MultiLayerItem.
//!
//! @homepage http://apps.jcns.fz-juelich.de/BornAgain
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2013
//! @authors Scientific Computing Group at MLZ Garching
//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke
//
// ************************************************************************** //
#include "MultiLayerItem.h"
MultiLayerItem::MultiLayerItem()
: ParameterizedItem(QString("MultiLayer"))
{
m_parameters[QString("Cross Correlation Length")] = 0.0;
}
MultiLayerItem::~MultiLayerItem()
{
}
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Models/MultiLayerItem.h
//! @brief Defines class MultiLayerItem.
//!
//! @homepage http://apps.jcns.fz-juelich.de/BornAgain
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2013
//! @authors Scientific Computing Group at MLZ Garching
//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke
//
// ************************************************************************** //
#ifndef MULTILAYERITEM_H
#define MULTILAYERITEM_H
#include "ParameterizedItem.h"
class MultiLayerItem : public ParameterizedItem
{
public:
explicit MultiLayerItem();
~MultiLayerItem();
};
#endif // MULTILAYERITEM_H
......@@ -14,32 +14,44 @@
// ************************************************************************** //
#include "ParameterizedItem.h"
#include "Exceptions.h"
ParameterizedItem::ParameterizedItem(BA_MODEL_ID::Model_ID model_type,
const QString &name)
ParameterizedItem::ParameterizedItem(const QString &name)
: QStandardItem(name)
, m_model_type(model_type)
{
populateWithParameters();
}
ParameterizedItem::~ParameterizedItem()
{
}
double ParameterizedItem::getParameterValue(QString name)
{
if (!m_parameters.contains(name)) {
throw Exceptions::RuntimeErrorException("ParameterizedItem::getParameterValue: "
"parameter does not exist");
}
return m_parameters[name];
}
void ParameterizedItem::setParameter(QString name, double value)
{
if (m_parameters.contains(name)) {
m_parameters[name] = value;
if (!m_parameters.contains(name)) {
throw Exceptions::RuntimeErrorException("ParameterizedItem::getParameterValue: "
"parameter does not exist");
}
m_parameters[name] = value;
}
void ParameterizedItem::populateWithParameters()
bool ParameterizedItem::acceptsAsChild(ParameterizedItem *child)
{
m_parameters[QString("firstparam")] = 5.0;
m_parameters[QString("anotherparam")] = 6.0;
m_parameters[QString("lastparam")] = 7.0;
return child->isValidParent(this->text());
}
bool ParameterizedItem::isValidParent(QString parentName)
{
return m_valid_parents.contains(parentName);
}
......@@ -17,29 +17,36 @@
#define PARAMETERIZEDITEM_H_
#include <QStandardItem>
#include <QList>
#include <QMap>
namespace BA_MODEL_ID {
enum Model_ID {
MultiLayer,
Layer,
};
}
class ParameterizedItem : public QStandardItem
{
public:
explicit ParameterizedItem(BA_MODEL_ID::Model_ID model_type, const QString &name);
explicit ParameterizedItem(const QString &name);
~ParameterizedItem();
//! retrieves the parameter's value
double getParameterValue(QString name);
//! sets the parameter's value, if it exists
void setParameter(QString name, double value);
//! retrieves the whole list of paramaters
QMap<QString, double> &getParameters() {
return m_parameters;
}
private:
void populateWithParameters();
BA_MODEL_ID::Model_ID m_model_type;
//! indicates if the passed item can be set as
//! a child item
bool acceptsAsChild(ParameterizedItem *child);
protected:
QList<QString> m_valid_parents;
QMap<QString, double> m_parameters;
private:
//! indicates if the item name, passed as argument
//! can be the current item's parent
bool isValidParent(QString parentName);
};
......
......@@ -14,6 +14,7 @@
// ************************************************************************** //
#include "SessionModel.h"
#include "ItemFactory.h"
SessionModel::SessionModel(QObject *parent)
......@@ -27,7 +28,7 @@ SessionModel::~SessionModel()
}
QStandardItem *SessionModel::insertNewItem(BA_MODEL_ID::Model_ID model_type, const QModelIndex &index)
QStandardItem *SessionModel::insertNewItem(QString model_type, const QModelIndex &index)
{
QStandardItem *parent;
if (index.isValid()) {
......@@ -44,14 +45,11 @@ QStandardItem *SessionModel::insertNewItem(BA_MODEL_ID::Model_ID model_type, con
void SessionModel::initialize()
{
m_default_names[BA_MODEL_ID::MultiLayer] = QString("MultiLayer");
m_default_names[BA_MODEL_ID::Layer] = QString("Layer");
}
QStandardItem *SessionModel::createNewItem(QStandardItem *parent, BA_MODEL_ID::Model_ID model_type)
QStandardItem *SessionModel::createNewItem(QStandardItem *parent, QString model_type)
{
QString name = m_default_names[model_type];
ParameterizedItem *new_item = new ParameterizedItem(model_type, name);
ParameterizedItem *new_item = ItemFactory::createItem(model_type);
parent->appendRow(new_item);
return new_item;
}
......@@ -30,7 +30,7 @@ public:
void setFilename(const QString &filename) {
m_filename = filename;
}
QStandardItem *insertNewItem(BA_MODEL_ID::Model_ID model_type,
QStandardItem *insertNewItem(QString model_type,
const QModelIndex &index);
// void load(const QString &filename=QString());
......@@ -39,9 +39,8 @@ public:
private:
void initialize();
QStandardItem *createNewItem(QStandardItem *parent,
BA_MODEL_ID::Model_ID model_type);
QString model_type);
QString m_filename;
QMap<BA_MODEL_ID::Model_ID, QString> m_default_names;
};
#endif // SESSIONMODEL_H
......@@ -78,9 +78,9 @@ void SampleView::initSubWindows()
SessionModel *session_model = new SessionModel();
// Temporary for testing
QStandardItem *multilayer = session_model->insertNewItem(BA_MODEL_ID::MultiLayer, QModelIndex());
QStandardItem *layer = session_model->insertNewItem(BA_MODEL_ID::Layer, QModelIndex());
session_model->insertNewItem(BA_MODEL_ID::Layer, multilayer->index());
QStandardItem *multilayer = session_model->insertNewItem("MultiLayer", QModelIndex());
QStandardItem *layer = session_model->insertNewItem("Layer", QModelIndex());
session_model->insertNewItem("Layer", multilayer->index());
// END temporary
m_subWindows[SampleTreeView] = SampleViewComponents::createTreeView(session_model, this);
......
......@@ -29,7 +29,6 @@ SampleWidgetBox *SampleViewComponents::createWidgetBox(SampleDesignerInterface *
return new SampleWidgetBox(core, parent);
}
//SamplePropertyEditorInterface *SampleViewComponents::createPropertyEditor(QWidget *parent)
SamplePropertyEditor *SampleViewComponents::createPropertyEditor(SampleDesignerInterface *core, QWidget *parent)
{
......@@ -39,11 +38,14 @@ SamplePropertyEditor *SampleViewComponents::createPropertyEditor(SampleDesignerI
// result->setObjectName(QLatin1String("PropertyEditor"));
return new SamplePropertyEditor(core, parent);
}
QTreeView *SampleViewComponents::createTreeView(SessionModel *session_model, QWidget *parent)
{
QTreeView *tree_view = new QTreeView(parent);
tree_view->setModel(session_model);
tree_view->setAllColumnsShowFocus(true);
tree_view->setWindowTitle(QString("Object Tree View"));
tree_view->setObjectName(QString("ObjectTree"));
return tree_view;
}
......
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