mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-24 22:27:55 -05:00
Combined filters used to always show whatever literal string the user passed in (or the default "Combined Filter"). For programmatic creation without a name, that string never reflected the children, leaving the case-level "Data Filters" tree row stale when child bounds changed. Add an m_autoDeriveName flag (default true) to RimCombinedFilter. When on, the display name is recomputed on every relevant change — addFilter, removeFilter, onChildAdded, onChildFilterChanged, and combineMode toggle — by joining children's name() with " AND " / " OR ". The flag flips to false the first time the user renames the filter via the UI property panel or via Python (combined.user_description = "..."), preserving any explicitly typed name verbatim from then on. Two child-creation paths needed an extra triggerFilterChanged() so the combined parent recomputes after the child's final name is set: addPropertyFilterToCombinedFilter (setDefaults updates name without a signal) and RimcCombinedFilter_addRangeFilter (Rimc applies user params after addNewFilter). The Rimc factory passes setAutoDeriveName(false) only when a name is supplied. The Python example demonstrates both modes side by side, and test_combined_filter.py adds three cases: named filter preserves its name, auto-derived filter tracks bound mutations, and Python rename locks the auto-derived filter.
81 lines
3.1 KiB
C++
81 lines
3.1 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2026 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 "RimcDataFilterCollection.h"
|
|
|
|
#include "RimCellFilterCollection.h"
|
|
#include "RimCombinedFilter.h"
|
|
#include "RimDataFilterCollection.h"
|
|
|
|
#include "cafPdmAbstractFieldScriptingCapability.h"
|
|
#include "cafPdmFieldScriptingCapability.h"
|
|
|
|
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimDataFilterCollection, RimcDataFilterCollection_addCombinedFilter, "AddCombinedFilter" );
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimcDataFilterCollection_addCombinedFilter::RimcDataFilterCollection_addCombinedFilter( caf::PdmObjectHandle* self )
|
|
: caf::PdmObjectCreationMethod( self )
|
|
{
|
|
CAF_PDM_InitObject( "Add Combined Filter", "", "", "Add a new combined filter to the data filter collection" );
|
|
|
|
CAF_PDM_InitScriptableFieldNoDefault( &m_name, "Name", "Name" );
|
|
CAF_PDM_InitScriptableFieldNoDefault( &m_combineMode, "CombineMode", "Combine Mode (AND/OR)" );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::expected<caf::PdmObjectHandle*, QString> RimcDataFilterCollection_addCombinedFilter::execute()
|
|
{
|
|
auto* coll = self<RimDataFilterCollection>();
|
|
if ( !coll ) return std::unexpected( QString( "Self is not a RimDataFilterCollection" ) );
|
|
|
|
RimCombinedFilter* combined = coll->addNewCombinedFilter();
|
|
if ( !combined ) return std::unexpected( QString( "Failed to create combined filter" ) );
|
|
|
|
if ( !m_name().isEmpty() )
|
|
{
|
|
combined->setName( m_name() );
|
|
combined->setAutoDeriveName( false );
|
|
}
|
|
|
|
const QString modeStr = m_combineMode().trimmed().toUpper();
|
|
if ( modeStr == "AND" )
|
|
{
|
|
combined->setCombineMode( RimCellFilterCollection::AND );
|
|
}
|
|
else if ( modeStr == "OR" )
|
|
{
|
|
combined->setCombineMode( RimCellFilterCollection::OR );
|
|
}
|
|
|
|
coll->updateConnectedEditors();
|
|
|
|
return combined;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QString RimcDataFilterCollection_addCombinedFilter::classKeywordReturnedType() const
|
|
{
|
|
return RimCombinedFilter::classKeywordStatic();
|
|
}
|