diff --git a/GUI/Model/Data/DataItem.cpp b/GUI/Model/Data/DataItem.cpp index 7d279a269dac88650e19b41ccb38f877f3ac6cb0..4b7053f21b321ffcc5615ea1323937b47b6e1638 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 3ffbd4dfcb30c97364afd517dceeac822bdf6d9b..b5c709323cc8bb23efc1c05dd2dd82fa3f78b93f 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 fd8a2aa4d7bb680b627aee43c773ed3a212d46b0..10d6f531222895de5c26a5c8af29a94d32c9516d 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 a7a2369bc0a05adb4c16550e1b238a4d41c26060..94074be9175d7e9b54b2e6ca607c94dfe2b68267 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 9793446553298889d29efc5354840f20bb14d8ce..5a80ead8e8e487bd138bc57b01c054f124e92a47 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 ac5d3ad5e69167a53b5ca551ce498a7b9eca6322..f9c7f4a2c5c31b6a1b8e2fd8d096fb3d6fe43190 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 a465bebe1c7a3ee0ca97a423ec86bd70e21d7bd4..43fe45088b1b00da5e0227abfc0d6d426f73a4af 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 92aec0fdd92b3aa1f04b02f04c8014e789178ddf..ce446987d5174dab50b45f0c4d647cbcb8c002a9 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 ee67c0a81bdfd130518e23a0336639d300e8df21..edadeeafc870e15eb0f8d68816b0db8c4ae669ee 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 583d9b17101a758f4133934a59c5485f5ac30b34..cda446ac9663621474908817e42f4e5b21eea72f 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);