Skip to content
Snippets Groups Projects
Commit 33c1e822 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

ComboProperty m_current_index instead of vector<int>; further cleanup

parent 6642e568
No related branches found
No related tags found
1 merge request!2670ComboProperty further cleanup, and always have valid current index
......@@ -16,18 +16,11 @@
#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)
: m_values(values)
, m_current_index(-1)
{
}
......@@ -70,38 +63,10 @@ void ComboProperty::setToolTips(const QStringList& tooltips)
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
......
......@@ -38,12 +38,9 @@ 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);
......@@ -52,7 +49,7 @@ private:
QStringList m_values;
QStringList m_tooltips;
QVector<int> m_selected_indices;
int m_current_index;
};
Q_DECLARE_METATYPE(ComboProperty)
......
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