From 0e99b3dbc2f0584b126ad4c9e6261b6165162ddb Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Fri, 3 Feb 2017 12:05:33 +0100 Subject: [PATCH] ParticleDistributionItem switched to the new translation mechanism. --- GUI/coregui/Models/ParameterTreeUtils.cpp | 2 ++ .../Models/ParticleDistributionItem.cpp | 34 ++++++++++++++++--- GUI/coregui/Models/ParticleDistributionItem.h | 1 + GUI/coregui/Models/TransformFromDomain.cpp | 2 -- Tests/UnitTests/GUI/TestGroupProperty.h | 1 - .../GUI/TestParticleDistributionItem.h | 26 +------------- 6 files changed, 34 insertions(+), 32 deletions(-) diff --git a/GUI/coregui/Models/ParameterTreeUtils.cpp b/GUI/coregui/Models/ParameterTreeUtils.cpp index c6ee499e9d5..27c2f767324 100644 --- a/GUI/coregui/Models/ParameterTreeUtils.cpp +++ b/GUI/coregui/Models/ParameterTreeUtils.cpp @@ -91,6 +91,7 @@ void ParameterTreeUtils::visitParameterContainer(SessionItem* container, QStringList ParameterTreeUtils::parameterTreeNames(const SessionItem* source) { + Q_ASSERT(source); QStringList result; SampleModel model; @@ -112,6 +113,7 @@ QStringList ParameterTreeUtils::parameterTreeNames(const SessionItem* source) QStringList ParameterTreeUtils::translatedParameterTreeNames(const SessionItem* source) { + Q_ASSERT(source); QStringList result; SampleModel model; diff --git a/GUI/coregui/Models/ParticleDistributionItem.cpp b/GUI/coregui/Models/ParticleDistributionItem.cpp index 0a62a41dc8a..6969f6d37d4 100644 --- a/GUI/coregui/Models/ParticleDistributionItem.cpp +++ b/GUI/coregui/Models/ParticleDistributionItem.cpp @@ -97,7 +97,7 @@ void ParticleDistributionItem::updateParameterList() auto combo_prop = par_prop.value<ComboProperty>(); QString cached_par = combo_prop.getCachedValue(); if (!combo_prop.cacheContainsGUIValue()) { - auto gui_name = translateParameterNameToGUI(cached_par); + auto gui_name = translateParameterNameToGUI_V2(cached_par); if (!gui_name.isEmpty()) { cached_par = gui_name; combo_prop.setCachedValue(cached_par); @@ -132,9 +132,9 @@ QStringList ParticleDistributionItem::childParameterNames() const result << NO_SELECTION; return result; } - QString prefix = children.front()->displayName() + QString("/"); - result = ModelPath::getParameterTreeList(children.front(), prefix); -// result = ParameterTreeUtils::parameterTreeList(children.front()); +// QString prefix = children.front()->displayName() + QString("/"); +// result = ModelPath::getParameterTreeList(children.front(), prefix); + result = ParameterTreeUtils::parameterTreeNames(children.front()); result.prepend(NO_SELECTION); return result; @@ -152,3 +152,29 @@ QString ParticleDistributionItem::translateParameterNameToGUI(const QString& par } return {}; } + +QString ParticleDistributionItem::translateParameterNameToGUI_V2(const QString& par_name) +{ + QString domainName = par_name; + int firstSlash = par_name.indexOf('/'); + if(firstSlash==0) + domainName = domainName.mid(firstSlash + 1); + + QStringList parameterNames = childParameterNames(); + parameterNames.removeAll(NO_SELECTION); + if(parameterNames.isEmpty()) + return {}; + + QStringList translatedNames + = ParameterTreeUtils::translatedParameterTreeNames(getItems(T_PARTICLES).front()); + Q_ASSERT(parameterNames.size() == translatedNames.size()); + + int index(0); + for(QString translation : translatedNames) { + if(translation == domainName) + return parameterNames.at(index); + ++index; + } + return {}; +} + diff --git a/GUI/coregui/Models/ParticleDistributionItem.h b/GUI/coregui/Models/ParticleDistributionItem.h index e46f80155c0..24d31f3a47b 100644 --- a/GUI/coregui/Models/ParticleDistributionItem.h +++ b/GUI/coregui/Models/ParticleDistributionItem.h @@ -32,6 +32,7 @@ public: std::unique_ptr<ParticleDistribution> createParticleDistribution() const; QString translateParameterNameToGUI(const QString& par_name); + QString translateParameterNameToGUI_V2(const QString& par_name); void updateParameterList(); diff --git a/GUI/coregui/Models/TransformFromDomain.cpp b/GUI/coregui/Models/TransformFromDomain.cpp index 5e2fbb986d9..d31310abed4 100644 --- a/GUI/coregui/Models/TransformFromDomain.cpp +++ b/GUI/coregui/Models/TransformFromDomain.cpp @@ -54,7 +54,6 @@ #include "Units.h" #include "VectorItem.h" #include "ParameterTreeUtils.h" -#include <QDebug> #include <limits> void SetPDF1D(SessionItem* item, const IFTDistribution1D* pdf, QString group_name); @@ -154,7 +153,6 @@ void TransformFromDomain::setItemFromSample(SessionItem* item, const LayerRoughn sample->getLatteralCorrLength()); } -#include <QDebug> //! Initialization of ParticleDistributionItem void TransformFromDomain::setItemFromSample(SessionItem* item, const ParticleDistribution* sample) diff --git a/Tests/UnitTests/GUI/TestGroupProperty.h b/Tests/UnitTests/GUI/TestGroupProperty.h index d90133afd99..66132712f9e 100644 --- a/Tests/UnitTests/GUI/TestGroupProperty.h +++ b/Tests/UnitTests/GUI/TestGroupProperty.h @@ -1,5 +1,4 @@ #include <QtTest> -#include <QDebug> #include "GroupItem.h" #include "GroupPropertyRegistry.h" #include "GUIHelpers.h" diff --git a/Tests/UnitTests/GUI/TestParticleDistributionItem.h b/Tests/UnitTests/GUI/TestParticleDistributionItem.h index d1f63bc80c5..9769b6a4f37 100644 --- a/Tests/UnitTests/GUI/TestParticleDistributionItem.h +++ b/Tests/UnitTests/GUI/TestParticleDistributionItem.h @@ -31,7 +31,6 @@ private slots: void test_InitialState(); void test_AddParticle(); void test_FromDomain(); -// void test_ToDomain(); }; inline void TestParticleDistributionItem::test_InitialState() @@ -93,6 +92,7 @@ inline void TestParticleDistributionItem::test_FromDomain() Particle particle(HomogeneousMaterial("Particle", 6e-4, 2e-8), cylinder); DistributionGaussian gauss(1.0, 0.1); ParameterDistribution par_distr(pattern, gauss, 100, 3.0); + ParticleDistribution particle_collection(particle, par_distr); // creating GUI distribution @@ -115,27 +115,3 @@ inline void TestParticleDistributionItem::test_FromDomain() QCOMPARE(prop.getValue(), QString::fromStdString(pattern)); } - -//inline void TestParticleDistributionItem::test_ToDomain() -//{ -// MaterialModel materialModel; -// MaterialEditor editor(&materialModel); -// SampleModel model; -// SessionItem *distItem = model.insertNewItem(Constants::ParticleDistributionType); -// model.insertNewItem(Constants::ParticleType, distItem->index()); - -// ComboProperty prop = distItem->getItemValue(ParticleDistributionItem::P_DISTRIBUTED_PARAMETER) -// .value<ComboProperty>(); - -// prop.setValue("Particle/AnisoPyramid/Height"); -// distItem->setItemValue(ParticleDistributionItem::P_DISTRIBUTED_PARAMETER, -// prop.getVariant()); - -// // building domasin object -// auto domainDist = dynamic_cast<ParticleDistributionItem*>(distItem)->createParticleDistribution(); -// ParameterDistribution parDist = domainDist->getParameterDistribution(); - -// QCOMPARE(QString::fromStdString(parDist.getMainParameterName()), -// QString("Particle/AnisoPyramid/Height")); - -//} -- GitLab