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

rm obsolete path translations GUI <-> domain

last user of this has been ParticleDistribution, which was removed in the last commits
parent f07c7c93
No related branches found
No related tags found
1 merge request!65Refactor Distribution Handling
...@@ -55,12 +55,6 @@ SessionItem* GroupItem::setCurrentType(const QString& modelType) ...@@ -55,12 +55,6 @@ SessionItem* GroupItem::setCurrentType(const QString& modelType)
return currentItem(); return currentItem();
} }
QStringList GroupItem::translateList(const QStringList& list) const
{
// we do not add here the name of itself
return list;
}
SessionItem* GroupItem::getItemOfType(const QString& type) SessionItem* GroupItem::getItemOfType(const QString& type)
{ {
return m_controller->getItemOfType(type); return m_controller->getItemOfType(type);
......
...@@ -35,8 +35,6 @@ public: ...@@ -35,8 +35,6 @@ public:
SessionItem* setCurrentType(const QString& modelType); SessionItem* setCurrentType(const QString& modelType);
QStringList translateList(const QStringList& list) const;
SessionItem* getItemOfType(const QString& type); SessionItem* getItemOfType(const QString& type);
private: private:
......
...@@ -64,21 +64,6 @@ const QString InstrumentItem::P_IDENTIFIER = "Identifier"; ...@@ -64,21 +64,6 @@ const QString InstrumentItem::P_IDENTIFIER = "Identifier";
const QString InstrumentItem::P_BEAM = "Beam"; const QString InstrumentItem::P_BEAM = "Beam";
const QString InstrumentItem::P_BACKGROUND = "Background"; const QString InstrumentItem::P_BACKGROUND = "Background";
QStringList InstrumentItem::translateList(const QStringList& list) const
{
QStringList result;
if (list.back().endsWith(P_BACKGROUND) && list.size() == 2) {
result << list[0] << list[1];
} else {
result = SessionItem::translateList(list);
if (instrument_names.contains(result.back())) {
result.removeLast();
result << "Instrument";
}
}
return result;
}
QString InstrumentItem::id() const QString InstrumentItem::id() const
{ {
return getItemValue(P_IDENTIFIER).toString(); return getItemValue(P_IDENTIFIER).toString();
......
...@@ -40,8 +40,6 @@ public: ...@@ -40,8 +40,6 @@ public:
public: public:
InstrumentItem() = delete; InstrumentItem() = delete;
QStringList translateList(const QStringList& list) const override;
QString id() const; QString id() const;
void setId(const QString& id); void setId(const QString& id);
......
...@@ -46,12 +46,6 @@ const QString density_tooltip = ...@@ -46,12 +46,6 @@ const QString density_tooltip =
"Number of mesocrystals per square nanometer (particle surface density).\n " "Number of mesocrystals per square nanometer (particle surface density).\n "
"Should be defined for disordered and 1d-ordered particle collections."; "Should be defined for disordered and 1d-ordered particle collections.";
bool IsIParticleName(QString name)
{
return (name.startsWith("Particle") || name.startsWith("ParticleComposition")
|| name.startsWith("ParticleCoreShell") || name.startsWith("MesoCrystal"));
}
} // namespace } // namespace
const QString MesoCrystalItem::P_OUTER_SHAPE = "Outer Shape"; const QString MesoCrystalItem::P_OUTER_SHAPE = "Outer Shape";
...@@ -133,16 +127,6 @@ std::unique_ptr<MesoCrystal> MesoCrystalItem::createMesoCrystal() const ...@@ -133,16 +127,6 @@ std::unique_ptr<MesoCrystal> MesoCrystalItem::createMesoCrystal() const
return result; return result;
} }
QStringList MesoCrystalItem::translateList(const QStringList& list) const
{
QStringList result = list;
// Add CrystalType to path name of basis particle
if (IsIParticleName(list.back()))
result << QString::fromStdString("Crystal"); // this result is overwritten in any case with the next line
result = SessionItem::translateList(result);
return result;
}
Lattice3D MesoCrystalItem::getLattice() const Lattice3D MesoCrystalItem::getLattice() const
{ {
const kvector_t a1 = item<VectorItem>(P_VECTOR_A)->getVector(); const kvector_t a1 = item<VectorItem>(P_VECTOR_A)->getVector();
......
...@@ -37,8 +37,6 @@ public: ...@@ -37,8 +37,6 @@ public:
std::unique_ptr<MesoCrystal> createMesoCrystal() const; std::unique_ptr<MesoCrystal> createMesoCrystal() const;
QStringList translateList(const QStringList& list) const override;
Lattice3D getLattice() const; Lattice3D getLattice() const;
std::unique_ptr<IParticle> getBasis() const; std::unique_ptr<IParticle> getBasis() const;
std::unique_ptr<IFormFactor> getOuterShape() const; std::unique_ptr<IFormFactor> getOuterShape() const;
......
...@@ -93,16 +93,3 @@ const SessionItem* ModelPath::ancestor(const SessionItem* item, const QString& r ...@@ -93,16 +93,3 @@ const SessionItem* ModelPath::ancestor(const SessionItem* item, const QString& r
return cur; return cur;
} }
//! Returns translation of item path to domain name
QString ModelPath::itemPathTranslation(const SessionItem& item, const SessionItem* topItem)
{
QStringList pathList;
const SessionItem* current(&item);
while (current && current != topItem) {
pathList = current->translateList(pathList);
current = current->parent();
}
std::reverse(pathList.begin(), pathList.end());
return pathList.join("/");
}
...@@ -34,7 +34,6 @@ bool isValidItem(SessionModel* model, SessionItem* item, const QModelIndex& pare ...@@ -34,7 +34,6 @@ bool isValidItem(SessionModel* model, SessionItem* item, const QModelIndex& pare
const SessionItem* ancestor(const SessionItem* item, const QString& requiredModelType); const SessionItem* ancestor(const SessionItem* item, const QString& requiredModelType);
QString itemPathTranslation(const SessionItem& item, const SessionItem* topItem = 0);
} // namespace ModelPath } // namespace ModelPath
#endif // BORNAGAIN_GUI_COREGUI_MODELS_MODELPATH_H #endif // BORNAGAIN_GUI_COREGUI_MODELS_MODELPATH_H
...@@ -25,176 +25,10 @@ ...@@ -25,176 +25,10 @@
namespace { namespace {
QString removeLeadingSlash(const QString& name)
{
return name.indexOf('/') == 0 ? name.mid(1) : name;
}
void handleItem(SessionItem* tree, const SessionItem* source);
} // namespace
void ParameterTreeUtils::createParameterTree(JobItem* jobItem)
{
auto container = jobItem->model()->insertItem<ParameterContainerItem>(
jobItem, -1, JobItem::T_PARAMETER_TREE);
populateParameterContainer(container, jobItem->getItem(JobItem::T_MATERIAL_CONTAINER));
populateParameterContainer(container, jobItem->getItem(JobItem::T_SAMPLE));
populateParameterContainer(container, jobItem->getItem(JobItem::T_INSTRUMENT));
}
//! Populates ParameterContainer with ParameterItem's corresponding to all properties found
//! in a source item.
void ParameterTreeUtils::populateParameterContainer(SessionItem* container,
const SessionItem* source)
{
if (container->modelType() != "Parameter Container")
throw GUIHelpers::Error("ParameterTreeUtils::populateParameterContainer() -> Error. "
"Not a ParameterContainerType.");
auto sourceLabel = container->model()->insertItem<ParameterLabelItem>(container);
handleItem(sourceLabel, source);
}
//! Visit all ParameterItem in container and execute user function.
void ParameterTreeUtils::visitParameterContainer(SessionItem* container,
std::function<void(ParameterItem*)> fun)
{
SessionItem* current(container);
QStack<SessionItem*> stack;
stack.push(current);
while (!stack.empty()) {
current = stack.pop();
if (current->modelType() == "Parameter Label"
|| current->modelType() == "Parameter Container") {
for (SessionItem* child : current->getItems())
stack.push(child);
} else {
if (ParameterItem* parItem = dynamic_cast<ParameterItem*>(current))
fun(parItem);
}
}
}
//! Creates list with parameter names of source item.
QStringList ParameterTreeUtils::parameterTreeNames(const SessionItem* source)
{
QStringList result;
for (auto pair : parameterDictionary(source))
result << pair.first;
return result;
}
//! Creates domain translated list of parameter names for source item.
QStringList ParameterTreeUtils::translatedParameterTreeNames(const SessionItem* source)
{
QStringList result;
for (auto pair : parameterDictionary(source))
result << pair.second;
return result;
}
//! Correspondence of parameter name to translated name for all properties found in source
//! in its children.
QVector<QPair<QString, QString>> ParameterTreeUtils::parameterDictionary(const SessionItem* source)
{
ASSERT(source);
QVector<QPair<QString, QString>> result;
// Create container with ParameterItem's of given source item
SampleModel model;
auto container = model.insertItem<ParameterContainerItem>();
populateParameterContainer(container, source);
// Iterate through all ParameterItems and retrieve necessary data.
visitParameterContainer(container, [&](ParameterItem* parItem) {
// TODO replace with the method from ModelPath
QString parPath = FitParameterHelper::getParameterItemPath(parItem);
QString relPath =
source->displayName() + "/" + parItem->getItemValue(ParameterItem::P_LINK).toString();
SessionItem* linkedItem = ModelPath::getItemFromPath(relPath, source);
QString translation = ModelPath::itemPathTranslation(*linkedItem, source->parent());
result.push_back(QPair<QString, QString>(parPath, translation));
});
std::reverse(result.begin(), result.end());
return result;
}
//! Converts domain name to parameterItem name. Parameter name should belong to item or
//! one of its children.
QString ParameterTreeUtils::domainNameToParameterName(const QString& domainName,
const SessionItem* source)
{
QString domain = removeLeadingSlash(domainName);
for (auto pair : parameterDictionary(source)) { // parName, domainName
if (pair.second == domain)
return pair.first;
}
return {};
}
//! Converts parameter name to domain name. Parameter name should belong to item or
//! one of its children.
QString ParameterTreeUtils::parameterNameToDomainName(const QString& parName,
const SessionItem* source)
{
for (auto pair : parameterDictionary(source)) // parName, domainName
if (pair.first == parName)
return "/" + pair.second;
return {};
}
//! Converts parameter item name to the corresponding item in the tree below the source.
SessionItem* ParameterTreeUtils::parameterNameToLinkedItem(const QString& parName,
const SessionItem* source)
{
SampleModel model;
auto container = model.insertItem<ParameterContainerItem>();
populateParameterContainer(container, source);
// Iterate through all ParameterItems and retrieve necessary data.
SessionItem* result(nullptr);
visitParameterContainer(container, [&](ParameterItem* parItem) {
// TODO replace with the method from ModelPath
QString parPath = FitParameterHelper::getParameterItemPath(parItem);
if (parPath == parName) {
QString relPath = source->displayName() + "/"
+ parItem->getItemValue(ParameterItem::P_LINK).toString();
result = ModelPath::getItemFromPath(relPath, source);
}
});
return result;
}
namespace {
void handleItem(SessionItem* tree, const SessionItem* source) void handleItem(SessionItem* tree, const SessionItem* source)
{ {
if (tree->modelType() == "Parameter Label") { if (tree->modelType() == "Parameter Label") {
tree->setDisplayName(source->itemName()); tree->setDisplayName(source->itemName());
} }
else if (tree->modelType() == "Parameter") { else if (tree->modelType() == "Parameter") {
...@@ -210,9 +44,8 @@ void handleItem(SessionItem* tree, const SessionItem* source) ...@@ -210,9 +44,8 @@ void handleItem(SessionItem* tree, const SessionItem* source)
return; return;
} }
else { else
return; return;
}
for (SessionItem* child : source->children()) { for (SessionItem* child : source->children()) {
if (child->isVisible() && child->isEnabled()) { if (child->isVisible() && child->isEnabled()) {
...@@ -236,4 +69,29 @@ void handleItem(SessionItem* tree, const SessionItem* source) ...@@ -236,4 +69,29 @@ void handleItem(SessionItem* tree, const SessionItem* source)
} }
} }
//! Populates ParameterContainer with ParameterItem's corresponding to all properties found
//! in a source item.
void populateParameterContainer(SessionItem* container, const SessionItem* source)
{
if (container->modelType() != "Parameter Container")
throw GUIHelpers::Error("ParameterTreeUtils::populateParameterContainer() -> Error. "
"Not a ParameterContainerType.");
auto sourceLabel = container->model()->insertItem<ParameterLabelItem>(container);
handleItem(sourceLabel, source);
}
} // namespace } // namespace
void ParameterTreeUtils::createParameterTree(JobItem* jobItem)
{
auto container = jobItem->model()->insertItem<ParameterContainerItem>(
jobItem, -1, JobItem::T_PARAMETER_TREE);
populateParameterContainer(container, jobItem->getItem(JobItem::T_MATERIAL_CONTAINER));
populateParameterContainer(container, jobItem->getItem(JobItem::T_SAMPLE));
populateParameterContainer(container, jobItem->getItem(JobItem::T_INSTRUMENT));
}
...@@ -31,22 +31,6 @@ namespace ParameterTreeUtils { ...@@ -31,22 +31,6 @@ namespace ParameterTreeUtils {
void createParameterTree(JobItem* jobItem); void createParameterTree(JobItem* jobItem);
void populateParameterContainer(SessionItem* container, const SessionItem* source);
void visitParameterContainer(SessionItem* container, std::function<void(ParameterItem*)> fun);
QStringList parameterTreeNames(const SessionItem* source);
QStringList translatedParameterTreeNames(const SessionItem* source);
QVector<QPair<QString, QString>> parameterDictionary(const SessionItem* source);
QString domainNameToParameterName(const QString& domainName, const SessionItem* source);
QString parameterNameToDomainName(const QString& parName, const SessionItem* source);
SessionItem* parameterNameToLinkedItem(const QString& parName, const SessionItem* source);
} // namespace ParameterTreeUtils } // namespace ParameterTreeUtils
#endif // BORNAGAIN_GUI_COREGUI_MODELS_PARAMETERTREEUTILS_H #endif // BORNAGAIN_GUI_COREGUI_MODELS_PARAMETERTREEUTILS_H
...@@ -553,16 +553,6 @@ ModelMapper* SessionItem::mapper() ...@@ -553,16 +553,6 @@ ModelMapper* SessionItem::mapper()
return m_mapper.get(); return m_mapper.get();
} }
QStringList SessionItem::translateList(const QStringList& list) const
{
QStringList result = list;
for (const IPathTranslator* translator : m_translators)
result = translator->translate(result);
// TODO consider adding displayName before translators
result << displayName();
return result;
}
void SessionItem::addTranslator(const IPathTranslator& translator) void SessionItem::addTranslator(const IPathTranslator& translator)
{ {
m_translators.push_back(translator.clone()); m_translators.push_back(translator.clone());
......
...@@ -126,8 +126,7 @@ public: ...@@ -126,8 +126,7 @@ public:
ModelMapper* mapper(); ModelMapper* mapper();
virtual QStringList translateList(const QStringList& list) const; void addTranslator(const IPathTranslator& translator); // #baRemoveParticleDistribution ++ obsolete?
void addTranslator(const IPathTranslator& translator);
virtual QByteArray serializeBinaryData() const; virtual QByteArray serializeBinaryData() const;
virtual void deserializeBinaryData(const QByteArray& data); virtual void deserializeBinaryData(const QByteArray& data);
......
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