Skip to content
Snippets Groups Projects
Commit 77608d5b authored by Mikhail Svechnikov's avatar Mikhail Svechnikov
Browse files

ComboProperty: rnm getters & add tooltip

parent b6685783
No related branches found
No related tags found
1 merge request!982GUI: preparing to rm descriptors
......@@ -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
......
......@@ -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
......
......@@ -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;
}
......@@ -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(); }
......
......@@ -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
......
......@@ -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());
......
......@@ -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";
}
......@@ -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;
......
......@@ -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.
......
......@@ -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);
......
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