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

Added LayerItem and implemented logic for checking if adding to a parent

is allowed
parent 7185ccaf
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,7 @@
#include "ItemFactory.h"
#include "MultiLayerItem.h"
#include "LayerItem.h"
ParameterizedItem *ItemFactory::createItem(const QString &model_name)
......@@ -22,4 +23,8 @@ ParameterizedItem *ItemFactory::createItem(const QString &model_name)
if (model_name==QString("MultiLayer")) {
return new MultiLayerItem();
}
if (model_name==QString("Layer")) {
return new LayerItem();
}
return 0;
}
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Models/LayerItem.cpp
//! @brief Implements class LayerItem.
//!
//! @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 "LayerItem.h"
LayerItem::LayerItem()
: ParameterizedItem(QString("Layer"))
{
m_parameters[QString("Thickness")] = 0.0;
m_valid_parents.append(QString("MultiLayer"));
}
LayerItem::~LayerItem()
{
}
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Models/LayerItem.h
//! @brief Defines class LayerItem.
//!
//! @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 LAYERITEM_H
#define LAYERITEM_H
#include "ParameterizedItem.h"
class LayerItem : public ParameterizedItem
{
public:
explicit LayerItem();
~LayerItem();
};
#endif // LAYERITEM_H
......@@ -25,7 +25,6 @@ SessionModel::SessionModel(QObject *parent)
SessionModel::~SessionModel()
{
}
QStandardItem *SessionModel::insertNewItem(QString model_type, const QModelIndex &index)
......@@ -50,6 +49,20 @@ void SessionModel::initialize()
QStandardItem *SessionModel::createNewItem(QStandardItem *parent, QString model_type)
{
ParameterizedItem *new_item = ItemFactory::createItem(model_type);
if (!new_item) {
return 0;
}
// Check if child is allowed to be added to parent
if (parent!=invisibleRootItem())
{
ParameterizedItem *p_par_parent = dynamic_cast<ParameterizedItem *>(parent);
if (!p_par_parent || !p_par_parent->acceptsAsChild(new_item)) {
delete new_item;
return 0;
}
}
parent->appendRow(new_item);
return new_item;
}
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