Skip to content
Snippets Groups Projects
Commit f93a0e17 authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

Cached units has gone from ComboProperty. Simplification in JobItem loading from disk.

parent 15455c6e
Branches
Tags
No related merge requests found
...@@ -33,6 +33,19 @@ void ComboProperty::setValue(const QString& name) ...@@ -33,6 +33,19 @@ void ComboProperty::setValue(const QString& name)
m_current_value = name; m_current_value = name;
} }
//! Sets new list of values. Current value will be preserved, if exists in a new list.
void ComboProperty::setValues(const QStringList& values)
{
QString current = getValue();
m_values = values;
// if no currentValue in the new list of values, take first value from the list
if(!m_values.contains(current) && !current.isEmpty())
setValue(m_values.front());
}
//! returns list of tool tips for all values //! returns list of tool tips for all values
QStringList ComboProperty::getToolTips() const QStringList ComboProperty::getToolTips() const
{ {
...@@ -69,19 +82,12 @@ QString ComboProperty::toString(int index) const ...@@ -69,19 +82,12 @@ QString ComboProperty::toString(int index) const
return name_list[index]; return name_list[index];
} }
void ComboProperty::setCachedValue(const QString& name)
{
m_cached_value = name;
}
bool ComboProperty::operator==(const ComboProperty& other) const bool ComboProperty::operator==(const ComboProperty& other) const
{ {
if (m_current_value != other.m_current_value) if (m_current_value != other.m_current_value)
return false; return false;
if (!GUIHelpers::isTheSame(m_values, other.m_values)) if (!GUIHelpers::isTheSame(m_values, other.m_values))
return false; return false;
if (m_cached_value != other.m_cached_value)
return false;
return true; return true;
} }
...@@ -94,9 +100,13 @@ bool ComboProperty::operator<(const ComboProperty& other) const ...@@ -94,9 +100,13 @@ bool ComboProperty::operator<(const ComboProperty& other) const
void ComboProperty::setStringOfValues(const QString& values) void ComboProperty::setStringOfValues(const QString& values)
{ {
QString currentValue = getValue();
m_values = values.split(QStringLiteral(";")); m_values = values.split(QStringLiteral(";"));
if(!m_values.contains(m_current_value) && !m_current_value.isEmpty())
m_current_value = m_values.front(); // if no currentValue in the new list of values, take first value from the list
if(!m_values.contains(currentValue) && !currentValue.isEmpty())
setValue(m_values.front());
} }
//! Returns a single string containing values delimited with ';'. //! Returns a single string containing values delimited with ';'.
......
...@@ -34,6 +34,7 @@ public: ...@@ -34,6 +34,7 @@ public:
QString getValue() const; QString getValue() const;
void setValue(const QString& name); void setValue(const QString& name);
void setValues(const QStringList& values);
bool isDefined(); bool isDefined();
QStringList getValues() const; QStringList getValues() const;
...@@ -51,9 +52,6 @@ public: ...@@ -51,9 +52,6 @@ public:
QVariant getVariant() const; QVariant getVariant() const;
QString getCachedValue() const;
void setCachedValue(const QString& name);
bool operator==(const ComboProperty& other) const; bool operator==(const ComboProperty& other) const;
bool operator!=(const ComboProperty& other) const bool operator!=(const ComboProperty& other) const
{ {
...@@ -68,7 +66,6 @@ private: ...@@ -68,7 +66,6 @@ private:
QStringList m_values; QStringList m_values;
QStringList m_values_tooltips; QStringList m_values_tooltips;
QString m_current_value; QString m_current_value;
QString m_cached_value; // for comboboxes with dynamically generated value lists
}; };
inline QString ComboProperty::getValue() const inline QString ComboProperty::getValue() const
...@@ -109,11 +106,6 @@ inline QVariant ComboProperty::getVariant() const ...@@ -109,11 +106,6 @@ inline QVariant ComboProperty::getVariant() const
return result; return result;
} }
inline QString ComboProperty::getCachedValue() const
{
return m_cached_value;
}
Q_DECLARE_METATYPE(ComboProperty) Q_DECLARE_METATYPE(ComboProperty)
#endif // COMBOPROPERTY_H #endif // COMBOPROPERTY_H
...@@ -149,7 +149,6 @@ void JobItemHelper::loadIntensityData(JobItem *jobItem, const QString &projectDi ...@@ -149,7 +149,6 @@ void JobItemHelper::loadIntensityData(JobItem *jobItem, const QString &projectDi
if (info.exists()) { if (info.exists()) {
std::unique_ptr<OutputData<double>> rawData( std::unique_ptr<OutputData<double>> rawData(
IntensityDataIOFactory::readOutputData(filename.toStdString())); IntensityDataIOFactory::readOutputData(filename.toStdString()));
setIntensityItemAxesUnits(intensityItem, jobItem->instrumentItem());
intensityItem->setOutputData(rawData.release()); intensityItem->setOutputData(rawData.release());
} else { } else {
...@@ -204,29 +203,15 @@ void JobItemHelper::setIntensityItemAxesUnits(IntensityDataItem *intensityItem, ...@@ -204,29 +203,15 @@ void JobItemHelper::setIntensityItemAxesUnits(IntensityDataItem *intensityItem,
void JobItemHelper::setIntensityItemAxesUnits(IntensityDataItem *intensityItem, void JobItemHelper::setIntensityItemAxesUnits(IntensityDataItem *intensityItem,
const IDetector2D *detector) const IDetector2D *detector)
{ {
ComboProperty orig = intensityItem->getItemValue(IntensityDataItem::P_AXES_UNITS)
.value<ComboProperty>();
// if(!combo.getValues().isEmpty())
// return;
QString cachedUnits = orig.getCachedValue();
intensityItem->getItem(IntensityDataItem::P_AXES_UNITS)->setVisible(true);
ComboProperty combo; ComboProperty combo;
foreach (auto units, detector->getValidAxesUnits()) {
foreach (auto units, detector->getValidAxesUnits())
combo << getNameFromAxesUnits(units); combo << getNameFromAxesUnits(units);
}
if (cachedUnits.isEmpty()) { IDetector2D::EAxesUnits preferrable_units
IDetector2D::EAxesUnits preferrable_units
= preferableGUIAxesUnits(detector->getDefaultAxesUnits()); = preferableGUIAxesUnits(detector->getDefaultAxesUnits());
combo.setValue(getNameFromAxesUnits(preferrable_units));
} else {
combo.setValue(cachedUnits);
}
combo.setValue(getNameFromAxesUnits(preferrable_units));
intensityItem->setItemValue(IntensityDataItem::P_AXES_UNITS, combo.getVariant()); intensityItem->setItemValue(IntensityDataItem::P_AXES_UNITS, combo.getVariant());
} }
......
...@@ -306,16 +306,9 @@ QString SessionReader::readProperty(QXmlStreamReader *reader, ...@@ -306,16 +306,9 @@ QString SessionReader::readProperty(QXmlStreamReader *reader,
= reader->attributes().value(SessionXML::ParameterExtAttribute).toString(); = reader->attributes().value(SessionXML::ParameterExtAttribute).toString();
ComboProperty combo_property; ComboProperty combo_property;
if(parameterExt.isEmpty()) { combo_property.setStringOfValues(parameterExt);
combo_property = item->value().value<ComboProperty>(); combo_property.setValue(parameter_value);
if (combo_property.getValues().contains(parameter_value)) {
combo_property.setValue(parameter_value);
}
} else {
combo_property.setStringOfValues(parameterExt);
combo_property.setValue(parameter_value);
}
combo_property.setCachedValue(parameter_value);
variant = combo_property.getVariant(); variant = combo_property.getVariant();
} }
......
...@@ -355,7 +355,6 @@ QString ComboPropertyEdit::comboValueText() ...@@ -355,7 +355,6 @@ QString ComboPropertyEdit::comboValueText()
void ComboPropertyEdit::onCurrentIndexChanged(QString current_value) void ComboPropertyEdit::onCurrentIndexChanged(QString current_value)
{ {
m_combo_property.setValue(current_value); m_combo_property.setValue(current_value);
m_combo_property.setCachedValue(current_value);
emit comboPropertyChanged(m_combo_property); emit comboPropertyChanged(m_combo_property);
} }
......
...@@ -67,6 +67,18 @@ inline void TestComboProperty::test_setValue() ...@@ -67,6 +67,18 @@ inline void TestComboProperty::test_setValue()
ComboProperty combo = ComboProperty() << expectedValues; ComboProperty combo = ComboProperty() << expectedValues;
QCOMPARE(combo.getValue(), QString("a1")); QCOMPARE(combo.getValue(), QString("a1"));
QStringList newValues = QStringList() << "b1" << "b2" << "b3";
combo.setValues(newValues);
QCOMPARE(combo.getValue(), QString("b1"));
QCOMPARE(combo.getValues(), newValues);
// checking that old value is preserved
newValues = QStringList() << "c1" << "b1" << "c2";
combo.setValues(newValues);
QCOMPARE(combo.getValue(), QString("b1"));
QCOMPARE(combo.getValues(), newValues);
} }
inline void TestComboProperty::test_stringOfValues() inline void TestComboProperty::test_stringOfValues()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment