From 77608d5b042de94a8044b498b58a7b235f26e4dc Mon Sep 17 00:00:00 2001
From: Mikhail Svechnikov <m.svechnikov@fz-juelich.de>
Date: Wed, 27 Jul 2022 11:02:02 +0200
Subject: [PATCH] ComboProperty: rnm getters & add tooltip

---
 GUI/Model/Data/DataItem.cpp                |  2 +-
 GUI/Model/Data/IntensityDataItem.cpp       |  2 +-
 GUI/Model/Data/JobItemUtils.cpp            |  2 +-
 GUI/Model/Descriptor/SelectionDescriptor.h |  4 +-
 GUI/Model/Job/FitParameterItem.cpp         |  4 +-
 GUI/Model/Job/MinimizerItem.cpp            | 14 +++---
 GUI/Util/ComboProperty.cpp                 | 24 ++++++++---
 GUI/Util/ComboProperty.h                   | 10 +++--
 GUI/View/PropertyEditor/CustomEditors.cpp  |  2 +-
 Tests/Unit/GUI/TestComboProperty.cpp       | 50 +++++++++++-----------
 10 files changed, 64 insertions(+), 50 deletions(-)

diff --git a/GUI/Model/Data/DataItem.cpp b/GUI/Model/Data/DataItem.cpp
index 7d279a269da..4b7053f21b3 100644
--- a/GUI/Model/Data/DataItem.cpp
+++ b/GUI/Model/Data/DataItem.cpp
@@ -107,7 +107,7 @@ void DataItem::setLastModified(const QDateTime& dtime)
 
 QString DataItem::selectedAxesUnits() const
 {
-    return getItemValue(P_AXES_UNITS).value<ComboProperty>().getValue();
+    return getItemValue(P_AXES_UNITS).value<ComboProperty>().currentValue();
 }
 
 int DataItem::xSize() const
diff --git a/GUI/Model/Data/IntensityDataItem.cpp b/GUI/Model/Data/IntensityDataItem.cpp
index 3ffbd4dfcb3..b5c709323cc 100644
--- a/GUI/Model/Data/IntensityDataItem.cpp
+++ b/GUI/Model/Data/IntensityDataItem.cpp
@@ -136,7 +136,7 @@ void IntensityDataItem::copyZRangeFromItem(DataItem* sourceItem)
 
 QCPColorGradient IntensityDataItem::gradientQCP() const
 {
-    return gradient_map.value(gradientCombo().getValue());
+    return gradient_map.value(gradientCombo().currentValue());
 }
 
 ComboProperty IntensityDataItem::gradientCombo() const
diff --git a/GUI/Model/Data/JobItemUtils.cpp b/GUI/Model/Data/JobItemUtils.cpp
index fd8a2aa4d7b..10d6f531222 100644
--- a/GUI/Model/Data/JobItemUtils.cpp
+++ b/GUI/Model/Data/JobItemUtils.cpp
@@ -110,6 +110,6 @@ ComboProperty GUI::Model::JobItemUtils::availableUnits(const ICoordSystem& conve
             result << unit_name;
     }
 
-    result.setValue(GUI::Util::CoordName::nameFromCoord(converter.defaultUnits()));
+    result.setCurrentValue(GUI::Util::CoordName::nameFromCoord(converter.defaultUnits()));
     return result;
 }
diff --git a/GUI/Model/Descriptor/SelectionDescriptor.h b/GUI/Model/Descriptor/SelectionDescriptor.h
index a7a2369bc0a..94074be9175 100644
--- a/GUI/Model/Descriptor/SelectionDescriptor.h
+++ b/GUI/Model/Descriptor/SelectionDescriptor.h
@@ -79,7 +79,7 @@ public:
     {
         label = item->displayName();
         tooltip = item->toolTip();
-        options = item->value().value<ComboProperty>().getValues();
+        options = item->value().value<ComboProperty>().values();
         currentIndexSetter = [=](int index) {
             auto comboProperty = item->value().value<ComboProperty>();
 
@@ -91,7 +91,7 @@ public:
         currentIndexGetter = [=] { return item->value().value<ComboProperty>().currentIndex(); };
 
         if constexpr (std::is_same<T, QString>::value)
-            currentItem = [=] { return item->value().value<ComboProperty>().getValue(); };
+            currentItem = [=] { return item->value().value<ComboProperty>().currentValue(); };
     }
 
     operator T() const { return currentItem(); }
diff --git a/GUI/Model/Job/FitParameterItem.cpp b/GUI/Model/Job/FitParameterItem.cpp
index 97934465532..5a80ead8e8e 100644
--- a/GUI/Model/Job/FitParameterItem.cpp
+++ b/GUI/Model/Job/FitParameterItem.cpp
@@ -34,7 +34,7 @@ ComboProperty fitParameterTypeCombo()
            << "lower limited"
            << "upper limited"
            << "free";
-    result.setValue("limited");
+    result.setCurrentValue("limited");
     result.setToolTips(tooltips);
     return result;
 }
@@ -215,7 +215,7 @@ void FitParameterItem::removeLink(const QString& link)
 QString FitParameterItem::parameterType() const
 {
     auto partype = getItemValue(P_TYPE).value<ComboProperty>();
-    return partype.getValue();
+    return partype.currentValue();
 }
 
 //! Enables/disables min, max properties on FitParameterItem's type
diff --git a/GUI/Model/Job/MinimizerItem.cpp b/GUI/Model/Job/MinimizerItem.cpp
index ac5d3ad5e69..f9c7f4a2c5c 100644
--- a/GUI/Model/Job/MinimizerItem.cpp
+++ b/GUI/Model/Job/MinimizerItem.cpp
@@ -59,7 +59,7 @@ MinimizerContainerItem::MinimizerContainerItem()
     ComboProperty metric_combo;
     for (auto& item : ObjectiveMetricUtils::metricNames())
         metric_combo << QString::fromStdString(item);
-    metric_combo.setValue(QString::fromStdString(ObjectiveMetricUtils::defaultMetricName()));
+    metric_combo.setCurrentValue(QString::fromStdString(ObjectiveMetricUtils::defaultMetricName()));
     addProperty(P_METRIC, metric_combo.variant())
         ->setToolTip("Objective metric to use for estimating distance between simulated and "
                      "experimental data.");
@@ -67,7 +67,7 @@ MinimizerContainerItem::MinimizerContainerItem()
     ComboProperty norm_combo;
     for (auto& item : ObjectiveMetricUtils::normNames())
         norm_combo << QString::fromStdString(item);
-    norm_combo.setValue(QString::fromStdString(ObjectiveMetricUtils::defaultNormName()));
+    norm_combo.setCurrentValue(QString::fromStdString(ObjectiveMetricUtils::defaultNormName()));
     addProperty(P_NORM, norm_combo.variant())
         ->setToolTip("Normalization to use for estimating distance between simulated and "
                      "experimental data.");
@@ -91,7 +91,7 @@ SelectionDescriptor<QString> MinimizerContainerItem::objectiveMetric() const
 MinimizerItem* MinimizerContainerItem::currentMinimizerItem() const
 {
     ComboProperty combo = getItemValue(P_MINIMIZERS).value<ComboProperty>();
-    QString M_TYPE_name = minimizer_names_map.value(combo.getValue());
+    QString M_TYPE_name = minimizer_names_map.value(combo.currentValue());
     return item<MinimizerItem>(M_TYPE_name);
 }
 
@@ -102,8 +102,8 @@ std::unique_ptr<IMinimizer> MinimizerContainerItem::createMinimizer() const
 
 std::unique_ptr<ObjectiveMetric> MinimizerContainerItem::createMetric() const
 {
-    QString metric = getItemValue(P_METRIC).value<ComboProperty>().getValue();
-    QString norm = getItemValue(P_NORM).value<ComboProperty>().getValue();
+    QString metric = getItemValue(P_METRIC).value<ComboProperty>().currentValue();
+    QString norm = getItemValue(P_NORM).value<ComboProperty>().currentValue();
     return ObjectiveMetricUtils::createMetric(metric.toStdString(), norm.toStdString());
 }
 
@@ -132,7 +132,7 @@ MinuitMinimizerItem::MinuitMinimizerItem()
 
 std::unique_ptr<IMinimizer> MinuitMinimizerItem::createMinimizer() const
 {
-    QString algorithmName = getItemValue(P_ALGORITHMS).value<ComboProperty>().getValue();
+    QString algorithmName = getItemValue(P_ALGORITHMS).value<ComboProperty>().currentValue();
 
     auto* domainMinimizer = new Minuit2Minimizer(algorithmName.toStdString());
     domainMinimizer->setStrategy(getItemValue(P_STRATEGY).toInt());
@@ -167,7 +167,7 @@ GSLMultiMinimizerItem::GSLMultiMinimizerItem()
 
 std::unique_ptr<IMinimizer> GSLMultiMinimizerItem::createMinimizer() const
 {
-    QString algorithmName = getItemValue(P_ALGORITHMS).value<ComboProperty>().getValue();
+    QString algorithmName = getItemValue(P_ALGORITHMS).value<ComboProperty>().currentValue();
 
     auto* domainMinimizer = new GSLMultiMinimizer(algorithmName.toStdString());
     domainMinimizer->setMaxIterations(getItemValue(P_MAXITERATIONS).toInt());
diff --git a/GUI/Util/ComboProperty.cpp b/GUI/Util/ComboProperty.cpp
index a465bebe1c7..43fe45088b1 100644
--- a/GUI/Util/ComboProperty.cpp
+++ b/GUI/Util/ComboProperty.cpp
@@ -35,17 +35,17 @@ ComboProperty ComboProperty::fromList(const QStringList& values, const QString&
     ComboProperty result(values);
 
     if (!current_value.isEmpty())
-        result.setValue(current_value);
+        result.setCurrentValue(current_value);
 
     return result;
 }
 
-QString ComboProperty::getValue() const
+QString ComboProperty::currentValue() const
 {
     return currentIndex() < 0 ? QString() : m_values.at(currentIndex());
 }
 
-void ComboProperty::setValue(const QString& name)
+void ComboProperty::setCurrentValue(const QString& name)
 {
     if (!m_values.contains(name))
         throw Error("ComboProperty::setValue() -> Error. Combo doesn't contain "
@@ -54,7 +54,7 @@ void ComboProperty::setValue(const QString& name)
     setCurrentIndex(m_values.indexOf(name));
 }
 
-QStringList ComboProperty::getValues() const
+QStringList ComboProperty::values() const
 {
     return m_values;
 }
@@ -64,11 +64,21 @@ QStringList ComboProperty::getValues() const
 void ComboProperty::setValues(const QStringList& values)
 {
     ASSERT(values.size());
-    QString current = getValue();
+    QString current = currentValue();
     m_values = values;
     setCurrentIndex(m_values.contains(current) ? m_values.indexOf(current) : 0);
 }
 
+QString ComboProperty::toolTip() const
+{
+    return m_tooltip;
+}
+
+void ComboProperty::setToolTip(const QString& tooltip)
+{
+    m_tooltip = tooltip;
+}
+
 //! Returns list of tool tips for all values
 QStringList ComboProperty::toolTips() const
 {
@@ -141,7 +151,7 @@ QString ComboProperty::stringOfValues() const
 
 void ComboProperty::setStringOfValues(const QString& values)
 {
-    QString current = getValue();
+    QString current = currentValue();
     m_values = values.split(value_separator);
     setCurrentIndex(m_values.contains(current) ? m_values.indexOf(current) : 0);
 }
@@ -227,6 +237,6 @@ QString ComboProperty::label() const
     if (m_selected_indices.size() > 1)
         return "Multiple";
     if (m_selected_indices.size() == 1)
-        return getValue();
+        return currentValue();
     return "None";
 }
diff --git a/GUI/Util/ComboProperty.h b/GUI/Util/ComboProperty.h
index 92aec0fdd92..ce446987d51 100644
--- a/GUI/Util/ComboProperty.h
+++ b/GUI/Util/ComboProperty.h
@@ -28,12 +28,15 @@ public:
 
     static ComboProperty fromList(const QStringList& values, const QString& current_value = "");
 
-    QString getValue() const;
-    void setValue(const QString& name);
+    QString currentValue() const;
+    void setCurrentValue(const QString& name);
 
-    QStringList getValues() const;
+    QStringList values() const;
     void setValues(const QStringList& values);
 
+    QString toolTip() const;
+    void setToolTip(const QString& tooltip);
+
     QStringList toolTips() const;
     void setToolTips(const QStringList& tooltips);
 
@@ -65,6 +68,7 @@ public:
 private:
     ComboProperty(QStringList values);
 
+    QString m_tooltip;
     QStringList m_values;
     QStringList m_tooltips;
     QVector<int> m_selected_indices;
diff --git a/GUI/View/PropertyEditor/CustomEditors.cpp b/GUI/View/PropertyEditor/CustomEditors.cpp
index ee67c0a81bd..edadeeafc87 100644
--- a/GUI/View/PropertyEditor/CustomEditors.cpp
+++ b/GUI/View/PropertyEditor/CustomEditors.cpp
@@ -114,7 +114,7 @@ QStringList ComboPropertyEditor::internLabels()
     if (!m_data.canConvert<ComboProperty>())
         return {};
     auto comboProperty = m_data.value<ComboProperty>();
-    return comboProperty.getValues();
+    return comboProperty.values();
 }
 
 //! Returns index for QComboBox.
diff --git a/Tests/Unit/GUI/TestComboProperty.cpp b/Tests/Unit/GUI/TestComboProperty.cpp
index 583d9b17101..cda446ac966 100644
--- a/Tests/Unit/GUI/TestComboProperty.cpp
+++ b/Tests/Unit/GUI/TestComboProperty.cpp
@@ -14,8 +14,8 @@ public:
 TEST_F(TestComboProperty, initialState)
 {
     ComboProperty combo;
-    EXPECT_EQ(combo.getValue(), "");
-    EXPECT_EQ(combo.getValues(), QStringList());
+    EXPECT_EQ(combo.currentValue(), "");
+    EXPECT_EQ(combo.values(), QStringList());
     EXPECT_EQ(combo.toolTips(), QStringList());
     EXPECT_EQ(combo.currentIndex(), -1);
     EXPECT_EQ(combo.stringOfValues(), "");
@@ -28,9 +28,9 @@ TEST_F(TestComboProperty, factoryMethods)
     QStringList expected = QStringList() << "a1"
                                          << "a2";
     ComboProperty combo = ComboProperty::fromList(expected);
-    EXPECT_EQ(combo.getValues(), expected);
+    EXPECT_EQ(combo.values(), expected);
     EXPECT_EQ(combo.currentIndex(), -1);
-    EXPECT_EQ(combo.getValue(), "");
+    EXPECT_EQ(combo.currentValue(), "");
     EXPECT_EQ(combo.selectedIndices(), QVector<int>());
 }
 
@@ -40,8 +40,8 @@ TEST_F(TestComboProperty, setValues)
     QStringList expectedValues = QStringList() << "a1"
                                                << "a2";
     ComboProperty combo = ComboProperty() << expectedValues;
-    EXPECT_EQ(combo.getValues(), expectedValues);
-    EXPECT_EQ(combo.getValue(), "a1");
+    EXPECT_EQ(combo.values(), expectedValues);
+    EXPECT_EQ(combo.currentValue(), "a1");
     EXPECT_EQ(combo.currentIndex(), 0);
     EXPECT_EQ(combo.selectedIndices(), QVector<int>({0}));
 
@@ -50,8 +50,8 @@ TEST_F(TestComboProperty, setValues)
                                           << "b2"
                                           << "b3";
     combo.setValues(newValues);
-    EXPECT_EQ(combo.getValue(), "b1");
-    EXPECT_EQ(combo.getValues(), newValues);
+    EXPECT_EQ(combo.currentValue(), "b1");
+    EXPECT_EQ(combo.values(), newValues);
     EXPECT_EQ(combo.currentIndex(), 0);
     EXPECT_EQ(combo.selectedIndices(), QVector<int>({0}));
 
@@ -60,8 +60,8 @@ TEST_F(TestComboProperty, setValues)
                               << "b1"
                               << "c2";
     combo.setValues(newValues);
-    EXPECT_EQ(combo.getValue(), "b1");
-    EXPECT_EQ(combo.getValues(), newValues);
+    EXPECT_EQ(combo.currentValue(), "b1");
+    EXPECT_EQ(combo.values(), newValues);
     EXPECT_EQ(combo.currentIndex(), 1);
     EXPECT_EQ(combo.selectedIndices(), QVector<int>({1}));
 }
@@ -76,12 +76,12 @@ TEST_F(TestComboProperty, setCurrentIndex)
     EXPECT_EQ(combo.currentIndex(), 0);
     EXPECT_EQ(combo.selectedIndices(), QVector<int>({0}));
 
-    combo.setValue("c2");
+    combo.setCurrentValue("c2");
     EXPECT_EQ(combo.currentIndex(), 1);
     EXPECT_EQ(combo.selectedIndices(), QVector<int>({1}));
 
     combo.setCurrentIndex(0);
-    EXPECT_EQ(combo.getValue(), "c1");
+    EXPECT_EQ(combo.currentValue(), "c1");
     EXPECT_EQ(combo.selectedIndices(), QVector<int>({0}));
 }
 
@@ -92,7 +92,7 @@ TEST_F(TestComboProperty, stringOfValues)
     ComboProperty combo = ComboProperty() << expectedValues;
 
     EXPECT_EQ(combo.stringOfValues(), "a1;a2");
-    EXPECT_EQ(combo.getValue(), "a1");
+    EXPECT_EQ(combo.currentValue(), "a1");
     EXPECT_EQ(combo.currentIndex(), 0);
     EXPECT_EQ(combo.selectedIndices(), QVector<int>({0}));
 
@@ -100,7 +100,7 @@ TEST_F(TestComboProperty, stringOfValues)
     QString stringOfValues("b1;b2;b3");
     combo.setStringOfValues(stringOfValues);
     EXPECT_EQ(combo.stringOfValues(), stringOfValues);
-    EXPECT_EQ(combo.getValue(), "b1");
+    EXPECT_EQ(combo.currentValue(), "b1");
     EXPECT_EQ(combo.currentIndex(), 0);
     EXPECT_EQ(combo.selectedIndices(), QVector<int>({0}));
 
@@ -108,7 +108,7 @@ TEST_F(TestComboProperty, stringOfValues)
     stringOfValues = "c1;b1;c3";
     combo.setStringOfValues(stringOfValues);
     EXPECT_EQ(combo.stringOfValues(), stringOfValues);
-    EXPECT_EQ(combo.getValue(), "b1");
+    EXPECT_EQ(combo.currentValue(), "b1");
     EXPECT_EQ(combo.currentIndex(), 1);
     EXPECT_EQ(combo.selectedIndices(), QVector<int>({1}));
 }
@@ -121,21 +121,21 @@ TEST_F(TestComboProperty, selectedIndices)
     ComboProperty combo = ComboProperty() << expectedValues;
 
     EXPECT_EQ(combo.currentIndex(), 0);
-    EXPECT_EQ(combo.getValue(), "a1");
+    EXPECT_EQ(combo.currentValue(), "a1");
     EXPECT_EQ(combo.selectedIndices(), QVector<int>({0}));
     EXPECT_EQ(combo.selectedValues(), QStringList({"a1"}));
 
     // selecting already selected element, nothing should change
     combo.setSelected(0);
     EXPECT_EQ(combo.currentIndex(), 0);
-    EXPECT_EQ(combo.getValue(), "a1");
+    EXPECT_EQ(combo.currentValue(), "a1");
     EXPECT_EQ(combo.selectedIndices(), QVector<int>({0}));
     EXPECT_EQ(combo.selectedValues(), QStringList({"a1"}));
 
     // deselecting index
     combo.setSelected(0, false);
     EXPECT_EQ(combo.currentIndex(), -1);
-    EXPECT_EQ(combo.getValue(), "");
+    EXPECT_EQ(combo.currentValue(), "");
     EXPECT_EQ(combo.selectedIndices(), QVector<int>());
     EXPECT_EQ(combo.selectedValues(), QStringList());
 
@@ -143,7 +143,7 @@ TEST_F(TestComboProperty, selectedIndices)
     combo.setSelected(1, true);
     combo.setSelected(2, true);
     EXPECT_EQ(combo.currentIndex(), 1);
-    EXPECT_EQ(combo.getValue(), "a2");
+    EXPECT_EQ(combo.currentValue(), "a2");
     EXPECT_EQ(combo.selectedIndices(), QVector<int>({1, 2}));
     EXPECT_EQ(combo.selectedValues(), QStringList({"a2", "a3"}));
 
@@ -151,7 +151,7 @@ TEST_F(TestComboProperty, selectedIndices)
     combo.setSelected("a2", false);
     combo.setSelected("a1", true);
     EXPECT_EQ(combo.currentIndex(), 0);
-    EXPECT_EQ(combo.getValue(), "a1");
+    EXPECT_EQ(combo.currentValue(), "a1");
     EXPECT_EQ(combo.selectedIndices(), QVector<int>({0, 2}));
     EXPECT_EQ(combo.selectedValues(), QStringList({"a1", "a3"}));
 }
@@ -205,12 +205,12 @@ TEST_F(TestComboProperty, comboEquality)
     c2 << "a3";
     EXPECT_TRUE(c1 != c2);
     EXPECT_FALSE(c1 == c2);
-    c2.setValue("a2");
+    c2.setCurrentValue("a2");
     EXPECT_TRUE(c1 != c2);
     EXPECT_FALSE(c1 == c2);
 
     c1 << "a3";
-    c1.setValue("a2");
+    c1.setCurrentValue("a2");
     EXPECT_TRUE(c1 == c2);
     EXPECT_FALSE(c1 != c2);
 
@@ -246,13 +246,13 @@ TEST_F(TestComboProperty, variantEquality)
         EXPECT_TRUE(c1.variant() == c2.variant());
 
         c2 << "a3";
-        c2.setValue("a2");
+        c2.setCurrentValue("a2");
 
         EXPECT_TRUE(c1.variant() != c2.variant());
         EXPECT_FALSE(c1.variant() == c2.variant());
 
         c1 << "a3";
-        c1.setValue("a2");
+        c1.setCurrentValue("a2");
 
         EXPECT_TRUE(c1.variant() == c2.variant());
         EXPECT_FALSE(c1.variant() != c2.variant());
@@ -278,7 +278,7 @@ TEST_F(TestComboProperty, comboXML)
 
     // reading from XML
     ComboProperty combo_property = propertyFromXML(expected);
-    EXPECT_EQ(combo_property.getValue(), "a1");
+    EXPECT_EQ(combo_property.currentValue(), "a1");
     EXPECT_EQ(combo_property.stringOfValues(), "a1;a2;a3");
     EXPECT_EQ(combo_property.stringOfSelections(), "0,2");
     EXPECT_TRUE(combo_property == combo);
-- 
GitLab