mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 06:55:56 -06:00
Improved integer slider editor
Use sliders for cell range filter
This commit is contained in:
parent
03fc06e6a4
commit
01ee943155
@ -23,6 +23,8 @@
|
||||
#include "RimReservoirView.h"
|
||||
#include "RigReservoir.h"
|
||||
|
||||
#include "cafPdmUiSliderEditor.h"
|
||||
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RimCellRangeFilter, "CellRangeFilter");
|
||||
|
||||
@ -35,13 +37,24 @@ RimCellRangeFilter::RimCellRangeFilter()
|
||||
CAF_PDM_InitObject("Cell Range Filter", ":/CellFilter_Range.png", "", "");
|
||||
|
||||
CAF_PDM_InitField(&startIndexI, "StartIndexI", 1, "Start index I", "", "","");
|
||||
startIndexI.setUiEditorTypeName(caf::PdmUiSliderEditor::uiEditorTypeName());
|
||||
|
||||
CAF_PDM_InitField(&cellCountI, "CellCountI", 1, "Cell Count I", "", "","");
|
||||
CAF_PDM_InitField(&startIndexJ, "StartIndexJ", 1, "Start index J", "", "","");
|
||||
CAF_PDM_InitField(&cellCountJ, "CellCountJ", 1, "Cell Count J", "", "","");
|
||||
CAF_PDM_InitField(&startIndexK, "StartIndexK", 1, "Start index K", "", "","");
|
||||
CAF_PDM_InitField(&cellCountK, "CellCountK", 1, "Cell Count K", "", "","");
|
||||
updateIconState();
|
||||
cellCountI.setUiEditorTypeName(caf::PdmUiSliderEditor::uiEditorTypeName());
|
||||
|
||||
CAF_PDM_InitField(&startIndexJ, "StartIndexJ", 1, "Start index J", "", "","");
|
||||
startIndexJ.setUiEditorTypeName(caf::PdmUiSliderEditor::uiEditorTypeName());
|
||||
|
||||
CAF_PDM_InitField(&cellCountJ, "CellCountJ", 1, "Cell Count J", "", "","");
|
||||
cellCountJ.setUiEditorTypeName(caf::PdmUiSliderEditor::uiEditorTypeName());
|
||||
|
||||
CAF_PDM_InitField(&startIndexK, "StartIndexK", 1, "Start index K", "", "","");
|
||||
startIndexK.setUiEditorTypeName(caf::PdmUiSliderEditor::uiEditorTypeName());
|
||||
|
||||
CAF_PDM_InitField(&cellCountK, "CellCountK", 1, "Cell Count K", "", "","");
|
||||
cellCountK.setUiEditorTypeName(caf::PdmUiSliderEditor::uiEditorTypeName());
|
||||
|
||||
updateIconState();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -118,22 +131,11 @@ void RimCellRangeFilter::setDefaultValues()
|
||||
max.z() = max.z() + 1;
|
||||
|
||||
startIndexI = min.x();
|
||||
startIndexI.setUiName(QString("I Start (%1)").arg(min.x()));
|
||||
|
||||
startIndexJ = min.y();
|
||||
startIndexJ.setUiName(QString("J Start (%1)").arg(min.y()));
|
||||
|
||||
startIndexK = min.z();
|
||||
startIndexK.setUiName(QString("K Start (%1)").arg(min.z()));
|
||||
|
||||
cellCountI = max.x() - min.x() + 1;
|
||||
cellCountI.setUiName(QString(" Width (%1)").arg(max.x() - min.x() + 1));
|
||||
|
||||
cellCountJ = max.y() - min.y() + 1;
|
||||
cellCountJ.setUiName(QString(" Width (%1)").arg(max.y() - min.y() + 1));
|
||||
|
||||
cellCountK = max.z() - min.z() + 1;
|
||||
cellCountK.setUiName(QString(" Width (%1)").arg(max.z() - min.z() + 1));
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,3 +147,54 @@ RimCellRangeFilterCollection* RimCellRangeFilter::parentContainer()
|
||||
return m_parentContainer;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimCellRangeFilter::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute * attribute)
|
||||
{
|
||||
caf::PdmUiSliderEditorAttribute* myAttr = static_cast<caf::PdmUiSliderEditorAttribute*>(attribute);
|
||||
if (!myAttr || !m_parentContainer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RigMainGrid* mainGrid = m_parentContainer->mainGrid();
|
||||
if (mainGrid)
|
||||
{
|
||||
cvf::Vec3st min, max;
|
||||
mainGrid->activeCellsBoundingBox(min, max);
|
||||
|
||||
// Adjust to Eclipse indexing
|
||||
min.x() = min.x() + 1;
|
||||
min.y() = min.y() + 1;
|
||||
min.z() = min.z() + 1;
|
||||
|
||||
max.x() = max.x() + 1;
|
||||
max.y() = max.y() + 1;
|
||||
max.z() = max.z() + 1;
|
||||
|
||||
startIndexI.setUiName(QString("I Start (%1)").arg(min.x()));
|
||||
startIndexJ.setUiName(QString("J Start (%1)").arg(min.y()));
|
||||
startIndexK.setUiName(QString("K Start (%1)").arg(min.z()));
|
||||
cellCountI.setUiName(QString(" Width (%1)").arg(max.x() - min.x() + 1));
|
||||
cellCountJ.setUiName(QString(" Width (%1)").arg(max.y() - min.y() + 1));
|
||||
cellCountK.setUiName(QString(" Width (%1)").arg(max.z() - min.z() + 1));
|
||||
|
||||
if (field == &startIndexI || field == &cellCountI)
|
||||
{
|
||||
myAttr->m_minimum = 1;
|
||||
myAttr->m_maximum = mainGrid->cellCountI();
|
||||
}
|
||||
else if (field == &startIndexJ || field == &cellCountJ)
|
||||
{
|
||||
myAttr->m_minimum = 1;
|
||||
myAttr->m_maximum = mainGrid->cellCountJ();
|
||||
}
|
||||
else if (field == &startIndexK || field == &cellCountK)
|
||||
{
|
||||
myAttr->m_minimum = 1;
|
||||
myAttr->m_maximum = mainGrid->cellCountK();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,9 @@ public:
|
||||
|
||||
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
|
||||
|
||||
protected:
|
||||
virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute);
|
||||
|
||||
private:
|
||||
RimCellRangeFilterCollection* m_parentContainer;
|
||||
};
|
||||
|
@ -46,14 +46,33 @@ void PdmUiSliderEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
{
|
||||
assert(!m_lineEdit.isNull());
|
||||
|
||||
m_groupBox->setTitle(field()->uiName(uiConfigName));
|
||||
QIcon ic = field()->uiIcon(uiConfigName);
|
||||
if (!ic.isNull())
|
||||
{
|
||||
m_label->setPixmap(ic.pixmap(ic.actualSize(QSize(64, 64))));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_label->setText(field()->uiName(uiConfigName));
|
||||
}
|
||||
|
||||
m_label->setVisible(!field()->isUiHidden(uiConfigName));
|
||||
m_label->setEnabled(!field()->isUiReadOnly(uiConfigName));
|
||||
|
||||
m_lineEdit->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_lineEdit->setText(field()->uiValue().toString());
|
||||
{
|
||||
m_slider->blockSignals(true);
|
||||
m_slider->setRange(m_attributes.m_minimum, m_attributes.m_maximum);
|
||||
m_slider->blockSignals(false);
|
||||
}
|
||||
|
||||
QString textValue = field()->uiValue().toString();
|
||||
m_lineEdit->setText(textValue);
|
||||
updateSliderPosition();
|
||||
}
|
||||
|
||||
@ -62,25 +81,32 @@ void PdmUiSliderEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QWidget* PdmUiSliderEditor::createEditorWidget(QWidget * parent)
|
||||
{
|
||||
m_groupBox = new QGroupBox(parent);
|
||||
QWidget* containerWidget = new QWidget(parent);
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout(parent);
|
||||
m_groupBox->setLayout(layout);
|
||||
QHBoxLayout* layout = new QHBoxLayout();
|
||||
layout->setMargin(0);
|
||||
containerWidget->setLayout(layout);
|
||||
|
||||
m_lineEdit = new QLineEdit(m_groupBox);
|
||||
m_lineEdit->setValidator(new QIntValidator(m_attributes.m_minimum, m_attributes.m_maximum, m_groupBox));
|
||||
m_lineEdit = new QLineEdit(containerWidget);
|
||||
m_lineEdit->setMaximumWidth(30);
|
||||
connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(slotEditingFinished()));
|
||||
|
||||
m_slider = new QSlider(Qt::Horizontal, m_groupBox);
|
||||
m_slider->setRange(m_attributes.m_minimum, m_attributes.m_maximum);
|
||||
|
||||
m_slider = new QSlider(Qt::Horizontal, containerWidget);
|
||||
layout->addWidget(m_lineEdit);
|
||||
layout->addWidget(m_slider);
|
||||
|
||||
|
||||
connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(slotSliderValueChanged(int)));
|
||||
|
||||
return m_groupBox;
|
||||
return containerWidget;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QWidget* PdmUiSliderEditor::createLabelWidget(QWidget * parent)
|
||||
{
|
||||
m_label = new QLabel(parent);
|
||||
return m_label;
|
||||
}
|
||||
|
||||
|
||||
@ -91,10 +117,7 @@ void PdmUiSliderEditor::slotEditingFinished()
|
||||
{
|
||||
updateSliderPosition();
|
||||
|
||||
QString textValue = m_lineEdit->text();
|
||||
QVariant v;
|
||||
v = textValue;
|
||||
this->setValueToField(v);
|
||||
writeValueToField();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -103,6 +126,8 @@ void PdmUiSliderEditor::slotEditingFinished()
|
||||
void PdmUiSliderEditor::slotSliderValueChanged(int position)
|
||||
{
|
||||
m_lineEdit->setText(QString::number(position));
|
||||
|
||||
writeValueToField();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -121,5 +146,16 @@ void PdmUiSliderEditor::updateSliderPosition()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiSliderEditor::writeValueToField()
|
||||
{
|
||||
QString textValue = m_lineEdit->text();
|
||||
QVariant v;
|
||||
v = textValue;
|
||||
this->setValueToField(v);
|
||||
}
|
||||
|
||||
|
||||
} // end namespace caf
|
||||
|
@ -19,7 +19,9 @@
|
||||
|
||||
#pragma once
|
||||
#include "cafPdmUiFieldEditorHandle.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
#include <QPointer>
|
||||
#include <QLineEdit>
|
||||
@ -60,6 +62,7 @@ public:
|
||||
protected:
|
||||
virtual void configureAndUpdateUi(const QString& uiConfigName);
|
||||
virtual QWidget* createEditorWidget(QWidget * parent);
|
||||
virtual QWidget* createLabelWidget(QWidget * parent);
|
||||
|
||||
protected slots:
|
||||
void slotEditingFinished();
|
||||
@ -67,11 +70,12 @@ protected slots:
|
||||
|
||||
private:
|
||||
void updateSliderPosition();
|
||||
void writeValueToField();
|
||||
|
||||
private:
|
||||
QPointer<QGroupBox> m_groupBox;
|
||||
QPointer<QLineEdit> m_lineEdit;
|
||||
QPointer<QSlider> m_slider;
|
||||
QPointer<QLabel> m_label;
|
||||
|
||||
PdmUiSliderEditorAttribute m_attributes;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user