mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3779 Implement AICD ui and settings
This commit is contained in:
parent
e67a9ef12a
commit
29c3e10617
@ -27,6 +27,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimNonDarcyPerforationParameters.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimWellPathComponentInterface.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimWellPathValve.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimMultipleValveLocations.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimWellPathAicdParameters.h
|
||||
)
|
||||
|
||||
|
||||
@ -57,6 +58,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimMswCompletionParameters.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimNonDarcyPerforationParameters.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimWellPathValve.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimMultipleValveLocations.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimWellPathAicdParameters.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
|
@ -0,0 +1,217 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018 - equinor ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
#include "RimWellPathAicdParameters.h"
|
||||
|
||||
#include "RimWellPath.h"
|
||||
|
||||
#include "cafPdmUiDoubleValueEditor.h"
|
||||
#include "cafPdmUiGroup.h"
|
||||
#include "cafPdmUiLineEditor.h"
|
||||
|
||||
#include <QDoubleValidator>
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RimWellPathAicdParameters, "WellPathAicdParameters");
|
||||
|
||||
class NumericStringValidator : public QDoubleValidator
|
||||
{
|
||||
public:
|
||||
NumericStringValidator(const QString& defaultValue)
|
||||
: m_defaultValue(defaultValue), QDoubleValidator(nullptr)
|
||||
{}
|
||||
|
||||
void fixup(QString& input) const override
|
||||
{
|
||||
input = m_defaultValue;
|
||||
}
|
||||
|
||||
State validate(QString& input, int& pos) const override
|
||||
{
|
||||
if (input == m_defaultValue)
|
||||
{
|
||||
return QValidator::Acceptable;
|
||||
}
|
||||
|
||||
return QDoubleValidator::validate(input, pos);
|
||||
}
|
||||
private:
|
||||
QString m_defaultValue;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimWellPathAicdParameters::RimWellPathAicdParameters()
|
||||
{
|
||||
// clang-format off
|
||||
CAF_PDM_InitObject("RimWellPathAicdParameters", "", "", "");
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_strengthOfAICD, "StrengthAICD", "Strength of AICD", "", "", "");
|
||||
CAF_PDM_InitFieldNoDefault(&m_densityOfCalibrationFluid, "DensityCalibrationFluid", "Calibration Fluid Density (kg/m^3)", "", "", "");
|
||||
CAF_PDM_InitFieldNoDefault(&m_viscosityOfCalibrationFluid, "ViscosityCalibrationFluid", "Calibration Fluid Viscosity (cP)", "", "", "");
|
||||
CAF_PDM_InitFieldNoDefault(&m_volumeFlowRateExponent, "VolumeFlowRateExponent", "Volume Flow Rate Exponent", "", "", "");
|
||||
CAF_PDM_InitFieldNoDefault(&m_viscosityFunctionExponent, "ViscosityFunctionExponent", "Viscosity Function Exponent", "", "", "");
|
||||
CAF_PDM_InitField(&m_deviceOpen, "DeviceOpen", true, "Device Open?", "", "", "");
|
||||
|
||||
CAF_PDM_InitField(&m_lengthOfAICD, "LengthOfAICD", 12.0, "Length of AICD (m)", "", "", "");
|
||||
m_lengthOfAICD.uiCapability()->setUiEditorTypeName(caf::PdmUiDoubleValueEditor::uiEditorTypeName());
|
||||
|
||||
CAF_PDM_InitField(&m_criticalWaterInLiquidFractionEmulsions, "CriticalWaterLiquidFractionEmul", QString("1*"), "Critical Water in Liquid Fraction for emulsions", "", "", "");
|
||||
CAF_PDM_InitField(&m_emulsionViscosityTransitionRegion, "ViscosityTransitionRegionEmul", QString("1*"), "Emulsion Viscosity Transition Region", "", "", "");
|
||||
CAF_PDM_InitField(&m_maxRatioOfEmulsionVisc, "MaxRatioOfEmulsionVisc", QString("1*"), "Max Ratio of Emulsion to Continuous Viscosity", "", "", "");
|
||||
CAF_PDM_InitField(&m_maxFlowRate, "MaxFlowRate", QString("1*"), "Max Flow Rate for AICD Device (m^3 / day)", "", "", "");
|
||||
CAF_PDM_InitField(&m_exponentOilFractionInDensityMixCalc, "ExponentOilDensity", QString("1*"), "Density Exponent of Oil Fraction", "", "", "");
|
||||
CAF_PDM_InitField(&m_exponentWaterFractionInDensityMixCalc, "ExponentWaterDensity", QString("1*"), "Density Exponent of Water Fraction", "", "", "");
|
||||
CAF_PDM_InitField(&m_exponentGasFractionInDensityMixCalc, "ExponentGasDensity", QString("1*"), "Density Exponent of Gas Fraction", "", "", "");
|
||||
CAF_PDM_InitField(&m_exponentOilFractionInViscosityMixCalc, "ExponentOilViscosity", QString("1*"), "Viscosity Exponent of Oil Fraction", "", "", "");
|
||||
CAF_PDM_InitField(&m_exponentWaterFractionInViscosityMixCalc, "ExponentWaterViscosity", QString("1*"), "Viscosity Exponent of Water Fraction", "", "", "");
|
||||
CAF_PDM_InitField(&m_exponentGasFractionInViscosityMixCalc, "ExponentGasViscosity", QString("1*"), "Viscosity Exponent of Gas Fraction", "", "", "");
|
||||
|
||||
std::vector<caf::PdmFieldHandle*> allFields;
|
||||
this->fields(allFields);
|
||||
for (caf::PdmFieldHandle* field : allFields)
|
||||
{
|
||||
caf::PdmField<QString>* stringField = dynamic_cast<caf::PdmField<QString>*>(field);
|
||||
if (stringField)
|
||||
{
|
||||
stringField->uiCapability()->setUiEditorTypeName(caf::PdmUiLineEditor::uiEditorTypeName());
|
||||
}
|
||||
}
|
||||
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimWellPathAicdParameters::~RimWellPathAicdParameters() {}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Requires that all the required parameters are set and a proper value
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimWellPathAicdParameters::isValid() const
|
||||
{
|
||||
for (const caf::PdmField<QString>* stringField : stringFieldsWithNoValidDefault())
|
||||
{
|
||||
if (stringField->value().isEmpty()) return false;
|
||||
bool ok = true;
|
||||
stringField->value().toDouble(&ok);
|
||||
if (!ok) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimWellPathAicdParameters::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
|
||||
{
|
||||
caf::PdmUiGroup* requiredGroup = uiOrdering.addNewGroup("Required Parameters");
|
||||
requiredGroup->add(&m_strengthOfAICD);
|
||||
requiredGroup->add(&m_densityOfCalibrationFluid);
|
||||
requiredGroup->add(&m_viscosityOfCalibrationFluid);
|
||||
requiredGroup->add(&m_volumeFlowRateExponent);
|
||||
requiredGroup->add(&m_viscosityFunctionExponent);
|
||||
|
||||
caf::PdmUiGroup* additionalGroup = uiOrdering.addNewGroup("Additional Parameters");
|
||||
additionalGroup->add(&m_deviceOpen);
|
||||
additionalGroup->add(&m_lengthOfAICD);
|
||||
additionalGroup->add(&m_criticalWaterInLiquidFractionEmulsions);
|
||||
additionalGroup->add(&m_emulsionViscosityTransitionRegion);
|
||||
additionalGroup->add(&m_maxRatioOfEmulsionVisc);
|
||||
additionalGroup->add(&m_maxFlowRate);
|
||||
additionalGroup->add(&m_exponentOilFractionInDensityMixCalc);
|
||||
additionalGroup->add(&m_exponentWaterFractionInDensityMixCalc);
|
||||
additionalGroup->add(&m_exponentGasFractionInDensityMixCalc);
|
||||
additionalGroup->add(&m_exponentOilFractionInViscosityMixCalc);
|
||||
additionalGroup->add(&m_exponentWaterFractionInViscosityMixCalc);
|
||||
additionalGroup->add(&m_exponentGasFractionInViscosityMixCalc);
|
||||
|
||||
additionalGroup->setCollapsedByDefault(true);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimWellPathAicdParameters::defineEditorAttribute(const caf::PdmFieldHandle* field,
|
||||
QString uiConfigName,
|
||||
caf::PdmUiEditorAttribute* attribute)
|
||||
{
|
||||
const caf::PdmField<QString>* stringField = dynamic_cast<const caf::PdmField<QString>*>(field);
|
||||
caf::PdmUiLineEditorAttribute* lineEditorAttr = dynamic_cast<caf::PdmUiLineEditorAttribute*>(attribute);
|
||||
if (stringField && lineEditorAttr)
|
||||
{
|
||||
if (stringFieldsWithNoValidDefault().count(stringField))
|
||||
{
|
||||
lineEditorAttr->validator = new NumericStringValidator("");
|
||||
}
|
||||
else
|
||||
{
|
||||
lineEditorAttr->validator = new NumericStringValidator("1*");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::set<const caf::PdmField<QString>*> RimWellPathAicdParameters::stringFieldsWithNoValidDefault() const
|
||||
{
|
||||
std::set<const caf::PdmField<QString>*> fields = {&m_strengthOfAICD,
|
||||
&m_densityOfCalibrationFluid,
|
||||
&m_viscosityOfCalibrationFluid,
|
||||
&m_volumeFlowRateExponent,
|
||||
&m_viscosityFunctionExponent};
|
||||
return fields;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimWellPathAicdParameters::setUnitLabels()
|
||||
{
|
||||
if (isMetric())
|
||||
{
|
||||
m_densityOfCalibrationFluid.uiCapability()->setUiName("Calibration Fluid Density (kg / m ^ 3)");
|
||||
m_lengthOfAICD.uiCapability()->setUiName("Length of AICD (m)");
|
||||
m_maxFlowRate.uiCapability()->setUiName("Max Flow Rate for AICD Device(m ^ 3 / day)");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_densityOfCalibrationFluid.uiCapability()->setUiName("Calibration Fluid Density (lb / ft ^3)");
|
||||
m_lengthOfAICD.uiCapability()->setUiName("Length of AICD (ft)");
|
||||
m_maxFlowRate.uiCapability()->setUiName("Max Flow Rate for AICD Device(ft ^ 3 / day)");
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimWellPathAicdParameters::isMetric() const
|
||||
{
|
||||
bool metric = false;
|
||||
RimWellPath* wellPath;
|
||||
firstAncestorOrThisOfType(wellPath);
|
||||
if (wellPath)
|
||||
{
|
||||
if (wellPath->unitSystem() == RiaEclipseUnitTools::UNITS_METRIC)
|
||||
{
|
||||
metric = true;
|
||||
}
|
||||
}
|
||||
return metric;
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018 - equinor ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
|
||||
#include "cafPdmBase.h"
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmField.h"
|
||||
|
||||
class RimWellPathAicdParameters : public caf::PdmObject
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
public:
|
||||
RimWellPathAicdParameters();
|
||||
~RimWellPathAicdParameters();
|
||||
bool isValid() const;
|
||||
|
||||
protected:
|
||||
void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override;
|
||||
void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute) override;
|
||||
|
||||
private:
|
||||
std::set<const caf::PdmField<QString>*> stringFieldsWithNoValidDefault() const;
|
||||
void setUnitLabels();
|
||||
bool isMetric() const;
|
||||
private:
|
||||
// Required parameters
|
||||
caf::PdmField<QString> m_strengthOfAICD;
|
||||
caf::PdmField<QString> m_densityOfCalibrationFluid;
|
||||
caf::PdmField<QString> m_viscosityOfCalibrationFluid;
|
||||
caf::PdmField<QString> m_volumeFlowRateExponent;
|
||||
caf::PdmField<QString> m_viscosityFunctionExponent;
|
||||
|
||||
// Additional parameters
|
||||
caf::PdmField<bool> m_deviceOpen;
|
||||
caf::PdmField<double> m_lengthOfAICD;
|
||||
|
||||
caf::PdmField<QString> m_criticalWaterInLiquidFractionEmulsions;
|
||||
caf::PdmField<QString> m_emulsionViscosityTransitionRegion;
|
||||
caf::PdmField<QString> m_maxRatioOfEmulsionVisc;
|
||||
caf::PdmField<QString> m_maxFlowRate;
|
||||
caf::PdmField<QString> m_exponentOilFractionInDensityMixCalc;
|
||||
caf::PdmField<QString> m_exponentWaterFractionInDensityMixCalc;
|
||||
caf::PdmField<QString> m_exponentGasFractionInDensityMixCalc;
|
||||
caf::PdmField<QString> m_exponentOilFractionInViscosityMixCalc;
|
||||
caf::PdmField<QString> m_exponentWaterFractionInViscosityMixCalc;
|
||||
caf::PdmField<QString> m_exponentGasFractionInViscosityMixCalc;
|
||||
|
||||
};
|
||||
|
@ -54,6 +54,11 @@ RimWellPathValve::RimWellPathValve()
|
||||
|
||||
CAF_PDM_InitField(&m_orificeDiameter, "OrificeDiameter", 8.0, "Orifice Diameter [mm]", "", "", "");
|
||||
CAF_PDM_InitField(&m_flowCoefficient, "FlowCoefficient", 0.7, "Flow Coefficient", "", "", "");
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_aicdParameters, "AICDParameters", "AICD Parameters", "", "", "");
|
||||
m_aicdParameters = new RimWellPathAicdParameters;
|
||||
m_aicdParameters.uiCapability()->setUiTreeHidden(true);
|
||||
m_aicdParameters.uiCapability()->setUiTreeChildrenHidden(true);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -368,6 +373,11 @@ void RimWellPathValve::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering
|
||||
group->add(&m_orificeDiameter);
|
||||
group->add(&m_flowCoefficient);
|
||||
}
|
||||
else
|
||||
{
|
||||
caf::PdmUiGroup* group = uiOrdering.addNewGroup("MSW AICD Parameters");
|
||||
m_aicdParameters->uiOrdering(uiConfigName, *group);
|
||||
}
|
||||
uiOrdering.skipRemainingFields(true);
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "RiaEclipseUnitTools.h"
|
||||
|
||||
#include "RimCheckableNamedObject.h"
|
||||
#include "RimWellPathAicdParameters.h"
|
||||
#include "RimWellPathComponentInterface.h"
|
||||
|
||||
#include "cafPdmObject.h"
|
||||
@ -82,6 +83,7 @@ private:
|
||||
caf::PdmField<double> m_orificeDiameter;
|
||||
caf::PdmField<double> m_flowCoefficient;
|
||||
|
||||
caf::PdmChildField<RimWellPathAicdParameters*> m_aicdParameters;
|
||||
};
|
||||
|
||||
|
||||
|
@ -50,6 +50,7 @@ set (MOC_HEADER_FILES
|
||||
cafPdmUiTreeSelectionQModel.h
|
||||
cafPdmUiFormLayoutObjectEditor.h
|
||||
cafPdmUiDoubleValueEditor.h
|
||||
cafPdmUniqueIdValidator.h
|
||||
)
|
||||
|
||||
if ( NOT CMAKE_AUTOMOC )
|
||||
@ -152,6 +153,7 @@ set( PROJECT_FILES
|
||||
cafQTreeViewStateSerializer.cpp
|
||||
cafMemoryInspector.h
|
||||
cafMemoryInspector.cpp
|
||||
cafPdmUniqueIdValidator.cpp
|
||||
)
|
||||
|
||||
add_library( ${PROJECT_NAME}
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "cafPdmUiDefaultObjectEditor.h"
|
||||
#include "cafPdmUiFieldEditorHandle.h"
|
||||
#include "cafPdmUiOrdering.h"
|
||||
#include "cafPdmUniqueIdValidator.h"
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include <QApplication>
|
||||
@ -56,96 +57,6 @@
|
||||
#include <QString>
|
||||
|
||||
|
||||
|
||||
|
||||
class PdmUniqueIdValidator : public QValidator
|
||||
{
|
||||
public:
|
||||
PdmUniqueIdValidator(const std::set<int>& usedIds, bool multipleSelectionOfSameFieldsSelected, const QString& errorMessage, QObject* parent)
|
||||
: QValidator(parent),
|
||||
m_usedIds(usedIds),
|
||||
m_nextValidValue(0),
|
||||
m_multipleSelectionOfSameFieldsSelected(multipleSelectionOfSameFieldsSelected),
|
||||
m_errorMessage(errorMessage)
|
||||
{
|
||||
computeNextValidId();
|
||||
}
|
||||
|
||||
State validate(QString& currentString, int &) const override
|
||||
{
|
||||
if (m_multipleSelectionOfSameFieldsSelected)
|
||||
{
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
|
||||
if (currentString.isEmpty())
|
||||
{
|
||||
return QValidator::Intermediate;
|
||||
}
|
||||
|
||||
bool isValidInteger = false;
|
||||
int currentValue = currentString.toInt(&isValidInteger);
|
||||
|
||||
if (!isValidInteger)
|
||||
{
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
|
||||
if (currentValue < 0)
|
||||
{
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
|
||||
if (m_usedIds.find(currentValue) != m_usedIds.end())
|
||||
{
|
||||
foreach(QWidget* widget, QApplication::topLevelWidgets())
|
||||
{
|
||||
if (widget->inherits("QMainWindow"))
|
||||
{
|
||||
QMainWindow* mainWindow = qobject_cast<QMainWindow*>(widget);
|
||||
if (mainWindow && mainWindow->statusBar())
|
||||
{
|
||||
mainWindow->statusBar()->showMessage(m_errorMessage, 3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QValidator::Intermediate;
|
||||
}
|
||||
|
||||
return QValidator::Acceptable;
|
||||
}
|
||||
|
||||
void fixup(QString& editorText) const override
|
||||
{
|
||||
editorText = QString::number(m_nextValidValue);
|
||||
}
|
||||
|
||||
private:
|
||||
int computeNextValidId()
|
||||
{
|
||||
if (!m_usedIds.empty())
|
||||
{
|
||||
m_nextValidValue = *m_usedIds.rbegin();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_nextValidValue = 1;
|
||||
}
|
||||
|
||||
return m_nextValidValue;
|
||||
}
|
||||
|
||||
private:
|
||||
std::set<int> m_usedIds;
|
||||
|
||||
int m_nextValidValue;
|
||||
bool m_multipleSelectionOfSameFieldsSelected;
|
||||
QString m_errorMessage;
|
||||
};
|
||||
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
@ -209,33 +120,14 @@ void PdmUiLineEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
uiObject->editorAttribute(uiField()->fieldHandle(), uiConfigName, &leab);
|
||||
}
|
||||
|
||||
if (leab.useRangeValidator)
|
||||
if (leab.validator)
|
||||
{
|
||||
m_lineEdit->setValidator(new QIntValidator(leab.minValue, leab.maxValue, this));
|
||||
m_lineEdit->setValidator(leab.validator);
|
||||
}
|
||||
|
||||
m_lineEdit->setAvoidSendingEnterEventToParentWidget(leab.avoidSendingEnterEventToParentWidget);
|
||||
}
|
||||
|
||||
{
|
||||
PdmUiLineEditorAttributeUniqueValues leab;
|
||||
caf::PdmUiObjectHandle* uiObject = uiObj(uiField()->fieldHandle()->ownerObject());
|
||||
if (uiObject)
|
||||
{
|
||||
uiObject->editorAttribute(uiField()->fieldHandle(), uiConfigName, &leab);
|
||||
}
|
||||
if (leab.usedIds.size() > 0)
|
||||
{
|
||||
if (isMultipleFieldsWithSameKeywordSelected(uiField()->fieldHandle()))
|
||||
{
|
||||
QMessageBox::information(nullptr, "Invalid operation", "The field you are manipulating is defined to have unique values. A selection of multiple fields is detected. Please select a single item.");
|
||||
}
|
||||
|
||||
m_lineEdit->setValidator(new PdmUniqueIdValidator(leab.usedIds, isMultipleFieldsWithSameKeywordSelected(uiField()->fieldHandle()), leab.errorMessage, this));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool fromMenuOnly = true;
|
||||
QList<PdmOptionItemInfo> enumNames = uiField()->valueOptions(&fromMenuOnly);
|
||||
CAF_ASSERT(fromMenuOnly); // Not supported
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include <QLineEdit>
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
#include <QValidator>
|
||||
#include <QWidget>
|
||||
|
||||
class QGridLayout;
|
||||
@ -59,31 +60,11 @@ public:
|
||||
PdmUiLineEditorAttribute()
|
||||
{
|
||||
avoidSendingEnterEventToParentWidget = false;
|
||||
useRangeValidator = false;
|
||||
minValue = 0;
|
||||
maxValue = 0;
|
||||
}
|
||||
|
||||
public:
|
||||
bool avoidSendingEnterEventToParentWidget;
|
||||
bool useRangeValidator;
|
||||
int minValue;
|
||||
int maxValue;
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class PdmUiLineEditorAttributeUniqueValues : public PdmUiEditorAttribute
|
||||
{
|
||||
public:
|
||||
PdmUiLineEditorAttributeUniqueValues()
|
||||
{}
|
||||
|
||||
public:
|
||||
std::set<int> usedIds;
|
||||
QString errorMessage;
|
||||
QPointer<QValidator> validator;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
132
Fwk/AppFwk/cafUserInterface/cafPdmUniqueIdValidator.cpp
Normal file
132
Fwk/AppFwk/cafUserInterface/cafPdmUniqueIdValidator.cpp
Normal file
@ -0,0 +1,132 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) Ceetron Solutions AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "cafPdmUniqueIdValidator.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMainWindow>
|
||||
#include <QStatusBar>
|
||||
|
||||
using namespace caf;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmUniqueIdValidator::PdmUniqueIdValidator(const std::set<int>& usedIds,
|
||||
bool multipleSelectionOfSameFieldsSelected,
|
||||
const QString& errorMessage,
|
||||
QObject* parent)
|
||||
: QValidator(parent)
|
||||
, m_usedIds(usedIds)
|
||||
, m_nextValidValue(0)
|
||||
, m_multipleSelectionOfSameFieldsSelected(multipleSelectionOfSameFieldsSelected)
|
||||
, m_errorMessage(errorMessage)
|
||||
{
|
||||
computeNextValidId();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QValidator::State PdmUniqueIdValidator::validate(QString& currentString, int&) const
|
||||
{
|
||||
if (m_multipleSelectionOfSameFieldsSelected)
|
||||
{
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
|
||||
if (currentString.isEmpty())
|
||||
{
|
||||
return QValidator::Intermediate;
|
||||
}
|
||||
|
||||
bool isValidInteger = false;
|
||||
int currentValue = currentString.toInt(&isValidInteger);
|
||||
|
||||
if (!isValidInteger)
|
||||
{
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
|
||||
if (currentValue < 0)
|
||||
{
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
|
||||
if (m_usedIds.find(currentValue) != m_usedIds.end())
|
||||
{
|
||||
foreach (QWidget* widget, QApplication::topLevelWidgets())
|
||||
{
|
||||
if (widget->inherits("QMainWindow"))
|
||||
{
|
||||
QMainWindow* mainWindow = qobject_cast<QMainWindow*>(widget);
|
||||
if (mainWindow && mainWindow->statusBar())
|
||||
{
|
||||
mainWindow->statusBar()->showMessage(m_errorMessage, 3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QValidator::Intermediate;
|
||||
}
|
||||
|
||||
return QValidator::Acceptable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUniqueIdValidator::fixup(QString& editorText) const
|
||||
{
|
||||
editorText = QString::number(m_nextValidValue);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int PdmUniqueIdValidator::computeNextValidId()
|
||||
{
|
||||
if (!m_usedIds.empty())
|
||||
{
|
||||
m_nextValidValue = *m_usedIds.rbegin();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_nextValidValue = 1;
|
||||
}
|
||||
|
||||
return m_nextValidValue;
|
||||
}
|
62
Fwk/AppFwk/cafUserInterface/cafPdmUniqueIdValidator.h
Normal file
62
Fwk/AppFwk/cafUserInterface/cafPdmUniqueIdValidator.h
Normal file
@ -0,0 +1,62 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) Ceetron Solutions AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
#pragma once
|
||||
|
||||
#include <QValidator>
|
||||
#include <set>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class PdmUniqueIdValidator : public QValidator
|
||||
{
|
||||
public:
|
||||
PdmUniqueIdValidator(const std::set<int>& usedIds, bool multipleSelectionOfSameFieldsSelected, const QString& errorMessage, QObject* parent);
|
||||
|
||||
State validate(QString& currentString, int &) const override;
|
||||
|
||||
void fixup(QString& editorText) const override;
|
||||
|
||||
private:
|
||||
int computeNextValidId();
|
||||
|
||||
private:
|
||||
std::set<int> m_usedIds;
|
||||
|
||||
int m_nextValidValue;
|
||||
bool m_multipleSelectionOfSameFieldsSelected;
|
||||
QString m_errorMessage;
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user