mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Use spin box instead of line edit for slider editor
p4#: 21446
This commit is contained in:
parent
b14b138dae
commit
9ecd48fe2d
@ -44,7 +44,7 @@ CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT(PdmUiSliderEditor);
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiSliderEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
{
|
||||
assert(!m_lineEdit.isNull());
|
||||
assert(!m_spinBox.isNull());
|
||||
|
||||
QIcon ic = field()->uiIcon(uiConfigName);
|
||||
if (!ic.isNull())
|
||||
@ -57,11 +57,17 @@ void PdmUiSliderEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
}
|
||||
|
||||
m_label->setEnabled(!field()->isUiReadOnly(uiConfigName));
|
||||
m_lineEdit->setEnabled(!field()->isUiReadOnly(uiConfigName));
|
||||
m_spinBox->setEnabled(!field()->isUiReadOnly(uiConfigName));
|
||||
m_slider->setEnabled(!field()->isUiReadOnly(uiConfigName));
|
||||
|
||||
field()->ownerObject()->editorAttribute(field(), uiConfigName, &m_attributes);
|
||||
m_lineEdit->setValidator(new QIntValidator(m_attributes.m_minimum, m_attributes.m_maximum, this));
|
||||
|
||||
{
|
||||
m_spinBox->blockSignals(true);
|
||||
m_spinBox->setMinimum(m_attributes.m_minimum);
|
||||
m_spinBox->setMaximum(m_attributes.m_maximum);
|
||||
m_spinBox->blockSignals(false);
|
||||
}
|
||||
|
||||
{
|
||||
m_slider->blockSignals(true);
|
||||
@ -70,7 +76,8 @@ void PdmUiSliderEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
}
|
||||
|
||||
QString textValue = field()->uiValue().toString();
|
||||
m_lineEdit->setText(textValue);
|
||||
m_spinBox->setValue(textValue.toInt());
|
||||
|
||||
updateSliderPosition();
|
||||
}
|
||||
|
||||
@ -85,12 +92,12 @@ QWidget* PdmUiSliderEditor::createEditorWidget(QWidget * parent)
|
||||
layout->setMargin(0);
|
||||
containerWidget->setLayout(layout);
|
||||
|
||||
m_lineEdit = new QLineEdit(containerWidget);
|
||||
m_lineEdit->setMaximumWidth(30);
|
||||
connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(slotEditingFinished()));
|
||||
m_spinBox = new QSpinBox(containerWidget);
|
||||
m_spinBox->setMaximumWidth(60);
|
||||
connect(m_spinBox, SIGNAL(valueChanged(int)), this, SLOT(slotSpinBoxValueChanged(int)));
|
||||
|
||||
m_slider = new QSlider(Qt::Horizontal, containerWidget);
|
||||
layout->addWidget(m_lineEdit);
|
||||
layout->addWidget(m_spinBox);
|
||||
layout->addWidget(m_slider);
|
||||
|
||||
connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(slotSliderValueChanged(int)));
|
||||
@ -107,33 +114,32 @@ QWidget* PdmUiSliderEditor::createLabelWidget(QWidget * parent)
|
||||
return m_label;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiSliderEditor::slotSliderValueChanged(int position)
|
||||
{
|
||||
m_spinBox->setValue(position);
|
||||
|
||||
writeValueToField();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiSliderEditor::slotEditingFinished()
|
||||
void PdmUiSliderEditor::slotSpinBoxValueChanged(int spinBoxValue)
|
||||
{
|
||||
updateSliderPosition();
|
||||
|
||||
writeValueToField();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiSliderEditor::slotSliderValueChanged(int position)
|
||||
{
|
||||
m_lineEdit->setText(QString::number(position));
|
||||
|
||||
writeValueToField();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiSliderEditor::updateSliderPosition()
|
||||
{
|
||||
QString textValue = m_lineEdit->text();
|
||||
QString textValue = m_spinBox->text();
|
||||
|
||||
bool convertOk = false;
|
||||
int newSliderValue = textValue.toInt(&convertOk);
|
||||
@ -149,7 +155,7 @@ void PdmUiSliderEditor::updateSliderPosition()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiSliderEditor::writeValueToField()
|
||||
{
|
||||
QString textValue = m_lineEdit->text();
|
||||
QString textValue = m_spinBox->text();
|
||||
QVariant v;
|
||||
v = textValue;
|
||||
this->setValueToField(v);
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
#include <QPointer>
|
||||
#include <QLineEdit>
|
||||
#include <QSpinBox>
|
||||
#include <QGroupBox>
|
||||
#include <QSlider>
|
||||
|
||||
@ -35,7 +35,6 @@ namespace caf
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
|
||||
class PdmUiSliderEditorAttribute : public PdmUiEditorAttribute
|
||||
{
|
||||
public:
|
||||
@ -44,9 +43,10 @@ public:
|
||||
m_minimum = 0;
|
||||
m_maximum = 10;
|
||||
}
|
||||
|
||||
public:
|
||||
int m_minimum;
|
||||
int m_maximum;
|
||||
int m_minimum;
|
||||
int m_maximum;
|
||||
};
|
||||
|
||||
|
||||
@ -65,15 +65,15 @@ protected:
|
||||
virtual QWidget* createLabelWidget(QWidget * parent);
|
||||
|
||||
protected slots:
|
||||
void slotEditingFinished();
|
||||
void slotSliderValueChanged(int position);
|
||||
void slotSpinBoxValueChanged(int position);
|
||||
|
||||
private:
|
||||
void updateSliderPosition();
|
||||
void writeValueToField();
|
||||
|
||||
private:
|
||||
QPointer<QLineEdit> m_lineEdit;
|
||||
QPointer<QSpinBox> m_spinBox;
|
||||
QPointer<QSlider> m_slider;
|
||||
QPointer<QLabel> m_label;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user