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

Implemented caching for selected parameter name and fixed bug when saved value...

Implemented caching for selected parameter name and fixed bug when saved value is not present in the comboproperty
parent aec4afed
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,9 @@ const QString ParticleDistributionItem::P_DISTRIBUTED_PARAMETER =
const QString ParticleDistributionItem::P_DISTRIBUTION = "Distribution";
const QString ParticleDistributionItem::P_SAMPLE_NUMBER = "Number of samples";
const QString ParticleDistributionItem::P_SIGMA_FACTOR = "Sigma factor";
const QString ParticleDistributionItem::P_CACHED_SELECTED_PARAMETER =
"Cached selected parameter name";
const QString ParticleDistributionItem::NO_SELECTION = "None";
ParticleDistributionItem::ParticleDistributionItem(ParameterizedItem *parent)
: ParameterizedGraphicsItem(Constants::ParticleDistributionType, parent)
......@@ -37,6 +39,9 @@ ParticleDistributionItem::ParticleDistributionItem(ParameterizedItem *parent)
addToValidChildren(Constants::ParticleType, PortInfo::Port0);
addToValidChildren(Constants::ParticleCoreShellType, PortInfo::Port0);
registerProperty(P_CACHED_SELECTED_PARAMETER, QString("None"),
PropertyAttribute::hiddenProperty());
ComboProperty par_prop;
registerProperty(P_DISTRIBUTED_PARAMETER, par_prop.getVariant());
updateParameterList();
......@@ -46,6 +51,20 @@ ParticleDistributionItem::~ParticleDistributionItem()
{
}
void ParticleDistributionItem::onPropertyChange(const QString &name)
{
ParameterizedItem::onPropertyChange(name);
if (name == P_DISTRIBUTED_PARAMETER
&& isRegisteredProperty(P_DISTRIBUTED_PARAMETER) ) {
QVariant par_var = getRegisteredProperty(P_DISTRIBUTED_PARAMETER);
ComboProperty par_prop = par_var.value<ComboProperty>();
if (par_prop.getValue() != NO_SELECTION) {
setRegisteredProperty(P_CACHED_SELECTED_PARAMETER,
par_prop.getValue());
}
}
}
void ParticleDistributionItem::onChildPropertyChange()
{
updateParameterList();
......@@ -57,20 +76,28 @@ void ParticleDistributionItem::updateParameterList()
if (!isRegisteredProperty(P_DISTRIBUTED_PARAMETER)) return;
QVariant par_prop = getRegisteredProperty(P_DISTRIBUTED_PARAMETER);
QString selected_par = par_prop.value<ComboProperty>().getValue();
QString cached_par =
getRegisteredProperty(P_CACHED_SELECTED_PARAMETER).toString();
removeRegisteredProperty(P_DISTRIBUTED_PARAMETER);
ComboProperty updated_prop;
if (childItems().size()>0) {
QStringList par_names = childItems()[0]->getParameterTreeList();
par_names.prepend(QString("None"));
par_names.prepend(NO_SELECTION);
par_names.removeAll(ParticleItem::P_ABUNDANCE);
updated_prop = ComboProperty(par_names);
} else {
updated_prop << "None";
updated_prop << NO_SELECTION;
}
if (updated_prop.getValues().contains(selected_par)) {
if (updated_prop.getValues().contains(cached_par)) {
updated_prop.setValue(cached_par);
} else if (updated_prop.getValues().contains(selected_par)) {
updated_prop.setValue(selected_par);
} else {
updated_prop.setValue(QString("None"));
updated_prop.setValue(NO_SELECTION);
}
if (updated_prop.getValue() != NO_SELECTION) {
setRegisteredProperty(P_CACHED_SELECTED_PARAMETER,
updated_prop.getValue());
}
registerProperty(P_DISTRIBUTED_PARAMETER, updated_prop.getVariant());
}
......@@ -28,12 +28,17 @@ public:
static const QString P_DISTRIBUTION;
static const QString P_SAMPLE_NUMBER;
static const QString P_SIGMA_FACTOR;
static const QString P_CACHED_SELECTED_PARAMETER;
explicit ParticleDistributionItem(ParameterizedItem *parent=0);
~ParticleDistributionItem();
void onPropertyChange(const QString &name);
void onChildPropertyChange();
public slots:
void updateParameterList();
private:
static const QString NO_SELECTION;
};
#endif // PARTICLEDISTRIBUTIONITEM_H
......
......@@ -536,7 +536,9 @@ QString SessionModel::readProperty(QXmlStreamReader *reader, ParameterizedItem *
.toString();
ComboProperty combo_property = item->getRegisteredProperty(parameter_name).value<ComboProperty>();
combo_property.setValue(parameter_value);
if (combo_property.getValues().contains(parameter_value)) {
combo_property.setValue(parameter_value);
}
item->setRegisteredProperty(parameter_name, combo_property.getVariant());
}
else if (parameter_type == "ScientificDoubleProperty") {
......
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