mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Add step support to range text format (#10311)
* Add step support to range text format * Add step support to integer selection filter
This commit is contained in:
parent
6a137f5ca9
commit
f17c02ce86
@ -25,17 +25,20 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimCellFilterInterval::RimCellFilterInterval( size_t minIncludeVal, size_t maxIncludeVal )
|
||||
RimCellFilterInterval::RimCellFilterInterval( size_t minIncludeVal, size_t maxIncludeVal, size_t step )
|
||||
: m_minIncludeVal( minIncludeVal )
|
||||
, m_maxIncludeVal( maxIncludeVal )
|
||||
, m_step( step )
|
||||
{
|
||||
m_valid = maxIncludeVal >= minIncludeVal;
|
||||
m_valid = m_valid && minIncludeVal > 0;
|
||||
m_valid = m_valid && step > 0;
|
||||
}
|
||||
|
||||
RimCellFilterInterval::RimCellFilterInterval( size_t includeVal )
|
||||
: m_minIncludeVal( includeVal )
|
||||
, m_maxIncludeVal( includeVal )
|
||||
, m_step( 1 )
|
||||
{
|
||||
m_valid = includeVal > 0;
|
||||
}
|
||||
@ -52,7 +55,12 @@ RimCellFilterInterval::~RimCellFilterInterval()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimCellFilterInterval::isIncluded( size_t val ) const
|
||||
{
|
||||
if ( ( val >= m_minIncludeVal ) && ( val <= m_maxIncludeVal ) ) return m_valid;
|
||||
if ( ( val < m_minIncludeVal ) || ( val > m_maxIncludeVal ) ) return false;
|
||||
|
||||
size_t tmp = val - m_minIncludeVal;
|
||||
|
||||
if ( m_valid && ( tmp % m_step == 0 ) ) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -99,7 +107,8 @@ size_t RimCellFilterIntervalTool::numberFromPart( std::string strVal ) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
// Define a range with the comma separated format A,B,C-D, etc., i.e. 1,4,5-8
|
||||
// Only positive numbers are supported.
|
||||
// Only numbers > 0 are supported.
|
||||
// For a range with increment > 1, use i.e. 4-8:2
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimCellFilterIntervalTool::setInterval( bool enabled, std::string intervalText )
|
||||
{
|
||||
@ -113,7 +122,14 @@ void RimCellFilterIntervalTool::setInterval( bool enabled, std::string intervalT
|
||||
|
||||
for ( auto& part : parts )
|
||||
{
|
||||
QStringList minmax = RiaTextStringTools::splitSkipEmptyParts( part, "-" );
|
||||
QStringList rangeStep = RiaTextStringTools::splitSkipEmptyParts( part, ":" );
|
||||
QStringList minmax = RiaTextStringTools::splitSkipEmptyParts( rangeStep[0], "-" );
|
||||
size_t step = 1;
|
||||
if ( rangeStep.size() == 2 )
|
||||
{
|
||||
step = numberFromPart( rangeStep[1].toStdString() );
|
||||
}
|
||||
|
||||
switch ( minmax.size() )
|
||||
{
|
||||
case 1:
|
||||
@ -121,7 +137,7 @@ void RimCellFilterIntervalTool::setInterval( bool enabled, std::string intervalT
|
||||
break;
|
||||
case 2:
|
||||
m_intervals.push_back(
|
||||
RimCellFilterInterval( numberFromPart( minmax[0].toStdString() ), numberFromPart( minmax[1].toStdString() ) ) );
|
||||
RimCellFilterInterval( numberFromPart( minmax[0].toStdString() ), numberFromPart( minmax[1].toStdString() ), step ) );
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -24,7 +24,7 @@
|
||||
class RimCellFilterInterval
|
||||
{
|
||||
public:
|
||||
RimCellFilterInterval( size_t minIncludeVal, size_t maxIncludeVal );
|
||||
RimCellFilterInterval( size_t minIncludeVal, size_t maxIncludeVal, size_t step = 1 );
|
||||
RimCellFilterInterval( size_t includeVal );
|
||||
~RimCellFilterInterval();
|
||||
|
||||
@ -33,6 +33,7 @@ public:
|
||||
private:
|
||||
size_t m_minIncludeVal;
|
||||
size_t m_maxIncludeVal;
|
||||
size_t m_step;
|
||||
bool m_valid;
|
||||
};
|
||||
|
||||
|
@ -153,7 +153,7 @@ RimPolygonFilter::RimPolygonFilter()
|
||||
CAF_PDM_InitField( &m_enableFiltering, "EnableFiltering", false, "Enable Filter" );
|
||||
|
||||
CAF_PDM_InitField( &m_enableKFilter, "EnableKFilter", false, "Enable K Range Filter" );
|
||||
CAF_PDM_InitFieldNoDefault( &m_kFilterStr, "KRangeFilter", "K Range Filter", "", "Example: 2,4,10-20,31", "" );
|
||||
CAF_PDM_InitFieldNoDefault( &m_kFilterStr, "KRangeFilter", "K Range Filter", "", "Example: 2,4-6,10-20:2", "" );
|
||||
|
||||
CAF_PDM_InitField( &m_polygonPlaneDepth, "PolygonPlaneDepth", 0.0, "Polygon Plane Depth" );
|
||||
CAF_PDM_InitField( &m_lockPolygonToPlane, "LockPolygon", false, "Lock Polygon to Plane" );
|
||||
|
@ -268,12 +268,12 @@ RimExtrudedCurveIntersection::RimExtrudedCurveIntersection()
|
||||
m_collectionDepthFilterType.uiCapability()->setUiHidden( true );
|
||||
|
||||
CAF_PDM_InitField( &m_enableKFilter, "EnableKFilter", false, "Enable K Range Filter" );
|
||||
CAF_PDM_InitFieldNoDefault( &m_kFilterText, "KRangeFilter", "K Range Filter", "", "Example: 2,4,10-20,31", "" );
|
||||
CAF_PDM_InitFieldNoDefault( &m_kFilterText, "KRangeFilter", "K Range Filter", "", "Example: 2,4-6,10-30:2", "" );
|
||||
|
||||
CAF_PDM_InitField( &m_kFilterCollectionOverride, "KFilterCollectionOverride", false, "K Range Filter is Controlled by Intersection Collection" );
|
||||
caf::PdmUiNativeCheckBoxEditor::configureFieldForEditor( &m_kFilterCollectionOverride );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_kFilterCollectionText, "KRangeCollectionFilter", "Collection K Range Filter", "", "Example: 2,4,10-20,31", "" );
|
||||
CAF_PDM_InitFieldNoDefault( &m_kFilterCollectionText, "KRangeCollectionFilter", "Collection K Range Filter", "", "Example: 2,4-6,10-30:2", "" );
|
||||
m_kFilterCollectionText.uiCapability()->setUiHidden( true );
|
||||
|
||||
setDeletable( true );
|
||||
|
@ -74,7 +74,7 @@ RimIntersectionCollection::RimIntersectionCollection()
|
||||
|
||||
CAF_PDM_InitField( &m_kFilterOverridden, "OverrideKFilter", false, "Override K Range Filter" );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_kFilterStr, "KRangeFilter", "K Range Filter", "", "Example: 2,4,10-20,31", "" );
|
||||
CAF_PDM_InitFieldNoDefault( &m_kFilterStr, "KRangeFilter", "K Range Filter", "", "Example: 2,4-6,10-30:2", "" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -296,7 +296,7 @@ void PdmUiTreeSelectionEditor::configureAndUpdateUi( const QString& uiConfigName
|
||||
// Set placeholder text based on content
|
||||
if ( hasOnlyIntegers( m_model ) )
|
||||
{
|
||||
m_textFilterLineEdit->setPlaceholderText( "Integer filter e.g. 1, 5-10" );
|
||||
m_textFilterLineEdit->setPlaceholderText( "Integer filter e.g. 1, 5-7, 9-18:3" );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -572,8 +572,9 @@ void PdmUiTreeSelectionEditor::slotInvertCheckedStateOfAll()
|
||||
/// Parse the filter text based on the following rules:
|
||||
/// 1. A comma separated list of integers
|
||||
/// 2. A range of integers separated by a dash
|
||||
/// 3. An optional step value for a range
|
||||
///
|
||||
/// Example: 1, 3, 5-10
|
||||
/// Example: 1, 3, 5-10, 4-10:2
|
||||
///
|
||||
/// Mark matching items as checked
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -591,7 +592,15 @@ void PdmUiTreeSelectionEditor::setCheckedStateForIntegerItemsMatchingFilter()
|
||||
QStringList parts = searchString.split( ",", SkipEmptyParts );
|
||||
for ( auto& part : parts )
|
||||
{
|
||||
QStringList minmax = part.split( "-", SkipEmptyParts );
|
||||
QStringList subparts = part.split( ":", SkipEmptyParts );
|
||||
QStringList minmax = subparts.front().split( "-", SkipEmptyParts );
|
||||
|
||||
int step = 1;
|
||||
if ( subparts.size() > 1 )
|
||||
{
|
||||
step = subparts.back().toInt();
|
||||
if ( step < 1 ) step = 1;
|
||||
}
|
||||
|
||||
switch ( minmax.size() )
|
||||
{
|
||||
@ -606,7 +615,7 @@ void PdmUiTreeSelectionEditor::setCheckedStateForIntegerItemsMatchingFilter()
|
||||
auto firstValue = minmax.front().toInt();
|
||||
auto secondValue = minmax.back().toInt();
|
||||
|
||||
for ( int val = firstValue; val <= secondValue; val++ )
|
||||
for ( int val = firstValue; val <= secondValue; val += step )
|
||||
{
|
||||
filterValues.insert( val );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user