qt: add getting the text representation from AbstractAssignableEditor

This commit is contained in:
jussi 2019-10-29 19:21:38 +02:00
parent fb2a273e12
commit 810b6097c9
5 changed files with 17 additions and 22 deletions

View File

@ -13,4 +13,6 @@ public:
virtual void setValue(QVariant value) = 0;
virtual void setAssignableData(const AssignableData &data) = 0;
virtual QVariant value() = 0;
// Get the textual representation of the current value
virtual QString text() = 0;
};

View File

@ -15,9 +15,17 @@ EnumEditor::EnumEditor(QWidget *parent) : AbstractAssignableEditor(parent) {
}
QVariant EnumEditor::value() {
return m_comboBox->currentIndex();
}
QString EnumEditor::text() {
return m_comboBox->currentText();
}
void EnumEditor::setValue(QVariant value) {
m_comboBox->setCurrentIndex(value.toInt());
}
void EnumEditor::setAssignableData(const AssignableData &data) {
// Remove old entries
m_comboBox->clear();

View File

@ -17,7 +17,8 @@ public:
// Return selected string
QVariant value();
void setValue(QVariant value) {}
QString text();
void setValue(QVariant value);
void setAssignableData(const AssignableData &data);
private:
QHBoxLayout *m_mainLayout;

View File

@ -24,31 +24,14 @@ IntRangeEditor::IntRangeEditor(QWidget *parent) : AbstractAssignableEditor(paren
setAutoFillBackground(true);
}
/*IntRangeEditor::IntRangeEditor(QWidget* parent, const AssignableData &data) : AbstractAssignableEditor(parent) {
m_mainLayout = new QHBoxLayout;
m_mainLayout->setMargin(0);
m_slider = new QSlider(Qt::Horizontal);
m_mainLayout->addWidget(m_slider);
m_spinBox = new QSpinBox;
m_mainLayout->addWidget(m_spinBox);
connect(m_slider, &QSlider::valueChanged, m_spinBox, &QSpinBox::setValue);
connect(m_slider, &QSlider::rangeChanged, m_spinBox, &QSpinBox::setRange);
connect(m_spinBox, QOverload<int>::of(&QSpinBox::valueChanged), m_slider, &QSlider::setValue);
m_slider->setRange(data.m_rangeInfo.int_range.min, data.m_rangeInfo.int_range.max);
setLayout(m_mainLayout);
setAutoFillBackground(true);
}*/
QVariant IntRangeEditor::value() {
return m_slider->value();
}
QString IntRangeEditor::text() {
return QString::number(m_slider->value());
}
void IntRangeEditor::setValue(QVariant value) {
m_slider->setValue(value.toInt());
}

View File

@ -17,6 +17,7 @@ public:
IntRangeEditor(QWidget *parent = nullptr);
//IntRangeEditor(QWidget *parent = nullptr, const AssignableData &data = nullptr);
QVariant value();
QString text();
void setValue(QVariant value);
void setRange(const tc_assignable_range_int_t &range);
void setAssignableData(const AssignableData & data);