diff --git a/GUI/coregui/Models/ComboProperty.cpp b/GUI/coregui/Models/ComboProperty.cpp index 934d99f97a8939c8f6b0554d0a17ca3bde725af7..82dd29861bc9a73327b75b68e48529e58a3d7f18 100644 --- a/GUI/coregui/Models/ComboProperty.cpp +++ b/GUI/coregui/Models/ComboProperty.cpp @@ -33,6 +33,19 @@ void ComboProperty::setValue(const QString& 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 QStringList ComboProperty::getToolTips() const { @@ -69,19 +82,12 @@ QString ComboProperty::toString(int index) const return name_list[index]; } -void ComboProperty::setCachedValue(const QString& name) -{ - m_cached_value = name; -} - bool ComboProperty::operator==(const ComboProperty& other) const { if (m_current_value != other.m_current_value) return false; if (!GUIHelpers::isTheSame(m_values, other.m_values)) return false; - if (m_cached_value != other.m_cached_value) - return false; return true; } @@ -94,9 +100,13 @@ bool ComboProperty::operator<(const ComboProperty& other) const void ComboProperty::setStringOfValues(const QString& values) { + QString currentValue = getValue(); + 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 ';'. diff --git a/GUI/coregui/Models/ComboProperty.h b/GUI/coregui/Models/ComboProperty.h index 7d7e6915ca0427901f42a330fc6e335e01abffd9..acd6befdbed86c0a8a3116b337233a93f3a39ce0 100644 --- a/GUI/coregui/Models/ComboProperty.h +++ b/GUI/coregui/Models/ComboProperty.h @@ -34,6 +34,7 @@ public: QString getValue() const; void setValue(const QString& name); + void setValues(const QStringList& values); bool isDefined(); QStringList getValues() const; @@ -51,9 +52,6 @@ public: QVariant getVariant() const; - QString getCachedValue() const; - void setCachedValue(const QString& name); - bool operator==(const ComboProperty& other) const; bool operator!=(const ComboProperty& other) const { @@ -68,7 +66,6 @@ private: QStringList m_values; QStringList m_values_tooltips; QString m_current_value; - QString m_cached_value; // for comboboxes with dynamically generated value lists }; inline QString ComboProperty::getValue() const @@ -109,11 +106,6 @@ inline QVariant ComboProperty::getVariant() const return result; } -inline QString ComboProperty::getCachedValue() const -{ - return m_cached_value; -} - Q_DECLARE_METATYPE(ComboProperty) #endif // COMBOPROPERTY_H diff --git a/GUI/coregui/Models/JobItemHelper.cpp b/GUI/coregui/Models/JobItemHelper.cpp index d2ed9163228bd0e8f022c3022c0a1dc3e38493f3..e1089011118ca065ebd3763fb86afed77b7b3bbb 100644 --- a/GUI/coregui/Models/JobItemHelper.cpp +++ b/GUI/coregui/Models/JobItemHelper.cpp @@ -149,7 +149,6 @@ void JobItemHelper::loadIntensityData(JobItem *jobItem, const QString &projectDi if (info.exists()) { std::unique_ptr<OutputData<double>> rawData( IntensityDataIOFactory::readOutputData(filename.toStdString())); - setIntensityItemAxesUnits(intensityItem, jobItem->instrumentItem()); intensityItem->setOutputData(rawData.release()); } else { @@ -204,29 +203,15 @@ void JobItemHelper::setIntensityItemAxesUnits(IntensityDataItem *intensityItem, void JobItemHelper::setIntensityItemAxesUnits(IntensityDataItem *intensityItem, 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; - foreach (auto units, detector->getValidAxesUnits()) { + + foreach (auto units, detector->getValidAxesUnits()) combo << getNameFromAxesUnits(units); - } - if (cachedUnits.isEmpty()) { - IDetector2D::EAxesUnits preferrable_units + IDetector2D::EAxesUnits preferrable_units = 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()); } diff --git a/GUI/coregui/Models/SessionXML.cpp b/GUI/coregui/Models/SessionXML.cpp index ede8cc480d52c2ecbdb9ab8af0c552caa1ee4524..b285f417cca76f298f8c670a38831436b248ffee 100644 --- a/GUI/coregui/Models/SessionXML.cpp +++ b/GUI/coregui/Models/SessionXML.cpp @@ -306,16 +306,9 @@ QString SessionReader::readProperty(QXmlStreamReader *reader, = reader->attributes().value(SessionXML::ParameterExtAttribute).toString(); ComboProperty combo_property; - if(parameterExt.isEmpty()) { - combo_property = item->value().value<ComboProperty>(); - 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); + combo_property.setStringOfValues(parameterExt); + combo_property.setValue(parameter_value); + variant = combo_property.getVariant(); } diff --git a/GUI/coregui/Views/PropertyEditor/PropertyBrowserUtils.cpp b/GUI/coregui/Views/PropertyEditor/PropertyBrowserUtils.cpp index b5d254cc6c9d496a7cea0f08787e251e147e3c2a..f6ae5280fe125259be728bfc6823e307252a4348 100644 --- a/GUI/coregui/Views/PropertyEditor/PropertyBrowserUtils.cpp +++ b/GUI/coregui/Views/PropertyEditor/PropertyBrowserUtils.cpp @@ -355,7 +355,6 @@ QString ComboPropertyEdit::comboValueText() void ComboPropertyEdit::onCurrentIndexChanged(QString current_value) { m_combo_property.setValue(current_value); - m_combo_property.setCachedValue(current_value); emit comboPropertyChanged(m_combo_property); } diff --git a/Tests/UnitTests/GUI/TestComboProperty.h b/Tests/UnitTests/GUI/TestComboProperty.h index 8503590f2f13d1fada1532e9ff379e40bff83478..d39e8caca92e5652b7d3e4df7ac968751ebc94b7 100644 --- a/Tests/UnitTests/GUI/TestComboProperty.h +++ b/Tests/UnitTests/GUI/TestComboProperty.h @@ -67,6 +67,18 @@ inline void TestComboProperty::test_setValue() ComboProperty combo = ComboProperty() << expectedValues; 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()