diff --git a/GUI/Model/Descriptor/ComboProperty.cpp b/GUI/Model/Descriptor/ComboProperty.cpp index 084b2e193f04b45c64d4de6b7a180504441a06b6..86455615f2872376e9cc8d8139cb5877731f287f 100644 --- a/GUI/Model/Descriptor/ComboProperty.cpp +++ b/GUI/Model/Descriptor/ComboProperty.cpp @@ -16,42 +16,27 @@ #include "Base/Util/Assert.h" #include "GUI/Model/Util/UtilXML.h" -namespace { - -const QString value_separator = ";"; -const QString selection_separator = ","; - -} // namespace - - ComboProperty::ComboProperty() = default; -ComboProperty::ComboProperty(const QStringList& values) +ComboProperty::ComboProperty(const QStringList& values, int index) : m_values(values) + , m_current_index(index) { + ASSERT(!values.empty()); + ASSERT(index >= 0 && index < m_values.size()); } -ComboProperty ComboProperty::fromList(const QStringList& values, const QString& current_value) +ComboProperty ComboProperty::fromList(const QStringList& values, int index) { - ComboProperty result(values); - - if (!current_value.isEmpty()) - result.setCurrentValue(current_value); - - return result; + return ComboProperty(values, index); } -ComboProperty ComboProperty::fromStdVec(const std::vector<std::string>& values, - const std::string& current_value) +ComboProperty ComboProperty::fromStdVec(const std::vector<std::string>& values, int index) { QStringList q_list; - for (const std::string& val : values) q_list << QString::fromStdString(val); - - QString q_value = QString::fromStdString(current_value); - - return fromList(q_list, q_value); + return ComboProperty(q_list, index); } QString ComboProperty::currentValue() const @@ -67,41 +52,14 @@ void ComboProperty::setCurrentValue(const QString& name) void ComboProperty::setToolTips(const QStringList& tooltips) { + ASSERT(tooltips.size() == m_values.size()); m_tooltips = tooltips; } -int ComboProperty::currentIndex() const -{ - return m_selected_indices.empty() ? -1 : m_selected_indices.at(0); -} - void ComboProperty::setCurrentIndex(int index) { ASSERT(index >= 0 && index < m_values.size()); - m_selected_indices.clear(); - m_selected_indices.push_back(index); -} - -//! Sets given index selection flag. -//! If false, index will be excluded from selection. - -void ComboProperty::setSelected(int index, bool value) -{ - if (index < 0 || index >= m_values.size()) - return; - - if (value) { - if (!m_selected_indices.contains(index)) - m_selected_indices.push_back(index); - } else { - m_selected_indices.removeAll(index); - } - std::sort(m_selected_indices.begin(), m_selected_indices.end()); -} - -void ComboProperty::setSelected(const QString& name, bool value) -{ - setSelected(m_values.indexOf(name), value); + m_current_index = index; } void ComboProperty::writeTo(QXmlStreamWriter* w) const @@ -118,8 +76,5 @@ void ComboProperty::readFrom(QXmlStreamReader* r) Q_UNUSED(version) int index = XML::readInt(r, XML::Attrib::index); - ASSERT(index < m_values.size()); - // 'ComboProperty' can be in unselected state - if (index >= 0) - setCurrentIndex(index); + setCurrentIndex(index); } diff --git a/GUI/Model/Descriptor/ComboProperty.h b/GUI/Model/Descriptor/ComboProperty.h index 5ed680f41954e6735c980d2e9e1d10584c839766..94ae65c6154d655ef4b090bc16ddde1a7f761724 100644 --- a/GUI/Model/Descriptor/ComboProperty.h +++ b/GUI/Model/Descriptor/ComboProperty.h @@ -26,9 +26,8 @@ class ComboProperty { public: ComboProperty(); - static ComboProperty fromList(const QStringList& values, const QString& current_value = ""); - static ComboProperty fromStdVec(const std::vector<std::string>& values, - const std::string& current_value = ""); + static ComboProperty fromList(const QStringList& values, int index = 0); + static ComboProperty fromStdVec(const std::vector<std::string>& values, int index = 0); const QStringList& values() const { return m_values; } const QStringList& toolTips() const { return m_tooltips; } @@ -38,21 +37,18 @@ public: void setToolTips(const QStringList& tooltips); - int currentIndex() const; + int currentIndex() const { return m_current_index; } void setCurrentIndex(int index); - void setSelected(int index, bool value = true); - void setSelected(const QString& name, bool value = true); - void writeTo(QXmlStreamWriter* w) const; void readFrom(QXmlStreamReader* r); private: - ComboProperty(const QStringList& values); + ComboProperty(const QStringList& values, int index); QStringList m_values; QStringList m_tooltips; - QVector<int> m_selected_indices; + int m_current_index; }; Q_DECLARE_METATYPE(ComboProperty) diff --git a/GUI/Model/Mini/MinimizerItems.cpp b/GUI/Model/Mini/MinimizerItems.cpp index 9f9b77d127c2395b4dac3381df8c8b0b62adc0ff..671ccb2cf9e3ff98c95242f6ada4d55d104275b3 100644 --- a/GUI/Model/Mini/MinimizerItems.cpp +++ b/GUI/Model/Mini/MinimizerItems.cpp @@ -153,14 +153,12 @@ MinimizerContainerItem::MinimizerContainerItem() QString default_minimizer = minimizerTypeToName(MinimizerType::Genetic); create_algorithm_list_and_map(default_common_algorithm, common_algorithms_list, common_algorithms_descriptions); - m_algorithm = ComboProperty::fromList(common_algorithms_list, default_common_algorithm); + m_algorithm = ComboProperty::fromList(common_algorithms_list); m_algorithm.setToolTips(common_algorithms_descriptions); - m_minimizer = ComboProperty::fromList(minimizer_names_map.keys(), default_minimizer); - m_metric = ComboProperty::fromStdVec(ObjectiveMetricUtil::metricNames(), - ObjectiveMetricUtil::defaultMetricName()); - m_norm = ComboProperty::fromStdVec(ObjectiveMetricUtil::normNames(), - ObjectiveMetricUtil::defaultNormName()); + m_minimizer = ComboProperty::fromList(minimizer_names_map.keys()); + m_metric = ComboProperty::fromStdVec(ObjectiveMetricUtil::metricNames()); + m_norm = ComboProperty::fromStdVec(ObjectiveMetricUtil::normNames()); } MinimizerContainerItem::~MinimizerContainerItem() = default; diff --git a/GUI/View/Widget/AppConfig.cpp b/GUI/View/Widget/AppConfig.cpp index 624c8b119774f63bb2e3f794e5148ffdcd7b589a..c848f3a06354c52f8e276006e36c534844d9ffb2 100644 --- a/GUI/View/Widget/AppConfig.cpp +++ b/GUI/View/Widget/AppConfig.cpp @@ -58,8 +58,9 @@ const QString startGradient = "Inferno"; AppConfig::AppConfig() { - color_gradient_combo = std::make_unique<ComboProperty>( - ComboProperty::fromList(::gradient_map.keys(), ::startGradient)); + color_gradient_combo = + std::make_unique<ComboProperty>(ComboProperty::fromList(::gradient_map.keys())); + color_gradient_combo->setCurrentValue(::startGradient); xml_dir = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); artifact_export_dir = QDir::homePath();