mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-24 22:27:55 -05:00
#14081 Register experimental features and show them as checkboxes
Replace the free-text experimental-feature keyword box with a discoverable registry and a checkbox list in Preferences -> System. Add RiaExperimentalFeatures as a single, discoverable list of available experimental features (keyword, display name, description). RiaPreferencesSystem now stores the enabled features in a tree-selection (checkbox) field populated from this registry, and isFeatureEnabled() checks that selection. The legacy semicolon-separated keyword string is migrated in initAfterRead(), preserving existing preference files and the 'enable-all' keyword.
This commit is contained in:
1 parent
19c547cc2e
commit
5434873984
5 files changed
+146
-6
No files matched your search
@@ -10,6 +10,7 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaPreferencesGeoMech.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaPreferencesGrid.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaPreferencesSystem.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaExperimentalFeatures.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaPreferencesOsdu.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaPreferencesOpm.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaPreferencesSumo.cpp
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RiaExperimentalFeatures.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<RiaExperimentalFeatures::Feature>& RiaExperimentalFeatures::availableFeatures()
|
||||
{
|
||||
// Register experimental features here. Each entry automatically becomes a checkbox in
|
||||
// Preferences -> System -> Experimental Features. Gate the related code path behind
|
||||
// RiaPreferencesSystem::isFeatureEnabled( "<keyword>" ).
|
||||
//
|
||||
// Example:
|
||||
// { "my-feature", "My Feature", "Short description of what it does." },
|
||||
static const std::vector<Feature> features = {};
|
||||
|
||||
return features;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <vector>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Central, discoverable registry of experimental features.
|
||||
///
|
||||
/// To add a new experimental feature, append an entry to the list returned by availableFeatures()
|
||||
/// (see RiaExperimentalFeatures.cpp) and gate the code path behind
|
||||
/// RiaPreferencesSystem::isFeatureEnabled( "<keyword>" ).
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class RiaExperimentalFeatures
|
||||
{
|
||||
public:
|
||||
struct Feature
|
||||
{
|
||||
QString keyword; ///< Stable identifier, passed to RiaPreferencesSystem::isFeatureEnabled().
|
||||
QString displayName; ///< Human readable name shown as the checkbox label.
|
||||
QString description; ///< Short explanation, appended to the checkbox label.
|
||||
};
|
||||
|
||||
/// The single, discoverable list of all experimental features.
|
||||
static const std::vector<Feature>& availableFeatures();
|
||||
};
|
||||
@@ -18,12 +18,17 @@
|
||||
|
||||
#include "RiaApplication.h"
|
||||
|
||||
#include "RiaExperimentalFeatures.h"
|
||||
#include "RiaPreferences.h"
|
||||
#include "RiaPreferencesSystem.h"
|
||||
|
||||
#include "cafPdmUiCheckBoxAndTextEditor.h"
|
||||
#include "cafPdmUiCheckBoxEditor.h"
|
||||
#include "cafPdmUiFilePathEditor.h"
|
||||
#include "cafPdmUiTextEditor.h"
|
||||
#include "cafPdmUiTreeSelectionEditor.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
@@ -92,10 +97,25 @@ RiaPreferencesSystem::RiaPreferencesSystem()
|
||||
QString(),
|
||||
"Keywords to enable debug logging, separated by semicolon.\nType 'enable-all' to enable logging for all objects." );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_enabledFeatures, "EnabledFeatures", "Experimental Features" );
|
||||
m_enabledFeatures.uiCapability()->setUiEditorTypeName( caf::PdmUiTreeSelectionEditor::uiEditorTypeName() );
|
||||
|
||||
// Transient UI helper fields, not stored in the preferences file.
|
||||
CAF_PDM_InitFieldNoDefault( &m_currentFeatureKeyword, "currentFeatureKeyword", "" );
|
||||
m_currentFeatureKeyword.uiCapability()->setUiHidden( true );
|
||||
m_currentFeatureKeyword.xmlCapability()->disableIO();
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_selectedFeatureDescription, "selectedFeatureDescription", "Description" );
|
||||
m_selectedFeatureDescription.uiCapability()->setUiEditorTypeName( caf::PdmUiTextEditor::uiEditorTypeName() );
|
||||
m_selectedFeatureDescription.uiCapability()->setUiReadOnly( true );
|
||||
m_selectedFeatureDescription.xmlCapability()->disableIO();
|
||||
|
||||
// Legacy free-text field, kept only to migrate older preference files into m_enabledFeatures.
|
||||
CAF_PDM_InitField( &m_featureKeywords,
|
||||
"FeatureKeywords",
|
||||
QString(),
|
||||
"Keywords to enable experimental features separated by semicolon.\nType 'enable-all' for all." );
|
||||
m_featureKeywords.uiCapability()->setUiHidden( true );
|
||||
|
||||
CAF_PDM_InitField( &m_maximumNumberOfThreads, "maximumNumberOfThreads", std::make_pair( false, QString( "4" ) ), "Maximum Number of Threads" );
|
||||
m_maximumNumberOfThreads.uiCapability()->setUiEditorTypeName( caf::PdmUiCheckBoxAndTextEditor::uiEditorTypeName() );
|
||||
@@ -283,11 +303,9 @@ bool RiaPreferencesSystem::isFeatureEnabled( const QString& keyword ) const
|
||||
{
|
||||
if ( keyword.isEmpty() ) return false;
|
||||
|
||||
const QStringList keywords = m_featureKeywords().split( ";", Qt::SkipEmptyParts );
|
||||
const std::vector<QString>& enabled = m_enabledFeatures();
|
||||
|
||||
if ( keywords.contains( "enable-all" ) ) return true;
|
||||
|
||||
return keywords.contains( keyword );
|
||||
return std::find( enabled.begin(), enabled.end(), keyword ) != enabled.end();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -323,10 +341,14 @@ void RiaPreferencesSystem::defineUiOrdering( QString uiConfigName, caf::PdmUiOrd
|
||||
group->add( &m_mimimumAngularCellCount );
|
||||
}
|
||||
|
||||
{
|
||||
caf::PdmUiGroup* group = uiOrdering.addNewGroup( "Experimental Features" );
|
||||
group->add( &m_enabledFeatures );
|
||||
}
|
||||
|
||||
{
|
||||
caf::PdmUiGroup* group = uiOrdering.addNewGroup( "Developer Settings" );
|
||||
group->add( &m_keywordsForLogging );
|
||||
group->add( &m_featureKeywords );
|
||||
group->add( &m_gtestFilter );
|
||||
}
|
||||
|
||||
@@ -340,9 +362,41 @@ QList<caf::PdmOptionItemInfo> RiaPreferencesSystem::calculateValueOptions( const
|
||||
{
|
||||
QList<caf::PdmOptionItemInfo> options;
|
||||
|
||||
if ( fieldNeedingOptions == &m_enabledFeatures )
|
||||
{
|
||||
for ( const auto& feature : RiaExperimentalFeatures::availableFeatures() )
|
||||
{
|
||||
options.push_back( caf::PdmOptionItemInfo( feature.displayName, feature.keyword ) );
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaPreferencesSystem::initAfterRead()
|
||||
{
|
||||
// Migrate the legacy semicolon-separated keyword string into the checkbox-based field.
|
||||
if ( !m_featureKeywords().isEmpty() )
|
||||
{
|
||||
std::vector<QString> enabled = m_enabledFeatures();
|
||||
|
||||
const QStringList legacyKeywords = m_featureKeywords().split( ";", Qt::SkipEmptyParts );
|
||||
for ( const QString& keyword : legacyKeywords )
|
||||
{
|
||||
if ( std::find( enabled.begin(), enabled.end(), keyword ) == enabled.end() )
|
||||
{
|
||||
enabled.push_back( keyword );
|
||||
}
|
||||
}
|
||||
|
||||
m_enabledFeatures = enabled;
|
||||
m_featureKeywords = QString();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -70,6 +70,8 @@ protected:
|
||||
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
|
||||
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override;
|
||||
void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override;
|
||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
||||
void initAfterRead() override;
|
||||
|
||||
private:
|
||||
caf::PdmField<bool> m_appendClassNameToUiText;
|
||||
@@ -96,7 +98,11 @@ private:
|
||||
caf::PdmField<EclipseTextFileReaderModeType> m_eclipseReaderMode;
|
||||
|
||||
caf::PdmField<QString> m_keywordsForLogging;
|
||||
caf::PdmField<QString> m_featureKeywords;
|
||||
|
||||
caf::PdmField<std::vector<QString>> m_enabledFeatures;
|
||||
caf::PdmField<QString> m_currentFeatureKeyword; // Transient: keyword of the highlighted feature row
|
||||
caf::PdmField<QString> m_selectedFeatureDescription; // Transient: description shown below the list
|
||||
caf::PdmField<QString> m_featureKeywords; // Legacy free-text field, kept for migration only
|
||||
|
||||
caf::PdmField<std::pair<bool, QString>> m_maximumNumberOfThreads;
|
||||
};
|
||||
Reference in new issue
Block a user